Finally working cubemap
This commit is contained in:
1 parent
d132060e19
commit
f413bbe265
16 files changed
+406
-119
No files matched your search
Binary file not shown.
|
After Width: | Height: | Size: 768 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 768 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 768 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 768 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 768 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 768 KiB |
@@ -0,0 +1,36 @@
|
||||
uniform sampler2D Texture;
|
||||
uniform sampler2D NormalMap;
|
||||
uniform int NormalMapExists;
|
||||
uniform float FogBeginDistance;
|
||||
uniform float FogEndDistance;
|
||||
uniform vec4 FogColor;
|
||||
|
||||
varying vec2 texCoord;
|
||||
varying vec3 camVec;
|
||||
varying vec3 lightVec;
|
||||
varying vec3 vertexPos;
|
||||
|
||||
|
||||
void main()
|
||||
{
|
||||
vec3 lVec = lightVec;
|
||||
vec3 cVec = normalize(camVec);
|
||||
|
||||
//go-go-go
|
||||
vec3 TexRGB = texture2D(Texture, texCoord.xy).xyz;
|
||||
|
||||
vec3 norm = vec3(0.0,0.0,1.0);
|
||||
|
||||
float shineFactor = 15.0 * pow(max(dot(cVec, norm),0.0),gl_FrontMaterial.shininess) / (129.0 - gl_FrontMaterial.shininess);
|
||||
|
||||
float light_coef = 1.0;
|
||||
|
||||
vec4 ambient = gl_LightSource[0].ambient;
|
||||
vec4 diffuse = gl_FrontMaterial.diffuse * gl_LightSource[0].diffuse * min( max(dot(lVec,norm),0.0), light_coef);
|
||||
vec4 specular = gl_LightSource[0].specular * min(shineFactor, light_coef);
|
||||
|
||||
float fogFactor = min(max(max(abs(vertexPos.x)-FogBeginDistance, abs(vertexPos.z)-FogBeginDistance),0.0)/(FogEndDistance - FogBeginDistance),1.0);
|
||||
|
||||
gl_FragColor = mix(vec4(TexRGB,1.0)*ambient+(vec4(TexRGB,1.0)*diffuse+specular), FogColor, fogFactor);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
uniform vec3 CamPos;
|
||||
uniform mat3 ModelRotateMatrix;
|
||||
uniform vec3 ModelTranslateVector;
|
||||
|
||||
attribute vec3 Tangent;
|
||||
attribute vec3 Binormal;
|
||||
|
||||
varying vec2 texCoord;
|
||||
varying vec3 camVec;
|
||||
varying vec3 lightVec;
|
||||
varying vec3 vertexPos;
|
||||
|
||||
void main()
|
||||
{
|
||||
vec4 realVertexPos = vec4(ModelRotateMatrix * gl_Vertex.xyz + ModelTranslateVector, 1.0);
|
||||
gl_Position = gl_ModelViewProjectionMatrix * realVertexPos;
|
||||
|
||||
texCoord = gl_MultiTexCoord0.st;
|
||||
|
||||
vec3 lVec = normalize(gl_LightSource[0].position.xyz);
|
||||
vec3 cVec = (CamPos - gl_Vertex.xyz);
|
||||
|
||||
vertexPos = gl_Vertex.xyz;
|
||||
|
||||
mat3 rot;
|
||||
rot[0] = normalize(Tangent);
|
||||
rot[1] = normalize(Binormal);
|
||||
rot[2] = normalize(gl_Normal.xyz);
|
||||
|
||||
rot = ModelRotateMatrix * rot;
|
||||
|
||||
lightVec = lVec * rot;
|
||||
camVec = cVec * rot;
|
||||
|
||||
}
|
||||
@@ -1,36 +1,23 @@
|
||||
uniform sampler2D Texture;
|
||||
uniform sampler2D NormalMap;
|
||||
uniform int NormalMapExists;
|
||||
uniform float FogBeginDistance;
|
||||
uniform float FogEndDistance;
|
||||
uniform vec4 FogColor;
|
||||
|
||||
varying vec2 texCoord;
|
||||
varying vec3 camVec;
|
||||
varying vec3 lightVec;
|
||||
varying vec3 vertexPos;
|
||||
|
||||
|
||||
void main()
|
||||
{
|
||||
vec3 lVec = lightVec;
|
||||
vec3 cVec = normalize(camVec);
|
||||
vec4 texColor = texture2D(Texture,texCoord).rgba;
|
||||
|
||||
//go-go-go
|
||||
vec3 TexRGB = texture2D(Texture, texCoord.xy).xyz;
|
||||
vec4 fogColor = vec4(0.25, 0.55, 1.0, 1.0);
|
||||
|
||||
vec3 norm = vec3(0.0,0.0,1.0);
|
||||
float fogDistCoef = (vertexPos.z - FogBeginDistance) / (FogEndDistance - FogBeginDistance);
|
||||
|
||||
float shineFactor = 15.0 * pow(max(dot(cVec, norm),0.0),gl_FrontMaterial.shininess) / (129.0 - gl_FrontMaterial.shininess);
|
||||
fogDistCoef = clamp(fogDistCoef, 0.0, 1.0);
|
||||
|
||||
float light_coef = 1.0;
|
||||
|
||||
vec4 ambient = gl_LightSource[0].ambient;
|
||||
vec4 diffuse = gl_FrontMaterial.diffuse * gl_LightSource[0].diffuse * min( max(dot(lVec,norm),0.0), light_coef);
|
||||
vec4 specular = gl_LightSource[0].specular * min(shineFactor, light_coef);
|
||||
|
||||
float fogFactor = min(max(max(abs(vertexPos.x)-FogBeginDistance, abs(vertexPos.z)-FogBeginDistance),0.0)/(FogEndDistance - FogBeginDistance),1.0);
|
||||
vec4 resultColor = mix(texColor, fogColor, fogDistCoef);
|
||||
|
||||
gl_FragColor = mix(vec4(TexRGB,1.0)*ambient+(vec4(TexRGB,1.0)*diffuse+specular), FogColor, fogFactor);
|
||||
gl_FragColor = vec4(resultColor.rgb, 1.0);
|
||||
|
||||
}
|
||||
@@ -1,35 +1,46 @@
|
||||
uniform vec3 CamPos;
|
||||
attribute vec3 vPosition;
|
||||
attribute vec2 vTexCoord;
|
||||
|
||||
uniform mat4 ProjectionMatrix;
|
||||
uniform mat3 ModelRotateMatrix;
|
||||
uniform vec3 ModelTranslateVector;
|
||||
|
||||
attribute vec3 Tangent;
|
||||
attribute vec3 Binormal;
|
||||
|
||||
varying vec2 texCoord;
|
||||
varying vec3 camVec;
|
||||
varying vec3 lightVec;
|
||||
varying vec3 vertexPos;
|
||||
|
||||
void main()
|
||||
{
|
||||
vec4 realVertexPos = vec4(ModelRotateMatrix * gl_Vertex.xyz + ModelTranslateVector, 1.0);
|
||||
gl_Position = gl_ModelViewProjectionMatrix * realVertexPos;
|
||||
vec4 realVertexPos = vec4(ModelRotateMatrix * vPosition.xyz + ModelTranslateVector, 1.0);
|
||||
gl_Position = ProjectionMatrix * realVertexPos;
|
||||
vertexPos = gl_Position.xyz;
|
||||
|
||||
texCoord = gl_MultiTexCoord0.st;
|
||||
texCoord = vTexCoord.st;
|
||||
|
||||
//vertexPos = vPosition.xyz;
|
||||
|
||||
//vec3 cVec = (CamPos - vPosition.xyz);
|
||||
|
||||
/*
|
||||
vec3 lVec = normalize(gl_LightSource[0].position.xyz);
|
||||
vec3 cVec = (CamPos - gl_Vertex.xyz);
|
||||
vec3 cVec = (CamPos - vPosition.xyz);
|
||||
|
||||
vertexPos = gl_Vertex.xyz;
|
||||
|
||||
mat3 rot;
|
||||
rot[0] = normalize(Tangent);
|
||||
rot[1] = normalize(Binormal);
|
||||
rot[2] = normalize(gl_Normal.xyz);
|
||||
|
||||
rot = ModelRotateMatrix * rot;
|
||||
vertexPos = vPosition.xyz;
|
||||
|
||||
lightVec = lVec * rot;
|
||||
camVec = cVec * rot;
|
||||
|
||||
vec3 normal = normalize(gl_NormalMatrix * gl_Normal);
|
||||
|
||||
// Используем производные для вычисления тангентного и бинормального вектора
|
||||
vec3 dp1 = dFdx(vPosition.xyz);
|
||||
vec3 dp2 = dFdy(vPosition.xyz);
|
||||
vec2 duv1 = dFdx(vTexCoord.st);
|
||||
vec2 duv2 = dFdy(vTexCoord.st);
|
||||
|
||||
vec3 tangent = normalize(dp1 * duv2.y - dp2 * duv1.y);
|
||||
vec3 binormal = normalize(dp2 * duv1.x - dp1 * duv2.x);
|
||||
|
||||
// Создаем матрицу тангенциального пространства
|
||||
mat3 tbnMatrix = mat3(tangent, binormal, normal);
|
||||
tbnMatrix = ModelRotateMatrix * tbnMatrix;
|
||||
|
||||
lightVec = lVec * tbnMatrix;
|
||||
camVec = cVec * tbnMatrix;*/
|
||||
}
|
||||
@@ -3,6 +3,7 @@ uniform samplerCube Env;
|
||||
varying vec3 dir;
|
||||
|
||||
void main(){
|
||||
gl_FragColor = textureCube(Env, dir);
|
||||
gl_FragColor = textureCube(Env, normalize(dir));
|
||||
//gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);
|
||||
|
||||
}
|
||||
@@ -1,7 +1,14 @@
|
||||
attribute vec3 vPosition;
|
||||
|
||||
uniform mat4 ProjectionMatrix;
|
||||
uniform mat3 ModelRotateMatrix;
|
||||
uniform vec3 ModelTranslateVector;
|
||||
|
||||
varying vec3 dir;
|
||||
|
||||
void main(){
|
||||
gl_Position = ftransform();
|
||||
vec4 realVertexPos = vec4(ModelRotateMatrix * vPosition.xyz + ModelTranslateVector, 1.0);
|
||||
gl_Position = ProjectionMatrix * realVertexPos;
|
||||
|
||||
dir = gl_Vertex.xyz;
|
||||
dir = -vPosition;
|
||||
}
|
||||
Reference in new issue
Block a user