lighting single buffer

This commit is contained in:
Tim Barnes 2018-11-21 15:53:02 +10:00
parent c4a4fe5304
commit 9e65e940d0
37 changed files with 309 additions and 813 deletions

Binary file not shown.

View file

@ -9,40 +9,6 @@ singleton ShaderData( DeferredColorShader )
pixVersion = 2.0;
};
// Primary Deferred Shader
new GFXStateBlockData( AL_DeferredShadingState : PFX_DefaultStateBlock )
{
cullMode = GFXCullNone;
blendDefined = true;
blendEnable = true;
blendSrc = GFXBlendSrcAlpha;
blendDest = GFXBlendInvSrcAlpha;
samplersDefined = true;
samplerStates[0] = SamplerWrapLinear;
samplerStates[1] = SamplerWrapLinear;
samplerStates[2] = SamplerWrapLinear;
samplerStates[3] = SamplerWrapLinear;
samplerStates[4] = SamplerWrapLinear;
};
new ShaderData( AL_DeferredShader )
{
DXVertexShaderFile = "shaders/common/postFx/postFxV.hlsl";
DXPixelShaderFile = "shaders/common/lighting/advanced/deferredShadingP.hlsl";
OGLVertexShaderFile = "shaders/common/postFx/gl/postFxV.glsl";
OGLPixelShaderFile = "shaders/common/lighting/advanced/gl/deferredShadingP.glsl";
samplerNames[0] = "colorBufferTex";
samplerNames[1] = "diffuseLightingBuffer";
samplerNames[2] = "matInfoTex";
samplerNames[3] = "specularLightingBuffer";
samplerNames[4] = "deferredTex";
pixVersion = 2.0;
};
new GFXStateBlockData( AL_DeferredCaptureState : PFX_DefaultStateBlock )
{
blendEnable = false;
@ -94,23 +60,6 @@ singleton PostEffect( AL_PreCapture )
allowReflectPass = true;
};
singleton PostEffect( AL_DeferredShading )
{
renderTime = "PFXAfterBin";
renderBin = "BeginBin";
shader = AL_DeferredShader;
stateBlock = AL_DeferredShadingState;
texture[0] = "#color";
texture[1] = "#diffuseLighting";
texture[2] = "#matinfo";
texture[3] = "#specularLighting";
texture[4] = "#deferred";
target = "$backBuffer";
renderPriority = 10000;
allowReflectPass = true;
};
// Debug Shaders.
new ShaderData( AL_ColorBufferShader )
{

View file

@ -67,7 +67,7 @@ singleton PostEffect( AL_DepthVisualize )
shader = AL_DepthVisualizeShader;
stateBlock = AL_DefaultVisualizeState;
texture[0] = "#deferred";
texture[1] = "depthviz";
texture[1] = "core/scripts/client/lighting/advanced/depthviz";
target = "$backBuffer";
renderPriority = 9999;
};
@ -75,11 +75,7 @@ singleton PostEffect( AL_DepthVisualize )
function AL_DepthVisualize::onEnabled( %this )
{
AL_NormalsVisualize.disable();
AL_LightColorVisualize.disable();
AL_LightSpecularVisualize.disable();
$AL_NormalsVisualizeVar = false;
$AL_LightColorVisualizeVar = false;
$AL_LightSpecularVisualizeVar = false;
return true;
}
@ -130,83 +126,7 @@ singleton PostEffect( AL_NormalsVisualize )
function AL_NormalsVisualize::onEnabled( %this )
{
AL_DepthVisualize.disable();
AL_LightColorVisualize.disable();
AL_LightSpecularVisualize.disable();
$AL_DepthVisualizeVar = false;
$AL_LightColorVisualizeVar = false;
$AL_LightSpecularVisualizeVar = false;
return true;
}
new ShaderData( AL_LightColorVisualizeShader )
{
DXVertexShaderFile = "shaders/common/postFx/postFxV.hlsl";
DXPixelShaderFile = "shaders/common/lighting/advanced/dbgLightColorVisualizeP.hlsl";
OGLVertexShaderFile = "shaders/common/postFx/gl/postFxV.glsl";
OGLPixelShaderFile = "shaders/common/lighting/advanced/gl/dbgLightColorVisualizeP.glsl";
samplerNames[0] = "diffuseLightingBuffer";
pixVersion = 2.0;
};
singleton PostEffect( AL_LightColorVisualize )
{
shader = AL_LightColorVisualizeShader;
stateBlock = AL_DefaultVisualizeState;
texture[0] = "#diffuseLighting";
target = "$backBuffer";
renderPriority = 9999;
};
function AL_LightColorVisualize::onEnabled( %this )
{
AL_NormalsVisualize.disable();
AL_DepthVisualize.disable();
AL_LightSpecularVisualize.disable();
$AL_NormalsVisualizeVar = false;
$AL_DepthVisualizeVar = false;
$AL_LightSpecularVisualizeVar = false;
return true;
}
new ShaderData( AL_LightSpecularVisualizeShader )
{
DXVertexShaderFile = "shaders/common/postFx/postFxV.hlsl";
DXPixelShaderFile = "shaders/common/lighting/advanced/dbgLightSpecularVisualizeP.hlsl";
OGLVertexShaderFile = "shaders/common/postFx/gl/postFxV.glsl";
OGLPixelShaderFile = "shaders/common/lighting/advanced/gl/dbgLightSpecularVisualizeP.glsl";
samplerNames[0] = "diffuseLightingBuffer";
pixVersion = 2.0;
};
singleton PostEffect( AL_LightSpecularVisualize )
{
shader = AL_LightColorVisualizeShader;
stateBlock = AL_DefaultVisualizeState;
texture[0] = "#specularLighting";
target = "$backBuffer";
renderPriority = 9999;
};
function AL_LightSpecularVisualize::onEnabled( %this )
{
AL_NormalsVisualize.disable();
AL_DepthVisualize.disable();
AL_LightColorVisualize.disable();
$AL_NormalsVisualizeVar = false;
$AL_DepthVisualizeVar = false;
$AL_LightColorVisualizeVar = false;
$AL_DepthVisualizeVar = false;
return true;
}
@ -238,48 +158,6 @@ function toggleGlowViz( %enable )
AL_GlowVisualize.disable();
}
/// Toggles the visualization of the AL normals buffer.
function toggleNormalsViz( %enable )
{
if ( %enable $= "" )
{
$AL_NormalsVisualizeVar = AL_NormalsVisualize.isEnabled() ? false : true;
AL_NormalsVisualize.toggle();
}
else if ( %enable )
AL_NormalsVisualize.enable();
else if ( !%enable )
AL_NormalsVisualize.disable();
}
/// Toggles the visualization of the AL lighting color buffer.
function toggleLightColorViz( %enable )
{
if ( %enable $= "" )
{
$AL_LightColorVisualizeVar = AL_LightColorVisualize.isEnabled() ? false : true;
AL_LightColorVisualize.toggle();
}
else if ( %enable )
AL_LightColorVisualize.enable();
else if ( !%enable )
AL_LightColorVisualize.disable();
}
/// Toggles the visualization of the AL lighting specular power buffer.
function toggleLightSpecularViz( %enable )
{
if ( %enable $= "" )
{
$AL_LightSpecularVisualizeVar = AL_LightSpecularVisualize.isEnabled() ? false : true;
AL_LightSpecularVisualize.toggle();
}
else if ( %enable )
AL_LightSpecularVisualize.enable();
else if ( !%enable )
AL_LightSpecularVisualize.disable();
}
function toggleBackbufferViz( %enable )
{
if ( %enable $= "" )

View file

@ -73,8 +73,9 @@ new ShaderData( AL_VectorLightShader )
samplerNames[2] = "$dynamicShadowMap";
samplerNames[3] = "$ssaoMask";
samplerNames[4] = "$gTapRotationTex";
samplerNames[5] = "$colorBuffer";
samplerNames[6] = "$matInfoBuffer";
samplerNames[5] = "$lightBuffer";
samplerNames[6] = "$colorBuffer";
samplerNames[7] = "$matInfoBuffer";
pixVersion = 3.0;
};
@ -86,7 +87,8 @@ new CustomMaterial( AL_VectorLightMaterial )
sampler["deferredBuffer"] = "#deferred";
sampler["shadowMap"] = "$dynamiclight";
sampler["dynamicShadowMap"] = "$dynamicShadowMap";
sampler["ssaoMask"] = "#ssaoMask";
sampler["ssaoMask"] = "#ssaoMask";
sampler["lightBuffer"] = "#specularLighting";
sampler["colorBuffer"] = "#color";
sampler["matInfoBuffer"] = "#matinfo";
@ -148,8 +150,9 @@ new ShaderData( AL_PointLightShader )
samplerNames[2] = "$dynamicShadowMap";
samplerNames[3] = "$cookieMap";
samplerNames[4] = "$gTapRotationTex";
samplerNames[5] = "$colorBuffer";
samplerNames[6] = "$matInfoBuffer";
samplerNames[5] = "$lightBuffer";
samplerNames[6] = "$colorBuffer";
samplerNames[7] = "$matInfoBuffer";
pixVersion = 3.0;
};
@ -163,6 +166,7 @@ new CustomMaterial( AL_PointLightMaterial )
sampler["shadowMap"] = "$dynamiclight";
sampler["dynamicShadowMap"] = "$dynamicShadowMap";
sampler["cookieMap"] = "$dynamiclightmask";
sampler["lightBuffer"] = "#specularLighting";
sampler["colorBuffer"] = "#color";
sampler["matInfoBuffer"] = "#matinfo";
@ -185,8 +189,9 @@ new ShaderData( AL_SpotLightShader )
samplerNames[2] = "$dynamicShadowMap";
samplerNames[3] = "$cookieMap";
samplerNames[4] = "$gTapRotationTex";
samplerNames[5] = "$colorBuffer";
samplerNames[6] = "$matInfoBuffer";
samplerNames[5] = "$lightBuffer";
samplerNames[6] = "$colorBuffer";
samplerNames[7] = "$matInfoBuffer";
pixVersion = 3.0;
};
@ -200,6 +205,7 @@ new CustomMaterial( AL_SpotLightMaterial )
sampler["shadowMap"] = "$dynamiclight";
sampler["dynamicShadowMap"] = "$dynamicShadowMap";
sampler["cookieMap"] = "$dynamiclightmask";
sampler["lightBuffer"] = "#specularLighting";
sampler["colorBuffer"] = "#color";
sampler["matInfoBuffer"] = "#matinfo";

View file

@ -62,7 +62,7 @@ function initRenderManager()
DiffuseRenderPassManager.addManager( new RenderMeshMgr(DecalBin) { bintype = "Decal"; renderOrder = 0.81; processAddOrder = 0.81; } );
DiffuseRenderPassManager.addManager( new RenderOcclusionMgr(OccluderBin){ bintype = "Occluder"; renderOrder = 0.9; processAddOrder = 0.9; } );
// Render the sky last
DiffuseRenderPassManager.addManager( new RenderObjectMgr(SkyBin) { bintype = "Sky"; renderOrder = 1.95; processAddOrder = 1.95; } );
DiffuseRenderPassManager.addManager( new RenderObjectMgr(SkyBin) { bintype = "Sky"; renderOrder = 0.95; processAddOrder = 0.95; } );
// We now render translucent objects that should handle
// their own fogging and lighting.

View file

@ -25,7 +25,8 @@
#include "./torque.hlsl"
// BRDF from Frostbite presentation:
// Moving Frostbite to Physically Based Rendering// S´ebastien Lagarde - Electronic Arts Frostbite
// Moving Frostbite to Physically Based Rendering
// S´ebastien Lagarde - Electronic Arts Frostbite
// Charles de Rousiers - Electronic Arts Frostbite
// SIGGRAPH 2014

View file

@ -45,12 +45,22 @@ uniform float4 albedo;
#endif // !TORQUE_SHADERGEN
//deferred lighting output
struct LightTargetOutput
inline float3 getDistanceVectorToPlane( float3 origin, float3 direction, float4 plane )
{
float4 spec: TORQUE_TARGET0;
float4 diffuse: TORQUE_TARGET1;
};
float denum = dot( plane.xyz, direction.xyz );
float num = dot( plane, float4( origin, 1.0 ) );
float t = -num / denum;
return direction.xyz * t;
}
inline float3 getDistanceVectorToPlane( float negFarPlaneDotEye, float3 direction, float4 plane )
{
float denum = dot( plane.xyz, direction.xyz );
float t = negFarPlaneDotEye / denum;
return direction.xyz * t;
}
//TODO fix compute 4 lights
void compute4Lights( float3 wsView,
@ -121,7 +131,7 @@ inline Surface CreateSurface(float4 gbuffer0, TORQUE_SAMPLER2D(gbufferTex1), TOR
surface.depth = gbuffer0.a;
surface.P = wsEyePos + wsEyeRay * surface.depth;
surface.N = mul(invView, float4(gbuffer0.xyz,0)).xyz;
surface.N = mul(invView, float4(gbuffer0.xyz,0)).xyz; //TODO move t3d to use WS normals
surface.V = normalize(wsEyePos - surface.P);
surface.baseColor = gbuffer1;
const float minRoughness=1e-4;
@ -166,48 +176,56 @@ float3 BRDF_GetSpecular(in Surface surface, in SurfaceToLight surfaceToLight)
return Fr;
}
float BRDF_GetDiffuse(in Surface surface, in SurfaceToLight surfaceToLight)
float3 BRDF_GetDiffuse(in Surface surface, in SurfaceToLight surfaceToLight)
{
//getting some banding with disney method, using lambert instead - todo futher testing
float Fd = 1.0 / M_PI_F;//Fr_DisneyDiffuse(surface.NdotV, surfaceToLight.NdotL, surfaceToLight.HdotV, surface.roughness) / M_PI_F;
return Fd;
float Fd = 1.0 / M_PI_F;
//energy conservation - remove this if reverting back to disney method
float3 kD = 1.0.xxx - surface.F;
kD *= 1.0 - surface.metalness;
float3 diffuse = kD * surface.baseColor.rgb * Fd;
return diffuse;
}
struct LightResult
// inverse square falloff from Epic Games' paper
float Attenuate(float distToLight, float radius)
{
float3 diffuse;
float3 spec;
};
inline LightResult GetDirectionalLight(in Surface surface, in SurfaceToLight surfaceToLight, float3 lightColor, float lightIntensity, float shadow)
{
LightResult result = (LightResult)0;
float3 factor = lightColor * max(surfaceToLight.NdotL, 0) * shadow * lightIntensity;
result.diffuse = BRDF_GetDiffuse(surface,surfaceToLight) * factor;
result.spec = BRDF_GetSpecular(surface,surfaceToLight) * factor;
result.diffuse = max(0.0f, result.diffuse);
result.spec = max(0.0f, result.spec);
return result;
}
inline LightResult GetPointLight(in Surface surface, in SurfaceToLight surfaceToLight, float3 lightColor, float lightIntensity,float distToLight, float radius, float shadow)
{
LightResult result = (LightResult)0;
// Distance attenuation from Epic Games' paper
float distanceByRadius = 1.0f - pow((distToLight / radius), 4);
float clamped = pow(clamp(distanceByRadius, 0.0f, 1.0f), 2.0f);
float attenuation = clamped / (sqr(distToLight) + 1.0f);
return clamped / (sqr(distToLight) + 1.0f);
}
inline float3 GetDirectionalLight(in Surface surface, in SurfaceToLight surfaceToLight, float3 lightColor, float lightIntensity, float shadow)
{
float3 factor = lightColor * max(surfaceToLight.NdotL, 0) * shadow * lightIntensity;
float3 diffuse = BRDF_GetDiffuse(surface,surfaceToLight) * factor;
float3 spec = BRDF_GetSpecular(surface,surfaceToLight) * factor;
float3 final = max(0.0f, diffuse + spec * surface.ao);
return final;
}
inline float3 GetPointLight(in Surface surface, in SurfaceToLight surfaceToLight, float3 lightColor, float lightIntensity,float distToLight, float radius, float shadow)
{
float attenuation = Attenuate(distToLight,radius);
float3 factor = lightColor * max(surfaceToLight.NdotL, 0) * shadow * lightIntensity * attenuation;
result.diffuse = BRDF_GetDiffuse(surface,surfaceToLight) * factor;
result.spec = BRDF_GetSpecular(surface,surfaceToLight) * factor;
float3 diffuse = BRDF_GetDiffuse(surface,surfaceToLight) * factor;
float3 spec = BRDF_GetSpecular(surface,surfaceToLight) * factor;
result.diffuse = max(0.0f, result.diffuse);
result.spec = max(0.0f, result.spec);
return result;
float3 final = max(0.0f, diffuse + spec * surface.ao * surface.F);
return final;
}
inline float3 GetSpotLight(in Surface surface, in SurfaceToLight surfaceToLight, float3 lightColor, float lightIntensity,float distToLight, float radius, float shadow)
{
float attenuation = Attenuate(distToLight,radius);
//attenuation *= ( cosAlpha - lightSpotParams.x ) / lightSpotParams.y;
float3 factor = lightColor * max(surfaceToLight.NdotL, 0) * shadow * lightIntensity * attenuation;
float3 diffuse = BRDF_GetDiffuse(surface,surfaceToLight) * factor;
float3 spec = BRDF_GetSpecular(surface,surfaceToLight) * factor;
float3 final = max(0.0f, diffuse + spec * surface.ao * surface.F);
return final;
}

View file

@ -1,32 +0,0 @@
//-----------------------------------------------------------------------------
// Copyright (c) 2012 GarageGames, LLC
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------
#include "../../shaderModelAutoGen.hlsl"
#include "../../postfx/postFx.hlsl"
TORQUE_UNIFORM_SAMPLER2D(lightDeferredTex,0);
float4 main( PFXVertToPix IN ) : TORQUE_TARGET0
{
float4 lightColor = TORQUE_TEX2D( lightDeferredTex, IN.uv0 );
return float4( lightColor.rgb, 1.0 );
}

View file

@ -1,31 +0,0 @@
//-----------------------------------------------------------------------------
// Copyright (c) 2012 GarageGames, LLC
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------
#include "../../postfx/postFx.hlsl"
TORQUE_UNIFORM_SAMPLER2D(lightDeferredTex,0);
float4 main( PFXVertToPix IN ) : TORQUE_TARGET0
{
float specular = TORQUE_TEX2D( lightDeferredTex, IN.uv0 ).a;
return float4( specular, specular, specular, 1.0 );
}

View file

@ -1,54 +0,0 @@
//-----------------------------------------------------------------------------
// Copyright (c) 2012 GarageGames, LLC
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------
#include "../../postfx/postFx.hlsl"
#include "shaders/common/torque.hlsl"
#include "shaders/common/lighting.hlsl"
TORQUE_UNIFORM_SAMPLER2D(colorBufferTex,0);
TORQUE_UNIFORM_SAMPLER2D(diffuseLightingBuffer,1);
TORQUE_UNIFORM_SAMPLER2D(matInfoTex,2);
TORQUE_UNIFORM_SAMPLER2D(specularLightingBuffer,3);
TORQUE_UNIFORM_SAMPLER2D(deferredTex,4);
uniform float4x4 cameraToWorld;
uniform float3 eyePosWorld;
//TODO add in emission
float4 main( PFXVertToPix IN ) : TORQUE_TARGET0
{
//sky and editor background check
float4 normDepth = UnpackDepthNormal(TORQUE_SAMPLER2D_MAKEARG(deferredTex), IN.uv0);
if (normDepth.a>0.9999)
return float4(0,0,0,0);
//create surface
Surface surface = CreateSurface( normDepth, TORQUE_SAMPLER2D_MAKEARG(colorBufferTex),TORQUE_SAMPLER2D_MAKEARG(matInfoTex),
IN.uv0, eyePosWorld, IN.wsEyeRay, cameraToWorld);
float4 diffuse = TORQUE_TEX2DLOD( diffuseLightingBuffer, float4(IN.uv0,0,0));
float4 specular = TORQUE_TEX2DLOD( specularLightingBuffer, float4(IN.uv0,0,0));
float3 sceneColor = (surface.albedo * diffuse.rgb) + (surface.F * specular.rgb) * surface.ao;
return float4(sceneColor.rgb, 1.0);
}

View file

@ -1,51 +0,0 @@
//-----------------------------------------------------------------------------
// Copyright (c) 2012 GarageGames, LLC
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------
float attenuate( float4 lightColor, float2 attParams, float dist )
{
// We're summing the results of a scaled constant,
// linear, and quadratic attenuation.
#ifdef ACCUMULATE_LUV
return lightColor.w * ( 1.0 - dot( attParams, float2( dist, dist * dist ) ) );
#else
return 1.0 - dot( attParams, float2( dist, dist * dist ) );
#endif
}
float3 getDistanceVectorToPlane( float3 origin, float3 direction, float4 plane )
{
float denum = dot( plane.xyz, direction.xyz );
float num = dot( plane, float4( origin, 1.0 ) );
float t = -num / denum;
return direction.xyz * t;
}
float3 getDistanceVectorToPlane( float negFarPlaneDotEye, float3 direction, float4 plane )
{
float denum = dot( plane.xyz, direction.xyz );
float t = negFarPlaneDotEye / denum;
return direction.xyz * t;
}

View file

@ -23,7 +23,6 @@
#include "../../shaderModelAutoGen.hlsl"
#include "farFrustumQuad.hlsl"
#include "lightingUtils.hlsl"
#include "../../lighting.hlsl"
#include "../shadowMap/shadowMapIO_HLSL.h"
#include "softShadow.hlsl"
@ -88,7 +87,9 @@ TORQUE_UNIFORM_SAMPLERCUBE(cookieMap, 3);
// this value was found via experementation
// NOTE: this is wrong, it only biases in one direction, not towards the uv
// center ( 0.5 0.5 ).
//shadowCoord.xy *= 0.997;
float offsetVal = 0.95;
shadowCoord.xy *= offsetVal;
shadowCoord.xy += (1.0-offsetVal).xx / 2.0;
#ifndef SHADOW_PARABOLOID
@ -139,18 +140,14 @@ uniform float3x3 dynamicViewToLightProj;
uniform float3 eyePosWorld;
uniform float4x4 cameraToWorld;
LightTargetOutput main( ConvexConnectP IN )
float4 main( ConvexConnectP IN ) : SV_TARGET
{
LightTargetOutput Output = (LightTargetOutput)0;
// Compute scene UV
float3 ssPos = IN.ssPos.xyz / IN.ssPos.w;
float2 uvScene = getUVFromSSPos(ssPos, rtParams0);
//sky and editor background check
float4 normDepth = UnpackDepthNormal(TORQUE_SAMPLER2D_MAKEARG(deferredBuffer), uvScene);
if (normDepth.w>0.9999)
return Output;
//unpack normal and linear depth
float4 normDepth = TORQUE_DEFERRED_UNCONDITION(deferredBuffer, uvScene);
//eye ray WS/VS
float3 vsEyeRay = getDistanceVectorToPlane( -vsFarPlane.w, IN.vsEyeDir.xyz, vsFarPlane );
@ -163,15 +160,12 @@ LightTargetOutput main( ConvexConnectP IN )
//early out if emissive
if (getFlag(surface.matFlag, 0))
{
Output.diffuse = surface.baseColor;
Output.spec = surface.baseColor;
return Output;
return 0.0.xxxx;
}
//create surface to light
float3 L = lightPosition - surface.P;
float dist = length(L);
LightResult result = (LightResult)0;
float3 result = 0.0.xxx;
[branch]
if (dist < lightRange)
{
@ -215,10 +209,10 @@ LightTargetOutput main( ConvexConnectP IN )
#endif // !NO_SHADOW
float3 lightcol = lightColor.rgb;
/*#ifdef USE_COOKIE_TEX
#ifdef USE_COOKIE_TEX
// Lookup the cookie sample.
float4 cookie = TORQUE_TEXCUBE(cookieMap, mul(viewToLightProj, -surfaceToLight.L));
float4 cookie = TORQUE_TEXCUBE(cookieMap, mul(worldToLightProj, -surfaceToLight.L));
// Multiply the light with the cookie tex.
lightcol *= cookie.rgb;
@ -228,15 +222,11 @@ LightTargetOutput main( ConvexConnectP IN )
// regions of the cookie texture.
atten *= max(cookie.r, max(cookie.g, cookie.b));
#endif*/
#endif
//get point light contribution
result = GetPointLight(surface, surfaceToLight, lightcol, lightBrightness, dist, lightRange, shadowed);
}
//output
Output.diffuse = float4(result.diffuse, 0);
Output.spec = float4(result.spec, 0);
return Output;
return float4(result, 0);
}

View file

@ -1,7 +1,6 @@
#include "../../shaderModelAutoGen.hlsl"
#include "farFrustumQuad.hlsl"
#include "lightingUtils.hlsl"
#include "../../lighting.hlsl"
#include "../../torque.hlsl"
@ -44,16 +43,16 @@ uniform float useSphereMode;
// and https://seblagarde.wordpress.com/2012/09/29/image-based-lighting-approaches-and-parallax-corrected-cubemap/
float3 boxProject(float3 wsPosition, float3 reflectDir, float3 boxWSPos, float3 boxMin, float3 boxMax)
{
float3 nrdir = reflectDir;
float3 nrdir = reflectDir;
float3 offset = wsPosition;
float3 plane1vec = (boxMax - offset) / nrdir;
float3 plane2vec = (boxMin - offset) / nrdir;
float3 plane1vec = (boxMax - offset) / nrdir;
float3 plane2vec = (boxMin - offset) / nrdir;
float3 furthestPlane = max(plane1vec, plane2vec);
float dist = min(min(furthestPlane.x, furthestPlane.y), furthestPlane.z);
float3 posonbox = offset + nrdir * dist;
float3 posonbox = offset + nrdir * dist;
return posonbox - boxWSPos;
return posonbox - boxWSPos;
}
float3 iblBoxDiffuse(float3 normal,
@ -64,45 +63,37 @@ float3 iblBoxDiffuse(float3 normal,
float3 boxMax)
{
// Irradiance (Diffuse)
float3 cubeN = normalize(normal);
float3 irradiance = TORQUE_TEXCUBE(irradianceCube, cubeN).xyz;
float3 cubeN = normalize(normal);
float3 irradiance = TORQUE_TEXCUBE(irradianceCube, cubeN).xyz;
return irradiance;
return irradiance;
}
float3 iblBoxSpecular(float3 normal,
float3 wsPos,
float roughness,
float3 surfToEye,
TORQUE_SAMPLER2D(brdfTexture),
float3 iblBoxSpecular(float3 normal, float3 wsPos, float roughness, float3 surfToEye,
TORQUE_SAMPLER2D(brdfTexture),
TORQUE_SAMPLERCUBE(radianceCube),
float3 boxPos,
float3 boxMin,
float3 boxMax)
{
float ndotv = clamp(dot(normal, surfToEye), 0.0, 1.0);
float ndotv = clamp(dot(normal, surfToEye), 0.0, 1.0);
// BRDF
float2 brdf = TORQUE_TEX2D(brdfTexture, float2(roughness, ndotv)).xy;
float2 brdf = TORQUE_TEX2D(brdfTexture, float2(roughness, ndotv)).xy;
// Radiance (Specular)
float maxmip = pow(cubeMips+1,2);
float lod = roughness*maxmip;
float3 r = reflect(surfToEye, normal);
float3 cubeR = normalize(r);
cubeR = boxProject(wsPos, cubeR, boxPos, boxMin, boxMax);
float lod = roughness*maxmip;
float3 r = reflect(surfToEye, normal);
float3 cubeR = normalize(r);
cubeR = boxProject(wsPos, cubeR, boxPos, boxMin, boxMax);
float3 radiance = TORQUE_TEXCUBELOD(radianceCube, float4(cubeR, lod)).xyz * (brdf.x + brdf.y);
float3 radiance = TORQUE_TEXCUBELOD(radianceCube, float4(cubeR, lod)).xyz * (brdf.x + brdf.y);
return radiance;
return radiance;
}
struct PS_OUTPUT
{
float4 diffuse: TORQUE_TARGET1;
float4 spec: TORQUE_TARGET0;
};
/*
float defineSphereSpaceInfluence(float3 centroidPosVS, float rad, float2 atten, float3 surfPosVS, float3 norm)
{
// Build light vec, get length, clip pixel if needed
@ -125,6 +116,7 @@ float defineSphereSpaceInfluence(float3 centroidPosVS, float rad, float2 atten,
return saturate( nDotL * attn );
}
*/
float defineBoxSpaceInfluence(float3 surfPosWS, float3 probePos, float radius, float atten)
{
@ -139,9 +131,7 @@ float defineBoxSpaceInfluence(float3 surfPosWS, float3 probePos, float radius, f
float3 localDir = float3(abs(surfPosLS.x), abs(surfPosLS.y), abs(surfPosLS.z));
localDir = (localDir - boxInnerRange) / (boxOuterRange - boxInnerRange);
float influenceVal = max(localDir.x, max(localDir.y, localDir.z)) * -1;
return influenceVal;
return max(localDir.x, max(localDir.y, localDir.z)) * -1;
}
float defineDepthInfluence(float3 probePosWS, float3 surfPosWS, TORQUE_SAMPLERCUBE(radianceCube))
@ -156,55 +146,41 @@ float defineDepthInfluence(float3 probePosWS, float3 surfPosWS, TORQUE_SAMPLERCU
return depthRef-dist;
}
PS_OUTPUT main( ConvexConnectP IN )
float4 main( ConvexConnectP IN ) : SV_TARGET
{
PS_OUTPUT Output = (PS_OUTPUT)0;
// Compute scene UV
float3 ssPos = IN.ssPos.xyz / IN.ssPos.w;
float2 uvScene = getUVFromSSPos( ssPos, rtParams0 );
// Compute scene UV
float3 ssPos = IN.ssPos.xyz / IN.ssPos.w;
//eye ray WS/LS
float3 vsEyeRay = getDistanceVectorToPlane( -vsFarPlane.w, IN.vsEyeDir.xyz, vsFarPlane );
float3 wsEyeRay = mul(cameraToWorld, float4(vsEyeRay, 0)).xyz;
//unpack normal and linear depth
float4 normDepth = TORQUE_DEFERRED_UNCONDITION(deferredBuffer, uvScene);
//create surface
Surface surface = CreateSurface( normDepth, TORQUE_SAMPLER2D_MAKEARG(colorBuffer),TORQUE_SAMPLER2D_MAKEARG(matInfoBuffer),
uvScene, eyePosWorld, wsEyeRay, cameraToWorld);
float2 uvScene = getUVFromSSPos( ssPos, rtParams0 );
// Sample/unpack the normal/z data
float4 deferredSample = TORQUE_DEFERRED_UNCONDITION( deferredBuffer, uvScene );
float3 normal = deferredSample.rgb;
float depth = deferredSample.a;
if (depth>0.9999)
clip(-1);
// Matinfo flags
float4 matInfo = TORQUE_TEX2D( matInfoBuffer, uvScene );
// Need world-space normal.
float3 wsNormal = mul(cameraToWorld, float4(normal, 0)).xyz;
float3 vsEyeRay = getDistanceVectorToPlane( -vsFarPlane.w, IN.vsEyeDir.xyz, vsFarPlane );
float3 vsPos = vsEyeRay * depth;
float3 wsEyeRay = mul(cameraToWorld, float4(vsEyeRay, 0)).xyz;
// calculate world space position
float3 wsPos = float3(eyePosWorld + wsEyeRay * depth);
float blendVal = 1.0;
//clip bounds and (TODO properly: set falloff)
if(useSphereMode)
{
blendVal = defineSphereSpaceInfluence(probeLSPos, radius, attenuation, vsPos, normal);
}
else
{
float tempAttenVal = 3.5;
blendVal = defineBoxSpaceInfluence(wsPos, probeWSPos, radius, tempAttenVal);
}
float tempAttenVal = 3.5;
float blendVal = defineBoxSpaceInfluence(surface.P, probeWSPos, radius, tempAttenVal);
clip(blendVal);
//flip me on to have probes filter by depth
//clip(defineDepthInfluence(probeWSPos, worldPos, TORQUE_SAMPLERCUBE_MAKEARG(cubeMap)));
//clip(defineDepthInfluence(probeWSPos, worldPos, TORQUE_SAMPLERCUBE_MAKEARG(cubeMap)));
//render into the bound space defined above
float3 surfToEye = normalize(wsPos - eyePosWorld);
Output.diffuse = float4(iblBoxDiffuse(wsNormal, wsPos, TORQUE_SAMPLERCUBE_MAKEARG(irradianceCubemap), probeWSPos, bbMin, bbMax), blendVal);
Output.spec = float4(iblBoxSpecular(wsNormal, wsPos, 1.0 - matInfo.b, surfToEye, TORQUE_SAMPLER2D_MAKEARG(BRDFTexture), TORQUE_SAMPLERCUBE_MAKEARG(cubeMap), probeWSPos, bbMin, bbMax), blendVal);
return Output;
float3 surfToEye = normalize(surface.P - eyePosWorld);
float3 irradiance = iblBoxDiffuse(surface.N, surface.P, TORQUE_SAMPLERCUBE_MAKEARG(irradianceCubemap), probeWSPos, bbMin, bbMax);
float3 specular = iblBoxSpecular(surface.N, surface.P, surface.roughness, surfToEye, TORQUE_SAMPLER2D_MAKEARG(BRDFTexture), TORQUE_SAMPLERCUBE_MAKEARG(cubeMap), probeWSPos, bbMin, bbMax);
//energy conservation
float3 F = FresnelSchlickRoughness(surface.NdotV, surface.f0, surface.roughness);
float3 kD = 1.0.xxx - F;
kD *= 1.0 - surface.metalness;
//final diffuse color
float3 diffuse = kD * irradiance * surface.baseColor.rgb;
return float4((diffuse+specular) * surface.ao, blendVal);
}

View file

@ -1,7 +1,6 @@
#include "../../shaderModelAutoGen.hlsl"
#include "farFrustumQuad.hlsl"
#include "lightingUtils.hlsl"
#include "../../lighting.hlsl"
#include "../../torque.hlsl"
@ -25,19 +24,16 @@ uniform float4 vsFarPlane;
uniform float4x4 cameraToWorld;
uniform float3 eyePosWorld;
float3 iblSpecular(float3 v, float3 n, float roughness)
float3 iblSpecular(in Surface surface, float3 F)
{
float3 R = reflect(v, n);
const float MAX_REFLECTION_LOD = 4.0;
float3 prefilteredColor = TORQUE_TEXCUBELOD(cubeMap, float4(R, roughness * MAX_REFLECTION_LOD)).rgb;
float2 envBRDF = TORQUE_TEX2D(BRDFTexture, float2(max(dot(n, v), 0.0), roughness)).rg;
return prefilteredColor * (envBRDF.x + envBRDF.y);
float3 prefilteredColor = TORQUE_TEXCUBELOD(cubeMap, float4(surface.R, surface.roughness * MAX_REFLECTION_LOD)).rgb;
float2 envBRDF = TORQUE_TEX2D(BRDFTexture, float2(surface.NdotV, surface.roughness)).rg;
return prefilteredColor * (F * envBRDF.x + envBRDF.y);
}
LightTargetOutput main( ConvexConnectP IN )
float4 main( ConvexConnectP IN ) : SV_TARGET
{
LightTargetOutput Output = (LightTargetOutput)0;
// Compute scene UV
float3 ssPos = IN.ssPos.xyz / IN.ssPos.w;
float2 uvScene = getUVFromSSPos( ssPos, rtParams0 );
@ -46,22 +42,23 @@ LightTargetOutput main( ConvexConnectP IN )
float3 vsEyeRay = getDistanceVectorToPlane( -vsFarPlane.w, IN.vsEyeDir.xyz, vsFarPlane );
float3 wsEyeRay = mul(cameraToWorld, float4(vsEyeRay, 0)).xyz;
//sky and editor background check
float4 normDepth = UnpackDepthNormal(TORQUE_SAMPLER2D_MAKEARG(deferredBuffer), uvScene);
if (normDepth.a>0.9999)
return Output;
//unpack normal and linear depth
float4 normDepth = TORQUE_DEFERRED_UNCONDITION(deferredBuffer, uvScene);
//create surface
Surface surface = CreateSurface( normDepth, TORQUE_SAMPLER2D_MAKEARG(colorBuffer),TORQUE_SAMPLER2D_MAKEARG(matInfoBuffer),
uvScene, eyePosWorld, wsEyeRay, cameraToWorld);
float3 diffuse = TORQUE_TEXCUBELOD(irradianceCubemap, float4(surface.N,0)).rgb;
float3 specular = iblSpecular(wsEyeRay, surface.N, surface.roughness);
float3 F = FresnelSchlickRoughness(surface.NdotV, surface.f0, surface.roughness);
float3 irradiance = TORQUE_TEXCUBELOD(irradianceCubemap, float4(surface.N,0)).rgb;
float3 specular = iblSpecular(surface, F);
//energy conservation
float3 kD = 1.0.xxx - F;
kD *= 1.0 - surface.metalness;
//final diffuse color
float3 diffuse = kD * irradiance * surface.baseColor.rgb;
float blendVal = 0.0001;// ?????
Output.diffuse = float4(diffuse, blendVal);
Output.spec = float4(specular, blendVal);
return Output;
float blendVal = 0.0001;
return float4(diffuse + specular * surface.ao, blendVal);
}

View file

@ -24,7 +24,6 @@
#include "../../shaderModelAutoGen.hlsl"
#include "farFrustumQuad.hlsl"
#include "lightingUtils.hlsl"
#include "../../lighting.hlsl"
#include "../shadowMap/shadowMapIO_HLSL.h"
#include "softShadow.hlsl"
@ -64,123 +63,57 @@ uniform float3 lightDirection;
uniform float4 lightSpotParams;
uniform float4 lightMapParams;
uniform float4 vsFarPlane;
uniform float4x4 viewToLightProj;
uniform float4x4 worldToLightProj;
uniform float4 lightParams;
uniform float4x4 dynamicViewToLightProj;
uniform float2 lightAttenuation;
uniform float shadowSoftness;
uniform float3 eyePosWorld;
uniform float4x4 cameraToWorld;
LightTargetOutput main( ConvexConnectP IN )
float4 main( ConvexConnectP IN ) : SV_TARGET
{
LightTargetOutput Output = (LightTargetOutput)0;
// Compute scene UV
float3 ssPos = IN.ssPos.xyz / IN.ssPos.w;
float2 uvScene = getUVFromSSPos( ssPos, rtParams0 );
//sky and editor background check
float4 normDepth = UnpackDepthNormal(TORQUE_SAMPLER2D_MAKEARG(deferredBuffer), uvScene);
if (normDepth.a>0.9999)
return Output;
// Eye ray - Eye -> Pixel
float3 eyeRay = getDistanceVectorToPlane( -vsFarPlane.w, IN.vsEyeDir.xyz, vsFarPlane );
float3 viewSpacePos = eyeRay * normDepth.w;
// Build light vec, get length, clip pixel if needed
float3 lightToPxlVec = viewSpacePos - lightPosition;
float lenLightV = length( lightToPxlVec );
lightToPxlVec /= lenLightV;
float2 uvScene = getUVFromSSPos(ssPos, rtParams0);
//lightDirection = float3( -lightDirection.xy, lightDirection.z ); //float3( 0, 0, -1 );
float cosAlpha = dot( lightDirection, lightToPxlVec );
clip( cosAlpha - lightSpotParams.x );
clip( lightRange - lenLightV );
//unpack normal and linear depth
float4 normDepth = TORQUE_DEFERRED_UNCONDITION(deferredBuffer, uvScene);
//eye ray WS/VS
float3 vsEyeRay = getDistanceVectorToPlane( -vsFarPlane.w, IN.vsEyeDir.xyz, vsFarPlane );
float3 wsEyeRay = mul(cameraToWorld, float4(vsEyeRay, 0)).xyz;
float atten = attenuate( lightColor, lightAttenuation, lenLightV );
atten *= ( cosAlpha - lightSpotParams.x ) / lightSpotParams.y;
clip( atten - 1e-6 );
atten = saturate( atten );
//create surface
Surface surface = CreateSurface( normDepth, TORQUE_SAMPLER2D_MAKEARG(colorBuffer),TORQUE_SAMPLER2D_MAKEARG(matInfoBuffer),
uvScene, eyePosWorld, eyeRay, cameraToWorld);
uvScene, eyePosWorld, wsEyeRay, cameraToWorld);
//early out if emissive
if (getFlag(surface.matFlag, 0))
{
Output.diffuse = surface.baseColor;
Output.spec = surface.baseColor;
return Output;
return 0.0.xxxx;
}
float3 L = lightPosition - surface.P;
float dist = length(L);
float3 result = 0.0.xxx;
[branch]
if (dist < lightRange)
{
float distToLight = dist / lightRange;
float spotFactor = dot(L, lightDirection);
float spotCutOff = lightSpotParams.x;
[branch]
//if (spotFactor > spotCutOff)
{
SurfaceToLight surfaceToLight = CreateSurfaceToLight(surface, L);
float shadowed = 1.0;
float3 lightcol = lightColor.rgb;
//get spot light contribution
result = GetSpotLight(surface, surfaceToLight, lightcol, lightBrightness, dist, lightRange, shadowed);
//result = float3(1.0,0,0);
}
}
//create surface to light
float3 wsLightDir = mul(cameraToWorld, float4(lightDirection,0)).xyz;
SurfaceToLight surfaceToLight = CreateSurfaceToLight(surface, -wsLightDir);
float nDotL = dot( normDepth.xyz, -lightToPxlVec );
// Get the shadow texture coordinate
float4 pxlPosLightProj = mul( viewToLightProj, float4( viewSpacePos, 1 ) );
float2 shadowCoord = ( ( pxlPosLightProj.xy / pxlPosLightProj.w ) * 0.5 ) + float2( 0.5, 0.5 );
shadowCoord.y = 1.0f - shadowCoord.y;
// Get the dynamic shadow texture coordinate
float4 dynpxlPosLightProj = mul( dynamicViewToLightProj, float4( viewSpacePos, 1 ) );
float2 dynshadowCoord = ( ( dynpxlPosLightProj.xy / dynpxlPosLightProj.w ) * 0.5 ) + float2( 0.5, 0.5 );
dynshadowCoord.y = 1.0f - dynshadowCoord.y;
#ifdef NO_SHADOW
float shadowed = 1.0;
#else
// Get a linear depth from the light source.
float distToLight = pxlPosLightProj.z / lightRange;
float static_shadowed = softShadow_filter( TORQUE_SAMPLER2D_MAKEARG(shadowMap),
ssPos.xy,
shadowCoord,
shadowSoftness,
distToLight,
nDotL,
lightParams.y );
float dynamic_shadowed = softShadow_filter( TORQUE_SAMPLER2D_MAKEARG(dynamicShadowMap),
ssPos.xy,
dynshadowCoord,
shadowSoftness,
distToLight,
nDotL,
lightParams.y );
float shadowed = min(static_shadowed, dynamic_shadowed);
#endif // !NO_SHADOW
float3 lightcol = lightColor.rgb;
#ifdef USE_COOKIE_TEX
// Lookup the cookie sample.
float4 cookie = TORQUE_TEX2D( cookieMap, shadowCoord );
// Multiply the light with the cookie tex.
lightcol *= cookie.rgb;
// Use a maximum channel luminance to attenuate
// the lighting else we get specular in the dark
// regions of the cookie texture.
atten *= max( cookie.r, max( cookie.g, cookie.b ) );
#endif
//get directional light contribution
LightResult result = GetDirectionalLight(surface, surfaceToLight, lightColor.rgb, lightBrightness, shadowed);
//output
Output.diffuse = float4(result.diffuse*atten, 0);
Output.spec = float4(result.spec*atten, 0);
return Output;
return float4(result, 0);
}

View file

@ -26,7 +26,6 @@
#include "farFrustumQuad.hlsl"
#include "../../torque.hlsl"
#include "../../lighting.hlsl"
#include "lightingUtils.hlsl"
#include "../shadowMap/shadowMapIO_HLSL.h"
#include "softShadow.hlsl"
@ -182,15 +181,11 @@ float4 AL_VectorLightShadowCast( TORQUE_SAMPLER2D(sourceShadowMap),
};
LightTargetOutput main(FarFrustumQuadConnectP IN)
float4 main(FarFrustumQuadConnectP IN) : SV_TARGET
{
LightTargetOutput Output = (LightTargetOutput)0;
//sky and editor background check
float4 normDepth = UnpackDepthNormal(TORQUE_SAMPLER2D_MAKEARG(deferredBuffer), IN.uv0);
if (normDepth.w>0.9999)
return Output;
//unpack normal and linear depth
float4 normDepth = TORQUE_DEFERRED_UNCONDITION(deferredBuffer, IN.uv0);
//create surface
Surface surface = CreateSurface( normDepth, TORQUE_SAMPLER2D_MAKEARG(colorBuffer),TORQUE_SAMPLER2D_MAKEARG(matInfoBuffer),
IN.uv0, eyePosWorld, IN.wsEyeRay, cameraToWorld);
@ -198,9 +193,7 @@ LightTargetOutput main(FarFrustumQuadConnectP IN)
//early out if emissive
if (getFlag(surface.matFlag, 0))
{
Output.diffuse = surface.baseColor;
Output.spec = surface.baseColor;
return Output;
return 0.0.xxxx;
}
//create surface to light
@ -217,7 +210,7 @@ LightTargetOutput main(FarFrustumQuadConnectP IN)
float4 zDist = (zNearFarInvNearFar.x + zNearFarInvNearFar.y * surface.depth);
float fadeOutAmt = ( zDist.x - fadeStartLength.x ) * fadeStartLength.y;
//there must be a better way of doing this, two shadowcast lookups = very yucky!
//there must be a more effecient way of doing this, two shadowcast lookups = very yucky!
float4 static_shadowed_colors = AL_VectorLightShadowCast( TORQUE_SAMPLER2D_MAKEARG(shadowMap), IN.uv0.xy, worldToLightProj, surface.P, scaleX, scaleY, offsetX, offsetY,
farPlaneScalePSSM, surfaceToLight.NdotL);
@ -244,10 +237,7 @@ LightTargetOutput main(FarFrustumQuadConnectP IN)
#endif //NO_SHADOW
//get directional light contribution
LightResult result = GetDirectionalLight(surface, surfaceToLight, lightingColor.rgb, lightBrightness, shadow);
//output
Output.diffuse = float4(result.diffuse, 0);
Output.spec = float4(result.spec, 0);
float3 result = GetDirectionalLight(surface, surfaceToLight, lightingColor.rgb, lightBrightness, shadow);
return Output;
return float4(result, 0);
}

View file

@ -28,22 +28,6 @@
// Portability helpers for autogenConditioners
//todo deprecate this function
#define TORQUE_DEFERRED_UNCONDITION(tex, coords) deferredUncondition(tex, texture_##tex, coords)
inline float4 UnpackDepthNormal(TORQUE_SAMPLER2D(tex), float2 screenUVVar)
{
// Sampler g-buffer
float4 bufferSample = TORQUE_TEX2DLOD(tex,float4(screenUVVar,0,0));
// g-buffer unconditioner: float4(normal.X, normal.Y, depth Hi, depth Lo)
float2 _inpXY = bufferSample.xy;
float _xySQ = dot(_inpXY, _inpXY);
float4 _gbUnconditionedInput = float4( sqrt(half(1.0 - (_xySQ / 4.0))) * _inpXY, -1.0 + (_xySQ / 2.0), bufferSample.a).xzyw;
// Decode depth
_gbUnconditionedInput.w = dot( bufferSample.zw, float2(1.0, 1.0/65535.0));
return _gbUnconditionedInput;
}
#endif //_TORQUE_SHADERMODEL_AUTOGEN_