Advertisement
Guest User

Untitled

a guest
Oct 30th, 2014
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.82 KB | None | 0 0
  1. #import "Common/ShaderLib/Skinning.glsllib"
  2. uniform mat4 m_LightViewProjectionMatrix0;
  3. uniform mat4 m_LightViewProjectionMatrix1;
  4. uniform mat4 m_LightViewProjectionMatrix2;
  5. uniform mat4 m_LightViewProjectionMatrix3;
  6.  
  7. uniform mat4 g_WorldViewProjectionMatrix;
  8. uniform mat4 g_WorldMatrix;
  9.  
  10. #ifdef NUM_LIGHTS
  11.  
  12. uniform vec4 m_LightPosition0;
  13. uniform vec4 m_LightPosition1;
  14. uniform vec4 m_LightPosition2;
  15. uniform vec4 m_LightPosition3;
  16. uniform vec4 m_LightPosition4;
  17. uniform vec4 m_LightPosition5;
  18.  
  19. varying float shadsub0;
  20. varying float shadsub1;
  21. varying float shadsub2;
  22. varying float shadsub3;
  23. varying float shadsub4;
  24. varying float shadsub5;
  25.  
  26. varying float initMaxss;
  27. uniform vec3 m_LightPos;
  28. uniform float m_LightRadius;
  29. #endif
  30.  
  31. out vec4 projCoord0;
  32. out vec4 projCoord1;
  33. out vec4 projCoord2;
  34. out vec4 projCoord3;
  35.  
  36. #ifdef POINTLIGHT
  37. uniform mat4 m_LightViewProjectionMatrix4;
  38. uniform mat4 m_LightViewProjectionMatrix5;
  39. out vec4 projCoord4;
  40. out vec4 projCoord5;
  41. out vec4 worldPos;
  42. #else
  43. #ifndef PSSM
  44. uniform vec3 m_LightPos;
  45. uniform vec3 m_LightDir;
  46. out float lightDot;
  47. #endif
  48. #endif
  49.  
  50. #ifdef PSSM
  51. out float shadowPosition;
  52. #endif
  53. out vec3 lightVec;
  54.  
  55. out vec2 texCoord;
  56.  
  57. in vec3 inPosition;
  58.  
  59. #ifdef DISCARD_ALPHA
  60. in vec2 inTexCoord;
  61. #endif
  62.  
  63. const mat4 biasMat = mat4(0.5, 0.0, 0.0, 0.0,
  64. 0.0, 0.5, 0.0, 0.0,
  65. 0.0, 0.0, 0.5, 0.0,
  66. 0.5, 0.5, 0.5, 1.0);
  67.  
  68. //const mat4 biasMat = mat4(0.5, 0.0, 0.0, 0.0,
  69. // 0.0, 0.5, 0.0, 0.0,
  70. // 0.0, 0.0, 0.5, 0.0,
  71. // 0.5, 0.5, 0.5, 1.0);
  72.  
  73.  
  74. void main(){
  75. vec4 modelSpacePos = vec4(inPosition, 1.0);
  76.  
  77. #ifdef NUM_BONES
  78. Skinning_Compute(modelSpacePos);
  79. #endif
  80. gl_Position = g_WorldViewProjectionMatrix * modelSpacePos;
  81.  
  82.  
  83.  
  84. #ifndef POINTLIGHT
  85. #ifdef PSSM
  86. shadowPosition = gl_Position.z;
  87. #endif
  88. vec4 worldPos=vec4(0.0);
  89. #endif
  90. // get the vertex in world space
  91. worldPos = g_WorldMatrix * modelSpacePos;
  92.  
  93. #ifdef NUM_LIGHTS
  94.  
  95. vec3 lightVector = m_LightPos - worldPos.xyz; //vLightPos.xyz - worldPos.xyz;
  96. float dist = length(lightVector);
  97. float lrh = m_LightRadius / 2;
  98. initMaxss = 0.0;
  99. if (dist > lrh && lrh > 0)
  100. {
  101. dist -= lrh;
  102. initMaxss = (dist / lrh);
  103. }
  104.  
  105. shadsub0 = -0.55 * length(m_LightPosition0.xyz - worldPos.xyz) * (m_LightPosition0.w / 0.25) + 1.40;
  106. shadsub1 = -0.55 * length(m_LightPosition1.xyz - worldPos.xyz) * (m_LightPosition1.w / 0.25) + 1.40;
  107. shadsub2 = -0.55 * length(m_LightPosition2.xyz - worldPos.xyz) * (m_LightPosition2.w / 0.25) + 1.40;
  108. shadsub3 = -0.55 * length(m_LightPosition3.xyz - worldPos.xyz) * (m_LightPosition3.w / 0.25) + 1.40;
  109. shadsub4 = -0.55 * length(m_LightPosition4.xyz - worldPos.xyz) * (m_LightPosition4.w / 0.25) + 1.40;
  110. shadsub5 = -0.55 * length(m_LightPosition5.xyz - worldPos.xyz) * (m_LightPosition5.w / 0.25) + 1.40;
  111.  
  112. #endif
  113.  
  114. #ifdef DISCARD_ALPHA
  115. texCoord = inTexCoord;
  116. #endif
  117. // populate the light view matrices array and convert vertex to light viewProj space
  118. projCoord0 = biasMat * m_LightViewProjectionMatrix0 * worldPos;
  119. projCoord1 = biasMat * m_LightViewProjectionMatrix1 * worldPos;
  120. projCoord2 = biasMat * m_LightViewProjectionMatrix2 * worldPos;
  121. projCoord3 = biasMat * m_LightViewProjectionMatrix3 * worldPos;
  122. #ifdef POINTLIGHT
  123. projCoord4 = biasMat * m_LightViewProjectionMatrix4 * worldPos;
  124. projCoord5 = biasMat * m_LightViewProjectionMatrix5 * worldPos;
  125. #else
  126. #ifndef PSSM
  127. vec3 lightDir = worldPos.xyz - m_LightPos;
  128. lightDot = dot(m_LightDir,lightDir);
  129. #endif
  130. #endif
  131. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement