Add shader for projective texture.
This commit is contained in:
8
examples/OpenGLWindow/Shaders/useShadowMapInstancingPS.glsl
Normal file → Executable file
8
examples/OpenGLWindow/Shaders/useShadowMapInstancingPS.glsl
Normal file → Executable file
@@ -12,9 +12,11 @@ in Vert
|
||||
} vert;
|
||||
|
||||
uniform sampler2D Diffuse;
|
||||
uniform sampler2DShadow shadowMap;
|
||||
uniform mat4 ViewMatrixInverse;
|
||||
|
||||
in vec3 lightPos,cameraPosition, normal,ambient;
|
||||
in vec4 ShadowCoord;
|
||||
in vec4 vertexPos;
|
||||
in float materialShininess;
|
||||
in vec3 lightSpecularIntensity;
|
||||
@@ -26,7 +28,7 @@ out vec4 color;
|
||||
|
||||
void main(void)
|
||||
{
|
||||
vec4 texel = fragment.color*texture(Diffuse,vert.texcoord.xy);
|
||||
vec4 texel = fragment.color*texture(Diffuse,vert.texcoord);
|
||||
vec3 ct,cf;
|
||||
float intensity,at,af;
|
||||
if (fragment.color.w==0)
|
||||
@@ -63,7 +65,9 @@ void main(void)
|
||||
}
|
||||
|
||||
|
||||
float visibility = 1.0;
|
||||
float visibility = texture(shadowMap, vec3(ShadowCoord.xy,(ShadowCoord.z)/ShadowCoord.w));
|
||||
if (intensity<0.5)
|
||||
visibility = 0;
|
||||
|
||||
intensity = 0.7*intensity + 0.3*intensity*visibility;
|
||||
|
||||
|
||||
8
examples/OpenGLWindow/Shaders/useShadowMapInstancingPS.h
Normal file → Executable file
8
examples/OpenGLWindow/Shaders/useShadowMapInstancingPS.h
Normal file → Executable file
@@ -11,8 +11,10 @@ static const char* useShadowMapInstancingFragmentShader= \
|
||||
" vec2 texcoord;\n"
|
||||
"} vert;\n"
|
||||
"uniform sampler2D Diffuse;\n"
|
||||
"uniform sampler2DShadow shadowMap;\n"
|
||||
"uniform mat4 ViewMatrixInverse;\n"
|
||||
"in vec3 lightPos,cameraPosition, normal,ambient;\n"
|
||||
"in vec4 ShadowCoord;\n"
|
||||
"in vec4 vertexPos;\n"
|
||||
"in float materialShininess;\n"
|
||||
"in vec3 lightSpecularIntensity;\n"
|
||||
@@ -20,7 +22,7 @@ static const char* useShadowMapInstancingFragmentShader= \
|
||||
"out vec4 color;\n"
|
||||
"void main(void)\n"
|
||||
"{\n"
|
||||
" vec4 texel = fragment.color*texture(Diffuse,vert.texcoord.xy);\n"
|
||||
" vec4 texel = fragment.color*texture(Diffuse,vert.texcoord);\n"
|
||||
" vec3 ct,cf;\n"
|
||||
" float intensity,at,af;\n"
|
||||
" if (fragment.color.w==0)\n"
|
||||
@@ -56,7 +58,9 @@ static const char* useShadowMapInstancingFragmentShader= \
|
||||
" \n"
|
||||
" }\n"
|
||||
" \n"
|
||||
" float visibility = 1.0;\n"
|
||||
" float visibility = texture(shadowMap, vec3(ShadowCoord.xy,(ShadowCoord.z)/ShadowCoord.w));\n"
|
||||
" if (intensity<0.5)\n"
|
||||
" visibility = 0;\n"
|
||||
" intensity = 0.7*intensity + 0.3*intensity*visibility;\n"
|
||||
" \n"
|
||||
" cf = intensity*(vec3(1.0,1.0,1.0)-ambient)+ambient+specularReflection*visibility;\n"
|
||||
|
||||
6
examples/OpenGLWindow/Shaders/useShadowMapInstancingVS.glsl
Normal file → Executable file
6
examples/OpenGLWindow/Shaders/useShadowMapInstancingVS.glsl
Normal file → Executable file
@@ -11,6 +11,8 @@ layout (location = 5) in vec4 instance_color;
|
||||
layout (location = 6) in vec3 instance_scale;
|
||||
|
||||
|
||||
uniform mat4 ModelViewMatrix;
|
||||
uniform mat4 ProjectionMatrix;
|
||||
uniform mat4 DepthBiasModelViewProjectionMatrix;
|
||||
uniform mat4 MVP;
|
||||
uniform vec3 lightPosIn;
|
||||
@@ -91,9 +93,9 @@ void main(void)
|
||||
|
||||
vec4 vertexLoc = MVP* vec4((instance_position+localcoord).xyz,1);
|
||||
gl_Position = vertexLoc;
|
||||
ShadowCoord = DepthBiasModelViewProjectionMatrix * vec4((instance_position+localcoord).xyz,1);
|
||||
|
||||
fragment.color = instance_color;
|
||||
vec4 projcoords = DepthBiasModelViewProjectionMatrix * vec4((instance_position+localcoord).xyz,1);
|
||||
vert.texcoord = projcoords.xy;
|
||||
vert.texcoord = uvcoords;
|
||||
}
|
||||
|
||||
|
||||
6
examples/OpenGLWindow/Shaders/useShadowMapInstancingVS.h
Normal file → Executable file
6
examples/OpenGLWindow/Shaders/useShadowMapInstancingVS.h
Normal file → Executable file
@@ -9,6 +9,8 @@ static const char* useShadowMapInstancingVertexShader= \
|
||||
"layout (location = 4) in vec3 vertexnormal;\n"
|
||||
"layout (location = 5) in vec4 instance_color;\n"
|
||||
"layout (location = 6) in vec3 instance_scale;\n"
|
||||
"uniform mat4 ModelViewMatrix;\n"
|
||||
"uniform mat4 ProjectionMatrix;\n"
|
||||
"uniform mat4 DepthBiasModelViewProjectionMatrix;\n"
|
||||
"uniform mat4 MVP;\n"
|
||||
"uniform vec3 lightPosIn;\n"
|
||||
@@ -79,8 +81,8 @@ static const char* useShadowMapInstancingVertexShader= \
|
||||
" \n"
|
||||
" vec4 vertexLoc = MVP* vec4((instance_position+localcoord).xyz,1);\n"
|
||||
" gl_Position = vertexLoc;\n"
|
||||
" ShadowCoord = DepthBiasModelViewProjectionMatrix * vec4((instance_position+localcoord).xyz,1);\n"
|
||||
" fragment.color = instance_color;\n"
|
||||
" vec4 projcoords = DepthBiasModelViewProjectionMatrix * vec4((instance_position+localcoord).xyz,1);\n"
|
||||
" vert.texcoord = projcoords.xy;\n"
|
||||
" vert.texcoord = uvcoords;\n"
|
||||
"}\n"
|
||||
;
|
||||
|
||||
Reference in New Issue
Block a user