Advertisement
Guest User

Untitled

a guest
Mar 27th, 2014
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.67 KB | None | 0 0
  1. 1) textureProjOffset used
  2. VERT:
  3. #version 330
  4. #extension GL_ARB_separate_shader_objects : enable
  5. uniform mat4 modelMatrix;
  6. uniform mat4 viewMatrix;
  7. uniform mat4 projMatrix;
  8. uniform mat4 shadowViewMatrix;
  9. uniform mat4 shadowProjMatrix;
  10. uniform sampler2DShadow shadowTex;
  11.  
  12. layout(location = 0) in vec4 vertex;
  13.  
  14. out vec4 vertexLight;
  15. void main()
  16. {
  17. gl_Position = projMatrix * viewMatrix * modelMatrix * vertex;
  18. vertexLight = shadowProjMatrix * shadowViewMatrix * modelMatrix * vertex;
  19. }
  20.  
  21. FRAG:
  22. #version 330
  23. #extension GL_ARB_separate_shader_objects : enable
  24. uniform mat4 modelMatrix;
  25. uniform mat4 viewMatrix;
  26. uniform mat4 projMatrix;
  27. uniform mat4 shadowViewMatrix;
  28. uniform mat4 shadowProjMatrix;
  29. uniform sampler2DShadow shadowTex;
  30.  
  31. in vec4 vertexLight;
  32. out vec4 color;
  33.  
  34. void main()
  35. {
  36. const mat4 bias = mat4(
  37. 0.5, 0.0, 0.0, 0.0,
  38. 0.0, 0.5, 0.0, 0.0,
  39. 0.0, 0.0, 0.5, 0.0,
  40. 0.5, 0.5, 0.5, 1.0);
  41.  
  42. vec4 shadowTexCoords = vec4(vertexLight.x,vertexLight.y,vertexLight.z-0.001,vertexLight.w) / vertexLight.w;
  43. shadowTexCoords = bias * shadowTexCoords;
  44. float shadeFactor = textureProjOffset(shadowTex, shadowTexCoords, ivec2(0.0));
  45. shadeFactor += textureProjOffset(shadowTex, shadowTexCoords, ivec2(1, 0));
  46. shadeFactor += textureProjOffset(shadowTex, shadowTexCoords, ivec2(-1, 0));
  47. shadeFactor += textureProjOffset(shadowTex, shadowTexCoords, ivec2(0, 1));
  48. shadeFactor += textureProjOffset(shadowTex, shadowTexCoords, ivec2(0, -1));
  49. shadeFactor /= 5.0;
  50.  
  51. float shadowAttenuation = 1;
  52. if(shadeFactor < 0.5) shadowAttenuation = 0.5;
  53. color = vec4(1,0,0,1) * shadowAttenuation;
  54. }
  55.  
  56.  
  57. 2) textureProjOffset unused
  58. VERT: same as before
  59.  
  60. FRAG:
  61. #version 330
  62. #extension GL_ARB_separate_shader_objects : enable
  63. uniform mat4 modelMatrix;
  64. uniform mat4 viewMatrix;
  65. uniform mat4 projMatrix;
  66. uniform mat4 shadowViewMatrix;
  67. uniform mat4 shadowProjMatrix;
  68. uniform sampler2DShadow shadowTex;
  69.  
  70. in vec4 vertexLight;
  71. out vec4 color;
  72.  
  73. void main()
  74. {
  75. const mat4 bias = mat4(
  76. 0.5, 0.0, 0.0, 0.0,
  77. 0.0, 0.5, 0.0, 0.0,
  78. 0.0, 0.0, 0.5, 0.0,
  79. 0.5, 0.5, 0.5, 1.0);
  80.  
  81. vec4 shadowTexCoords = vec4(vertexLight.x,vertexLight.y,vertexLight.z-0.001,vertexLight.w) / vertexLight.w;
  82. shadowTexCoords = bias * shadowTexCoords;
  83. float shadeFactor = textureProj(shadowTex, shadowTexCoords);
  84. shadeFactor += textureProj(shadowTex, shadowTexCoords);
  85. shadeFactor += textureProj(shadowTex, shadowTexCoords);
  86. shadeFactor += textureProj(shadowTex, shadowTexCoords);
  87. shadeFactor += textureProj(shadowTex, shadowTexCoords);
  88. shadeFactor /= 5.0;
  89.  
  90. float shadowAttenuation = 1;
  91. if(shadeFactor < 0.5) shadowAttenuation = 0.5;
  92. color = vec4(1,0,0,1) * shadowAttenuation;
  93. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement