Commit f498cfb8 authored by 魔大农's avatar 魔大农

Improved input

parent 1535d014
This diff is collapsed.
This diff is collapsed.
<renderpath>
<rendertarget name="bright2" tag="BloomHDR" sizedivisor="2 2" format="rgba16f" filter="true" />
<rendertarget name="bright4" tag="BloomHDR" sizedivisor="4 4" format="rgba16f" filter="true" />
<rendertarget name="bright8" tag="BloomHDR" sizedivisor="8 8" format="rgba16f" filter="true" />
<rendertarget name="bright16" tag="BloomHDR" sizedivisor="16 16" format="rgba16f" filter="true" />
<rendertarget name="blur2" tag="BloomHDR" sizedivisor="2 2" format="rgba16f" filter="true" />
<rendertarget name="blur4" tag="BloomHDR" sizedivisor="4 4" format="rgba16f" filter="true" />
<rendertarget name="blur8" tag="BloomHDR" sizedivisor="8 8" format="rgba16f" filter="true" />
<rendertarget name="blur16" tag="BloomHDR" sizedivisor="16 16" format="rgba16f" filter="true" />
<command type="quad" tag="BloomHDR" vs="BloomHDR" ps="BloomHDR" vsdefines="BRIGHT" psdefines="BRIGHT" output="bright2">
<parameter name="BloomHDRThreshold" value="0.8" />
<texture unit="diffuse" name="viewport" />
</command>
<command type="quad" tag="BloomHDR" vs="CopyFramebuffer" ps="CopyFramebuffer" output="bright4">
<texture unit="diffuse" name="bright2" />
</command>
<command type="quad" tag="BloomHDR" vs="CopyFramebuffer" ps="CopyFramebuffer" output="bright8">
<texture unit="diffuse" name="bright4" />
</command>
<command type="quad" tag="BloomHDR" vs="CopyFramebuffer" ps="CopyFramebuffer" output="bright16">
<texture unit="diffuse" name="bright8" />
</command>
<command type="quad" tag="BloomHDR" vs="BloomHDR" ps="BloomHDR" vsdefines="BLUR16" psdefines="BLUR16" output="blur16">
<parameter name="BloomHDRBlurDir" value="1.0 0.0" />
<parameter name="BloomHDRBlurRadius" value="1.0" />
<parameter name="BloomHDRBlurSigma" value="2.0" />
<texture unit="diffuse" name="bright16" />
</command>
<command type="quad" tag="BloomHDR" vs="BloomHDR" ps="BloomHDR" vsdefines="BLUR16" psdefines="BLUR16" output="bright16">
<parameter name="BloomHDRBlurDir" value="0.0 1.0" />
<parameter name="BloomHDRBlurRadius" value="1.0" />
<parameter name="BloomHDRBlurSigma" value="2.0" />
<texture unit="diffuse" name="blur16" />
</command>
<command type="quad" tag="BloomHDR" vs="BloomHDR" ps="BloomHDR" vsdefines="COMBINE16" psdefines="COMBINE16" output="blur8">
<texture unit="diffuse" name="bright8" />
<texture unit="normal" name="bright16" />
</command>
<command type="quad" tag="BloomHDR" vs="BloomHDR" ps="BloomHDR" vsdefines="BLUR8" psdefines="BLUR8" output="bright8">
<parameter name="BloomHDRBlurDir" value="1.0 0.0" />
<parameter name="BloomHDRBlurRadius" value="1.0" />
<parameter name="BloomHDRBlurSigma" value="2.0" />
<texture unit="diffuse" name="blur8" />
</command>
<command type="quad" tag="BloomHDR" vs="BloomHDR" ps="BloomHDR" vsdefines="BLUR8" psdefines="BLUR8" output="blur8">
<parameter name="BloomHDRBlurDir" value="0.0 1.0" />
<parameter name="BloomHDRBlurRadius" value="1.0" />
<parameter name="BloomHDRBlurSigma" value="2.0" />
<texture unit="diffuse" name="bright8" />
</command>
<command type="quad" tag="BloomHDR" vs="BloomHDR" ps="BloomHDR" vsdefines="COMBINE8" psdefines="COMBINE8" output="blur4">
<texture unit="diffuse" name="bright4" />
<texture unit="normal" name="blur8" />
</command>
<command type="quad" tag="BloomHDR" vs="BloomHDR" ps="BloomHDR" vsdefines="BLUR4" psdefines="BLUR4" output="bright4">
<parameter name="BloomHDRBlurDir" value="1.0 0.0" />
<parameter name="BloomHDRBlurRadius" value="1.0" />
<parameter name="BloomHDRBlurSigma" value="2.0" />
<texture unit="diffuse" name="blur4" />
</command>
<command type="quad" tag="BloomHDR" vs="BloomHDR" ps="BloomHDR" vsdefines="BLUR4" psdefines="BLUR4" output="blur4">
<parameter name="BloomHDRBlurDir" value="0.0 1.0" />
<parameter name="BloomHDRBlurRadius" value="1.0" />
<parameter name="BloomHDRBlurSigma" value="2.0" />
<texture unit="diffuse" name="bright4" />
</command>
<command type="quad" tag="BloomHDR" vs="BloomHDR" ps="BloomHDR" vsdefines="COMBINE4" psdefines="COMBINE4" output="blur2">
<texture unit="diffuse" name="bright2" />
<texture unit="normal" name="blur4" />
</command>
<command type="quad" tag="BloomHDR" vs="BloomHDR" ps="BloomHDR" vsdefines="BLUR2" psdefines="BLUR2" output="bright2">
<parameter name="BloomHDRBlurDir" value="1.0 0.0" />
<parameter name="BloomHDRBlurRadius" value="1.0" />
<parameter name="BloomHDRBlurSigma" value="2.0" />
<texture unit="diffuse" name="blur2" />
</command>
<command type="quad" tag="BloomHDR" vs="BloomHDR" ps="BloomHDR" vsdefines="BLUR2" psdefines="BLUR2" output="blur2">
<parameter name="BloomHDRBlurDir" value="0.0 1.0" />
<parameter name="BloomHDRBlurRadius" value="1.0" />
<parameter name="BloomHDRBlurSigma" value="2.0" />
<texture unit="diffuse" name="bright2" />
</command>
<command type="quad" tag="BloomHDR" vs="BloomHDR" ps="BloomHDR" vsdefines="COMBINE2" psdefines="COMBINE2" output="viewport">
<parameter name="BloomHDRMix" value="1.0 0.4" />
<texture unit="diffuse" name="viewport" />
<texture unit="normal" name="blur2" />
</command>
</renderpath>
<renderpath>
<command type="quad" tag="FXAA3" vs="FXAA3" ps="FXAA3" psdefines="FXAA_QUALITY_PRESET=12" output="viewport">
<texture unit="diffuse" name="viewport" />
</command>
</renderpath>
<renderpath>
<rendertarget name="bright2" tag="BloomHDR" sizedivisor="2 2" format="rgba16f" filter="true" />
<rendertarget name="bright4" tag="BloomHDR" sizedivisor="4 4" format="rgba16f" filter="true" />
<rendertarget name="bright8" tag="BloomHDR" sizedivisor="8 8" format="rgba16f" filter="true" />
<rendertarget name="bright16" tag="BloomHDR" sizedivisor="16 16" format="rgba16f" filter="true" />
<rendertarget name="blur2" tag="BloomHDR" sizedivisor="2 2" format="rgba16f" filter="true" />
<rendertarget name="blur4" tag="BloomHDR" sizedivisor="4 4" format="rgba16f" filter="true" />
<rendertarget name="blur8" tag="BloomHDR" sizedivisor="8 8" format="rgba16f" filter="true" />
<rendertarget name="blur16" tag="BloomHDR" sizedivisor="16 16" format="rgba16f" filter="true" />
<command type="quad" tag="BloomHDR" vs="BloomHDR" ps="BloomHDR" vsdefines="BRIGHT" psdefines="BRIGHT" output="bright2">
<parameter name="BloomHDRThreshold" value="0.8" />
<texture unit="diffuse" name="viewport" />
</command>
<command type="quad" tag="BloomHDR" vs="CopyFramebuffer" ps="CopyFramebuffer" output="bright4">
<texture unit="diffuse" name="bright2" />
</command>
<command type="quad" tag="BloomHDR" vs="CopyFramebuffer" ps="CopyFramebuffer" output="bright8">
<texture unit="diffuse" name="bright4" />
</command>
<command type="quad" tag="BloomHDR" vs="CopyFramebuffer" ps="CopyFramebuffer" output="bright16">
<texture unit="diffuse" name="bright8" />
</command>
<command type="quad" tag="BloomHDR" vs="BloomHDR" ps="BloomHDR" vsdefines="BLUR16" psdefines="BLUR16" output="blur16">
<parameter name="BloomHDRBlurDir" value="1.0 0.0" />
<parameter name="BloomHDRBlurRadius" value="1.0" />
<parameter name="BloomHDRBlurSigma" value="2.0" />
<texture unit="diffuse" name="bright16" />
</command>
<command type="quad" tag="BloomHDR" vs="BloomHDR" ps="BloomHDR" vsdefines="BLUR16" psdefines="BLUR16" output="bright16">
<parameter name="BloomHDRBlurDir" value="0.0 1.0" />
<parameter name="BloomHDRBlurRadius" value="1.0" />
<parameter name="BloomHDRBlurSigma" value="2.0" />
<texture unit="diffuse" name="blur16" />
</command>
<command type="quad" tag="BloomHDR" vs="BloomHDR" ps="BloomHDR" vsdefines="COMBINE16" psdefines="COMBINE16" output="blur8">
<texture unit="diffuse" name="bright8" />
<texture unit="normal" name="bright16" />
</command>
<command type="quad" tag="BloomHDR" vs="BloomHDR" ps="BloomHDR" vsdefines="BLUR8" psdefines="BLUR8" output="bright8">
<parameter name="BloomHDRBlurDir" value="1.0 0.0" />
<parameter name="BloomHDRBlurRadius" value="1.0" />
<parameter name="BloomHDRBlurSigma" value="2.0" />
<texture unit="diffuse" name="blur8" />
</command>
<command type="quad" tag="BloomHDR" vs="BloomHDR" ps="BloomHDR" vsdefines="BLUR8" psdefines="BLUR8" output="blur8">
<parameter name="BloomHDRBlurDir" value="0.0 1.0" />
<parameter name="BloomHDRBlurRadius" value="1.0" />
<parameter name="BloomHDRBlurSigma" value="2.0" />
<texture unit="diffuse" name="bright8" />
</command>
<command type="quad" tag="BloomHDR" vs="BloomHDR" ps="BloomHDR" vsdefines="COMBINE8" psdefines="COMBINE8" output="blur4">
<texture unit="diffuse" name="bright4" />
<texture unit="normal" name="blur8" />
</command>
<command type="quad" tag="BloomHDR" vs="BloomHDR" ps="BloomHDR" vsdefines="BLUR4" psdefines="BLUR4" output="bright4">
<parameter name="BloomHDRBlurDir" value="1.0 0.0" />
<parameter name="BloomHDRBlurRadius" value="1.0" />
<parameter name="BloomHDRBlurSigma" value="2.0" />
<texture unit="diffuse" name="blur4" />
</command>
<command type="quad" tag="BloomHDR" vs="BloomHDR" ps="BloomHDR" vsdefines="BLUR4" psdefines="BLUR4" output="blur4">
<parameter name="BloomHDRBlurDir" value="0.0 1.0" />
<parameter name="BloomHDRBlurRadius" value="1.0" />
<parameter name="BloomHDRBlurSigma" value="2.0" />
<texture unit="diffuse" name="bright4" />
</command>
<command type="quad" tag="BloomHDR" vs="BloomHDR" ps="BloomHDR" vsdefines="COMBINE4" psdefines="COMBINE4" output="blur2">
<texture unit="diffuse" name="bright2" />
<texture unit="normal" name="blur4" />
</command>
<command type="quad" tag="BloomHDR" vs="BloomHDR" ps="BloomHDR" vsdefines="BLUR2" psdefines="BLUR2" output="bright2">
<parameter name="BloomHDRBlurDir" value="1.0 0.0" />
<parameter name="BloomHDRBlurRadius" value="1.0" />
<parameter name="BloomHDRBlurSigma" value="2.0" />
<texture unit="diffuse" name="blur2" />
</command>
<command type="quad" tag="BloomHDR" vs="BloomHDR" ps="BloomHDR" vsdefines="BLUR2" psdefines="BLUR2" output="blur2">
<parameter name="BloomHDRBlurDir" value="0.0 1.0" />
<parameter name="BloomHDRBlurRadius" value="1.0" />
<parameter name="BloomHDRBlurSigma" value="2.0" />
<texture unit="diffuse" name="bright2" />
</command>
<command type="quad" tag="BloomHDR" vs="BloomHDR" ps="BloomHDR" vsdefines="COMBINE2" psdefines="COMBINE2" output="viewport">
<parameter name="BloomHDRMix" value="1.0 0.4" />
<texture unit="diffuse" name="viewport" />
<texture unit="normal" name="blur2" />
</command>
</renderpath>
<renderpath>
<command type="quad" tag="FXAA3" vs="FXAA3" ps="FXAA3" psdefines="FXAA_QUALITY_PRESET=12" output="viewport">
<texture unit="diffuse" name="viewport" />
</command>
</renderpath>
<renderpath>
<command type="clear" color="fog" depth="1.0" stencil="0" />
<command type="scenepass" pass="base" vertexlights="true" metadata="base" />
<command type="forwardlights" pass="light" />
<command type="scenepass" pass="postopaque" />
<command type="scenepass" pass="refract">
<texture unit="environment" name="viewport" />
</command>
<command type="scenepass" pass="alpha" vertexlights="true" sort="backtofront" metadata="alpha" />
<command type="scenepass" pass="postalpha" sort="backtofront" />
</renderpath>
\ No newline at end of file
#include "Uniforms.glsl"
#include "Samplers.glsl"
#include "Transform.glsl"
#include "ScreenPos.glsl"
#include "PostProcess.glsl"
varying vec2 vTexCoord;
varying vec2 vScreenPos;
#ifdef COMPILEPS
uniform float cBloomHDRThreshold;
uniform float cBloomHDRBlurSigma;
uniform float cBloomHDRBlurRadius;
uniform vec2 cBloomHDRBlurDir;
uniform vec2 cBloomHDRMix;
uniform vec2 cBright2InvSize;
uniform vec2 cBright4InvSize;
uniform vec2 cBright8InvSize;
uniform vec2 cBright16InvSize;
const int BlurKernelSize = 5;
#endif
void VS()
{
mat4 modelMatrix = iModelMatrix;
vec3 worldPos = GetWorldPos(modelMatrix);
gl_Position = GetClipPos(worldPos);
vTexCoord = GetQuadTexCoord(gl_Position);
vScreenPos = GetScreenPosPreDiv(gl_Position);
}
void PS()
{
#ifdef BRIGHT
vec3 color = texture2D(sDiffMap, vScreenPos).rgb;
gl_FragColor = vec4(max(color - cBloomHDRThreshold, 0.0), 1.0);
#endif
#ifdef BLUR16
gl_FragColor = GaussianBlur(BlurKernelSize, cBloomHDRBlurDir, cBright16InvSize * cBloomHDRBlurRadius, cBloomHDRBlurSigma, sDiffMap, vScreenPos);
#endif
#ifdef BLUR8
gl_FragColor = GaussianBlur(BlurKernelSize, cBloomHDRBlurDir, cBright8InvSize * cBloomHDRBlurRadius, cBloomHDRBlurSigma, sDiffMap, vScreenPos);
#endif
#ifdef BLUR4
gl_FragColor = GaussianBlur(BlurKernelSize, cBloomHDRBlurDir, cBright4InvSize * cBloomHDRBlurRadius, cBloomHDRBlurSigma, sDiffMap, vScreenPos);
#endif
#ifdef BLUR2
gl_FragColor = GaussianBlur(BlurKernelSize, cBloomHDRBlurDir, cBright2InvSize * cBloomHDRBlurRadius, cBloomHDRBlurSigma, sDiffMap, vScreenPos);
#endif
#ifdef COMBINE16
gl_FragColor = texture2D(sDiffMap, vScreenPos) + texture2D(sNormalMap, vTexCoord);
#endif
#ifdef COMBINE8
gl_FragColor = texture2D(sDiffMap, vScreenPos) + texture2D(sNormalMap, vTexCoord);
#endif
#ifdef COMBINE4
gl_FragColor = texture2D(sDiffMap, vScreenPos) + texture2D(sNormalMap, vTexCoord);
#endif
#ifdef COMBINE2
vec3 color = texture2D(sDiffMap, vScreenPos).rgb * cBloomHDRMix.x;
vec3 bloom = texture2D(sNormalMap, vTexCoord).rgb * cBloomHDRMix.y;
gl_FragColor = vec4(color + bloom, 1.0);
#endif
}
#include "Uniforms.glsl"
#include "Samplers.glsl"
#include "Transform.glsl"
#include "ScreenPos.glsl"
varying vec2 vScreenPos;
void VS()
{
mat4 modelMatrix = iModelMatrix;
vec3 worldPos = GetWorldPos(modelMatrix);
gl_Position = GetClipPos(worldPos);
vScreenPos = GetScreenPosPreDiv(gl_Position);
}
void PS()
{
gl_FragColor = texture2D(sDiffMap, vScreenPos);
}
This diff is collapsed.
#ifdef COMPILEPS
vec3 GetFog(vec3 color, float fogFactor)
{
return mix(cFogColor, color, fogFactor);
}
vec3 GetLitFog(vec3 color, float fogFactor)
{
return color * fogFactor;
}
float GetFogFactor(float depth)
{
return clamp((cFogParams.x - depth) * cFogParams.y, 0.0, 1.0);
}
float GetHeightFogFactor(float depth, float height)
{
float fogFactor = GetFogFactor(depth);
float heightFogFactor = (height - cFogParams.z) * cFogParams.w;
heightFogFactor = 1.0 - clamp(exp(-(heightFogFactor * heightFogFactor)), 0.0, 1.0);
return min(heightFogFactor, fogFactor);
}
#endif
This diff is collapsed.
#include "Uniforms.glsl"
#include "Samplers.glsl"
#include "Transform.glsl"
#include "ScreenPos.glsl"
#include "Lighting.glsl"
#include "Fog.glsl"
#ifdef NORMALMAP
varying vec4 vTexCoord;
varying vec4 vTangent;
#else
varying vec2 vTexCoord;
#endif
varying vec3 vNormal;
varying vec4 vWorldPos;
#ifdef VERTEXCOLOR
varying vec4 vColor;
#endif
#ifdef PERPIXEL
#ifdef SHADOW
varying vec4 vShadowPos[NUMCASCADES];
#endif
#ifdef SPOTLIGHT
varying vec4 vSpotPos;
#endif
#ifdef POINTLIGHT
varying vec3 vCubeMaskVec;
#endif
#else
varying vec3 vVertexLight;
varying vec4 vScreenPos;
#ifdef ENVCUBEMAP
varying vec3 vReflectionVec;
#endif
#if defined(LIGHTMAP) || defined(AO)
varying vec2 vTexCoord2;
#endif
#endif
void VS()
{
mat4 modelMatrix = iModelMatrix;
vec3 worldPos = GetWorldPos(modelMatrix);
gl_Position = GetClipPos(worldPos);
vNormal = GetWorldNormal(modelMatrix);
vWorldPos = vec4(worldPos, GetDepth(gl_Position));
#ifdef VERTEXCOLOR
vColor = iColor;
#endif
#ifdef NORMALMAP
vec3 tangent = GetWorldTangent(modelMatrix);
vec3 bitangent = cross(tangent, vNormal) * iTangent.w;
vTexCoord = vec4(GetTexCoord(iTexCoord), bitangent.xy);
vTangent = vec4(tangent, bitangent.z);
#else
vTexCoord = GetTexCoord(iTexCoord);
#endif
#ifdef PERPIXEL
// Per-pixel forward lighting
vec4 projWorldPos = vec4(worldPos, 1.0);
#ifdef SHADOW
// Shadow projection: transform from world space to shadow space
for (int i = 0; i < NUMCASCADES; i++)
vShadowPos[i] = GetShadowPos(i, vNormal, projWorldPos);
#endif
#ifdef SPOTLIGHT
// Spotlight projection: transform from world space to projector texture coordinates
vSpotPos = projWorldPos * cLightMatrices[0];
#endif
#ifdef POINTLIGHT
vCubeMaskVec = (worldPos - cLightPos.xyz) * mat3(cLightMatrices[0][0].xyz, cLightMatrices[0][1].xyz, cLightMatrices[0][2].xyz);
#endif
#else
// Ambient & per-vertex lighting
#if defined(LIGHTMAP) || defined(AO)
// If using lightmap, disregard zone ambient light
// If using AO, calculate ambient in the PS
vVertexLight = vec3(0.0, 0.0, 0.0);
vTexCoord2 = iTexCoord1;
#else
vVertexLight = GetAmbient(GetZonePos(worldPos));
#endif
#ifdef NUMVERTEXLIGHTS
for (int i = 0; i < NUMVERTEXLIGHTS; ++i)
vVertexLight += GetVertexLight(i, worldPos, vNormal) * cVertexLights[i * 3].rgb;
#endif
vScreenPos = GetScreenPos(gl_Position);
#ifdef ENVCUBEMAP
vReflectionVec = worldPos - cCameraPos;
#endif
#endif
}
void PS()
{
// Get material diffuse albedo
#ifdef DIFFMAP
vec4 diffInput = texture2D(sDiffMap, vTexCoord.xy);
#ifdef ALPHAMASK
if (diffInput.a < 0.5)
discard;
#endif
vec4 diffColor = cMatDiffColor * diffInput;
#else
vec4 diffColor = cMatDiffColor;
#endif
#ifdef VERTEXCOLOR
diffColor *= vColor;
#endif
// Get material specular albedo
#ifdef SPECMAP
vec3 specColor = cMatSpecColor.rgb * texture2D(sSpecMap, vTexCoord.xy).rgb;
#else
vec3 specColor = cMatSpecColor.rgb;
#endif
// Get normal
#ifdef NORMALMAP
mat3 tbn = mat3(vTangent.xyz, vec3(vTexCoord.zw, vTangent.w), vNormal);
vec3 normal = normalize(tbn * DecodeNormal(texture2D(sNormalMap, vTexCoord.xy)));
#else
vec3 normal = normalize(vNormal);
#endif
// Get fog factor
#ifdef HEIGHTFOG
float fogFactor = GetHeightFogFactor(vWorldPos.w, vWorldPos.y);
#else
float fogFactor = GetFogFactor(vWorldPos.w);
#endif
#if defined(PERPIXEL)
// Per-pixel forward lighting
vec3 lightColor;
vec3 lightDir;
vec3 finalColor;
float diff = GetDiffuse(normal, vWorldPos.xyz, lightDir);
#ifdef SHADOW
diff *= GetShadow(vShadowPos, vWorldPos.w);
#endif
#if defined(SPOTLIGHT)
lightColor = vSpotPos.w > 0.0 ? texture2DProj(sLightSpotMap, vSpotPos).rgb * cLightColor.rgb : vec3(0.0, 0.0, 0.0);
#elif defined(CUBEMASK)
lightColor = textureCube(sLightCubeMap, vCubeMaskVec).rgb * cLightColor.rgb;
#else
lightColor = cLightColor.rgb;
#endif
#ifdef SPECULAR
float spec = GetSpecular(normal, cCameraPosPS - vWorldPos.xyz, lightDir, cMatSpecColor.a);
finalColor = diff * lightColor * (diffColor.rgb + spec * specColor * cLightColor.a);
#else
finalColor = diff * lightColor * diffColor.rgb;
#endif
#ifdef AMBIENT
finalColor += cAmbientColor * diffColor.rgb;
finalColor += cMatEmissiveColor;
gl_FragColor = vec4(GetFog(finalColor, fogFactor), diffColor.a);
#else
gl_FragColor = vec4(GetLitFog(finalColor, fogFactor), diffColor.a);
#endif
#elif defined(PREPASS)
// Fill light pre-pass G-Buffer
float specPower = cMatSpecColor.a / 255.0;
gl_FragData[0] = vec4(normal * 0.5 + 0.5, specPower);
gl_FragData[1] = vec4(EncodeDepth(vWorldPos.w), 0.0);
#elif defined(DEFERRED)
// Fill deferred G-buffer
float specIntensity = specColor.g;
float specPower = cMatSpecColor.a / 255.0;
vec3 finalColor = vVertexLight * diffColor.rgb;
#ifdef AO
// If using AO, the vertex light ambient is black, calculate occluded ambient here
finalColor += texture2D(sEmissiveMap, vTexCoord2).rgb * cAmbientColor * diffColor.rgb;
#endif
#ifdef ENVCUBEMAP
finalColor += cMatEnvMapColor * textureCube(sEnvCubeMap, reflect(vReflectionVec, normal)).rgb;
#endif
#ifdef LIGHTMAP
finalColor += texture2D(sEmissiveMap, vTexCoord2).rgb * diffColor.rgb;
#endif
#ifdef EMISSIVEMAP
finalColor += cMatEmissiveColor * texture2D(sEmissiveMap, vTexCoord.xy).rgb;
#else
finalColor += cMatEmissiveColor;
#endif
gl_FragData[0] = vec4(GetFog(finalColor, fogFactor), 1.0);
gl_FragData[1] = fogFactor * vec4(diffColor.rgb, specIntensity);
gl_FragData[2] = vec4(normal * 0.5 + 0.5, specPower);
gl_FragData[3] = vec4(EncodeDepth(vWorldPos.w), 0.0);
#else
// Ambient & per-vertex lighting
vec3 finalColor = vVertexLight * diffColor.rgb;
#ifdef AO
// If using AO, the vertex light ambient is black, calculate occluded ambient here
finalColor += texture2D(sEmissiveMap, vTexCoord2).rgb * cAmbientColor * diffColor.rgb;
#endif
#ifdef MATERIAL
// Add light pre-pass accumulation result
// Lights are accumulated at half intensity. Bring back to full intensity now
vec4 lightInput = 2.0 * texture2DProj(sLightBuffer, vScreenPos);
vec3 lightSpecColor = lightInput.a * lightInput.rgb / max(GetIntensity(lightInput.rgb), 0.001);
finalColor += lightInput.rgb * diffColor.rgb + lightSpecColor * specColor;
#endif
#ifdef ENVCUBEMAP
finalColor += cMatEnvMapColor * textureCube(sEnvCubeMap, reflect(vReflectionVec, normal)).rgb;
#endif
#ifdef LIGHTMAP
finalColor += texture2D(sEmissiveMap, vTexCoord2).rgb * diffColor.rgb;
#endif
#ifdef EMISSIVEMAP
finalColor += cMatEmissiveColor * texture2D(sEmissiveMap, vTexCoord.xy).rgb;
#else
finalColor += cMatEmissiveColor;
#endif
gl_FragColor = vec4(GetFog(finalColor, fogFactor), diffColor.a);
#endif
}
#ifdef COMPILEPS
const float PI = 3.14159265;
vec2 Noise(vec2 coord)
{
float noiseX = clamp(fract(sin(dot(coord, vec2(12.9898, 78.233))) * 43758.5453), 0.0, 1.0);
float noiseY = clamp(fract(sin(dot(coord, vec2(12.9898, 78.233) * 2.0)) * 43758.5453), 0.0, 1.0);
return vec2(noiseX, noiseY);
}
// Adapted: http://callumhay.blogspot.com/2010/09/gaussian-blur-shader-glsl.html
vec4 GaussianBlur(int blurKernelSize, vec2 blurDir, vec2 blurRadius, float sigma, sampler2D texSampler, vec2 texCoord)
{
int blurKernelSizeHalfSize = blurKernelSize / 2;
// Incremental Gaussian Coefficent Calculation (See GPU Gems 3 pp. 877 - 889)
vec3 gaussCoeff;
gaussCoeff.x = 1.0 / (sqrt(2.0 * PI) * sigma);
gaussCoeff.y = exp(-0.5 / (sigma * sigma));
gaussCoeff.z = gaussCoeff.y * gaussCoeff.y;
vec2 blurVec = blurRadius * blurDir;
vec4 avgValue = vec4(0.0);
float gaussCoeffSum = 0.0;
avgValue += texture2D(texSampler, texCoord) * gaussCoeff.x;
gaussCoeffSum += gaussCoeff.x;
gaussCoeff.xy *= gaussCoeff.yz;
for (int i = 1; i <= blurKernelSizeHalfSize; i++)
{
avgValue += texture2D(texSampler, texCoord - float(i) * blurVec) * gaussCoeff.x;
avgValue += texture2D(texSampler, texCoord + float(i) * blurVec) * gaussCoeff.x;
gaussCoeffSum += 2.0 * gaussCoeff.x;
gaussCoeff.xy *= gaussCoeff.yz;
}
return avgValue / gaussCoeffSum;
}
const vec3 LumWeights = vec3(0.2126, 0.7152, 0.0722);
vec3 ReinhardEq3Tonemap(vec3 x)
{
return x / (1.0 + x);
}
vec3 ReinhardEq4Tonemap(vec3 x, float white)
{
return x * (1.0 + x / white) / (1.0 + x);
}
// Unchared2 tone mapping (See http://filmicgames.com)
const float A = 0.15;
const float B = 0.50;
const float C = 0.10;
const float D = 0.20;
const float E = 0.02;
const float F = 0.30;
vec3 Uncharted2Tonemap(vec3 x)
{
return ((x*(A*x+C*B)+D*E)/(x*(A*x+B)+D*F))-E/F;
}
#ifndef GL_ES
vec3 ColorCorrection(vec3 color, sampler3D lut)
{
float lutSize = 16.0;
float scale = (lutSize - 1.0) / lutSize;
float offset = 1.0 / (2.0 * lutSize);
return texture3D(lut, clamp(color, 0.0, 1.0) * scale + offset).rgb;
}
#endif
const float Gamma = 2.2;
const float InverseGamma = 1.0 / 2.2;
vec3 ToGamma(vec3 color)
{
return vec3(pow(color.r, Gamma), pow(color.g, Gamma), pow(color.b, Gamma));
}
vec3 ToInverseGamma(vec3 color)
{
return vec3(pow(color.r, InverseGamma), pow(color.g, InverseGamma), pow(color.b, InverseGamma));
}
#endif
#ifdef COMPILEPS
uniform sampler2D sDiffMap;
uniform samplerCube sDiffCubeMap;
uniform sampler2D sNormalMap;
uniform sampler2D sSpecMap;
uniform sampler2D sEmissiveMap;
uniform sampler2D sEnvMap;
uniform samplerCube sEnvCubeMap;
uniform sampler2D sLightRampMap;
uniform sampler2D sLightSpotMap;
uniform samplerCube sLightCubeMap;
#ifndef GL_ES
uniform sampler3D sVolumeMap;
uniform sampler2D sAlbedoBuffer;
uniform sampler2D sNormalBuffer;
uniform sampler2D sDepthBuffer;
uniform sampler2D sLightBuffer;
#ifdef VSM_SHADOW
uniform sampler2D sShadowMap;
#else
uniform sampler2DShadow sShadowMap;