Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "Uniforms.glsl"
- #include "Samplers.glsl"
- #include "Transform.glsl"
- #include "ScreenPos.glsl"
- #include "Fog.glsl"
- varying vec2 vScreenPos;
- varying vec2 vTexCoord;
- varying vec4 vWorldPos;
- varying vec3 vFarRay;
- varying vec4 vPosProj;
- #ifdef VERTEXCOLOR
- varying vec4 vColor;
- #endif
- #ifdef SP
- varying float vParticleViewProjZ;
- #endif
- #line 17
- void VS()
- {
- mat4 modelMatrix = iModelMatrix;
- vec3 worldPos = GetWorldPos(modelMatrix);
- gl_Position = GetClipPos(worldPos);
- vPosProj = vec4(worldPos, 1.0) * cViewProj;
- vScreenPos = GetScreenPosPreDiv(gl_Position);
- vFarRay = GetFarRay(gl_Position);
- vTexCoord = GetTexCoord(iTexCoord);
- vWorldPos = vec4(worldPos, GetDepth(gl_Position));
- #ifdef VERTEXCOLOR
- vColor = iColor;
- #endif
- #ifdef SP
- vParticleViewProjZ = gl_Position.z;
- //vParticleViewProjZ = gl_Position.z / gl_Position.w;
- //vParticleViewProjZ = GetDepth(gl_Position);
- //vParticleViewProjZ = gl_Position.w;
- #endif
- }
- void PS()
- {
- // Get material diffuse albedo
- #ifdef DIFFMAP
- vec4 diffColor = cMatDiffColor * texture2D(sDiffMap, vTexCoord);
- #ifdef ALPHAMASK
- if (diffColor.a < 0.5)
- discard;
- #endif
- #else
- vec4 diffColor = cMatDiffColor;
- #endif
- #ifdef VERTEXCOLOR
- diffColor *= vColor;
- #endif
- // Get fog factor
- #ifdef HEIGHTFOG
- float fogFactor = GetHeightFogFactor(vWorldPos.w, vWorldPos.y);
- #else
- float fogFactor = GetFogFactor(vWorldPos.w);
- #endif
- #if defined(PREPASS)
- // Fill light pre-pass G-Buffer
- gl_FragData[0] = vec4(0.5, 0.5, 0.5, 1.0);
- gl_FragData[1] = vec4(EncodeDepth(vWorldPos.w), 0.0);
- #elif defined(DEFERRED)
- gl_FragData[0] = vec4(GetFog(diffColor.rgb, fogFactor), diffColor.a);
- gl_FragData[1] = vec4(0.0, 0.0, 0.0, 0.0);
- gl_FragData[2] = vec4(0.5, 0.5, 0.5, 1.0);
- gl_FragData[3] = vec4(EncodeDepth(vWorldPos.w), 0.0);
- #else
- #ifdef OUTMRT01
- // diffuse
- gl_FragData[0] = vec4(GetFog(diffColor.rgb, fogFactor), diffColor.a);
- gl_FragData[1] = vec4(vParticleViewProjZ, 0, 0, 1.0);
- // depth
- #ifdef SP
- //gl_FragData[1] = vec4(vParticleViewProjZ, 0.0, 0.0, 0.0);
- #else
- //gl_FragData[1] = vec4(0.0, 0.0, 0.0, 0.0);
- #endif
- #else
- // VS :: vScreenPos = GetScreenPosPreDiv(gl_Position);
- float sceneZ = texture2D(sDepthBuffer, vScreenPos).r; // read depthstencil texture(readabledepth)
- float restoredSceneZ = ReconstructDepth(sceneZ); // to 0..1 range
- vec3 sceneWorldPos = vFarRay * restoredSceneZ; // restore worldpos of backgroud sceneZ
- vec4 sceneViewPos = vec4(sceneWorldPos, 1.0) * cProj; // restore viewproj of backgroud sceneZ
- float scale = 2.0;
- // calc difference between sceneZ and particleZ
- float diffZ = (sceneViewPos.z - vParticleViewProjZ) * scale;
- //float diffZ = (sceneViewPos.w - vWorldPos.z) * scale;
- float input = clamp(diffZ, 0.0, 1.0);
- float contrastPower = 1.0;
- float output = 0.5 * pow(clamp(2*((input > 0.5) ? 1 - input : input), 0.0, 1.0), contrastPower);
- float weight = (input > 0.5) ? 1 - output : output;
- diffColor.a *= weight;
- gl_FragColor = vec4(GetFog(diffColor.rgb, fogFactor), diffColor.a);
- #endif
- #endif
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement