Commit 70cb7134 authored by 魔大农's avatar 魔大农 🍀

Tried to switch to PBR... and failed

parent 21cb9d48
<material>
<technique name="Techniques/DiffNormalPackedEnvCube.xml" quality="1" />
<technique name="Techniques/Diff.xml" quality="0" />
<technique name="Techniques/DiffNormalPackedEnvCube.xml" quality="0" />
<texture unit="diffuse" name="Textures/StoneDiffuse.dds" />
<texture unit="normal" name="Textures/StoneNormal.dds" />
<texture unit="environment" name="Textures/LeafyKnoll.xml" />
<parameter name="MatDiffColor" value="1.0 0.0 0.0 1" />
<parameter name="MatEnvMapColor" value="0.08 0.1 0.08" />
<!--texture unit="environment" name="Textures/LeafyKnoll.xml" /-->
<parameter name="MatDiffColor" value="1.0 0.0 0.0 1" />
<parameter name="MatEnvMapColor" value="0.08 0.1 0.08" />
<parameter name="MatSpecColor" value="0.23 0.23 0.27 23" />
</material>
\ No newline at end of file
<parameter name="Roughness" value="0.1" />
<parameter name="Metallic" value="0.3" />
</material>
......@@ -7,4 +7,13 @@
<parameter name="MatEmissiveColor" value="0 0 0" />
<parameter name="MatEnvMapColor" value="0.05 0.05 0.05" />
<parameter name="MatSpecColor" value="0.32 0.35 0.3 5" />
<parameter name="Roughness" value="0.4" />
<parameter name="Metallic" value="0.5" />
<cull value="ccw" />
<shadowcull value="ccw" />
<fill value="solid" />
<depthbias constant="0" slopescaled="0" />
<alphatocoverage enable="false" />
<renderorder value="128" />
<occlusion enable="true" />
</material>
......@@ -7,4 +7,13 @@
<parameter name="MatEmissiveColor" value="0 0 0" />
<parameter name="MatEnvMapColor" value="0.4 0.5 0.4" />
<parameter name="MatSpecColor" value="0.3 0.3 0.3 5" />
<parameter name="Roughness" value="0.4" />
<parameter name="Metallic" value="0.5" />
<cull value="ccw" />
<shadowcull value="ccw" />
<fill value="solid" />
<depthbias constant="0" slopescaled="0" />
<alphatocoverage enable="false" />
<renderorder value="128" />
<occlusion enable="true" />
</material>
<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>
File mode changed from 100755 to 100644
#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 cAutoExposureAdaptRate;
uniform vec2 cAutoExposureLumRange;
uniform float cAutoExposureMiddleGrey;
uniform vec2 cHDR128InvSize;
uniform vec2 cLum64InvSize;
uniform vec2 cLum16InvSize;
uniform vec2 cLum4InvSize;
float GatherAvgLum(sampler2D texSampler, vec2 texCoord, vec2 texelSize)
{
float lumAvg = 0.0;
lumAvg += texture2D(texSampler, texCoord + vec2(1.0, -1.0) * texelSize).r;
lumAvg += texture2D(texSampler, texCoord + vec2(-1.0, 1.0) * texelSize).r;
lumAvg += texture2D(texSampler, texCoord + vec2(1.0, 1.0) * texelSize).r;
lumAvg += texture2D(texSampler, texCoord + vec2(1.0, -1.0) * texelSize).r;
return lumAvg / 4.0;
}
#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 LUMINANCE64
float logLumSum = 0.0;
logLumSum += log(dot(texture2D(sDiffMap, vTexCoord + vec2(-1.0, -1.0) * cHDR128InvSize).rgb, LumWeights) + 1e-5);
logLumSum += log(dot(texture2D(sDiffMap, vTexCoord + vec2(-1.0, 1.0) * cHDR128InvSize).rgb, LumWeights) + 1e-5);
logLumSum += log(dot(texture2D(sDiffMap, vTexCoord + vec2(1.0, 1.0) * cHDR128InvSize).rgb, LumWeights) + 1e-5);
logLumSum += log(dot(texture2D(sDiffMap, vTexCoord + vec2(1.0, -1.0) * cHDR128InvSize).rgb, LumWeights) + 1e-5);
gl_FragColor.r = logLumSum;
#endif
#ifdef LUMINANCE16
gl_FragColor.r = GatherAvgLum(sDiffMap, vTexCoord, cLum64InvSize);
#endif
#ifdef LUMINANCE4
gl_FragColor.r = GatherAvgLum(sDiffMap, vTexCoord, cLum16InvSize);
#endif
#ifdef LUMINANCE1
gl_FragColor.r = exp(GatherAvgLum(sDiffMap, vTexCoord, cLum4InvSize) / 16.0);
#endif
#ifdef ADAPTLUMINANCE
float adaptedLum = texture2D(sDiffMap, vTexCoord).r;
float lum = clamp(texture2D(sNormalMap, vTexCoord).r, cAutoExposureLumRange.x, cAutoExposureLumRange.y);
gl_FragColor.r = adaptedLum + (lum - adaptedLum) * (1.0 - exp(-cDeltaTimePS * cAutoExposureAdaptRate));
#endif
#ifdef EXPOSE
vec3 color = texture2D(sDiffMap, vScreenPos).rgb;
float adaptedLum = texture2D(sNormalMap, vTexCoord).r;
gl_FragColor = vec4(color * (cAutoExposureMiddleGrey / adaptedLum), 1.0);
#endif
}
#line 20001
#ifdef COMPILEPS
#ifdef PBR
// Following BRDF methods are based upon research Frostbite EA
//[Lagrade et al. 2014, "Moving Frostbite to Physically Based Rendering"]
//Schlick Fresnel
//specular = the rgb specular color value of the pixel
//VdotH = the dot product of the camera view direction and the half vector
vec3 SchlickFresnel(vec3 specular, float VdotH)
{
return specular + (vec3(1.0, 1.0, 1.0) - specular) * pow(1.0 - VdotH, 5.0);
}
//Schlick Gaussian Fresnel
//specular = the rgb specular color value of the pixel
//VdotH = the dot product of the camera view direction and the half vector
vec3 SchlickGaussianFresnel(in vec3 specular, in float VdotH)
{
float sphericalGaussian = pow(2.0, (-5.55473 * VdotH - 6.98316) * VdotH);
return specular + (vec3(1.0, 1.0, 1.0) - specular) * sphericalGaussian;
}
//Get Fresnel
//specular = the rgb specular color value of the pixel
//VdotH = the dot product of the camera view direction and the half vector
vec3 Fresnel(vec3 specular, float VdotH)
{
return SchlickFresnel(specular, VdotH);
}
// Smith GGX corrected Visibility
// NdotL = the dot product of the normal and direction to the light
// NdotV = the dot product of the normal and the camera view direction
// roughness = the roughness of the pixel
float SmithGGXSchlickVisibility(float NdotL, float NdotV, float roughness)
{
float rough2 = roughness * roughness;
float lambdaV = NdotL * sqrt((-NdotV * rough2 + NdotV) * NdotV + rough2);
float lambdaL = NdotV * sqrt((-NdotL * rough2 + NdotL) * NdotL + rough2);
return 0.5 / (lambdaV + lambdaL);
}
// Get Visibility
// NdotL = the dot product of the normal and direction to the light
// NdotV = the dot product of the normal and the camera view direction
// roughness = the roughness of the pixel
float Visibility(float NdotL, float NdotV, float roughness)
{
return SmithGGXSchlickVisibility(NdotL, NdotV, roughness);
}
// Blinn Distribution
// NdotH = the dot product of the normal and the half vector
// roughness = the roughness of the pixel
float BlinnPhongDistribution(in float NdotH, in float roughness)
{
float specPower = max((2.0 / (roughness * roughness)) - 2.0, 1e-4); // Calculate specular power from roughness
return pow(clamp(NdotH, 0.0, 1.0), specPower);
}
// Beckmann Distribution
// NdotH = the dot product of the normal and the half vector
// roughness = the roughness of the pixel
float BeckmannDistribution(in float NdotH, in float roughness)
{
float rough2 = roughness * roughness;
float roughnessA = 1.0 / (4.0 * rough2 * pow(NdotH, 4.0));
float roughnessB = NdotH * NdotH - 1.0;
float roughnessC = rough2 * NdotH * NdotH;
return roughnessA * exp(roughnessB / roughnessC);
}
// GGX Distribution
// NdotH = the dot product of the normal and the half vector
// roughness = the roughness of the pixel
float GGXDistribution(float NdotH, float roughness)
{
float rough2 = roughness * roughness;
float tmp = (NdotH * rough2 - NdotH) * NdotH + 1.0;
return rough2 / (tmp * tmp);
}
// Get Distribution
// NdotH = the dot product of the normal and the half vector
// roughness = the roughness of the pixel
float Distribution(float NdotH, float roughness)
{
return GGXDistribution(NdotH, roughness);
}
// Lambertian Diffuse
// diffuseColor = the rgb color value of the pixel
// roughness = the roughness of the pixel
// NdotV = the normal dot with the camera view direction
// NdotL = the normal dot with the light direction
// VdotH = the camera view direction dot with the half vector
vec3 LambertianDiffuse(vec3 diffuseColor, float NdotL)
{
return diffuseColor * NdotL;
}
// Burley Diffuse
// diffuseColor = the rgb color value of the pixel
// roughness = the roughness of the pixel
// NdotV = the normal dot with the camera view direction
// NdotL = the normal dot with the light direction
// VdotH = the camera view direction dot with the half vector
vec3 BurleyDiffuse(vec3 diffuseColor, float roughness, float NdotV, float NdotL, float VdotH)
{
float energyBias = mix(roughness, 0.0, 0.5);
float energyFactor = mix(roughness, 1.0, 1.0 / 1.51);
float fd90 = energyBias + 2.0 * VdotH * VdotH * roughness;
float f0 = 1.0;
float lightScatter = f0 + (fd90 - f0) * pow(1.0 - NdotL, 5.0);
float viewScatter = f0 + (fd90 - f0) * pow(1.0 - NdotV, 5.0);
return diffuseColor * lightScatter * viewScatter * energyFactor;
}
//Get Diffuse
// diffuseColor = the rgb color value of the pixel
// roughness = the roughness of the pixel
// NdotV = the normal dot with the camera view direction
// NdotL = the normal dot with the light direction
// VdotH = the camera view direction dot with the half vector
vec3 Diffuse(vec3 diffuseColor, float roughness, float NdotV, float NdotL, float VdotH)
{
//return LambertianDiffuse(diffuseColor, NdotL);
return BurleyDiffuse(diffuseColor, roughness, NdotV, NdotL, VdotH);
}
#endif
#endif
#include "Uniforms.glsl"
#include "Samplers.glsl"
#include "Transform.glsl"
#if defined(DIFFMAP) || defined(ALPHAMAP)
varying vec2 vTexCoord;
#endif
#ifdef VERTEXCOLOR
varying vec4 vColor;
#endif
void VS()
{
mat4 modelMatrix = iModelMatrix;
vec3 worldPos = GetWorldPos(modelMatrix);
gl_Position = GetClipPos(worldPos);
#ifdef DIFFMAP
vTexCoord = iTexCoord;
#endif
#ifdef VERTEXCOLOR
vColor = iColor;
#endif
}
void PS()
{
vec4 diffColor = cMatDiffColor;
#ifdef VERTEXCOLOR
diffColor *= vColor;
#endif
#if (!defined(DIFFMAP)) && (!defined(ALPHAMAP))
gl_FragColor = diffColor;
#endif
#ifdef DIFFMAP
vec4 diffInput = texture2D(sDiffMap, vTexCoord);
#ifdef ALPHAMASK
if (diffInput.a < 0.5)
discard;
#endif
gl_FragColor = diffColor * diffInput;
#endif
#ifdef ALPHAMAP
#ifdef GL3
float alphaInput = texture2D(sDiffMap, vTexCoord).r;
#else
float alphaInput = texture2D(sDiffMap, vTexCoord).a;
#endif
gl_FragColor = vec4(diffColor.rgb, diffColor.a * alphaInput);
#endif
}
#include "Uniforms.glsl"
#include "Samplers.glsl"
#include "Transform.glsl"
#include "ScreenPos.glsl"
varying vec2 vTexCoord;
varying vec2 vScreenPos;
#ifdef COMPILEPS
uniform float cBloomThreshold;
uniform vec2 cBloomMix;
uniform vec2 cBlurHInvSize;
#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 rgb = texture2D(sDiffMap, vScreenPos).rgb;
gl_FragColor = vec4((rgb - vec3(cBloomThreshold, cBloomThreshold, cBloomThreshold)) / (1.0 - cBloomThreshold), 1.0);
#endif
#ifdef BLURH
vec3 rgb = texture2D(sDiffMap, vTexCoord + vec2(-2.0, 0.0) * cBlurHInvSize).rgb * 0.1;
rgb += texture2D(sDiffMap, vTexCoord + vec2(-1.0, 0.0) * cBlurHInvSize).rgb * 0.25;
rgb += texture2D(sDiffMap, vTexCoord + vec2(0.0, 0.0) * cBlurHInvSize).rgb * 0.3;
rgb += texture2D(sDiffMap, vTexCoord + vec2(1.0, 0.0) * cBlurHInvSize).rgb * 0.25;
rgb += texture2D(sDiffMap, vTexCoord + vec2(2.0, 0.0) * cBlurHInvSize).rgb * 0.1;
gl_FragColor = vec4(rgb, 1.0);
#endif
#ifdef BLURV
vec3 rgb = texture2D(sDiffMap, vTexCoord + vec2(0.0, -2.0) * cBlurHInvSize).rgb * 0.1;
rgb += texture2D(sDiffMap, vTexCoord + vec2(0.0, -1.0) * cBlurHInvSize).rgb * 0.25;
rgb += texture2D(sDiffMap, vTexCoord + vec2(0.0, 0.0) * cBlurHInvSize).rgb * 0.3;
rgb += texture2D(sDiffMap, vTexCoord + vec2(0.0, 1.0) * cBlurHInvSize).rgb * 0.25;
rgb += texture2D(sDiffMap, vTexCoord + vec2(0.0, 2.0) * cBlurHInvSize).rgb * 0.1;
gl_FragColor = vec4(rgb, 1.0);
#endif
#ifdef COMBINE
vec3 original = texture2D(sDiffMap, vScreenPos).rgb * cBloomMix.x;
vec3 bloom = texture2D(sNormalMap, vTexCoord).rgb * cBloomMix.y;
// Prevent oversaturation
original *= max(vec3(1.0) - bloom, vec3(0.0));
gl_FragColor = vec4(original + bloom, 1.0);
#endif
}
File mode changed from 100755 to 100644
#include "Uniforms.glsl"
#include "Samplers.glsl"
#include "Transform.glsl"
#include "ScreenPos.glsl"
#include "PostProcess.glsl"
varying vec2 vTexCoord;
varying vec2 vScreenPos;
#ifdef COMPILEPS
uniform vec2 cBlurDir;
uniform float cBlurRadius;
uniform float cBlurSigma;
uniform vec2 cBlurHInvSize;
#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 BLUR3
gl_FragColor = GaussianBlur(3, cBlurDir, cBlurHInvSize * cBlurRadius, cBlurSigma, sDiffMap, vTexCoord);
#endif
#ifdef BLUR5
gl_FragColor = GaussianBlur(5, cBlurDir, cBlurHInvSize * cBlurRadius, cBlurSigma, sDiffMap, vTexCoord);
#endif
#ifdef BLUR7
gl_FragColor = GaussianBlur(7, cBlurDir, cBlurHInvSize * cBlurRadius, cBlurSigma, sDiffMap, vTexCoord);
#endif
#ifdef BLUR9
gl_FragColor = GaussianBlur(9, cBlurDir, cBlurHInvSize * cBlurRadius, cBlurSigma, sDiffMap, vTexCoord);
#endif
}
#include "Uniforms.glsl"
#include "Samplers.glsl"
#include "Transform.glsl"
#include "ScreenPos.glsl"
#include "PostProcess.glsl"
varying vec2 vScreenPos;
void VS()
{
mat4 modelMatrix = iModelMatrix;
vec3 worldPos = GetWorldPos(modelMatrix);
gl_Position = GetClipPos(worldPos);
vScreenPos = GetScreenPosPreDiv(gl_Position);
}
void PS()
{
vec3 color = texture2D(sDiffMap, vScreenPos).rgb;
gl_FragColor = vec4(ColorCorrection(color, sVolumeMap), 1.0);
}
#define M_PI 3.14159265358979323846
#define M_EPSILON 0.0001
#ifdef PBR
#define ROUGHNESS_FLOOR 0.003
#define METALNESS_FLOOR 0.03
#endif
File mode changed from 100755 to 100644
#include "Uniforms.glsl"
#include "Samplers.glsl"
#include "Transform.glsl"
#include "ScreenPos.glsl"
#include "Lighting.glsl"
#ifdef DIRLIGHT
varying vec2 vScreenPos;
#else
varying vec4 vScreenPos;
#endif
varying vec3 vFarRay;
#ifdef ORTHO
varying vec3 vNearRay;
#endif
void VS()
{
mat4 modelMatrix = iModelMatrix;
vec3 worldPos = GetWorldPos(modelMatrix);
gl_Position = GetClipPos(worldPos);
#ifdef DIRLIGHT
vScreenPos = GetScreenPosPreDiv(gl_Position);
vFarRay = GetFarRay(gl_Position);
#ifdef ORTHO
vNearRay = GetNearRay(gl_Position);
#endif
#else
vScreenPos = GetScreenPos(gl_Position);
vFarRay = GetFarRay(gl_Position) * gl_Position.w;
#ifdef ORTHO
vNearRay = GetNearRay(gl_Position) * gl_Position.w;
#endif
#endif
}
void PS()
{
// If rendering a directional light quad, optimize out the w divide
#ifdef DIRLIGHT
#ifdef HWDEPTH
float depth = ReconstructDepth(texture2D(sDepthBuffer, vScreenPos).r);
#else
float depth = DecodeDepth(texture2D(sDepthBuffer, vScreenPos).rgb);
#endif
#ifdef ORTHO
vec3 worldPos = mix(vNearRay, vFarRay, depth);
#else
vec3 worldPos = vFarRay * depth;
#endif
vec4 albedoInput = texture2D(sAlbedoBuffer, vScreenPos);
vec4 normalInput = texture2D(sNormalBuffer, vScreenPos);
#else
#ifdef HWDEPTH
float depth = ReconstructDepth(texture2DProj(sDepthBuffer, vScreenPos).r);
#else
float depth = DecodeDepth(texture2DProj(sDepthBuffer, vScreenPos).rgb);
#endif
#ifdef ORTHO
vec3 worldPos = mix(vNearRay, vFarRay, depth) / vScreenPos.w;
#else
vec3 worldPos = vFarRay * depth / vScreenPos.w;
#endif
vec4 albedoInput = texture2DProj(sAlbedoBuffer, vScreenPos);
vec4 normalInput = texture2DProj(sNormalBuffer, vScreenPos);
#endif
// Position acquired via near/far ray is relative to camera. Bring position to world space
vec3 eyeVec = -worldPos;
worldPos += cCameraPosPS;
vec3 normal = normalize(normalInput.rgb * 2.0 - 1.0);
vec4 projWorldPos = vec4(worldPos, 1.0);
vec3 lightColor;
vec3 lightDir;
float diff = GetDiffuse(normal, worldPos, lightDir);
#ifdef SHADOW
diff *= GetShadowDeferred(projWorldPos, normal, depth);
#endif
#if defined(SPOTLIGHT)
vec4 spotPos = projWorldPos * cLightMatricesPS[0];
lightColor = spotPos.w > 0.0 ? texture2DProj(sLightSpotMap, spotPos).rgb * cLightColor.rgb : vec3(0.0);
#elif defined(CUBEMASK)
mat3 lightVecRot = mat3(cLightMatricesPS[0][0].xyz, cLightMatricesPS[0][1].xyz, cLightMatricesPS[0][2].xyz);
lightColor = textureCube(sLightCubeMap, (worldPos - cLightPosPS.xyz) * lightVecRot).rgb * cLightColor.rgb;
#else
lightColor = cLightColor.rgb;
#endif
#ifdef SPECULAR
float spec = GetSpecular(normal, eyeVec, lightDir, normalInput.a * 255.0);
gl_FragColor = diff * vec4(lightColor * (albedoInput.rgb + spec * cLightColor.a * albedoInput.aaa), 0.0);
#else
gl_FragColor = diff * vec4(lightColor * albedoInput.rgb, 0.0);
#endif
}
#include "Uniforms.glsl"
#include "Samplers.glsl"
#include "Transform.glsl"
varying vec3 vTexCoord;
void VS()
{
mat4 modelMatrix = iModelMatrix;
vec3 worldPos = GetWorldPos(modelMatrix);
gl_Position = GetClipPos(worldPos);
vTexCoord = vec3(GetTexCoord(iTexCoord), GetDepth(gl_Position));
}
void PS()
{
#ifdef ALPHAMASK
float alpha = texture2D(sDiffMap, vTexCoord.xy).a;
if (alpha < 0.5)