Resurrection

This commit is contained in:
Vladislav Khorev committed 2024-06-06 16:25:38 +03:00
commit d132060e19
59 files changed
+2616

No files matched your search

+23
View File
@@ -0,0 +1,23 @@
uniform sampler2D Texture;
varying vec2 texCoord;
void main()
{
float xstep = 0.5f/800.0f;
float ystep = 0.5f/600.0f;
vec4 texColor =
vec4(texture2D(Texture,texCoord).rgb,1.0) * 0.2
+ vec4(texture2D(Texture, vec2(texCoord.x+xstep, texCoord.y+ystep)).rgb,1.0) * 0.1
+ vec4(texture2D(Texture, vec2(texCoord.x-xstep, texCoord.y+ystep)).rgb,1.0) * 0.1
+ vec4(texture2D(Texture, vec2(texCoord.x-xstep, texCoord.y-ystep)).rgb,1.0) * 0.1
+ vec4(texture2D(Texture, vec2(texCoord.x+xstep, texCoord.y-ystep)).rgb,1.0) * 0.1
+ vec4(texture2D(Texture, vec2(texCoord.x, texCoord.y+2.0*ystep)).rgb,1.0) * 0.1
+ vec4(texture2D(Texture, vec2(texCoord.x, texCoord.y-2.0*ystep)).rgb,1.0) * 0.1
+ vec4(texture2D(Texture, vec2(texCoord.x-2.0*xstep, texCoord.y)).rgb,1.0) * 0.1
+ vec4(texture2D(Texture, vec2(texCoord.x+2.0*xstep, texCoord.y)).rgb,1.0) * 0.1;
gl_FragColor = texColor;
}
+7
View File
@@ -0,0 +1,7 @@
varying vec2 texCoord;
void main()
{
gl_Position = ftransform();
texCoord = gl_MultiTexCoord0.st;
}
@@ -0,0 +1,38 @@
uniform sampler2D Texture;
uniform sampler2D NormalMap;
uniform int NormalMapExists;
varying vec2 texCoord;
varying vec3 camVec;
varying vec3 lightVec;
void main()
{
vec3 norm;
vec4 ambient;
vec4 diffuse;
vec4 specular;
vec3 TexRGB = texture2D(Texture, texCoord.st).rgb;
vec3 cVec = normalize(camVec);
if (NormalMapExists == 0)
{
norm = vec3(0.0,0.0,1.0);
}
else
{
norm = (texture2D(NormalMap, texCoord.st).rgb - 0.5) * 2.0;
}
float shineFactor = 15.0 * pow(max(dot(cVec, norm),0.0),gl_FrontMaterial.shininess) / (129.0 - gl_FrontMaterial.shininess);
ambient = gl_LightSource[0].ambient;
diffuse = gl_FrontMaterial.diffuse * gl_LightSource[0].diffuse * max( dot(lightVec,norm),0.0);
specular = gl_LightSource[0].specular * shineFactor;
gl_FragColor = vec4(TexRGB,1.0)*ambient+(vec4(TexRGB,1.0)*diffuse+specular);
}
@@ -0,0 +1,35 @@
/*
Bump mapping shader without parallax mapping for single directional light source
The fastest shader for bump mapping
*/
uniform vec3 CamPos;
uniform mat3 ModelRotateMatrix;
uniform vec3 ModelTranslateVector;
attribute vec3 Tangent;
attribute vec3 Binormal;
varying vec2 texCoord;
varying vec3 camVec;
varying vec3 lightVec;
void main()
{
gl_Position = gl_ModelViewProjectionMatrix * vec4(ModelRotateMatrix * gl_Vertex.xyz + ModelTranslateVector, 1.0);
texCoord = gl_MultiTexCoord0.st;
vec3 lVec = normalize(gl_LightSource[0].position.xyz);
vec3 cVec = (CamPos - gl_Vertex.xyz);
mat3 rot;
rot[0] = Tangent;
rot[1] = Binormal;
rot[2] = gl_Normal.xyz;
rot = ModelRotateMatrix * rot;
lightVec = lVec * rot;
camVec = cVec * rot;
}
@@ -0,0 +1,72 @@
/*
Bump mapping shader without parallax mapping but with shadows for single directional light source
*/
uniform sampler2D Texture;
uniform sampler2D NormalMap;
uniform int NormalMapExists;
varying vec2 texCoord;
varying vec3 camVec;
varying vec3 lightVec;
//For shadows
uniform sampler2D ShadowMap;
uniform float ShadowDepth;
varying vec4 vPos;
varying vec4 gPos;
float shadowCoef()
{
vec4 shadow_coord = gl_TextureMatrix[2]*vPos;
shadow_coord.w = shadow_coord.z;
// get the stored depth
float shadow_d = texture2D(ShadowMap, shadow_coord.xy).x;
// get the difference of the stored depth and the distance of this fragment to the light
float diff = min(shadow_d - shadow_coord.z,0.0);
float shadow_coef = clamp( 20*ShadowDepth*diff + 1.0, 0.0, 1.0); //[0..1]
return shadow_coef;
}
void main()
{
vec3 norm;
vec4 ambient;
vec4 diffuse;
vec4 specular;
vec3 TexRGB = texture2D(Texture, texCoord.st).rgb;
vec3 cVec = normalize(camVec);
if (NormalMapExists == 0)
{
norm = vec3(0.0,0.0,1.0);
}
else
{
norm = (texture2D(NormalMap, texCoord.st).rgb - 0.5) * 2.0;
}
float shineFactor = 15.0 * pow(max(dot(cVec, norm),0.0),gl_FrontMaterial.shininess) / (129.0 - gl_FrontMaterial.shininess);
float shadow_coef = shadowCoef();
ambient = gl_LightSource[0].ambient;
diffuse = gl_FrontMaterial.diffuse * gl_LightSource[0].diffuse * min( max(dot(lightVec,norm),0.0),shadow_coef);
specular = gl_LightSource[0].specular * min(shineFactor,shadow_coef);
gl_FragColor = vec4(TexRGB,1.0)*max(ambient,diffuse)+specular;
}
@@ -0,0 +1,44 @@
/*
Bump mapping shader without parallax mapping but with shadows for single directional light source
*/
uniform vec3 CamPos;
uniform mat3 ModelRotateMatrix;
uniform vec3 ModelTranslateVector;
attribute vec3 Tangent;
attribute vec3 Binormal;
varying vec2 texCoord;
varying vec3 camVec;
varying vec3 lightVec;
//for fragment shader
varying vec4 vPos;
varying vec4 gPos;
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);
mat3 rot;
rot[0] = Tangent;
rot[1] = Binormal;
rot[2] = gl_Normal.xyz;
rot = ModelRotateMatrix * rot;
lightVec = lVec * rot;
camVec = cVec * rot;
//For shadows
vPos = realVertexPos;
gPos = gl_ProjectionMatrix * gl_Position;
gl_TexCoord[0] = gl_MultiTexCoord0;
}
@@ -0,0 +1,78 @@
uniform sampler2D Texture;
uniform sampler2D NormalMap;
uniform int NormalMapExists;
varying vec2 texCoord;
varying vec3 camVec;
varying vec3 lightVec;
//For shadows
uniform sampler2D ShadowMap;
uniform float ShadowDepth;
varying vec4 vPos;
varying vec4 gPos;
float shadowCoef()
{
vec4 shadow_coord = gl_TextureMatrix[2]*vPos;
shadow_coord.w = shadow_coord.z;
// get the stored depth
float shadow_d = texture2D(ShadowMap, shadow_coord.xy).x;
// get the difference of the stored depth and the distance of this fragment to the light
float diff = min(shadow_d - shadow_coord.z,0.0);
float shadow_coef = clamp( 20*ShadowDepth*diff + 1.0, 0.0, 1.0); //[0..1]
return shadow_coef;
}
void main()
{
vec3 lVec = lightVec;
vec3 cVec = normalize(camVec);
vec4 ambient;
vec4 diffuse;
vec4 specular;
float parallax = 0.035;
//double refinement
float height = texture2D(NormalMap, texCoord.xy).a;
float offset = parallax * (2.0 * height - 1.0);
vec2 parallaxTexCoord = texCoord.xy + offset * cVec.xy;
height += texture2D(NormalMap, parallaxTexCoord).a;
offset = parallax * (height - 1.0);
parallaxTexCoord = texCoord.xy + offset * cVec.xy;
//go-go-go
vec3 TexRGB = texture2D(Texture, parallaxTexCoord).xyz;
vec3 norm;
if (NormalMapExists == 0)
{
norm = vec3(0.0,0.0,1.0);
}
else
{
norm = texture2D(NormalMap, parallaxTexCoord).xyz * 2.0 - 1.0;
}
float shineFactor = 15.0 * pow(max(dot(cVec, norm),0.0),gl_FrontMaterial.shininess) / (129.0 - gl_FrontMaterial.shininess);
float shadow_coef = shadowCoef();
ambient = gl_LightSource[0].ambient;
diffuse = gl_FrontMaterial.diffuse * gl_LightSource[0].diffuse * min( max(dot(lightVec,norm),0.0),shadow_coef);
specular = gl_LightSource[0].specular * min(shineFactor,shadow_coef);
gl_FragColor = vec4(TexRGB,1.0)*max(ambient,diffuse)+specular;
}
@@ -0,0 +1,46 @@
/*
Bump/parallax mapping shader for single directional light source
The fastest shader for bump/bump mapping
*/
uniform vec3 CamPos;
uniform mat3 ModelRotateMatrix;
uniform vec3 ModelTranslateVector;
attribute vec3 Tangent;
attribute vec3 Binormal;
varying vec2 texCoord;
varying vec3 camVec;
varying vec3 lightVec;
//for fragment shader
varying vec4 vPos;
varying vec4 gPos;
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);
mat3 rot;
rot[0] = Tangent;
rot[1] = Binormal;
rot[2] = gl_Normal.xyz;
rot = ModelRotateMatrix * rot;
lightVec = lVec * rot;
camVec = cVec * rot;
//For shadows
vPos = realVertexPos;
gPos = gl_ProjectionMatrix * gl_Position;
gl_TexCoord[0] = gl_MultiTexCoord0;
}
+4
View File
@@ -0,0 +1,4 @@
void main()
{
gl_FragColor = vec4(1.0,1.0,1.0,1.0);
}
+12
View File
@@ -0,0 +1,12 @@
/* Shader to draw nothing. This shader is used when render scene to depth buffer only
For example, to make depth texture from light source position
*/
uniform mat3 ModelRotateMatrix;
uniform vec3 ModelTranslateVector;
void main()
{
vec4 realVertexPos = vec4(ModelRotateMatrix * gl_Vertex.xyz + ModelTranslateVector, 1.0);
gl_Position = gl_ModelViewProjectionMatrix * realVertexPos;
}
@@ -0,0 +1,43 @@
uniform sampler2D Texture;
uniform sampler2D NormalMap;
uniform int NormalMapExists;
varying vec2 texCoord;
varying int activeLightCount;
varying vec3 camVec;
varying vec3 lightVec[8];
void main()
{
vec3 norm;
vec4 ambient;
vec4 diffuse;
vec4 specular;
vec3 cVec = normalize(camVec);
vec3 lVec;
vec3 TexRGB = texture2D(Texture, texCoord.st).rgb;
if (NormalMapExists == 0)
{
norm = vec3(0.0,0.0,1.0);
}
else
{
norm = (texture2D(NormalMap, texCoord.st).rgb - 0.5) * 2.0;
}
float shineFactor = 15.0 * pow(max(dot(cVec, norm),0.0),gl_FrontMaterial.shininess) / (129.0 - gl_FrontMaterial.shininess);
gl_FragColor = vec4(0.0,0.0,0.0,1.0);
for (int i=0; i<activeLightCount; i++)
{
lVec = normalize(lightVec[i]);
ambient = gl_LightSource[i].ambient;
diffuse = gl_FrontMaterial.diffuse * gl_LightSource[i].diffuse * max( dot(lVec,norm),0.0);
specular = gl_LightSource[i].specular * shineFactor;
gl_FragColor += vec4(TexRGB,1.0)*ambient+(vec4(TexRGB,1.0)*diffuse+specular);
}
}
@@ -0,0 +1,51 @@
/*
Bump mapping shader without parallax mapping for not more than 8 light sources
The slowest bump mapping shader
*/
uniform vec3 CamPos;
uniform int ActiveLightCount;
uniform mat3 ModelRotateMatrix;
uniform vec3 ModelTranslateVector;
attribute vec3 Tangent;
attribute vec3 Binormal;
varying vec2 texCoord;
varying int activeLightCount;
varying vec3 camVec;
varying vec3 lightVec[8];
void main()
{
gl_Position = gl_ModelViewProjectionMatrix * vec4(ModelRotateMatrix * gl_Vertex.xyz + ModelTranslateVector, 1.0);
texCoord = gl_MultiTexCoord0.st;
activeLightCount = ActiveLightCount;
mat3 rot;
rot[0] = Tangent;
rot[1] = Binormal;
rot[2] = gl_Normal.xyz;
rot = ModelRotateMatrix * rot;
vec3 lVec;
vec3 cVec = CamPos - gl_Vertex.xyz;
camVec = cVec * rot;
for (int i=0; i<ActiveLightCount; i++)
{
if (gl_LightSource[i].position.w == 0.0)
lVec = gl_LightSource[i].position.xyz;
else
lVec = gl_LightSource[i].position.xyz - gl_Vertex.xyz;
lightVec[i] = lVec * rot;
}
}
@@ -0,0 +1,54 @@
uniform sampler2D Texture;
uniform sampler2D NormalMap;
uniform int NormalMapExists;
varying vec2 texCoord;
varying int activeLightCount;
varying vec3 camVec;
varying vec3 lightVec[8];
void main()
{
vec3 lVec;
vec3 cVec = normalize(camVec);
float parallax = 0.035;
//double refinement
float height = texture2D(NormalMap, texCoord.xy).a;
float offset = parallax * (2.0 * height - 1.0);
vec2 parallaxTexCoord = texCoord.xy + offset * cVec.xy;
height += texture2D(NormalMap, parallaxTexCoord).a;
offset = parallax * (height - 1.0);
parallaxTexCoord = texCoord.xy + offset * cVec.xy;
//go-go-go
vec3 TexRGB = texture2D(Texture, parallaxTexCoord).xyz;
vec3 norm;
if (NormalMapExists == 0)
{
norm = vec3(0.0,0.0,1.0);
}
else
{
norm = texture2D(NormalMap, parallaxTexCoord).xyz * 2.0 - 1.0;
}
float shineFactor = 15.0 * pow(max(dot(cVec, norm),0.0),gl_FrontMaterial.shininess) / (129.0 - gl_FrontMaterial.shininess);
gl_FragColor = vec4(0.0,0.0,0.0,1.0);
for (int i=0;i<activeLightCount;i++)
{
vec3 lVec = normalize(lightVec[i]);
vec4 ambient = gl_LightSource[i].ambient;
vec4 diffuse = gl_FrontMaterial.diffuse * gl_LightSource[i].diffuse * max( dot(lVec,norm),0.0);
vec4 specular = gl_LightSource[i].specular * shineFactor;
gl_FragColor += vec4(TexRGB,1.0)*ambient+(vec4(TexRGB,1.0)*diffuse+specular);
}
}
@@ -0,0 +1,49 @@
/*
Bump/parallax mapping shader for not more than 8 light sources
The slowest bump/parallax mapping shader
*/
uniform vec3 CamPos;
uniform mat3 ModelRotateMatrix;
uniform vec3 ModelTranslateVector;
uniform int ActiveLightCount;
attribute vec3 Tangent;
attribute vec3 Binormal;
varying vec2 texCoord;
varying int activeLightCount;
varying vec3 camVec;
varying vec3 lightVec[8];
void main()
{
gl_Position = gl_ModelViewProjectionMatrix * vec4(ModelRotateMatrix * gl_Vertex.xyz + ModelTranslateVector, 1.0);
texCoord = gl_MultiTexCoord0.st;
activeLightCount = ActiveLightCount;
mat3 rot;
rot[0] = Tangent;
rot[1] = Binormal;
rot[2] = gl_Normal.xyz;
rot = ModelRotateMatrix * rot;
vec3 lVec;
vec3 cVec = (CamPos - gl_Vertex.xyz);
camVec = cVec * rot;
for (int i=0;i<ActiveLightCount;i++)
{
if (gl_LightSource[i].position.w == 0.0)
lVec = gl_LightSource[i].position.xyz;
else
lVec = gl_LightSource[i].position.xyz - gl_Vertex.xyz;
lightVec[i] = lVec * rot;
}
}
@@ -0,0 +1,39 @@
uniform sampler2D Texture;
uniform sampler2D NormalMap;
uniform int NormalMapExists;
varying vec2 texCoord;
varying vec3 camVec;
varying vec3 lightVec;
void main()
{
vec3 norm;
vec4 diffuse;
vec4 specular;
vec3 cVec = normalize(camVec);
vec3 lVec = normalize(lightVec);
vec3 TexRGB = texture2D(Texture, texCoord.st).rgb;
if (NormalMapExists == 0)
{
norm = vec3(0.0,0.0,1.0);
}
else
{
norm = (texture2D(NormalMap, texCoord.st).rgb - 0.5)* 2.0;
}
float shineFactor = 15.0 * pow(max(dot(cVec, norm),0.0),gl_FrontMaterial.shininess) / (129.0 - gl_FrontMaterial.shininess);
diffuse = gl_FrontMaterial.diffuse * gl_LightSource[0].diffuse * max( dot(lVec,norm),0.0);
specular = gl_LightSource[0].specular * shineFactor;
gl_FragColor = vec4(TexRGB,1.0)*gl_LightSource[0].ambient+(vec4(TexRGB,1.0)*diffuse+specular);
}
@@ -0,0 +1,38 @@
// Bump mapping shader without parallax mapping for single light source
// Slower than directlight_bump but faster than multilight_bump
uniform vec3 CamPos;
uniform mat3 ModelRotateMatrix;
uniform vec3 ModelTranslateVector;
attribute vec3 Tangent;
attribute vec3 Binormal;
varying vec2 texCoord;
varying vec3 camVec;
varying vec3 lightVec;
void main()
{
gl_Position = gl_ModelViewProjectionMatrix * vec4(ModelRotateMatrix * gl_Vertex.xyz + ModelTranslateVector, 1.0);
texCoord = gl_MultiTexCoord0.st;
vec3 lVec;
if (gl_LightSource[0].position.w == 0.0)
lVec = gl_LightSource[0].position.xyz;
else
lVec = gl_LightSource[0].position.xyz - gl_Vertex.xyz;
vec3 cVec = CamPos - gl_Vertex.xyz;
mat3 rot;
rot[0] = Tangent;
rot[1] = Binormal;
rot[2] = gl_Normal.xyz;
rot = ModelRotateMatrix * rot;
lightVec = lVec * rot;
camVec = cVec * rot;
}
@@ -0,0 +1,47 @@
uniform sampler2D Texture;
uniform sampler2D NormalMap;
uniform int NormalMapExists;
varying vec2 texCoord;
varying vec3 camVec;
varying vec3 lightVec;
void main()
{
vec3 lVec = normalize(lightVec);
vec3 cVec = normalize(camVec);
float parallax = 0.035;
//double refinement
float height = texture2D(NormalMap, texCoord.xy).a;
float offset = parallax * (2.0 * height - 1.0);
vec2 parallaxTexCoord = texCoord.xy + offset * cVec.xy;
height += texture2D(NormalMap, parallaxTexCoord).a;
offset = parallax * (height - 1.0);
parallaxTexCoord = texCoord.xy + offset * cVec.xy;
//go-go-go
vec3 TexRGB = texture2D(Texture, parallaxTexCoord).xyz;
vec3 norm;
if (NormalMapExists == 0)
{
norm = vec3(0.0,0.0,1.0);
}
else
{
norm = texture2D(NormalMap, parallaxTexCoord).xyz * 2.0 - 1.0;
}
float shineFactor = 15.0 * pow(max(dot(cVec, norm),0.0),gl_FrontMaterial.shininess) / (129.0 - gl_FrontMaterial.shininess);
vec4 ambient = gl_LightSource[0].ambient;
vec4 diffuse = gl_FrontMaterial.diffuse * gl_LightSource[0].diffuse * max( dot(lVec,norm),0.0);
vec4 specular = gl_LightSource[0].specular * shineFactor;
gl_FragColor = vec4(TexRGB,1.0)*ambient+(vec4(TexRGB,1.0)*diffuse+specular);
}
@@ -0,0 +1,41 @@
/*
Bump/parallax mapping shader for single light source
Slower than directlight_parallax but faster than multilight_parallax
*/
uniform vec3 CamPos;
uniform mat3 ModelRotateMatrix;
uniform vec3 ModelTranslateVector;
attribute vec3 Tangent;
attribute vec3 Binormal;
varying vec2 texCoord;
varying vec3 camVec;
varying vec3 lightVec;
void main()
{
gl_Position = gl_ModelViewProjectionMatrix * vec4(ModelRotateMatrix * gl_Vertex.xyz + ModelTranslateVector, 1.0);
texCoord = gl_MultiTexCoord0.st;
vec3 lVec;
vec3 cVec = (CamPos - gl_Vertex.xyz);
if (gl_LightSource[0].position.w == 0.0)
lVec = gl_LightSource[0].position.xyz;
else
lVec = gl_LightSource[0].position.xyz - gl_Vertex.xyz;
mat3 rot;
rot[0] = Tangent;
rot[1] = Binormal;
rot[2] = gl_Normal.xyz;
rot = ModelRotateMatrix * rot;
lightVec = lVec * rot;
camVec = cVec * rot;
}
+36
View File
@@ -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);
}
+35
View File
@@ -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;
}
@@ -0,0 +1,209 @@
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;
//For shadows
uniform sampler2D ShadowMapGlobal;
uniform sampler2D ShadowMapLocal;
uniform float ShadowClampValue;
varying vec4 vPos;
varying vec4 gPos;
float CalcPCFGlobal(vec4 shadowCoord);
float CalcPCFLocal(vec4 shadowCoord);
vec2 myrand2(vec2 co)
{
return vec2(fract(sin(dot(co.xy ,vec2(12.9898,78.233))) * 43758.5453),
fract(sin(dot(vec2(1-co.y,1-co.x) ,vec2(12.9898,78.233))) * 43758.5453));
}
float shadowCoef()
{
vec4 shadow_coord = gl_TextureMatrix[3]*vPos;
float shadow_d;
float pcf;
if (shadow_coord.x < 0.0 || shadow_coord.x > 1.0
|| shadow_coord.y < 0.0 || shadow_coord.y > 1.0)
{
shadow_coord = gl_TextureMatrix[2]*vPos;
shadow_coord.w = shadow_coord.z;
pcf = CalcPCFGlobal(shadow_coord);
}
else
{
shadow_coord.w = shadow_coord.z;
pcf = CalcPCFLocal(shadow_coord);
}
return clamp(1.0 - pcf, ShadowClampValue, 1.0);
}
float CalcPCFGlobal(vec4 shadowCoord)
{
float diff;
float shadow_d;
vec3 shadow_coord = shadowCoord.xyz;
shadow_d = texture2D(ShadowMapGlobal, shadow_coord.xy).x;
diff = clamp(60000*(shadow_d - shadow_coord.z+0.004), 0.0, 1.0);
shadow_coord.x += 0.001;
shadow_d = texture2D(ShadowMapGlobal, shadow_coord.xy).x;
diff += clamp(60000*(shadow_d - shadow_coord.z+0.004), 0.0, 1.0);
shadow_coord.xy = shadowCoord.xy;
shadow_coord.x -= 0.001;
shadow_d = texture2D(ShadowMapGlobal, shadow_coord.xy).x;
diff += clamp(60000*(shadow_d - shadow_coord.z+0.004), 0.0, 1.0);
shadow_coord.xy = shadowCoord.xy;
shadow_coord.y += 0.001;
shadow_d = texture2D(ShadowMapGlobal, shadow_coord.xy).x;
diff += clamp(60000*(shadow_d - shadow_coord.z+0.004), 0.0, 1.0);
shadow_coord.xy = shadowCoord.xy;
shadow_coord.y -= 0.001;
shadow_d = texture2D(ShadowMapGlobal, shadow_coord.xy).x;
diff += clamp(60000*(shadow_d - shadow_coord.z+0.004), 0.0, 1.0);
return diff*0.2;
}
float CalcPCFLocal(vec4 shadowCoord)
{
float diff;
float shadow_d;
vec3 shadow_coord;
shadow_coord = shadowCoord.xyz;
shadow_d = texture2D(ShadowMapLocal, shadow_coord.xy).x;
diff = clamp(60000*(shadow_d - shadow_coord.z+0.004), 0.0, 1.0);
shadow_coord.xy = shadowCoord.xy;
shadow_coord.x += 0.001;
shadow_coord.xy = shadow_coord.xy + myrand2(shadow_coord.xy)*0.004;
shadow_d = texture2D(ShadowMapLocal, shadow_coord.xy).x;
diff += clamp(60000*(shadow_d - shadow_coord.z+0.004), 0.0, 1.0);
shadow_coord.xy = shadowCoord.xy;
shadow_coord.x -= 0.001;
shadow_coord.xy = shadow_coord.xy + myrand2(shadow_coord.xy)*0.004;
shadow_d = texture2D(ShadowMapLocal, shadow_coord.xy).x;
diff += clamp(60000*(shadow_d - shadow_coord.z+0.004), 0.0, 1.0);
shadow_coord.xy = shadowCoord.xy;
shadow_coord.y += 0.001;
shadow_coord.xy = shadow_coord.xy + myrand2(shadow_coord.xy)*0.004;
shadow_d = texture2D(ShadowMapLocal, shadow_coord.xy).x;
diff += clamp(60000*(shadow_d - shadow_coord.z+0.004), 0.0, 1.0);
shadow_coord.xy = shadowCoord.xy;
shadow_coord.y -= 0.001;
shadow_coord.xy = shadow_coord.xy + myrand2(shadow_coord.xy)*0.004;
shadow_d = texture2D(ShadowMapLocal, shadow_coord.xy).x;
diff += clamp(60000*(shadow_d - shadow_coord.z+0.004), 0.0, 1.0);
shadow_coord.xy = shadowCoord.xy;
shadow_coord.x += 0.001;
shadow_coord.y += 0.001;
shadow_coord.xy = shadow_coord.xy + myrand2(shadow_coord.xy)*0.004;
shadow_d = texture2D(ShadowMapLocal, shadow_coord.xy).x;
diff += clamp(60000*(shadow_d - shadow_coord.z+0.004), 0.0, 1.0);
shadow_coord.xy = shadowCoord.xy;
shadow_coord.x -= 0.001;
shadow_coord.y += 0.001;
shadow_coord.xy = shadow_coord.xy + myrand2(shadow_coord.xy)*0.004;
shadow_d = texture2D(ShadowMapLocal, shadow_coord.xy).x;
diff += clamp(60000*(shadow_d - shadow_coord.z+0.004), 0.0, 1.0);
shadow_coord.xy = shadowCoord.xy;
shadow_coord.x += 0.001;
shadow_coord.y -= 0.001;
shadow_coord.xy = shadow_coord.xy + myrand2(shadow_coord.xy)*0.004;
shadow_d = texture2D(ShadowMapLocal, shadow_coord.xy).x;
diff += clamp(60000*(shadow_d - shadow_coord.z+0.004), 0.0, 1.0);
shadow_coord.xy = shadowCoord.xy;
shadow_coord.x -= 0.001;
shadow_coord.y -= 0.001;
shadow_coord.xy = shadow_coord.xy + myrand2(shadow_coord.xy)*0.004;
shadow_d = texture2D(ShadowMapLocal, shadow_coord.xy).x;
diff += clamp(60000*(shadow_d - shadow_coord.z+0.004), 0.0, 1.0);
return diff*0.11;
}
void main()
{
vec3 lVec = lightVec;
vec3 cVec = normalize(camVec);
float parallax = 0.035;
//double refinement
float height;
float offset;
vec2 parallaxTexCoord;
if (NormalMapExists != 0)
{
height = texture2D(NormalMap, texCoord.xy).a;
offset = parallax * (2.0 * height - 1.0);
parallaxTexCoord = texCoord.xy + offset * cVec.xy;
height += texture2D(NormalMap, parallaxTexCoord).a;
offset = parallax * (height - 1.0);
parallaxTexCoord = texCoord.xy + offset * cVec.xy;
}
else
{
parallaxTexCoord = texCoord.xy;
}
//go-go-go
vec3 TexRGB = texture2D(Texture, parallaxTexCoord).xyz;
vec3 norm;
norm = (1-NormalMapExists) * vec3(0.0,0.0,1.0) + NormalMapExists*(texture2D(NormalMap, parallaxTexCoord).xyz * 2.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;
if (lightVec.z <= 0.2)
{
light_coef = 1.0;
}
else
{
light_coef = 1.0 - shadowCoef();
}
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,48 @@
attribute vec3 vPosition;
attribute vec2 vTexCoord;
uniform vec3 CamPos;
uniform mat3 ModelRotateMatrix;
uniform vec3 ModelTranslateVector;
uniform mat4 ProjectionMatrix;
uniform mat4 ProjectionMatrix1;
attribute vec3 Tangent;
attribute vec3 Binormal;
varying vec2 texCoord;
varying vec3 camVec;
varying vec3 lightVec;
varying vec3 vertexPos;
//For shadows
varying vec4 vPos;
varying vec4 gPos;
void main()
{
vec4 realVertexPos = vec4(ModelRotateMatrix * vPosition.xyz + ModelTranslateVector, 1.0);
gl_Position = ProjectionMatrix * realVertexPos;
texCoord = gl_MultiTexCoord0.st;
vec3 lVec = normalize(gl_LightSource[0].position.xyz);
vec3 cVec = (CamPos - vPosition.xyz);
vertexPos = vPosition.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;
//For shadows
vPos = realVertexPos;
gPos = ProjectionMatrix1 * vec4(vPosition.xyz, 1.0);
}
+8
View File
@@ -0,0 +1,8 @@
uniform samplerCube Env;
varying vec3 dir;
void main(){
gl_FragColor = textureCube(Env, dir);
}
+7
View File
@@ -0,0 +1,7 @@
varying vec3 dir;
void main(){
gl_Position = ftransform();
dir = gl_Vertex.xyz;
}
@@ -0,0 +1,10 @@
uniform sampler2D Texture;
varying vec2 texCoord;
void main()
{
vec4 texColor = texture2D(Texture,texCoord).rgba;
gl_FragColor = vec4(texColor.rgb,gl_FrontMaterial.diffuse.a * texColor.a);
}
+11
View File
@@ -0,0 +1,11 @@
attribute vec3 vPosition;
attribute vec2 vTexCoord;
varying vec2 texCoord;
uniform mat4 ProjectionMatrix;
void main()
{
gl_Position = ProjectionMatrix * vec4(vPosition.xyz, 1.0);
texCoord = vTexCoord.st;
}
+4
View File
@@ -0,0 +1,4 @@
void main()
{
gl_FragColor = vec4(1.0,1.0,1.0,1.0);
}
+17
View File
@@ -0,0 +1,17 @@
/* Shader to draw nothing. This shader is used when render scene to depth buffer only
For example, to make depth texture from light source position
*/
uniform mat3 ModelRotateMatrix;
uniform vec3 ModelTranslateVector;
attribute vec3 vPosition;
uniform mat4 ProjectionMatrix;
void main()
{
vec4 realVertexPos = vec4(ModelRotateMatrix * vPosition.xyz + ModelTranslateVector, 1.0);
gl_Position = ProjectionMatrix * realVertexPos;
}
+10
View File
@@ -0,0 +1,10 @@
uniform sampler2D Texture;
varying vec2 texCoord;
void main()
{
vec4 texColor = texture2D(Texture,texCoord).rgba;
gl_FragColor = vec4(texColor.rgb, 1.0);
}
+16
View File
@@ -0,0 +1,16 @@
attribute vec3 vPosition;
attribute vec2 vTexCoord;
varying vec2 texCoord;
uniform mat4 ProjectionMatrix;
uniform mat3 ModelRotateMatrix;
uniform vec3 ModelTranslateVector;
void main()
{
vec4 realVertexPos = vec4(ModelRotateMatrix * vPosition.xyz + ModelTranslateVector, 1.0);
gl_Position = ProjectionMatrix * realVertexPos;
texCoord = vTexCoord.st;
}
+10
View File
@@ -0,0 +1,10 @@
uniform sampler2D Texture;
varying vec2 texCoord;
void main()
{
vec4 texColor = texture2D(Texture,texCoord).rgba;
gl_FragColor = vec4(texColor.rgb,gl_FrontMaterial.diffuse.a * texColor.a);
}
+11
View File
@@ -0,0 +1,11 @@
attribute vec3 vPosition;
attribute vec2 vTexCoord;
varying vec2 texCoord;
uniform mat4 ProjectionMatrix;
void main()
{
gl_Position = ProjectionMatrix * vec4(vPosition.xyz, 1.0);
texCoord = vTexCoord.st;
}
+45
View File
@@ -0,0 +1,45 @@
uniform samplerCube Env;
uniform sampler2D NormalMap;
uniform vec3 CamPos;
uniform float WaterTimer;
varying vec3 camVec;
void main()
{
vec2 texCoord = gl_TexCoord[0].st;
mat3 rot;
rot[0] = vec3(0.0,0.0,1.0);
rot[1] = vec3(1.0,0.0,0.0);
rot[2] = vec3(0.0,1.0,0.0);
float sinx = 0.025*sin(WaterTimer+texCoord.x*5);
vec3 NVec1 = texture2D(NormalMap, vec2(-WaterTimer*0.04 + texCoord.x + sinx, -WaterTimer*0.04 + texCoord.y - sinx)).rgb;
vec3 NVec2 = texture2D(NormalMap, vec2( WaterTimer*0.04 + texCoord.y - sinx, -WaterTimer*0.04 + (1.0-texCoord.x) + sinx)).rgb;
NVec1 = (NVec1 -0.5) * 2.0;
NVec2 = (NVec2 -0.5) * 2.0;
vec3 NVec = NVec1 + NVec2;
vec3 NVecReflect = normalize(rot * (NVec1 + NVec2) + vec3(0,8,0));
vec3 NVecRefract = normalize(rot * (NVec1 + NVec2));
vec3 dir1 = reflect((camVec),NVecReflect);
//vec3 dir2 = refract((camVec),NVecRefract,0.9);
vec3 dir2 = reflect((camVec),NVecReflect);
dir2.y = - dir2.y;
vec4 reflectColor = textureCube(Env, dir1);
vec4 refractColor = textureCube(Env, dir2);
vec4 texColor = reflectColor*0.2 + refractColor*0.8;
gl_FragColor = vec4(texColor.xyz, 1.0f);
}
+13
View File
@@ -0,0 +1,13 @@
uniform vec3 CamPos;
varying vec3 camVec;
void main()
{
gl_Position = ftransform();
gl_TexCoord[0] = gl_MultiTexCoord0;
camVec = (gl_Vertex.xyz - CamPos);
}