Advertisement
Guest User

Untitled

a guest
Dec 4th, 2015
506
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.67 KB | None | 0 0
  1. #include "Uniforms.glsl"
  2. #include "Samplers.glsl"
  3. #include "Transform.glsl"
  4. #include "ScreenPos.glsl"
  5. #include "Fog.glsl"
  6.  
  7. varying vec2 vScreenPos;
  8. varying vec2 vTexCoord;
  9. varying vec4 vWorldPos;
  10. varying vec3 vFarRay;
  11. varying vec4 vPosProj;
  12.  
  13. #ifdef VERTEXCOLOR
  14.     varying vec4 vColor;
  15. #endif
  16.  
  17. #ifdef SP
  18.     varying float vParticleViewProjZ;
  19. #endif
  20.  
  21. #line 17
  22. void VS()
  23. {
  24.     mat4 modelMatrix = iModelMatrix;
  25.     vec3 worldPos = GetWorldPos(modelMatrix);
  26.     gl_Position = GetClipPos(worldPos);
  27.     vPosProj = vec4(worldPos, 1.0) * cViewProj;
  28.     vScreenPos = GetScreenPosPreDiv(gl_Position);
  29.     vFarRay = GetFarRay(gl_Position);
  30.     vTexCoord = GetTexCoord(iTexCoord);
  31.     vWorldPos = vec4(worldPos, GetDepth(gl_Position));
  32.  
  33.     #ifdef VERTEXCOLOR
  34.         vColor = iColor;
  35.     #endif
  36.    
  37.     #ifdef SP
  38.         vParticleViewProjZ = gl_Position.z;
  39.         //vParticleViewProjZ = gl_Position.z / gl_Position.w;
  40.         //vParticleViewProjZ = GetDepth(gl_Position);
  41.         //vParticleViewProjZ = gl_Position.w;
  42.     #endif  
  43. }
  44.  
  45. void PS()
  46. {
  47.     // Get material diffuse albedo
  48.     #ifdef DIFFMAP
  49.         vec4 diffColor = cMatDiffColor * texture2D(sDiffMap, vTexCoord);
  50.         #ifdef ALPHAMASK
  51.             if (diffColor.a < 0.5)
  52.                 discard;
  53.         #endif
  54.     #else
  55.         vec4 diffColor = cMatDiffColor;
  56.     #endif
  57.  
  58.     #ifdef VERTEXCOLOR
  59.         diffColor *= vColor;
  60.     #endif
  61.  
  62.     // Get fog factor
  63.     #ifdef HEIGHTFOG
  64.         float fogFactor = GetHeightFogFactor(vWorldPos.w, vWorldPos.y);
  65.     #else
  66.         float fogFactor = GetFogFactor(vWorldPos.w);
  67.     #endif
  68.  
  69.     #if defined(PREPASS)
  70.         // Fill light pre-pass G-Buffer
  71.         gl_FragData[0] = vec4(0.5, 0.5, 0.5, 1.0);
  72.         gl_FragData[1] = vec4(EncodeDepth(vWorldPos.w), 0.0);
  73.     #elif defined(DEFERRED)
  74.         gl_FragData[0] = vec4(GetFog(diffColor.rgb, fogFactor), diffColor.a);
  75.         gl_FragData[1] = vec4(0.0, 0.0, 0.0, 0.0);
  76.         gl_FragData[2] = vec4(0.5, 0.5, 0.5, 1.0);
  77.         gl_FragData[3] = vec4(EncodeDepth(vWorldPos.w), 0.0);
  78.     #else
  79.         #ifdef OUTMRT01
  80.             // diffuse
  81.             gl_FragData[0] = vec4(GetFog(diffColor.rgb, fogFactor), diffColor.a);
  82.             gl_FragData[1] = vec4(vParticleViewProjZ, 0, 0, 1.0);
  83.             // depth
  84.             #ifdef SP
  85.                 //gl_FragData[1] = vec4(vParticleViewProjZ, 0.0, 0.0, 0.0);
  86.             #else
  87.                 //gl_FragData[1] = vec4(0.0, 0.0, 0.0, 0.0);
  88.             #endif
  89.         #else
  90.             // VS :: vScreenPos = GetScreenPosPreDiv(gl_Position);
  91.             float sceneZ = texture2D(sDepthBuffer, vScreenPos).r;   // read depthstencil texture(readabledepth)
  92.             float restoredSceneZ = ReconstructDepth(sceneZ);        // to 0..1 range
  93.             vec3 sceneWorldPos = vFarRay * restoredSceneZ;          // restore worldpos of backgroud sceneZ
  94.             vec4 sceneViewPos = vec4(sceneWorldPos, 1.0) * cProj;   // restore viewproj of backgroud sceneZ
  95.            
  96.            
  97.             float scale = 2.0;
  98.             // calc difference between sceneZ and particleZ
  99.             float diffZ = (sceneViewPos.z - vParticleViewProjZ) * scale;
  100.             //float diffZ = (sceneViewPos.w - vWorldPos.z) * scale;  
  101.             float input = clamp(diffZ, 0.0, 1.0);
  102.             float contrastPower = 1.0;
  103.             float output = 0.5 * pow(clamp(2*((input > 0.5) ? 1 - input : input), 0.0, 1.0), contrastPower);
  104.             float weight = (input > 0.5) ? 1 - output : output;
  105.            
  106.             diffColor.a *= weight;
  107.            
  108.             gl_FragColor = vec4(GetFog(diffColor.rgb, fogFactor), diffColor.a);
  109.         #endif
  110.     #endif
  111. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement