| 19 | */ |
| 20 | |
| 21 | ShaderRef BuildFogShader() |
| 22 | { |
| 23 | /*const UInt8 fragmentSource[] = { |
| 24 | #include <Nazara/Graphics/Resources/DeferredShading/Shaders/FXAA.frag.h> |
| 25 | };*/ |
| 26 | |
| 27 | const char* fragmentSource = |
| 28 | "#version 140\n" |
| 29 | |
| 30 | "out vec4 RenderTarget0;\n" |
| 31 | |
| 32 | "uniform sampler2D ColorTexture;\n" |
| 33 | "uniform sampler2D GBuffer2;\n" |
| 34 | "uniform mat4 InvViewProjMatrix;\n" |
| 35 | "uniform vec2 InvTargetSize;\n" |
| 36 | "uniform vec3 EyePosition;\n" |
| 37 | |
| 38 | "float n = 0.1;" |
| 39 | "float f = 1000.0;" |
| 40 | |
| 41 | "float color_to_float(vec3 color)\n" |
| 42 | "{\n" |
| 43 | "const vec3 byte_to_float = vec3(1.0, 1.0/256, 1.0/(256*256));\n" |
| 44 | "return dot(color, byte_to_float);\n" |
| 45 | "}\n" |
| 46 | |
| 47 | "void main()\n" |
| 48 | "{" |
| 49 | "vec2 texCoord = gl_FragCoord.xy * InvTargetSize;\n" |
| 50 | "\t" "vec3 color = texture(ColorTexture, texCoord).xyz;\n" |
| 51 | "vec4 gVec2 = textureLod(GBuffer2, texCoord, 0.0);\n" |
| 52 | "float depth = color_to_float(gVec2.xyz)*2.0 - 1.0;\n" |
| 53 | "float linearDepth = (2 * n) / (f + n - depth * (f - n));" |
| 54 | |
| 55 | "vec3 viewSpace = vec3(texCoord*2.0 - 1.0, depth);\n" |
| 56 | |
| 57 | "vec4 worldPos = InvViewProjMatrix * vec4(viewSpace, 1.0);\n" |
| 58 | "worldPos.xyz /= worldPos.w;\n" |
| 59 | |
| 60 | /*"float lumThreshold = 0.1;" |
| 61 | "float lumMultipler = 2.0;" |
| 62 | //"float lumFactor = max(dot(color, vec3(0.299, 0.587, 0.114)) - lumThreshold, 0.0) / (1.0-lumThreshold);" |
| 63 | "float fogFactor = (1.0 - clamp(worldPos.y-2.0, 0.0, 1.0)) - lumFactor*lumMultipler;" |
| 64 | "fogFactor += (1.0 - clamp(EyePosition.y-2.5, 0.0, 1.0));" |
| 65 | "fogFactor = clamp(fogFactor, 0.0, 1.0);"*/ |
| 66 | |
| 67 | "float lumThreshold = 0.8;" |
| 68 | "float lumMultipler = 2.0;" |
| 69 | "float luminosity = dot(color, vec3(0.299, 0.587, 0.114));" |
| 70 | "float lumFactor = max(luminosity - lumThreshold, 0.0) / (1.0-lumThreshold);" |
| 71 | |
| 72 | "vec4 fogColor = vec4(0.5, 0.5, 0.5, 1.0);\n" |
| 73 | "vec2 fogrange = vec2(0, 50);\n" |
| 74 | "float fogeffect = clamp( 1.0 - (fogrange.y - linearDepth*0.5*f) / (fogrange.y - fogrange.x) , 0.0, 1.0 ) * fogColor.w;\n" |
| 75 | "fogeffect = max(fogeffect-lumFactor, 0.0);" |
| 76 | |
| 77 | //fogeffect*=(1.0 - int(depth)); |
| 78 | "\t" "vec3 fragmentColor = color*(1.0-fogeffect) + fogColor.rgb * fogeffect;\n" |
no test coverage detected