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

@@ -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;
}