Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 1) textureProjOffset used
- VERT:
- #version 330
- #extension GL_ARB_separate_shader_objects : enable
- uniform mat4 modelMatrix;
- uniform mat4 viewMatrix;
- uniform mat4 projMatrix;
- uniform mat4 shadowViewMatrix;
- uniform mat4 shadowProjMatrix;
- uniform sampler2DShadow shadowTex;
- layout(location = 0) in vec4 vertex;
- out vec4 vertexLight;
- void main()
- {
- gl_Position = projMatrix * viewMatrix * modelMatrix * vertex;
- vertexLight = shadowProjMatrix * shadowViewMatrix * modelMatrix * vertex;
- }
- FRAG:
- #version 330
- #extension GL_ARB_separate_shader_objects : enable
- uniform mat4 modelMatrix;
- uniform mat4 viewMatrix;
- uniform mat4 projMatrix;
- uniform mat4 shadowViewMatrix;
- uniform mat4 shadowProjMatrix;
- uniform sampler2DShadow shadowTex;
- in vec4 vertexLight;
- out vec4 color;
- void main()
- {
- const mat4 bias = mat4(
- 0.5, 0.0, 0.0, 0.0,
- 0.0, 0.5, 0.0, 0.0,
- 0.0, 0.0, 0.5, 0.0,
- 0.5, 0.5, 0.5, 1.0);
- vec4 shadowTexCoords = vec4(vertexLight.x,vertexLight.y,vertexLight.z-0.001,vertexLight.w) / vertexLight.w;
- shadowTexCoords = bias * shadowTexCoords;
- float shadeFactor = textureProjOffset(shadowTex, shadowTexCoords, ivec2(0.0));
- shadeFactor += textureProjOffset(shadowTex, shadowTexCoords, ivec2(1, 0));
- shadeFactor += textureProjOffset(shadowTex, shadowTexCoords, ivec2(-1, 0));
- shadeFactor += textureProjOffset(shadowTex, shadowTexCoords, ivec2(0, 1));
- shadeFactor += textureProjOffset(shadowTex, shadowTexCoords, ivec2(0, -1));
- shadeFactor /= 5.0;
- float shadowAttenuation = 1;
- if(shadeFactor < 0.5) shadowAttenuation = 0.5;
- color = vec4(1,0,0,1) * shadowAttenuation;
- }
- 2) textureProjOffset unused
- VERT: same as before
- FRAG:
- #version 330
- #extension GL_ARB_separate_shader_objects : enable
- uniform mat4 modelMatrix;
- uniform mat4 viewMatrix;
- uniform mat4 projMatrix;
- uniform mat4 shadowViewMatrix;
- uniform mat4 shadowProjMatrix;
- uniform sampler2DShadow shadowTex;
- in vec4 vertexLight;
- out vec4 color;
- void main()
- {
- const mat4 bias = mat4(
- 0.5, 0.0, 0.0, 0.0,
- 0.0, 0.5, 0.0, 0.0,
- 0.0, 0.0, 0.5, 0.0,
- 0.5, 0.5, 0.5, 1.0);
- vec4 shadowTexCoords = vec4(vertexLight.x,vertexLight.y,vertexLight.z-0.001,vertexLight.w) / vertexLight.w;
- shadowTexCoords = bias * shadowTexCoords;
- float shadeFactor = textureProj(shadowTex, shadowTexCoords);
- shadeFactor += textureProj(shadowTex, shadowTexCoords);
- shadeFactor += textureProj(shadowTex, shadowTexCoords);
- shadeFactor += textureProj(shadowTex, shadowTexCoords);
- shadeFactor += textureProj(shadowTex, shadowTexCoords);
- shadeFactor /= 5.0;
- float shadowAttenuation = 1;
- if(shadeFactor < 0.5) shadowAttenuation = 0.5;
- color = vec4(1,0,0,1) * shadowAttenuation;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement