Advertisement
Guest User

Untitled

a guest
Dec 25th, 2015
671
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.84 KB | None | 0 0
  1.  
  2. #ifndef COMPILEGS //ONLY IF NOT GS Shader
  3.  
  4. #include "Uniforms.glsl"
  5. #include "Samplers.glsl"
  6. #include "Transform.glsl"
  7. #include "ScreenPos.glsl"
  8. #include "Fog.glsl"
  9.  
  10. #endif //ONLY IF NOT GS Shader
  11.  
  12. //---------------------------------------------VS-----------------------------------------------------
  13. #ifdef COMPILEVS
  14.  
  15. out vec2 vTexCoord;
  16. //out vec4 vWorldPos;
  17. out vec3 vNormal;
  18.  
  19. #ifdef VERTEXCOLOR
  20.     out vec4 vColor;
  21. #endif
  22.  
  23. void VS()
  24. {
  25.     gl_Position = iPos;
  26.     vNormal = iNormal;
  27.     vTexCoord = GetTexCoord(iTexCoord);
  28.    
  29.     //mat4 modelMatrix = iModelMatrix;
  30.     //vec3 worldPos = GetWorldPos(modelMatrix);
  31.     //gl_Position = GetClipPos(worldPos);
  32.     //vNormal = GetWorldNormal(modelMatrix);
  33.     //vTexCoord = GetTexCoord(iTexCoord);
  34.     //vWorldPos = vec4(worldPos, GetDepth(gl_Position));
  35.  
  36.     #ifdef VERTEXCOLOR
  37.         vColor = iColor;
  38.     #endif
  39. }
  40. #endif // COMPILEVS
  41.  
  42. //---------------------------------------------GS-----------------------------------------------------
  43. #ifdef COMPILEGS
  44.  
  45. #include "Uniforms.glsl"
  46. #include "Transform.glsl"
  47.  
  48. uniform mat4 cModel;
  49. uniform mat4 cViewProj;
  50. uniform vec4 cDepthMode;
  51. uniform float cOffset;
  52.  
  53.  
  54. layout(triangles) in;
  55. layout(triangle_strip, max_vertices = 3) out;
  56.  
  57. in vec2 vTexCoord[];
  58. //in vec4 vWorldPos[];
  59. in vec3 vNormal[];
  60.  
  61. out vec2 gTexCoord;
  62. out vec4 gWorldPos;
  63. out vec3 gNormal;
  64.  
  65. mat3 GetNormalMatrix(mat4 modelMatrix)
  66. {
  67.     return mat3(modelMatrix[0].xyz, modelMatrix[1].xyz, modelMatrix[2].xyz);
  68. }
  69.  
  70. float GetDepth(vec4 clipPos)
  71. {
  72.     return dot(clipPos.zw, cDepthMode.zw);
  73. }
  74.  
  75. void GS()
  76. {
  77.     mat4 modelMatrix = cModel;
  78.     vec3 faceNormal = vec3(0);
  79.     for ( int i=0; i<gl_in.length(); i++)
  80.     {
  81.         faceNormal +=  normalize(vNormal[i] * GetNormalMatrix(modelMatrix));
  82.     }
  83.    
  84.     faceNormal /= gl_in.length();
  85.    
  86.     for ( int i = 0; i < gl_in.length(); i++ )
  87.     {
  88.         vec4 iPos = gl_in[i].gl_Position;
  89.         vec3 worldPos = (iPos * modelMatrix).xyz + faceNormal * cOffset;
  90.         gNormal = normalize(vNormal[i] * GetNormalMatrix(modelMatrix));
  91.         gl_Position = vec4(vec3(worldPos), 1.0) * cViewProj;
  92.         gWorldPos = vec4(worldPos, GetDepth(gl_Position));
  93.         gTexCoord = vTexCoord[i];
  94.         EmitVertex ();
  95.     }
  96.     EndPrimitive ();
  97. }
  98. #endif // COMPILEGS
  99. //---------------------------------------------PS-----------------------------------------------------
  100. #ifdef COMPILEPS
  101.  
  102. in vec2 gTexCoord;
  103. in vec4 gWorldPos;
  104. in vec3 gNormal;
  105.  
  106. #ifdef VERTEXCOLOR
  107.     varying vec4 gColor;
  108. #endif
  109.  
  110. void PS()
  111. {
  112.     // Get material diffuse albedo
  113.     #ifdef DIFFMAP
  114.         vec4 diffColor = cMatDiffColor * texture2D(sDiffMap, gTexCoord);
  115.         #ifdef ALPHAMASK
  116.             if (diffColor.a < 0.5)
  117.                 discard;
  118.         #endif
  119.     #else
  120.         vec4 diffColor = cMatDiffColor;
  121.     #endif
  122.  
  123.     #ifdef VERTEXCOLOR
  124.         diffColor *= gColor;
  125.     #endif
  126.  
  127.     // Get fog factor
  128.     #ifdef HEIGHTFOG
  129.         float fogFactor = GetHeightFogFactor(gWorldPos.w, gWorldPos.y);
  130.     #else
  131.         float fogFactor = GetFogFactor(gWorldPos.w);
  132.     #endif
  133.  
  134.     #if defined(PREPASS)
  135.         // Fill light pre-pass G-Buffer
  136.         gl_FragData[0] = vec4(0.5, 0.5, 0.5, 1.0);
  137.         gl_FragData[1] = vec4(EncodeDepth(gWorldPos.w), 0.0);
  138.     #elif defined(DEFERRED)
  139.         gl_FragData[0] = vec4(GetFog(diffColor.rgb, fogFactor), diffColor.a);
  140.         gl_FragData[1] = vec4(0.0, 0.0, 0.0, 0.0);
  141.         gl_FragData[2] = vec4(0.5, 0.5, 0.5, 1.0);
  142.         gl_FragData[3] = vec4(EncodeDepth(gWorldPos.w), 0.0);
  143.     #else
  144.         #ifndef MRT1
  145.             gl_FragColor = vec4(GetFog(diffColor.rgb, fogFactor), diffColor.a);
  146.         #else
  147.             gl_FragData[0] = vec4(GetFog(diffColor.rgb, fogFactor), diffColor.a);
  148.             gl_FragData[1] = vec4(1.0);
  149.         #endif
  150.     #endif
  151. }
  152.  
  153. #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement