mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-07-13 07:34:45 +00:00
timmy merge work
This commit is contained in:
parent
f1e584ca69
commit
ab10cc0c87
29 changed files with 295 additions and 925 deletions
|
|
@ -92,7 +92,7 @@ new CustomMaterial( AL_VectorLightMaterial )
|
|||
sampler["colorBuffer"] = "#color";
|
||||
sampler["matInfoBuffer"] = "#matinfo";
|
||||
|
||||
target = "diffuseLighting";
|
||||
target = "AL_FormatToken";
|
||||
|
||||
pixVersion = 3.0;
|
||||
};
|
||||
|
|
@ -170,7 +170,7 @@ new CustomMaterial( AL_PointLightMaterial )
|
|||
sampler["colorBuffer"] = "#color";
|
||||
sampler["matInfoBuffer"] = "#matinfo";
|
||||
|
||||
target = "diffuseLighting";
|
||||
target = "AL_FormatToken";
|
||||
|
||||
pixVersion = 3.0;
|
||||
};
|
||||
|
|
@ -209,7 +209,7 @@ new CustomMaterial( AL_SpotLightMaterial )
|
|||
sampler["colorBuffer"] = "#color";
|
||||
sampler["matInfoBuffer"] = "#matinfo";
|
||||
|
||||
target = "diffuseLighting";
|
||||
target = "AL_FormatToken";
|
||||
|
||||
pixVersion = 3.0;
|
||||
};
|
||||
|
|
@ -375,17 +375,6 @@ new ShaderData( PrefiterCubemapShader )
|
|||
pixVersion = 3.0;
|
||||
};
|
||||
|
||||
new ShaderData( BRDFLookupShader )
|
||||
{
|
||||
DXVertexShaderFile = "shaders/common/lighting/advanced/cubemapV.hlsl";
|
||||
DXPixelShaderFile = "shaders/common/lighting/advanced/brdfLookupP.hlsl";
|
||||
|
||||
OGLVertexShaderFile = "shaders/common/lighting/advanced/gl/cubemapV.glsl";
|
||||
OGLPixelShaderFile = "shaders/common/lighting/advanced/gl/brdfLookupP.glsl";
|
||||
|
||||
pixVersion = 3.0;
|
||||
};
|
||||
|
||||
new ShaderData( SkyLightShader )
|
||||
{
|
||||
DXVertexShaderFile = "shaders/common/lighting/advanced/convexGeometryV.hlsl";
|
||||
|
|
|
|||
|
|
@ -138,16 +138,3 @@ singleton ShaderData( VolumetricFogReflectionShader )
|
|||
|
||||
pixVersion = 3.0;
|
||||
};
|
||||
|
||||
singleton ShaderData( CubemapSaveShader )
|
||||
{
|
||||
DXVertexShaderFile = "shaders/common/cubemapSaveV.hlsl";
|
||||
DXPixelShaderFile = "shaders/common/cubemapSaveP.hlsl";
|
||||
|
||||
OGLVertexShaderFile = "shaders/common/gl/cubemapSaveV.glsl";
|
||||
OGLPixelShaderFile = "shaders/common/gl/cubemapSaveP.glsl";
|
||||
|
||||
samplerNames[0] = "$cubemapTex";
|
||||
|
||||
pixVersion = 3.0;
|
||||
};
|
||||
|
|
@ -1,63 +0,0 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) 2016 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 "shaderModel.hlsl"
|
||||
|
||||
struct Conn
|
||||
{
|
||||
float4 hpos : TORQUE_POSITION;
|
||||
float3 face_pos_x : TEXCOORD0;
|
||||
float3 face_neg_x : TEXCOORD1;
|
||||
float3 face_pos_y : TEXCOORD2;
|
||||
float3 face_neg_y : TEXCOORD3;
|
||||
float3 face_pos_z : TEXCOORD4;
|
||||
float3 face_neg_z : TEXCOORD5;
|
||||
};
|
||||
|
||||
struct Fragout
|
||||
{
|
||||
float4 target0 : TORQUE_TARGET0;
|
||||
float4 target1 : TORQUE_TARGET1;
|
||||
float4 target2 : TORQUE_TARGET2;
|
||||
float4 target3 : TORQUE_TARGET3;
|
||||
float4 target4 : TORQUE_TARGET4;
|
||||
float4 target5 : TORQUE_TARGET5;
|
||||
};
|
||||
|
||||
TORQUE_UNIFORM_SAMPLERCUBE(cubemapTex, 0);
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Main
|
||||
//-----------------------------------------------------------------------------
|
||||
Fragout main(Conn In)
|
||||
{
|
||||
Fragout Out;
|
||||
|
||||
Out.target0 = TORQUE_TEXCUBE(cubemapTex, In.face_pos_x);
|
||||
Out.target1 = TORQUE_TEXCUBE(cubemapTex, In.face_neg_x);
|
||||
Out.target2 = TORQUE_TEXCUBE(cubemapTex, In.face_pos_y);
|
||||
Out.target3 = TORQUE_TEXCUBE(cubemapTex, In.face_neg_y);
|
||||
Out.target4 = TORQUE_TEXCUBE(cubemapTex, In.face_pos_z);
|
||||
Out.target5 = TORQUE_TEXCUBE(cubemapTex, In.face_neg_z);
|
||||
|
||||
return Out;
|
||||
}
|
||||
|
|
@ -1,56 +0,0 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) 2016 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 "shaderModel.hlsl"
|
||||
|
||||
struct Conn
|
||||
{
|
||||
float4 hpos : TORQUE_POSITION;
|
||||
float3 face_pos_x : TEXCOORD0;
|
||||
float3 face_neg_x : TEXCOORD1;
|
||||
float3 face_pos_y : TEXCOORD2;
|
||||
float3 face_neg_y : TEXCOORD3;
|
||||
float3 face_pos_z : TEXCOORD4;
|
||||
float3 face_neg_z : TEXCOORD5;
|
||||
};
|
||||
|
||||
uniform float4x4 matrix0;
|
||||
uniform float4x4 matrix1;
|
||||
uniform float4x4 matrix2;
|
||||
uniform float4x4 matrix3;
|
||||
uniform float4x4 matrix4;
|
||||
uniform float4x4 matrix5;
|
||||
|
||||
Conn main(uint id: SV_VertexID)
|
||||
{
|
||||
Conn Out;
|
||||
float4 vertex = float4(float2((id << 1) & 2, id & 2) * float2(2, -2) + float2(-1, 1), 0, 1);
|
||||
Out.hpos = vertex;
|
||||
Out.face_pos_x = mul(matrix0, vertex).xyz;
|
||||
Out.face_neg_x = mul(matrix1, vertex).xyz;
|
||||
Out.face_pos_y = mul(matrix2, vertex).xyz;
|
||||
Out.face_neg_y = mul(matrix3, vertex).xyz;
|
||||
Out.face_pos_z = mul(matrix4, vertex).xyz;
|
||||
Out.face_neg_z = mul(matrix5, vertex).xyz;
|
||||
|
||||
return Out;
|
||||
}
|
||||
|
|
@ -122,7 +122,7 @@ struct Surface
|
|||
}
|
||||
};
|
||||
|
||||
inline Surface CreateSurface(float4 gbuffer0, TORQUE_SAMPLER2D(gbufferTex1), TORQUE_SAMPLER2D(gbufferTex2), in float2 uv, in float3 wsEyePos, in float3 wsEyeRay, in float4x4 invView)
|
||||
inline Surface createSurface(float4 gbuffer0, TORQUE_SAMPLER2D(gbufferTex1), TORQUE_SAMPLER2D(gbufferTex2), in float2 uv, in float3 wsEyePos, in float3 wsEyeRay, in float4x4 invView)
|
||||
{
|
||||
Surface surface = (Surface)0;
|
||||
|
||||
|
|
@ -148,15 +148,17 @@ inline Surface CreateSurface(float4 gbuffer0, TORQUE_SAMPLER2D(gbufferTex1), TOR
|
|||
struct SurfaceToLight
|
||||
{
|
||||
float3 L; // surface to light vector
|
||||
float3 Lu; // un-normalized surface to light vector
|
||||
float3 H; // half-vector between view vector and light vector
|
||||
float NdotL; // cos(angle between N and L)
|
||||
float HdotV; // cos(angle between H and V) = HdotL = cos(angle between H and L)
|
||||
float NdotH; // cos(angle between N and H)
|
||||
};
|
||||
|
||||
inline SurfaceToLight CreateSurfaceToLight(in Surface surface, in float3 L)
|
||||
inline SurfaceToLight createSurfaceToLight(in Surface surface, in float3 L)
|
||||
{
|
||||
SurfaceToLight surfaceToLight = (SurfaceToLight)0;
|
||||
surfaceToLight.Lu = L;
|
||||
surfaceToLight.L = normalize(L);
|
||||
surfaceToLight.H = normalize(surface.V + surfaceToLight.L);
|
||||
surfaceToLight.NdotL = saturate(dot(surfaceToLight.L, surface.N));
|
||||
|
|
@ -187,15 +189,32 @@ float3 BRDF_GetDiffuse(in Surface surface, in SurfaceToLight surfaceToLight)
|
|||
return diffuse;
|
||||
}
|
||||
|
||||
// inverse square falloff from Epic Games' paper
|
||||
float Attenuate(float distToLight, float radius)
|
||||
//attenuations functions from "moving frostbite to pbr paper"
|
||||
//https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf
|
||||
float smoothDistanceAtt ( float squaredDistance , float invSqrAttRadius )
|
||||
{
|
||||
float distanceByRadius = 1.0f - pow((distToLight / radius), 4);
|
||||
float clamped = pow(clamp(distanceByRadius, 0.0f, 1.0f), 2.0f);
|
||||
return clamped / (sqr(distToLight) + 1.0f);
|
||||
float factor = squaredDistance * invSqrAttRadius ;
|
||||
float smoothFactor = saturate (1.0f - factor * factor );
|
||||
return sqr(smoothFactor);
|
||||
}
|
||||
|
||||
inline float3 GetDirectionalLight(in Surface surface, in SurfaceToLight surfaceToLight, float3 lightColor, float lightIntensity, float shadow)
|
||||
float getDistanceAtt( float3 unormalizedLightVector , float invSqrAttRadius )
|
||||
{
|
||||
float sqrDist = dot ( unormalizedLightVector , unormalizedLightVector );
|
||||
float attenuation = 1.0 / (max ( sqrDist , 0.01*0.01) );
|
||||
attenuation *= smoothDistanceAtt ( sqrDist , invSqrAttRadius );
|
||||
return attenuation;
|
||||
}
|
||||
|
||||
float getSpotAngleAtt( float3 normalizedLightVector , float3 lightDir , float2 lightSpotParams )
|
||||
{
|
||||
float cd = dot ( lightDir , normalizedLightVector );
|
||||
float attenuation = saturate ( ( cd - lightSpotParams.x ) / lightSpotParams.y );
|
||||
// smooth the transition
|
||||
return sqr(attenuation);
|
||||
}
|
||||
|
||||
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;
|
||||
|
|
@ -205,10 +224,9 @@ inline float3 GetDirectionalLight(in Surface surface, in SurfaceToLight surfaceT
|
|||
return final;
|
||||
}
|
||||
|
||||
inline float3 GetPointLight(in Surface surface, in SurfaceToLight surfaceToLight, float3 lightColor, float lightIntensity,float distToLight, float radius, float shadow)
|
||||
inline float3 getPunctualLight(in Surface surface, in SurfaceToLight surfaceToLight, float3 lightColor, float lightIntensity, float radius, float shadow)
|
||||
{
|
||||
float attenuation = Attenuate(distToLight,radius);
|
||||
|
||||
float attenuation = getDistanceAtt(surfaceToLight.Lu, radius);
|
||||
float3 factor = lightColor * max(surfaceToLight.NdotL, 0) * shadow * lightIntensity * attenuation;
|
||||
|
||||
float3 diffuse = BRDF_GetDiffuse(surface,surfaceToLight) * factor;
|
||||
|
|
@ -217,15 +235,3 @@ inline float3 GetPointLight(in Surface surface, in SurfaceToLight surfaceToLight
|
|||
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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,138 +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 "../../torque.hlsl"
|
||||
|
||||
struct ConnectData
|
||||
{
|
||||
float4 hpos : TORQUE_POSITION;
|
||||
float2 uv : TEXCOORD;
|
||||
};
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// http://holger.dammertz.org/stuff/notes_HammersleyOnHemisphere.html
|
||||
// efficient VanDerCorpus calculation.
|
||||
float RadicalInverse_VdC(uint bits)
|
||||
{
|
||||
bits = (bits << 16u) | (bits >> 16u);
|
||||
bits = ((bits & 0x55555555u) << 1u) | ((bits & 0xAAAAAAAAu) >> 1u);
|
||||
bits = ((bits & 0x33333333u) << 2u) | ((bits & 0xCCCCCCCCu) >> 2u);
|
||||
bits = ((bits & 0x0F0F0F0Fu) << 4u) | ((bits & 0xF0F0F0F0u) >> 4u);
|
||||
bits = ((bits & 0x00FF00FFu) << 8u) | ((bits & 0xFF00FF00u) >> 8u);
|
||||
return float(bits) * 2.3283064365386963e-10; // / 0x100000000
|
||||
}
|
||||
// ----------------------------------------------------------------------------
|
||||
float2 Hammersley(uint i, uint N)
|
||||
{
|
||||
return float2(float(i)/float(N), RadicalInverse_VdC(i));
|
||||
}
|
||||
// ----------------------------------------------------------------------------
|
||||
float3 ImportanceSampleGGX(float2 Xi, float3 N, float roughness)
|
||||
{
|
||||
float a = roughness*roughness;
|
||||
|
||||
float phi = 2.0 * M_PI_F * Xi.x;
|
||||
float cosTheta = sqrt((1.0 - Xi.y) / (1.0 + (a*a - 1.0) * Xi.y));
|
||||
float sinTheta = sqrt(1.0 - cosTheta*cosTheta);
|
||||
|
||||
// from spherical coordinates to cartesian coordinates - halfway vector
|
||||
float3 H;
|
||||
H.x = cos(phi) * sinTheta;
|
||||
H.y = sin(phi) * sinTheta;
|
||||
H.z = cosTheta;
|
||||
|
||||
// from tangent-space H vector to world-space sample vector
|
||||
float3 up = abs(N.z) < 0.999 ? float3(0.0, 0.0, 1.0) : float3(1.0, 0.0, 0.0);
|
||||
float3 tangent = normalize(cross(up, N));
|
||||
float3 bitangent = cross(N, tangent);
|
||||
|
||||
float3 sampleVec = tangent * H.x + bitangent * H.y + N * H.z;
|
||||
return normalize(sampleVec);
|
||||
}
|
||||
// ----------------------------------------------------------------------------
|
||||
float GeometrySchlickGGX(float NdotV, float roughness)
|
||||
{
|
||||
// note that we use a different k for IBL
|
||||
float a = roughness;
|
||||
float k = (a * a) / 2.0;
|
||||
|
||||
float nom = NdotV;
|
||||
float denom = NdotV * (1.0 - k) + k;
|
||||
|
||||
return nom / denom;
|
||||
}
|
||||
// ----------------------------------------------------------------------------
|
||||
float GeometrySmith(float3 N, float3 V, float3 L, float roughness)
|
||||
{
|
||||
float NdotV = max(dot(N, V), 0.0);
|
||||
float NdotL = max(dot(N, L), 0.0);
|
||||
float ggx2 = GeometrySchlickGGX(NdotV, roughness);
|
||||
float ggx1 = GeometrySchlickGGX(NdotL, roughness);
|
||||
|
||||
return ggx1 * ggx2;
|
||||
}
|
||||
// ----------------------------------------------------------------------------
|
||||
float2 IntegrateBRDF(float NdotV, float roughness)
|
||||
{
|
||||
float3 V;
|
||||
V.x = sqrt(1.0 - NdotV*NdotV);
|
||||
V.y = 0.0;
|
||||
V.z = NdotV;
|
||||
|
||||
float A = 0.0;
|
||||
float B = 0.0;
|
||||
|
||||
float3 N = float3(0.0, 0.0, 1.0);
|
||||
|
||||
const uint SAMPLE_COUNT = 1024u;
|
||||
for(uint i = 0u; i < SAMPLE_COUNT; ++i)
|
||||
{
|
||||
// generates a sample vector that's biased towards the
|
||||
// preferred alignment direction (importance sampling).
|
||||
float2 Xi = Hammersley(i, SAMPLE_COUNT);
|
||||
float3 H = ImportanceSampleGGX(Xi, N, roughness);
|
||||
float3 L = normalize(2.0 * dot(V, H) * H - V);
|
||||
|
||||
float NdotL = max(L.z, 0.0);
|
||||
float NdotH = max(H.z, 0.0);
|
||||
float VdotH = max(dot(V, H), 0.0);
|
||||
|
||||
if(NdotL > 0.0)
|
||||
{
|
||||
float G = GeometrySmith(N, V, L, roughness);
|
||||
float G_Vis = (G * VdotH) / (NdotH * NdotV);
|
||||
float Fc = pow(1.0 - VdotH, 5.0);
|
||||
|
||||
A += (1.0 - Fc) * G_Vis;
|
||||
B += Fc * G_Vis;
|
||||
}
|
||||
}
|
||||
A /= float(SAMPLE_COUNT);
|
||||
B /= float(SAMPLE_COUNT);
|
||||
return float2(A, B);
|
||||
}
|
||||
|
||||
float4 main(ConnectData IN) : TORQUE_TARGET0
|
||||
{
|
||||
return float4(IntegrateBRDF(IN.uv.x, IN.uv.y).rg,0,1);
|
||||
//return float2(1,1);
|
||||
}
|
||||
|
|
@ -36,7 +36,6 @@ struct ConvexConnectP
|
|||
float4 vsEyeDir : TEXCOORD2;
|
||||
};
|
||||
|
||||
|
||||
#ifdef USE_COOKIE_TEX
|
||||
|
||||
/// The texture for cookie rendering.
|
||||
|
|
@ -130,12 +129,11 @@ uniform float4 lightMapParams;
|
|||
uniform float4 vsFarPlane;
|
||||
uniform float4 lightParams;
|
||||
|
||||
uniform float lightRange;
|
||||
uniform float lightRange;
|
||||
uniform float lightInvSqrRange;
|
||||
uniform float shadowSoftness;
|
||||
uniform float4x4 worldToCamera;
|
||||
uniform float3x3 viewToLightProj;
|
||||
uniform float3x3 worldToLightProj;
|
||||
uniform float3x3 dynamicViewToLightProj;
|
||||
|
||||
uniform float3 eyePosWorld;
|
||||
uniform float4x4 cameraToWorld;
|
||||
|
|
@ -154,7 +152,7 @@ float4 main( ConvexConnectP IN ) : SV_TARGET
|
|||
float3 wsEyeRay = mul(cameraToWorld, float4(vsEyeRay, 0)).xyz;
|
||||
|
||||
//create surface
|
||||
Surface surface = CreateSurface( normDepth, TORQUE_SAMPLER2D_MAKEARG(colorBuffer),TORQUE_SAMPLER2D_MAKEARG(matInfoBuffer),
|
||||
Surface surface = createSurface( normDepth, TORQUE_SAMPLER2D_MAKEARG(colorBuffer),TORQUE_SAMPLER2D_MAKEARG(matInfoBuffer),
|
||||
uvScene, eyePosWorld, wsEyeRay, cameraToWorld);
|
||||
|
||||
//early out if emissive
|
||||
|
|
@ -165,12 +163,12 @@ float4 main( ConvexConnectP IN ) : SV_TARGET
|
|||
|
||||
float3 L = lightPosition - surface.P;
|
||||
float dist = length(L);
|
||||
float3 result = 0.0.xxx;
|
||||
float3 lighting = 0.0.xxx;
|
||||
[branch]
|
||||
if (dist < lightRange)
|
||||
if(dist < lightRange)
|
||||
{
|
||||
float distToLight = dist / lightRange;
|
||||
SurfaceToLight surfaceToLight = CreateSurfaceToLight(surface, L);
|
||||
SurfaceToLight surfaceToLight = createSurfaceToLight(surface, L);
|
||||
|
||||
#ifdef NO_SHADOW
|
||||
float shadowed = 1.0;
|
||||
|
|
@ -183,50 +181,29 @@ float4 main( ConvexConnectP IN ) : SV_TARGET
|
|||
float shadowed = saturate( exp( lightParams.y * ( occ - distToLight ) ) );
|
||||
|
||||
#else
|
||||
// Static
|
||||
float2 shadowCoord = decodeShadowCoord( mul( worldToLightProj, -surfaceToLight.L ) ).xy;
|
||||
float static_shadowed = softShadow_filter(TORQUE_SAMPLER2D_MAKEARG(shadowMap),
|
||||
ssPos.xy,
|
||||
shadowCoord,
|
||||
shadowSoftness,
|
||||
distToLight,
|
||||
surfaceToLight.NdotL,
|
||||
lightParams.y);
|
||||
|
||||
// Dynamic
|
||||
float dynamic_shadowed = softShadow_filter(TORQUE_SAMPLER2D_MAKEARG(dynamicShadowMap),
|
||||
ssPos.xy,
|
||||
shadowCoord,
|
||||
shadowSoftness,
|
||||
distToLight,
|
||||
surfaceToLight.NdotL,
|
||||
lightParams.y);
|
||||
|
||||
float static_shadowed = softShadow_filter(TORQUE_SAMPLER2D_MAKEARG(shadowMap), ssPos.xy, shadowCoord, shadowSoftness, distToLight, surfaceToLight.NdotL, lightParams.y);
|
||||
float dynamic_shadowed = softShadow_filter(TORQUE_SAMPLER2D_MAKEARG(dynamicShadowMap), ssPos.xy, shadowCoord, shadowSoftness, distToLight, surfaceToLight.NdotL, lightParams.y);
|
||||
float shadowed = min(static_shadowed, dynamic_shadowed);
|
||||
|
||||
#endif
|
||||
|
||||
#endif // !NO_SHADOW
|
||||
|
||||
float3 lightcol = lightColor.rgb;
|
||||
float3 lightCol = lightColor.rgb;
|
||||
#ifdef USE_COOKIE_TEX
|
||||
|
||||
// Lookup the cookie sample.
|
||||
float4 cookie = TORQUE_TEXCUBE(cookieMap, mul(worldToLightProj, -surfaceToLight.L));
|
||||
|
||||
// Multiply the light with the cookie tex.
|
||||
lightcol *= cookie.rgb;
|
||||
|
||||
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));
|
||||
|
||||
lightCol *= max(cookie.r, max(cookie.g, cookie.b));
|
||||
#endif
|
||||
|
||||
//get point light contribution
|
||||
result = GetPointLight(surface, surfaceToLight, lightcol, lightBrightness, dist, lightRange, shadowed);
|
||||
//get punctual light contribution
|
||||
lighting = getPunctualLight(surface, surfaceToLight, lightCol, lightBrightness, lightInvSqrRange, shadowed);
|
||||
}
|
||||
|
||||
return float4(result, 0);
|
||||
return float4(lighting, 0);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,69 +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"
|
||||
#include "shaders/common/torque.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 float radius;
|
||||
uniform float2 targetSize;
|
||||
uniform int captureRez;
|
||||
float4 main( PFXVertToPix IN ) : TORQUE_TARGET0
|
||||
{
|
||||
float depth = TORQUE_DEFERRED_UNCONDITION( deferredTex, IN.uv0 ).w;
|
||||
|
||||
if (depth>0.9999)
|
||||
return float4(0,0,0,0);
|
||||
|
||||
float3 albedo = TORQUE_TEX2D( colorBufferTex, IN.uv0 ).rgb; //albedo
|
||||
float4 matInfo = TORQUE_TEX2D(matInfoTex, IN.uv0); //flags|smoothness|ao|metallic
|
||||
|
||||
bool emissive = getFlag(matInfo.r, 0);
|
||||
if (emissive)
|
||||
{
|
||||
return float4(albedo, 1.0);
|
||||
}
|
||||
|
||||
float4 diffuse = TORQUE_TEX2D( diffuseLightingBuffer, IN.uv0 ); //shadowmap*specular
|
||||
float4 specular = TORQUE_TEX2D( specularLightingBuffer, IN.uv0 ); //environment mapping*lightmaps
|
||||
|
||||
float metalness = matInfo.a;
|
||||
|
||||
float3 diffuseColor = albedo - (albedo * metalness);
|
||||
float3 specularColor = lerp(float3(0.04,0.04,0.04), albedo, metalness);
|
||||
|
||||
float3 light = (diffuseColor * diffuse.rgb) + (specularColor * specular.rgb);
|
||||
float2 relUV = IN.uv0*targetSize/captureRez;
|
||||
|
||||
//we use a 1k depth range in the capture frustum.
|
||||
//reduce that a bit to get something resembling depth fidelity out of 8 bits
|
||||
depth*=2000/radius;
|
||||
|
||||
float rLen = length(float3(relUV,depth)-float3(0.5,0.5,0));
|
||||
return hdrEncode( float4(light,rLen));
|
||||
}
|
||||
|
|
@ -79,31 +79,6 @@ float3 iblBoxSpecular(float3 normal, float3 wsPos, float roughness, float3 surfT
|
|||
return radiance;
|
||||
}
|
||||
|
||||
/*
|
||||
float defineSphereSpaceInfluence(float3 centroidPosVS, float rad, float2 atten, float3 surfPosVS, float3 norm)
|
||||
{
|
||||
// Build light vec, get length, clip pixel if needed
|
||||
float3 lightVec = centroidPosVS - surfPosVS;
|
||||
float lenLightV = length( lightVec );
|
||||
if (( rad - lenLightV )<0)
|
||||
return -1;
|
||||
|
||||
// Get the attenuated falloff.
|
||||
float attn = attenuate( float4(1,1,1,1), atten, lenLightV );
|
||||
if ((attn - 1e-6)<0)
|
||||
return -1;
|
||||
|
||||
// Normalize lightVec
|
||||
lightVec = lightVec /= lenLightV;
|
||||
|
||||
// If we can do dynamic branching then avoid wasting
|
||||
// fillrate on pixels that are backfacing to the light.
|
||||
float nDotL = abs(dot( lightVec, norm ));
|
||||
|
||||
return saturate( nDotL * attn );
|
||||
}
|
||||
*/
|
||||
|
||||
float defineBoxSpaceInfluence(float3 surfPosWS, float3 probePos, float radius, float atten)
|
||||
{
|
||||
float3 surfPosLS = mul( worldToObj, float4(surfPosWS,1.0)).xyz;
|
||||
|
|
@ -120,18 +95,6 @@ float defineBoxSpaceInfluence(float3 surfPosWS, float3 probePos, float radius, f
|
|||
return max(localDir.x, max(localDir.y, localDir.z)) * -1;
|
||||
}
|
||||
|
||||
float defineDepthInfluence(float3 probePosWS, float3 surfPosWS, TORQUE_SAMPLERCUBE(radianceCube))
|
||||
{
|
||||
//TODO properly: filter out pixels projected uppon by probes behind walls by looking up the depth stored in the probes cubemap alpha
|
||||
//and comparing legths
|
||||
float3 probeToSurf = probePosWS-surfPosWS;
|
||||
|
||||
float depthRef = TORQUE_TEXCUBELOD(cubeMap, float4(-probeToSurf,0)).a*radius;
|
||||
float dist = length( probeToSurf );
|
||||
|
||||
return depthRef-dist;
|
||||
}
|
||||
|
||||
float4 main( ConvexConnectP IN ) : SV_TARGET
|
||||
{
|
||||
// Compute scene UV
|
||||
|
|
@ -146,16 +109,14 @@ float4 main( ConvexConnectP IN ) : SV_TARGET
|
|||
float4 normDepth = TORQUE_DEFERRED_UNCONDITION(deferredBuffer, uvScene);
|
||||
|
||||
//create surface
|
||||
Surface surface = CreateSurface( normDepth, TORQUE_SAMPLER2D_MAKEARG(colorBuffer),TORQUE_SAMPLER2D_MAKEARG(matInfoBuffer),
|
||||
Surface surface = createSurface( normDepth, TORQUE_SAMPLER2D_MAKEARG(colorBuffer),TORQUE_SAMPLER2D_MAKEARG(matInfoBuffer),
|
||||
uvScene, eyePosWorld, wsEyeRay, cameraToWorld);
|
||||
|
||||
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)));
|
||||
|
||||
|
||||
//render into the bound space defined above
|
||||
float3 surfToEye = normalize(surface.P - eyePosWorld);
|
||||
float3 irradiance = TORQUE_TEXCUBELOD(irradianceCubemap, float4(surface.N,0)).xyz;
|
||||
|
|
|
|||
|
|
@ -46,7 +46,7 @@ float4 main( ConvexConnectP IN ) : SV_TARGET
|
|||
float4 normDepth = TORQUE_DEFERRED_UNCONDITION(deferredBuffer, uvScene);
|
||||
|
||||
//create surface
|
||||
Surface surface = CreateSurface( normDepth, TORQUE_SAMPLER2D_MAKEARG(colorBuffer),TORQUE_SAMPLER2D_MAKEARG(matInfoBuffer),
|
||||
Surface surface = createSurface( normDepth, TORQUE_SAMPLER2D_MAKEARG(colorBuffer),TORQUE_SAMPLER2D_MAKEARG(matInfoBuffer),
|
||||
uvScene, eyePosWorld, wsEyeRay, cameraToWorld);
|
||||
|
||||
float3 F = FresnelSchlickRoughness(surface.NdotV, surface.f0, surface.roughness);
|
||||
|
|
@ -58,7 +58,5 @@ float4 main( ConvexConnectP IN ) : SV_TARGET
|
|||
//final diffuse color
|
||||
float3 diffuse = kD * irradiance * surface.baseColor.rgb;
|
||||
|
||||
float blendVal = 0.0001;
|
||||
|
||||
return float4(diffuse + specular * surface.ao, 0);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -57,10 +57,11 @@ uniform float3 lightPosition;
|
|||
|
||||
uniform float4 lightColor;
|
||||
|
||||
uniform float lightRange;
|
||||
uniform float lightRange;
|
||||
uniform float lightInvSqrRange;
|
||||
uniform float3 lightDirection;
|
||||
|
||||
uniform float4 lightSpotParams;
|
||||
uniform float2 lightSpotParams;
|
||||
uniform float4 lightMapParams;
|
||||
uniform float4 vsFarPlane;
|
||||
uniform float4x4 worldToLightProj;
|
||||
|
|
@ -70,6 +71,7 @@ uniform float shadowSoftness;
|
|||
uniform float3 eyePosWorld;
|
||||
|
||||
uniform float4x4 cameraToWorld;
|
||||
uniform float4x4 worldToCamera;
|
||||
|
||||
float4 main( ConvexConnectP IN ) : SV_TARGET
|
||||
{
|
||||
|
|
@ -85,7 +87,7 @@ float4 main( ConvexConnectP IN ) : SV_TARGET
|
|||
float3 wsEyeRay = mul(cameraToWorld, float4(vsEyeRay, 0)).xyz;
|
||||
|
||||
//create surface
|
||||
Surface surface = CreateSurface( normDepth, TORQUE_SAMPLER2D_MAKEARG(colorBuffer),TORQUE_SAMPLER2D_MAKEARG(matInfoBuffer),
|
||||
Surface surface = createSurface( normDepth, TORQUE_SAMPLER2D_MAKEARG(colorBuffer),TORQUE_SAMPLER2D_MAKEARG(matInfoBuffer),
|
||||
uvScene, eyePosWorld, wsEyeRay, cameraToWorld);
|
||||
|
||||
//early out if emissive
|
||||
|
|
@ -93,27 +95,45 @@ float4 main( ConvexConnectP IN ) : SV_TARGET
|
|||
{
|
||||
return 0.0.xxxx;
|
||||
}
|
||||
|
||||
|
||||
float3 L = lightPosition - surface.P;
|
||||
float dist = length(L);
|
||||
float3 result = 0.0.xxx;
|
||||
float3 lighting = 0.0.xxx;
|
||||
[branch]
|
||||
if (dist < lightRange)
|
||||
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);
|
||||
}
|
||||
SurfaceToLight surfaceToLight = createSurfaceToLight(surface, L);
|
||||
#ifdef NO_SHADOW
|
||||
float shadowed = 1.0;
|
||||
#else
|
||||
// Get the shadow texture coordinate
|
||||
float4 pxlPosLightProj = mul( worldToLightProj, float4( surface.P, 1 ) );
|
||||
float2 shadowCoord = ( ( pxlPosLightProj.xy / pxlPosLightProj.w ) * 0.5 ) + float2( 0.5, 0.5 );
|
||||
shadowCoord.y = 1.0f - shadowCoord.y;
|
||||
//distance to light in shadow map space
|
||||
float distToLight = pxlPosLightProj.z / lightRange;
|
||||
float static_shadowed = softShadow_filter(TORQUE_SAMPLER2D_MAKEARG(shadowMap), ssPos.xy, shadowCoord, shadowSoftness, distToLight, surfaceToLight.NdotL, lightParams.y);
|
||||
float dynamic_shadowed = softShadow_filter(TORQUE_SAMPLER2D_MAKEARG(dynamicShadowMap), ssPos.xy, shadowCoord, shadowSoftness, distToLight, surfaceToLight.NdotL, lightParams.y);
|
||||
float shadowed = min(static_shadowed, dynamic_shadowed);
|
||||
#endif
|
||||
|
||||
float3 lightCol = lightColor.rgb;
|
||||
#ifdef USE_COOKIE_TEX
|
||||
// Lookup the cookie sample.
|
||||
float4 cookie = TORQUE_TEXCUBE(cookieMap, mul(worldToLightProj, -surfaceToLight.L));
|
||||
// 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.
|
||||
lightCol *= max(cookie.r, max(cookie.g, cookie.b));
|
||||
#endif
|
||||
|
||||
//get Punctual light contribution
|
||||
lighting = getPunctualLight(surface, surfaceToLight, lightCol, lightBrightness, lightInvSqrRange, shadowed);
|
||||
//get spot angle attenuation
|
||||
lighting *= getSpotAngleAtt(-surfaceToLight.L, lightDirection, lightSpotParams );
|
||||
}
|
||||
|
||||
return float4(result, 0);
|
||||
return float4(lighting, 0);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -79,7 +79,6 @@ uniform float4 dynamicFarPlaneScalePSSM;
|
|||
|
||||
float4 AL_VectorLightShadowCast( TORQUE_SAMPLER2D(sourceShadowMap),
|
||||
float2 texCoord,
|
||||
float4x4 worldToLightProj,
|
||||
float3 worldPos,
|
||||
float4 scaleX,
|
||||
float4 scaleY,
|
||||
|
|
@ -187,7 +186,7 @@ float4 main(FarFrustumQuadConnectP IN) : SV_TARGET
|
|||
float4 normDepth = TORQUE_DEFERRED_UNCONDITION(deferredBuffer, IN.uv0);
|
||||
|
||||
//create surface
|
||||
Surface surface = CreateSurface( normDepth, TORQUE_SAMPLER2D_MAKEARG(colorBuffer),TORQUE_SAMPLER2D_MAKEARG(matInfoBuffer),
|
||||
Surface surface = createSurface( normDepth, TORQUE_SAMPLER2D_MAKEARG(colorBuffer),TORQUE_SAMPLER2D_MAKEARG(matInfoBuffer),
|
||||
IN.uv0, eyePosWorld, IN.wsEyeRay, cameraToWorld);
|
||||
|
||||
//early out if emissive
|
||||
|
|
@ -197,7 +196,7 @@ float4 main(FarFrustumQuadConnectP IN) : SV_TARGET
|
|||
}
|
||||
|
||||
//create surface to light
|
||||
SurfaceToLight surfaceToLight = CreateSurfaceToLight(surface, -lightDirection);
|
||||
SurfaceToLight surfaceToLight = createSurfaceToLight(surface, -lightDirection);
|
||||
|
||||
//light color might be changed by PSSM_DEBUG_RENDER
|
||||
float3 lightingColor = lightColor.rgb;
|
||||
|
|
@ -210,11 +209,10 @@ float4 main(FarFrustumQuadConnectP IN) : SV_TARGET
|
|||
float4 zDist = (zNearFarInvNearFar.x + zNearFarInvNearFar.y * surface.depth);
|
||||
float fadeOutAmt = ( zDist.x - fadeStartLength.x ) * fadeStartLength.y;
|
||||
|
||||
//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,
|
||||
float4 static_shadowed_colors = AL_VectorLightShadowCast( TORQUE_SAMPLER2D_MAKEARG(shadowMap), IN.uv0.xy, surface.P, scaleX, scaleY, offsetX, offsetY,
|
||||
farPlaneScalePSSM, surfaceToLight.NdotL);
|
||||
|
||||
float4 dynamic_shadowed_colors = AL_VectorLightShadowCast( TORQUE_SAMPLER2D_MAKEARG(dynamicShadowMap), IN.uv0.xy, dynamicWorldToLightProj, surface.P, dynamicScaleX,
|
||||
float4 dynamic_shadowed_colors = AL_VectorLightShadowCast( TORQUE_SAMPLER2D_MAKEARG(dynamicShadowMap), IN.uv0.xy, surface.P, dynamicScaleX,
|
||||
dynamicScaleY, dynamicOffsetX, dynamicOffsetY, dynamicFarPlaneScalePSSM, surfaceToLight.NdotL);
|
||||
|
||||
float static_shadowed = static_shadowed_colors.a;
|
||||
|
|
@ -237,7 +235,7 @@ float4 main(FarFrustumQuadConnectP IN) : SV_TARGET
|
|||
#endif //NO_SHADOW
|
||||
|
||||
//get directional light contribution
|
||||
float3 result = GetDirectionalLight(surface, surfaceToLight, lightingColor.rgb, lightBrightness, shadow);
|
||||
float3 lighting = getDirectionalLight(surface, surfaceToLight, lightingColor.rgb, lightBrightness, shadow);
|
||||
|
||||
return float4(result, 0);
|
||||
return float4(lighting, 0);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue