Full Template for ticket #1

This commit is contained in:
DavidWyand-GG 2012-09-19 11:54:25 -04:00
parent 74f265b3b3
commit f439dc8dcd
2150 changed files with 286240 additions and 0 deletions

View file

@ -0,0 +1,61 @@
//-----------------------------------------------------------------------------
// 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.
//-----------------------------------------------------------------------------
// Based on 'Cubic Lens Distortion HLSL Shader' by François Tarlier
// www.francois-tarlier.com/blog/index.php/2009/11/cubic-lens-distortion-shader
#include "./postFx.hlsl"
#include "./../torque.hlsl"
uniform sampler2D backBuffer : register( s0 );
uniform float distCoeff;
uniform float cubeDistort;
uniform float3 colorDistort;
float4 main( PFXVertToPix IN ) : COLOR0
{
float2 tex = IN.uv0;
float f = 0;
float r2 = (tex.x - 0.5) * (tex.x - 0.5) + (tex.y - 0.5) * (tex.y - 0.5);
// Only compute the cubic distortion if necessary.
if ( cubeDistort == 0.0 )
f = 1 + r2 * distCoeff;
else
f = 1 + r2 * (distCoeff + cubeDistort * sqrt(r2));
// Distort each color channel seperately to get a chromatic distortion effect.
float3 outColor;
float3 distort = f.xxx + colorDistort;
for ( int i=0; i < 3; i++ )
{
float x = distort[i] * ( tex.x - 0.5 ) + 0.5;
float y = distort[i] * ( tex.y - 0.5 ) + 0.5;
outColor[i] = tex2Dlod( backBuffer, float4(x,y,0,0) )[i];
}
return float4( outColor.rgb, 1 );
}

View file

@ -0,0 +1,52 @@
//-----------------------------------------------------------------------------
// 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.hlsl"
// These are set by the game engine.
uniform sampler2D shrunkSampler : register(S0); // Output of DofDownsample()
uniform sampler2D blurredSampler : register(S1); // Blurred version of the shrunk sampler
// This is the pixel shader function that calculates the actual
// value used for the near circle of confusion.
// "texCoords" are 0 at the bottom left pixel and 1 at the top right.
float4 main( PFXVertToPix IN ) : COLOR
{
float3 color;
float coc;
half4 blurred;
half4 shrunk;
shrunk = tex2D( shrunkSampler, IN.uv0 );
blurred = tex2D( blurredSampler, IN.uv1 );
color = shrunk.rgb;
//coc = shrunk.a;
//coc = blurred.a;
//coc = max( blurred.a, shrunk.a );
coc = 2 * max( blurred.a, shrunk.a ) - shrunk.a;
//return float4( coc.rrr, 1.0 );
//return float4( color, 1.0 );
return float4( color, coc );
//return float4( 1.0, 0.0, 1.0, 1.0 );
}

View file

@ -0,0 +1,70 @@
//-----------------------------------------------------------------------------
// 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.hlsl"
#include "./../../torque.hlsl"
uniform float4 rtParams0;
uniform float4 rtParams1;
uniform float4 rtParams2;
uniform float4 rtParams3;
PFXVertToPix main( PFXVert IN )
{
PFXVertToPix OUT;
/*
OUT.hpos = IN.pos;
OUT.uv0 = IN.uv;
OUT.uv1 = IN.uv;
OUT.uv2 = IN.uv;
OUT.uv3 = IN.uv;
*/
/*
OUT.hpos = IN.pos;
OUT.uv0 = IN.uv + rtParams0.xy;
OUT.uv1 = IN.uv + rtParams1.xy;
OUT.uv2 = IN.uv + rtParams2.xy;
OUT.uv3 = IN.uv + rtParams3.xy;
*/
/*
OUT.hpos = IN.pos;
OUT.uv0 = IN.uv * rtParams0.zw;
OUT.uv1 = IN.uv * rtParams1.zw;
OUT.uv2 = IN.uv * rtParams2.zw;
OUT.uv3 = IN.uv * rtParams3.zw;
*/
OUT.hpos = IN.pos;
OUT.uv0 = viewportCoordToRenderTarget( IN.uv, rtParams0 );
OUT.uv1 = viewportCoordToRenderTarget( IN.uv, rtParams1 );
OUT.uv2 = viewportCoordToRenderTarget( IN.uv, rtParams2 );
OUT.uv3 = viewportCoordToRenderTarget( IN.uv, rtParams3 );
OUT.wsEyeRay = IN.wsEyeRay;
return OUT;
}

View file

@ -0,0 +1,135 @@
//-----------------------------------------------------------------------------
// 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 "shadergen:/autogenConditioners.h"
// These are set by the game engine.
// The render target size is one-quarter the scene rendering size.
uniform sampler2D colorSampler : register(S0);
uniform sampler2D depthSampler : register(S1);
uniform float2 dofEqWorld;
uniform float depthOffset;
uniform float2 targetSize;
uniform float maxWorldCoC;
//uniform float2 dofEqWeapon;
//uniform float2 dofRowDelta; // float2( 0, 0.25 / renderTargetHeight )
struct Pixel
{
float4 position : POSITION;
float2 tcColor0 : TEXCOORD0;
float2 tcColor1 : TEXCOORD1;
float2 tcDepth0 : TEXCOORD2;
float2 tcDepth1 : TEXCOORD3;
float2 tcDepth2 : TEXCOORD4;
float2 tcDepth3 : TEXCOORD5;
};
half4 main( Pixel IN ) : COLOR
{
//return float4( 1.0, 0.0, 1.0, 1.0 );
float2 dofRowDelta = float2( 0, 0.25 / targetSize.y );
//float2 dofEqWorld = float2( -60, 1.0 );
half3 color;
half maxCoc;
float4 depth;
half4 viewCoc;
half4 sceneCoc;
half4 curCoc;
half4 coc;
float2 rowOfs[4];
// "rowOfs" reduces how many moves PS2.0 uses to emulate swizzling.
rowOfs[0] = 0;
rowOfs[1] = dofRowDelta.xy;
rowOfs[2] = dofRowDelta.xy * 2;
rowOfs[3] = dofRowDelta.xy * 3;
// Use bilinear filtering to average 4 color samples for free.
color = 0;
color += tex2D( colorSampler, IN.tcColor0.xy + rowOfs[0] ).rgb;
color += tex2D( colorSampler, IN.tcColor1.xy + rowOfs[0] ).rgb;
color += tex2D( colorSampler, IN.tcColor0.xy + rowOfs[2] ).rgb;
color += tex2D( colorSampler, IN.tcColor1.xy + rowOfs[2] ).rgb;
color /= 4;
// Process 4 samples at a time to use vector hardware efficiently.
// The CoC will be 1 if the depth is negative, so use "min" to pick
// between "sceneCoc" and "viewCoc".
for ( int i = 0; i < 4; i++ )
{
depth[0] = prepassUncondition( depthSampler, float4( IN.tcDepth0.xy + rowOfs[i], 0, 0 ) ).w;
depth[1] = prepassUncondition( depthSampler, float4( IN.tcDepth1.xy + rowOfs[i], 0, 0 ) ).w;
depth[2] = prepassUncondition( depthSampler, float4( IN.tcDepth2.xy + rowOfs[i], 0, 0 ) ).w;
depth[3] = prepassUncondition( depthSampler, float4( IN.tcDepth3.xy + rowOfs[i], 0, 0 ) ).w;
coc[i] = clamp( dofEqWorld.x * depth + dofEqWorld.y, 0.0, maxWorldCoC );
}
/*
depth[0] = tex2D( depthSampler, pixel.tcDepth0.xy + rowOfs[0] ).r;
depth[1] = tex2D( depthSampler, pixel.tcDepth1.xy + rowOfs[0] ).r;
depth[2] = tex2D( depthSampler, pixel.tcDepth2.xy + rowOfs[0] ).r;
depth[3] = tex2D( depthSampler, pixel.tcDepth3.xy + rowOfs[0] ).r;
viewCoc = saturate( dofEqWeapon.x * -depth + dofEqWeapon.y );
sceneCoc = saturate( dofEqWorld.x * depth + dofEqWorld.y );
curCoc = min( viewCoc, sceneCoc );
coc = curCoc;
depth[0] = tex2D( depthSampler, pixel.tcDepth0.xy + rowOfs[1] ).r;
depth[1] = tex2D( depthSampler, pixel.tcDepth1.xy + rowOfs[1] ).r;
depth[2] = tex2D( depthSampler, pixel.tcDepth2.xy + rowOfs[1] ).r;
depth[3] = tex2D( depthSampler, pixel.tcDepth3.xy + rowOfs[1] ).r;
viewCoc = saturate( dofEqWeapon.x * -depth + dofEqWeapon.y );
sceneCoc = saturate( dofEqWorld.x * depth + dofEqWorld.y );
curCoc = min( viewCoc, sceneCoc );
coc = max( coc, curCoc );
depth[0] = tex2D( depthSampler, pixel.tcDepth0.xy + rowOfs[2] ).r;
depth[1] = tex2D( depthSampler, pixel.tcDepth1.xy + rowOfs[2] ).r;
depth[2] = tex2D( depthSampler, pixel.tcDepth2.xy + rowOfs[2] ).r;
depth[3] = tex2D( depthSampler, pixel.tcDepth3.xy + rowOfs[2] ).r;
viewCoc = saturate( dofEqWeapon.x * -depth + dofEqWeapon.y );
sceneCoc = saturate( dofEqWorld.x * depth + dofEqWorld.y );
curCoc = min( viewCoc, sceneCoc );
coc = max( coc, curCoc );
depth[0] = tex2D( depthSampler, pixel.tcDepth0.xy + rowOfs[3] ).r;
depth[1] = tex2D( depthSampler, pixel.tcDepth1.xy + rowOfs[3] ).r;
depth[2] = tex2D( depthSampler, pixel.tcDepth2.xy + rowOfs[3] ).r;
depth[3] = tex2D( depthSampler, pixel.tcDepth3.xy + rowOfs[3] ).r;
viewCoc = saturate( dofEqWeapon.x * -depth + dofEqWeapon.y );
sceneCoc = saturate( dofEqWorld.x * depth + dofEqWorld.y );
curCoc = min( viewCoc, sceneCoc );
coc = max( coc, curCoc );
*/
maxCoc = max( max( coc[0], coc[1] ), max( coc[2], coc[3] ) );
//return half4( 1.0, 0.0, 1.0, 1.0 );
return half4( color, maxCoc );
//return half4( color, 1.0f );
//return half4( maxCoc.rrr, 1.0 );
}

View file

@ -0,0 +1,61 @@
//-----------------------------------------------------------------------------
// 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.hlsl"
#include "./../../torque.hlsl"
struct Vert
{
float4 pos : POSITION;
float2 tc : TEXCOORD0;
float3 wsEyeRay : TEXCOORD1;
};
struct Pixel
{
float4 position : POSITION;
float2 tcColor0 : TEXCOORD0;
float2 tcColor1 : TEXCOORD1;
float2 tcDepth0 : TEXCOORD2;
float2 tcDepth1 : TEXCOORD3;
float2 tcDepth2 : TEXCOORD4;
float2 tcDepth3 : TEXCOORD5;
};
uniform float4 rtParams0;
uniform float2 oneOverTargetSize;
Pixel main( Vert IN )
{
Pixel OUT;
OUT.position = IN.pos;
float2 uv = viewportCoordToRenderTarget( IN.tc, rtParams0 );
//OUT.position = mul( IN.pos, modelView );
OUT.tcColor1 = uv + float2( +1.0, -0.0 ) * oneOverTargetSize;
OUT.tcColor0 = uv + float2( -1.0, -0.0 ) * oneOverTargetSize;
OUT.tcDepth0 = uv + float2( -0.5, -0.0 ) * oneOverTargetSize;
OUT.tcDepth1 = uv + float2( -1.5, -0.0 ) * oneOverTargetSize;
OUT.tcDepth2 = uv + float2( +1.5, -0.0 ) * oneOverTargetSize;
OUT.tcDepth3 = uv + float2( +2.5, -0.0 ) * oneOverTargetSize;
return OUT;
}

View file

@ -0,0 +1,144 @@
//-----------------------------------------------------------------------------
// 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 "shadergen:/autogenConditioners.h"
#include "./../postFx.hlsl"
uniform sampler2D colorSampler : register(S0); // Original source image
uniform sampler2D smallBlurSampler : register(S1); // Output of SmallBlurPS()
uniform sampler2D largeBlurSampler : register(S2); // Blurred output of DofDownsample()
uniform sampler2D depthSampler : register(S3); //
uniform float2 oneOverTargetSize;
uniform float4 dofLerpScale;
uniform float4 dofLerpBias;
uniform float3 dofEqFar;
uniform float maxFarCoC;
//static float d0 = 0.1;
//static float d1 = 0.1;
//static float d2 = 0.8;
//static float4 dofLerpScale = float4( -1.0 / d0, -1.0 / d1, -1.0 / d2, 1.0 / d2 );
//static float4 dofLerpBias = float4( 1.0, (1.0 - d2) / d1, 1.0 / d2, (d2 - 1.0) / d2 );
//static float3 dofEqFar = float3( 2.0, 0.0, 1.0 );
float4 tex2Doffset( sampler2D s, float2 tc, float2 offset )
{
return tex2D( s, tc + offset * oneOverTargetSize );
}
half3 GetSmallBlurSample( float2 tc )
{
half3 sum;
const half weight = 4.0 / 17;
sum = 0; // Unblurred sample done by alpha blending
//sum += weight * tex2Doffset( colorSampler, tc, float2( 0, 0 ) ).rgb;
sum += weight * tex2Doffset( colorSampler, tc, float2( +0.5, -1.5 ) ).rgb;
sum += weight * tex2Doffset( colorSampler, tc, float2( -1.5, -0.5 ) ).rgb;
sum += weight * tex2Doffset( colorSampler, tc, float2( -0.5, +1.5 ) ).rgb;
sum += weight * tex2Doffset( colorSampler, tc, float2( +1.5, +0.5 ) ).rgb;
return sum;
}
half4 InterpolateDof( half3 small, half3 med, half3 large, half t )
{
//t = 2;
half4 weights;
half3 color;
half alpha;
// Efficiently calculate the cross-blend weights for each sample.
// Let the unblurred sample to small blur fade happen over distance
// d0, the small to medium blur over distance d1, and the medium to
// large blur over distance d2, where d0 + d1 + d2 = 1.
//float4 dofLerpScale = float4( -1 / d0, -1 / d1, -1 / d2, 1 / d2 );
//float4 dofLerpBias = float4( 1, (1 d2) / d1, 1 / d2, (d2 1) / d2 );
weights = saturate( t * dofLerpScale + dofLerpBias );
weights.yz = min( weights.yz, 1 - weights.xy );
// Unblurred sample with weight "weights.x" done by alpha blending
color = weights.y * small + weights.z * med + weights.w * large;
//color = med;
alpha = dot( weights.yzw, half3( 16.0 / 17, 1.0, 1.0 ) );
//alpha = 0.0;
return half4( color, alpha );
}
half4 main( PFXVertToPix IN ) : COLOR
{
//return half4( 1,0,1,1 );
//return half4( tex2D( colorSampler, IN.uv0 ).rgb, 1.0 );
//return half4( tex2D( colorSampler, texCoords ).rgb, 0 );
half3 small;
half4 med;
half3 large;
half depth;
half nearCoc;
half farCoc;
half coc;
small = GetSmallBlurSample( IN.uv0 );
//small = half3( 1,0,0 );
//return half4( small, 1.0 );
med = tex2D( smallBlurSampler, IN.uv1 );
//med.rgb = half3( 0,1,0 );
//return half4(med.rgb, 0.0);
large = tex2D( largeBlurSampler, IN.uv2 ).rgb;
//large = half3( 0,0,1 );
//return large;
//return half4(large.rgb,1.0);
nearCoc = med.a;
// Since the med blur texture is screwed up currently
// replace it with the large, but this needs to be fixed.
//med.rgb = large;
//nearCoc = 0;
depth = prepassUncondition( depthSampler, float4( IN.uv3, 0, 0 ) ).w;
//return half4(depth.rrr,1);
//return half4(nearCoc.rrr,1.0);
if (depth > 0.999 )
{
coc = nearCoc; // We don't want to blur the sky.
//coc = 0;
}
else
{
// dofEqFar.x and dofEqFar.y specify the linear ramp to convert
// to depth for the distant out-of-focus region.
// dofEqFar.z is the ratio of the far to the near blur radius.
farCoc = clamp( dofEqFar.x * depth + dofEqFar.y, 0.0, maxFarCoC );
coc = max( nearCoc, farCoc * dofEqFar.z );
//coc = nearCoc;
}
//coc = nearCoc;
//coc = farCoc;
//return half4(coc.rrr,0.5);
//return half4(farCoc.rrr,1);
//return half4(nearCoc.rrr,1);
//return half4( 1,0,1,0 );
return InterpolateDof( small, med.rgb, large, coc );
}

View file

@ -0,0 +1,72 @@
//-----------------------------------------------------------------------------
// 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.hlsl"
#include "./../../torque.hlsl"
uniform float4 rtParams0;
uniform float4 rtParams1;
uniform float4 rtParams2;
uniform float4 rtParams3;
uniform float2 oneOverTargetSize;
PFXVertToPix main( PFXVert IN )
{
PFXVertToPix OUT;
/*
OUT.hpos = IN.pos;
OUT.uv0 = IN.uv;
OUT.uv1 = IN.uv;
OUT.uv2 = IN.uv;
OUT.uv3 = IN.uv;
*/
/*
OUT.hpos = IN.pos;
OUT.uv0 = IN.uv + rtParams0.xy;
OUT.uv1 = IN.uv + rtParams1.xy;
OUT.uv2 = IN.uv + rtParams2.xy;
OUT.uv3 = IN.uv + rtParams3.xy;
*/
/*
OUT.hpos = IN.pos;
OUT.uv0 = IN.uv * rtParams0.zw;
OUT.uv1 = IN.uv * rtParams1.zw;
OUT.uv2 = IN.uv * rtParams2.zw;
OUT.uv3 = IN.uv * rtParams3.zw;
*/
OUT.hpos = IN.pos;
OUT.uv0 = viewportCoordToRenderTarget( IN.uv, rtParams0 );
OUT.uv1 = viewportCoordToRenderTarget( IN.uv, rtParams1 ); // + float2( -5, 1 ) * oneOverTargetSize;
OUT.uv2 = viewportCoordToRenderTarget( IN.uv, rtParams2 );
OUT.uv3 = viewportCoordToRenderTarget( IN.uv, rtParams3 );
OUT.wsEyeRay = IN.wsEyeRay;
return OUT;
}

View file

@ -0,0 +1,63 @@
//-----------------------------------------------------------------------------
// 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.hlsl"
uniform sampler2D diffuseMap : register(S0);
struct VertToPix
{
float4 hpos : POSITION;
float2 uv0 : TEXCOORD0;
float2 uv1 : TEXCOORD1;
float2 uv2 : TEXCOORD2;
float2 uv3 : TEXCOORD3;
float2 uv4 : TEXCOORD4;
float2 uv5 : TEXCOORD5;
float2 uv6 : TEXCOORD6;
float2 uv7 : TEXCOORD7;
};
float4 main( VertToPix IN ) : COLOR
{
float4 kernel = float4( 0.175, 0.275, 0.375, 0.475 ) * 0.5 / 1.3; //25f;
float4 OUT = 0;
OUT += tex2D( diffuseMap, IN.uv0 ) * kernel.x;
OUT += tex2D( diffuseMap, IN.uv1 ) * kernel.y;
OUT += tex2D( diffuseMap, IN.uv2 ) * kernel.z;
OUT += tex2D( diffuseMap, IN.uv3 ) * kernel.w;
OUT += tex2D( diffuseMap, IN.uv4 ) * kernel.x;
OUT += tex2D( diffuseMap, IN.uv5 ) * kernel.y;
OUT += tex2D( diffuseMap, IN.uv6 ) * kernel.z;
OUT += tex2D( diffuseMap, IN.uv7 ) * kernel.w;
// Calculate a lumenance value in the alpha so we
// can use alpha test to save fillrate.
//float3 rgb2lum = float3( 0.30, 0.59, 0.11 );
//OUT.a = dot( OUT.rgb, rgb2lum );
return OUT;
}

View file

@ -0,0 +1,80 @@
//-----------------------------------------------------------------------------
// 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.hlsl"
#include "./../../torque.hlsl"
uniform float2 texSize0;
uniform float4 rtParams0;
uniform float2 oneOverTargetSize;
struct VertToPix
{
float4 hpos : POSITION;
float2 uv0 : TEXCOORD0;
float2 uv1 : TEXCOORD1;
float2 uv2 : TEXCOORD2;
float2 uv3 : TEXCOORD3;
float2 uv4 : TEXCOORD4;
float2 uv5 : TEXCOORD5;
float2 uv6 : TEXCOORD6;
float2 uv7 : TEXCOORD7;
};
VertToPix main( PFXVert IN )
{
VertToPix OUT;
OUT.hpos = IN.pos;
IN.uv = viewportCoordToRenderTarget( IN.uv, rtParams0 );
// I don't know why this offset is necessary, but it is.
//IN.uv = IN.uv * oneOverTargetSize;
OUT.uv0 = IN.uv + ( ( BLUR_DIR * 3.5f ) / texSize0 );
OUT.uv1 = IN.uv + ( ( BLUR_DIR * 2.5f ) / texSize0 );
OUT.uv2 = IN.uv + ( ( BLUR_DIR * 1.5f ) / texSize0 );
OUT.uv3 = IN.uv + ( ( BLUR_DIR * 0.5f ) / texSize0 );
OUT.uv4 = IN.uv - ( ( BLUR_DIR * 3.5f ) / texSize0 );
OUT.uv5 = IN.uv - ( ( BLUR_DIR * 2.5f ) / texSize0 );
OUT.uv6 = IN.uv - ( ( BLUR_DIR * 1.5f ) / texSize0 );
OUT.uv7 = IN.uv - ( ( BLUR_DIR * 0.5f ) / texSize0 );
/*
OUT.uv0 = viewportCoordToRenderTarget( OUT.uv0, rtParams0 );
OUT.uv1 = viewportCoordToRenderTarget( OUT.uv1, rtParams0 );
OUT.uv2 = viewportCoordToRenderTarget( OUT.uv2, rtParams0 );
OUT.uv3 = viewportCoordToRenderTarget( OUT.uv3, rtParams0 );
OUT.uv4 = viewportCoordToRenderTarget( OUT.uv4, rtParams0 );
OUT.uv5 = viewportCoordToRenderTarget( OUT.uv5, rtParams0 );
OUT.uv6 = viewportCoordToRenderTarget( OUT.uv6, rtParams0 );
OUT.uv7 = viewportCoordToRenderTarget( OUT.uv7, rtParams0 );
*/
return OUT;
}

View file

@ -0,0 +1,70 @@
//-----------------------------------------------------------------------------
// 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.hlsl"
#include "./../../torque.hlsl"
uniform float4 rtParams0;
uniform float4 rtParams1;
uniform float4 rtParams2;
uniform float4 rtParams3;
PFXVertToPix main( PFXVert IN )
{
PFXVertToPix OUT;
/*
OUT.hpos = IN.pos;
OUT.uv0 = IN.uv;
OUT.uv1 = IN.uv;
OUT.uv2 = IN.uv;
OUT.uv3 = IN.uv;
*/
/*
OUT.hpos = IN.pos;
OUT.uv0 = IN.uv + rtParams0.xy;
OUT.uv1 = IN.uv + rtParams1.xy;
OUT.uv2 = IN.uv + rtParams2.xy;
OUT.uv3 = IN.uv + rtParams3.xy;
*/
/*
OUT.hpos = IN.pos;
OUT.uv0 = IN.uv * rtParams0.zw;
OUT.uv1 = IN.uv * rtParams1.zw;
OUT.uv2 = IN.uv * rtParams2.zw;
OUT.uv3 = IN.uv * rtParams3.zw;
*/
OUT.hpos = IN.pos;
OUT.uv0 = viewportCoordToRenderTarget( IN.uv, rtParams0 );
OUT.uv1 = viewportCoordToRenderTarget( IN.uv, rtParams1 );
OUT.uv2 = viewportCoordToRenderTarget( IN.uv, rtParams2 );
OUT.uv3 = viewportCoordToRenderTarget( IN.uv, rtParams3 );
OUT.wsEyeRay = IN.wsEyeRay;
return OUT;
}

View file

@ -0,0 +1,45 @@
//-----------------------------------------------------------------------------
// 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.
//-----------------------------------------------------------------------------
// This vertex and pixel shader applies a 3 x 3 blur to the image in
// colorMapSampler, which is the same size as the render target.
// The sample weights are 1/16 in the corners, 2/16 on the edges,
// and 4/16 in the center.
uniform sampler2D colorSampler; // Output of DofNearCoc()
struct Pixel
{
float4 position : POSITION;
float4 texCoords : TEXCOORD0;
};
float4 main( Pixel IN ) : COLOR
{
float4 color;
color = 0.0;
color += tex2D( colorSampler, IN.texCoords.xz );
color += tex2D( colorSampler, IN.texCoords.yz );
color += tex2D( colorSampler, IN.texCoords.xw );
color += tex2D( colorSampler, IN.texCoords.yw );
return color / 4.0;
}

View file

@ -0,0 +1,56 @@
//-----------------------------------------------------------------------------
// 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.
//-----------------------------------------------------------------------------
// This vertex and pixel shader applies a 3 x 3 blur to the image in
// colorMapSampler, which is the same size as the render target.
// The sample weights are 1/16 in the corners, 2/16 on the edges,
// and 4/16 in the center.
#include "./../postFx.hlsl"
#include "./../../torque.hlsl"
struct Vert
{
float4 position : POSITION;
float2 texCoords : TEXCOORD0;
};
struct Pixel
{
float4 position : POSITION;
float4 texCoords : TEXCOORD0;
};
uniform float2 oneOverTargetSize;
uniform float4 rtParams0;
Pixel main( Vert IN )
{
Pixel OUT;
const float4 halfPixel = { -0.5, 0.5, -0.5, 0.5 };
OUT.position = IN.position; //Transform_ObjectToClip( IN.position );
//float2 uv = IN.texCoords + rtParams0.xy;
float2 uv = viewportCoordToRenderTarget( IN.texCoords, rtParams0 );
OUT.texCoords = uv.xxyy + halfPixel * oneOverTargetSize.xxyy;
return OUT;
}

View file

@ -0,0 +1,30 @@
//-----------------------------------------------------------------------------
// 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.hlsl"
#include "shadergen:/autogenConditioners.h"
float4 main( PFXVertToPix IN,
uniform sampler2D edgeBuffer :register(S0) ) : COLOR0
{
return float4( tex2D( edgeBuffer, IN.uv0 ).rrr, 1.0 );
}

View file

@ -0,0 +1,66 @@
//-----------------------------------------------------------------------------
// 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.hlsl"
#include "shadergen:/autogenConditioners.h"
float4 main( PFXVertToPix IN,
uniform sampler2D edgeBuffer : register(S0),
uniform sampler2D backBuffer : register(S1),
uniform float2 targetSize : register(C0) ) : COLOR0
{
float2 pixelSize = 1.0 / targetSize;
// Sample edge buffer, bail if not on an edge
float edgeSample = tex2D(edgeBuffer, IN.uv0).r;
clip(edgeSample - 1e-6);
// Ok we're on an edge, so multi-tap sample, average, and return
float2 offsets[9] = {
float2( 0.0, 0.0),
float2(-1.0, -1.0),
float2( 0.0, -1.0),
float2( 1.0, -1.0),
float2( 1.0, 0.0),
float2( 1.0, 1.0),
float2( 0.0, 1.0),
float2(-1.0, 1.0),
float2(-1.0, 0.0),
};
float4 accumColor = 0;
for(int i = 0; i < 9; i++)
{
// Multiply the intensity of the edge, by the UV, so that things which maybe
// aren't quite full edges get sub-pixel sampling to reduce artifacts
// Scaling offsets by 0.5 to reduce the range bluriness from extending to
// far outward from the edge.
float2 offsetUV = IN.uv1 + edgeSample * ( offsets[i] * 0.5 ) * pixelSize;//rtWidthHeightInvWidthNegHeight.zw;
//offsetUV *= 0.999;
accumColor+= tex2D(backBuffer, offsetUV);
}
accumColor /= 9.0;
return accumColor;
}

View file

@ -0,0 +1,45 @@
//-----------------------------------------------------------------------------
// 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.hlsl"
#include "./../../torque.hlsl"
uniform float4 rtParams0;
uniform float4 rtParams1;
uniform float4 rtParams2;
uniform float4 rtParams3;
PFXVertToPix main( PFXVert IN )
{
PFXVertToPix OUT;
OUT.hpos = IN.pos;
OUT.uv0 = viewportCoordToRenderTarget( IN.uv, rtParams0 );
OUT.uv1 = viewportCoordToRenderTarget( IN.uv, rtParams1 );
OUT.uv2 = viewportCoordToRenderTarget( IN.uv, rtParams2 );
OUT.uv3 = viewportCoordToRenderTarget( IN.uv, rtParams3 );
OUT.wsEyeRay = IN.wsEyeRay;
return OUT;
}

View file

@ -0,0 +1,90 @@
//-----------------------------------------------------------------------------
// 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.hlsl"
#include "shadergen:/autogenConditioners.h"
// GPU Gems 3, pg 443-444
float GetEdgeWeight(float2 uv0, in sampler2D prepassBuffer, in float2 targetSize)
{
float2 offsets[9] = {
float2( 0.0, 0.0),
float2(-1.0, -1.0),
float2( 0.0, -1.0),
float2( 1.0, -1.0),
float2( 1.0, 0.0),
float2( 1.0, 1.0),
float2( 0.0, 1.0),
float2(-1.0, 1.0),
float2(-1.0, 0.0),
};
float2 PixelSize = 1.0 / targetSize;
float Depth[9];
float3 Normal[9];
for(int i = 0; i < 9; i++)
{
float2 uv = uv0 + offsets[i] * PixelSize;
float4 gbSample = prepassUncondition( prepassBuffer, uv );
Depth[i] = gbSample.a;
Normal[i] = gbSample.rgb;
}
float4 Deltas1 = float4(Depth[1], Depth[2], Depth[3], Depth[4]);
float4 Deltas2 = float4(Depth[5], Depth[6], Depth[7], Depth[8]);
Deltas1 = abs(Deltas1 - Depth[0]);
Deltas2 = abs(Depth[0] - Deltas2);
float4 maxDeltas = max(Deltas1, Deltas2);
float4 minDeltas = max(min(Deltas1, Deltas2), 0.00001);
float4 depthResults = step(minDeltas * 25.0, maxDeltas);
Deltas1.x = dot(Normal[1], Normal[0]);
Deltas1.y = dot(Normal[2], Normal[0]);
Deltas1.z = dot(Normal[3], Normal[0]);
Deltas1.w = dot(Normal[4], Normal[0]);
Deltas2.x = dot(Normal[5], Normal[0]);
Deltas2.y = dot(Normal[6], Normal[0]);
Deltas2.z = dot(Normal[7], Normal[0]);
Deltas2.w = dot(Normal[8], Normal[0]);
Deltas1 = abs(Deltas1 - Deltas2);
float4 normalResults = step(0.4, Deltas1);
normalResults = max(normalResults, depthResults);
return dot(normalResults, float4(1.0, 1.0, 1.0, 1.0)) * 0.25;
}
float4 main( PFXVertToPix IN,
uniform sampler2D prepassBuffer :register(S0),
uniform float2 targetSize : register(C0) ) : COLOR0
{
return GetEdgeWeight(IN.uv0, prepassBuffer, targetSize );//rtWidthHeightInvWidthNegHeight.zw);
}

View file

@ -0,0 +1,36 @@
//-----------------------------------------------------------------------------
// 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.hlsl"
#include "../torque.hlsl"
uniform float damageFlash;
uniform float whiteOut;
uniform sampler2D backBuffer : register(S0);
float4 main(PFXVertToPix IN) : COLOR0
{
float4 color1 = tex2D(backBuffer, IN.uv0);
float4 color2 = color1 * MUL_COLOR;
float4 damage = lerp(color1,color2,damageFlash);
return lerp(damage,WHITE_COLOR,whiteOut);
}

View file

@ -0,0 +1,50 @@
//-----------------------------------------------------------------------------
// 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 "shadergen:/autogenConditioners.h"
#include "./postFx.hlsl"
#include "./../torque.hlsl"
uniform sampler2D prepassTex : register(S0);
uniform float3 eyePosWorld;
uniform float4 fogColor;
uniform float3 fogData;
uniform float4 rtParams0;
float4 main( PFXVertToPix IN ) : COLOR
{
//float2 prepassCoord = ( IN.uv0.xy * rtParams0.zw ) + rtParams0.xy;
float depth = prepassUncondition( prepassTex, IN.uv0 ).w;
//return float4( depth, 0, 0, 0.7 );
// Skip fogging the extreme far plane so that
// the canvas clear color always appears.
clip( 0.9999 - depth );
float factor = computeSceneFog( eyePosWorld,
eyePosWorld + ( IN.wsEyeRay * depth ),
fogData.x,
fogData.y,
fogData.z );
return hdrEncode( float4( fogColor.rgb, 1.0 - saturate( factor ) ) );
}

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,128 @@
//-----------------------------------------------------------------------------
// 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.
//-----------------------------------------------------------------------------
#define FXAA_PC 1
#define FXAA_HLSL_3 1
#define FXAA_QUALITY__PRESET 12
#define FXAA_GREEN_AS_LUMA 1
#include "Fxaa3_11.h"
#include "../postFx.hlsl"
struct VertToPix
{
float4 hpos : POSITION;
float2 uv0 : TEXCOORD0;
};
uniform sampler2D colorTex : register(S0);
uniform float2 oneOverTargetSize;
float4 main( VertToPix IN ) : COLOR
{
return FxaaPixelShader(
IN.uv0, // vertex position
0, // Unused... console stuff
colorTex, // The color back buffer
colorTex, // Used for 360 optimization
colorTex, // Used for 360 optimization
oneOverTargetSize,
0, // Unused... console stuff
0, // Unused... console stuff
0, // Unused... console stuff
//
// Only used on FXAA Quality.
// This used to be the FXAA_QUALITY__SUBPIX define.
// It is here now to allow easier tuning.
// Choose the amount of sub-pixel aliasing removal.
// This can effect sharpness.
// 1.00 - upper limit (softer)
// 0.75 - default amount of filtering
// 0.50 - lower limit (sharper, less sub-pixel aliasing removal)
// 0.25 - almost off
// 0.00 - completely off
0.75,
//
// Only used on FXAA Quality.
// This used to be the FXAA_QUALITY__EDGE_THRESHOLD define.
// It is here now to allow easier tuning.
// The minimum amount of local contrast required to apply algorithm.
// 0.333 - too little (faster)
// 0.250 - low quality
// 0.166 - default
// 0.125 - high quality
// 0.063 - overkill (slower)
0.166,
//
// Only used on FXAA Quality.
// This used to be the FXAA_QUALITY__EDGE_THRESHOLD_MIN define.
// It is here now to allow easier tuning.
// Trims the algorithm from processing darks.
// 0.0833 - upper limit (default, the start of visible unfiltered edges)
// 0.0625 - high quality (faster)
// 0.0312 - visible limit (slower)
// Special notes when using FXAA_GREEN_AS_LUMA,
// Likely want to set this to zero.
// As colors that are mostly not-green
// will appear very dark in the green channel!
// Tune by looking at mostly non-green content,
// then start at zero and increase until aliasing is a problem.
0,
//
// Only used on FXAA Console.
// This used to be the FXAA_CONSOLE__EDGE_SHARPNESS define.
// It is here now to allow easier tuning.
// This does not effect PS3, as this needs to be compiled in.
// Use FXAA_CONSOLE__PS3_EDGE_SHARPNESS for PS3.
// Due to the PS3 being ALU bound,
// there are only three safe values here: 2 and 4 and 8.
// These options use the shaders ability to a free *|/ by 2|4|8.
// For all other platforms can be a non-power of two.
// 8.0 is sharper (default!!!)
// 4.0 is softer
// 2.0 is really soft (good only for vector graphics inputs)
8,
0, // Unused... console stuff
0, // Unused... console stuff
0 // Unused... console stuff
);
}

View file

@ -0,0 +1,42 @@
//-----------------------------------------------------------------------------
// 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"
#include "./../postFX.hlsl"
struct VertToPix
{
float4 hpos : POSITION;
float2 uv0 : TEXCOORD0;
};
uniform float4 rtParams0;
VertToPix main( PFXVert IN )
{
VertToPix OUT;
OUT.hpos = IN.pos;
OUT.uv0 = viewportCoordToRenderTarget( IN.uv, rtParams0 );
return OUT;
}

View file

@ -0,0 +1,46 @@
//-----------------------------------------------------------------------------
// 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 "shadergen:/autogenConditioners.h"
#include "./postFx.hlsl"
#include "../torque.hlsl"
uniform sampler2D backBuffer : register(S0);
uniform sampler1D colorCorrectionTex : register( s1 );
uniform float OneOverGamma;
float4 main( PFXVertToPix IN ) : COLOR0
{
float4 color = tex2D(backBuffer, IN.uv0.xy);
// Apply the color correction.
color.r = tex1D( colorCorrectionTex, color.r ).r;
color.g = tex1D( colorCorrectionTex, color.g ).g;
color.b = tex1D( colorCorrectionTex, color.b ).b;
// Apply gamma correction
color.rgb = pow( abs(color.rgb), OneOverGamma );
return color;
}

View file

@ -0,0 +1,63 @@
//-----------------------------------------------------------------------------
// 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.hlsl"
uniform sampler2D diffuseMap : register(S0);
struct VertToPix
{
float4 hpos : POSITION;
float2 uv0 : TEXCOORD0;
float2 uv1 : TEXCOORD1;
float2 uv2 : TEXCOORD2;
float2 uv3 : TEXCOORD3;
float2 uv4 : TEXCOORD4;
float2 uv5 : TEXCOORD5;
float2 uv6 : TEXCOORD6;
float2 uv7 : TEXCOORD7;
};
float4 main( VertToPix IN ) : COLOR
{
float4 kernel = float4( 0.175, 0.275, 0.375, 0.475 ) * 0.5f;
float4 OUT = 0;
OUT += tex2D( diffuseMap, IN.uv0 ) * kernel.x;
OUT += tex2D( diffuseMap, IN.uv1 ) * kernel.y;
OUT += tex2D( diffuseMap, IN.uv2 ) * kernel.z;
OUT += tex2D( diffuseMap, IN.uv3 ) * kernel.w;
OUT += tex2D( diffuseMap, IN.uv4 ) * kernel.x;
OUT += tex2D( diffuseMap, IN.uv5 ) * kernel.y;
OUT += tex2D( diffuseMap, IN.uv6 ) * kernel.z;
OUT += tex2D( diffuseMap, IN.uv7 ) * kernel.w;
// Calculate a lumenance value in the alpha so we
// can use alpha test to save fillrate.
float3 rgb2lum = float3( 0.30, 0.59, 0.11 );
OUT.a = dot( OUT.rgb, rgb2lum );
return OUT;
}

View file

@ -0,0 +1,63 @@
//-----------------------------------------------------------------------------
// 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.hlsl"
#include "./../torque.hlsl"
uniform float2 texSize0;
struct VertToPix
{
float4 hpos : POSITION;
float2 uv0 : TEXCOORD0;
float2 uv1 : TEXCOORD1;
float2 uv2 : TEXCOORD2;
float2 uv3 : TEXCOORD3;
float2 uv4 : TEXCOORD4;
float2 uv5 : TEXCOORD5;
float2 uv6 : TEXCOORD6;
float2 uv7 : TEXCOORD7;
};
VertToPix main( PFXVert IN )
{
VertToPix OUT;
OUT.hpos = IN.pos;
float2 uv = IN.uv + (0.5f / texSize0);
OUT.uv0 = uv + ( ( BLUR_DIR * 3.5f ) / texSize0 );
OUT.uv1 = uv + ( ( BLUR_DIR * 2.5f ) / texSize0 );
OUT.uv2 = uv + ( ( BLUR_DIR * 1.5f ) / texSize0 );
OUT.uv3 = uv + ( ( BLUR_DIR * 0.5f ) / texSize0 );
OUT.uv4 = uv - ( ( BLUR_DIR * 3.5f ) / texSize0 );
OUT.uv5 = uv - ( ( BLUR_DIR * 2.5f ) / texSize0 );
OUT.uv6 = uv - ( ( BLUR_DIR * 1.5f ) / texSize0 );
OUT.uv7 = uv - ( ( BLUR_DIR * 0.5f ) / texSize0 );
return OUT;
}

View file

@ -0,0 +1,69 @@
//-----------------------------------------------------------------------------
// 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.hlsl"
#include "shadergen:/autogenConditioners.h"
uniform sampler2D inputTex : register(S0);
uniform float2 oneOverTargetSize;
uniform float gaussMultiplier;
uniform float gaussMean;
uniform float gaussStdDev;
#define PI 3.141592654
float computeGaussianValue( float x, float mean, float std_deviation )
{
// The gaussian equation is defined as such:
/*
-(x - mean)^2
-------------
1.0 2*std_dev^2
f(x,mean,std_dev) = -------------------- * e^
sqrt(2*pi*std_dev^2)
*/
float tmp = ( 1.0f / sqrt( 2.0f * PI * std_deviation * std_deviation ) );
float tmp2 = exp( ( -( ( x - mean ) * ( x - mean ) ) ) / ( 2.0f * std_deviation * std_deviation ) );
return tmp * tmp2;
}
float4 main( PFXVertToPix IN ) : COLOR
{
float4 color = { 0.0f, 0.0f, 0.0f, 0.0f };
float offset = 0;
float weight = 0;
float x = 0;
float fI = 0;
for( int i = 0; i < 9; i++ )
{
fI = (float)i;
offset = (i - 4.0) * oneOverTargetSize.x;
x = (i - 4.0) / 4.0;
weight = gaussMultiplier * computeGaussianValue( x, gaussMean, gaussStdDev );
color += (tex2D( inputTex, IN.uv0 + float2( offset, 0.0f ) ) * weight );
}
return float4( color.rgb, 1.0f );
}

View file

@ -0,0 +1,68 @@
//-----------------------------------------------------------------------------
// 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.hlsl"
#include "shadergen:/autogenConditioners.h"
uniform sampler2D inputTex : register(S0);
uniform float2 oneOverTargetSize;
uniform float gaussMultiplier;
uniform float gaussMean;
uniform float gaussStdDev;
#define D3DX_PI 3.141592654
float computeGaussianValue( float x, float mean, float std_deviation )
{
// The gaussian equation is defined as such:
/*
-(x - mean)^2
-------------
1.0 2*std_dev^2
f(x,mean,std_dev) = -------------------- * e^
sqrt(2*pi*std_dev^2)
*/
float tmp = ( 1.0f / sqrt( 2.0f * D3DX_PI * std_deviation * std_deviation ) );
float tmp2 = exp( ( -( ( x - mean ) * ( x - mean ) ) ) / ( 2.0f * std_deviation * std_deviation ) );
return tmp * tmp2;
}
float4 main( PFXVertToPix IN ) : COLOR
{
float4 color = { 0.0f, 0.0f, 0.0f, 0.0f };
float offset = 0;
float weight = 0;
float x = 0;
float fI = 0;
for( int i = 0; i < 9; i++ )
{
fI = (float)i;
offset = (fI - 4.0) * oneOverTargetSize.y;
x = (fI - 4.0) / 4.0;
weight = gaussMultiplier * computeGaussianValue( x, gaussMean, gaussStdDev );
color += (tex2D( inputTex, IN.uv0 + float2( 0.0f, offset ) ) * weight );
}
return float4( color.rgb, 1.0f );
}

View file

@ -0,0 +1,63 @@
//-----------------------------------------------------------------------------
// 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.hlsl"
#include "shadergen:/autogenConditioners.h"
#include "../../torque.hlsl"
uniform sampler2D inputTex : register(S0);
uniform sampler2D luminanceTex : register(S1);
uniform float2 oneOverTargetSize;
uniform float brightPassThreshold;
uniform float g_fMiddleGray;
static const float3 LUMINANCE_VECTOR = float3(0.3125f, 0.6154f, 0.0721f);
static float2 gTapOffsets[4] =
{
{ -0.5, 0.5 }, { 0.5, -0.5 },
{ -0.5, -0.5 }, { 0.5, 0.5 }
};
float4 main( PFXVertToPix IN ) : COLOR
{
float4 average = { 0.0f, 0.0f, 0.0f, 0.0f };
// Combine and average 4 samples from the source HDR texture.
for( int i = 0; i < 4; i++ )
average += hdrDecode( tex2D( inputTex, IN.uv0 + ( gTapOffsets[i] * oneOverTargetSize ) ) );
average *= 0.25f;
// Determine the brightness of this particular pixel.
float adaptedLum = tex2D( luminanceTex, float2( 0.5f, 0.5f ) ).r;
float lum = (g_fMiddleGray / (adaptedLum + 0.0001)) * hdrLuminance( average.rgb );
//float lum = hdrLuminance( average.rgb );
// Determine whether this pixel passes the test...
if ( lum < brightPassThreshold )
average = float4( 0.0f, 0.0f, 0.0f, 1.0f );
// Write the colour to the bright-pass render target
return hdrEncode( average );
}

View file

@ -0,0 +1,45 @@
//-----------------------------------------------------------------------------
// 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.hlsl"
#include "shadergen:/autogenConditioners.h"
uniform sampler2D currLum : register( S0 );
uniform sampler2D lastAdaptedLum : register( S1 );
uniform float adaptRate;
uniform float deltaTime;
float4 main( PFXVertToPix IN ) : COLOR
{
float fAdaptedLum = tex2D( lastAdaptedLum, float2(0.5f, 0.5f) ).r;
float fCurrentLum = tex2D( currLum, float2(0.5f, 0.5f) ).r;
// The user's adapted luminance level is simulated by closing the gap between
// adapted luminance and current luminance by 2% every frame, based on a
// 30 fps rate. This is not an accurate model of human adaptation, which can
// take longer than half an hour.
float diff = fCurrentLum - fAdaptedLum;
float fNewAdaptation = fAdaptedLum + ( diff * ( 1.0 - exp( -deltaTime * adaptRate ) ) );
return float4( fNewAdaptation, 0.0, 0.0, 1.0f );
}

View file

@ -0,0 +1,52 @@
//-----------------------------------------------------------------------------
// 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.
//-----------------------------------------------------------------------------
#define IN_HLSL
#include "../../shdrConsts.h"
#include "../postFx.hlsl"
//-----------------------------------------------------------------------------
// Data
//-----------------------------------------------------------------------------
struct VertIn
{
float4 hpos : POSITION;
float4 texCoords[8] : TEXCOORD0;
};
//-----------------------------------------------------------------------------
// Main
//-----------------------------------------------------------------------------
float4 main( VertIn IN,
uniform sampler2D inputTex : register(S0) ) : COLOR
{
// We calculate the texture coords
// in the vertex shader as an optimization.
float4 sample = 0.0f;
for ( int i = 0; i < 8; i++ )
{
sample += tex2D( inputTex, IN.texCoords[i].xy );
sample += tex2D( inputTex, IN.texCoords[i].zw );
}
return sample / 16;
}

View file

@ -0,0 +1,137 @@
//-----------------------------------------------------------------------------
// 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.
//-----------------------------------------------------------------------------
#define IN_HLSL
#include "../../shdrConsts.h"
#include "../postFx.hlsl"
//-----------------------------------------------------------------------------
// Constants
//-----------------------------------------------------------------------------
struct Conn
{
float4 hpos : POSITION;
float4 texCoords[8] : TEXCOORD0;
};
//-----------------------------------------------------------------------------
// Main
//-----------------------------------------------------------------------------
Conn main( PFXVert In,
uniform float2 targetSize : register(C0) )
{
Conn Out;
Out.hpos = In.pos;
// Sample from the 16 surrounding points. Since the center point will be in
// the exact center of 16 texels, a 0.5f offset is needed to specify a texel
// center.
float2 texSize = float2( 1.0 / (targetSize.x - 1.0), 1.0 / (targetSize.y - 1.0) );
float4 uv;
uv.xy = In.uv.xy;
uv.zw = In.uv.xy;
Out.texCoords[0] = uv;
Out.texCoords[0].x += texSize.x;
Out.texCoords[0].y += texSize.y;
Out.texCoords[0].z += texSize.x;
Out.texCoords[0].w += texSize.y;
Out.texCoords[0].x += ( 0 - 1.5 ) * texSize.x;
Out.texCoords[0].y += ( 0 - 1.5 ) * texSize.y;
Out.texCoords[0].z += ( 1 - 1.5 ) * texSize.x;
Out.texCoords[0].w += ( 0 - 1.5 ) * texSize.y;
Out.texCoords[1] = uv;
Out.texCoords[1].x += texSize.x;
Out.texCoords[1].y += texSize.y;
Out.texCoords[1].z += texSize.x;
Out.texCoords[1].w += texSize.y;
Out.texCoords[1].x += ( 2 - 1.5 ) * texSize.x;
Out.texCoords[1].y += ( 0 - 1.5 ) * texSize.y;
Out.texCoords[1].z += ( 3 - 1.5 ) * texSize.x;
Out.texCoords[1].w += ( 0 - 1.5 ) * texSize.y;
Out.texCoords[2] = uv;
Out.texCoords[2].x += texSize.x;
Out.texCoords[2].y += texSize.y;
Out.texCoords[2].z += texSize.x;
Out.texCoords[2].w += texSize.y;
Out.texCoords[2].x += ( 0 - 1.5 ) * texSize.x;
Out.texCoords[2].y += ( 1 - 1.5 ) * texSize.y;
Out.texCoords[2].z += ( 1 - 1.5 ) * texSize.x;
Out.texCoords[2].w += ( 1 - 1.5 ) * texSize.y;
Out.texCoords[3] = uv;
Out.texCoords[3].x += texSize.x;
Out.texCoords[3].y += texSize.y;
Out.texCoords[3].z += texSize.x;
Out.texCoords[3].w += texSize.y;
Out.texCoords[3].x += ( 2 - 1.5 ) * texSize.x;
Out.texCoords[3].y += ( 1 - 1.5 ) * texSize.y;
Out.texCoords[3].z += ( 3 - 1.5 ) * texSize.x;
Out.texCoords[3].w += ( 1 - 1.5 ) * texSize.y;
Out.texCoords[4] = uv;
Out.texCoords[4].x += texSize.x;
Out.texCoords[4].y += texSize.y;
Out.texCoords[4].z += texSize.x;
Out.texCoords[4].w += texSize.y;
Out.texCoords[4].x += ( 0 - 1.5 ) * texSize.x;
Out.texCoords[4].y += ( 2 - 1.5 ) * texSize.y;
Out.texCoords[4].z += ( 1 - 1.5 ) * texSize.x;
Out.texCoords[4].w += ( 2 - 1.5 ) * texSize.y;
Out.texCoords[5] = uv;
Out.texCoords[5].x += texSize.x;
Out.texCoords[5].y += texSize.y;
Out.texCoords[5].z += texSize.x;
Out.texCoords[5].w += texSize.y;
Out.texCoords[5].x += ( 2 - 1.5 ) * texSize.x;
Out.texCoords[5].y += ( 2 - 1.5 ) * texSize.y;
Out.texCoords[5].z += ( 3 - 1.5 ) * texSize.x;
Out.texCoords[5].w += ( 2 - 1.5 ) * texSize.y;
Out.texCoords[6] = uv;
Out.texCoords[6].x += texSize.x;
Out.texCoords[6].y += texSize.y;
Out.texCoords[6].z += texSize.x;
Out.texCoords[6].w += texSize.y;
Out.texCoords[6].x += ( 0 - 1.5 ) * texSize.x;
Out.texCoords[6].y += ( 3 - 1.5 ) * texSize.y;
Out.texCoords[6].z += ( 1 - 1.5 ) * texSize.x;
Out.texCoords[6].w += ( 3 - 1.5 ) * texSize.y;
Out.texCoords[7] = uv;
Out.texCoords[7].x += texSize.x;
Out.texCoords[7].y += texSize.y;
Out.texCoords[7].z += texSize.x;
Out.texCoords[7].w += texSize.y;
Out.texCoords[7].x += ( 2 - 1.5 ) * texSize.x;
Out.texCoords[7].y += ( 3 - 1.5 ) * texSize.y;
Out.texCoords[7].z += ( 3 - 1.5 ) * texSize.x;
Out.texCoords[7].w += ( 3 - 1.5 ) * texSize.y;
return Out;
}

View file

@ -0,0 +1,95 @@
//-----------------------------------------------------------------------------
// 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"
#include "../postFx.hlsl"
uniform sampler2D sceneTex : register( s0 );
uniform sampler2D luminanceTex : register( s1 );
uniform sampler2D bloomTex : register( s2 );
uniform sampler1D colorCorrectionTex : register( s3 );
uniform float2 texSize0;
uniform float2 texSize2;
uniform float g_fEnableToneMapping;
uniform float g_fMiddleGray;
uniform float g_fWhiteCutoff;
uniform float g_fEnableBlueShift;
uniform float3 g_fBlueShiftColor;
uniform float g_fBloomScale;
uniform float g_fOneOverGamma;
float4 main( PFXVertToPix IN ) : COLOR0
{
float4 sample = hdrDecode( tex2D( sceneTex, IN.uv0 ) );
float adaptedLum = tex2D( luminanceTex, float2( 0.5f, 0.5f ) ).r;
float4 bloom = tex2D( bloomTex, IN.uv0 );
// For very low light conditions, the rods will dominate the perception
// of light, and therefore color will be desaturated and shifted
// towards blue.
if ( g_fEnableBlueShift > 0.0f )
{
const float3 LUMINANCE_VECTOR = float3(0.2125f, 0.7154f, 0.0721f);
// Define a linear blending from -1.5 to 2.6 (log scale) which
// determines the lerp amount for blue shift
float coef = 1.0f - ( adaptedLum + 1.5 ) / 4.1;
coef = saturate( coef * g_fEnableBlueShift );
// Lerp between current color and blue, desaturated copy
float3 rodColor = dot( sample.rgb, LUMINANCE_VECTOR ) * g_fBlueShiftColor;
sample.rgb = lerp( sample.rgb, rodColor, coef );
rodColor = dot( bloom.rgb, LUMINANCE_VECTOR ) * g_fBlueShiftColor;
bloom.rgb = lerp( bloom.rgb, rodColor, coef );
}
// Map the high range of color values into a range appropriate for
// display, taking into account the user's adaptation level,
// white point, and selected value for for middle gray.
if ( g_fEnableToneMapping > 0.0f )
{
float Lp = (g_fMiddleGray / (adaptedLum + 0.0001)) * hdrLuminance( sample.rgb );
//float toneScalar = ( Lp * ( 1.0 + ( Lp / ( g_fWhiteCutoff ) ) ) ) / ( 1.0 + Lp );
float toneScalar = Lp;
sample.rgb = lerp( sample.rgb, sample.rgb * toneScalar, g_fEnableToneMapping );
}
// Add the bloom effect.
sample += g_fBloomScale * bloom;
// Apply the color correction.
sample.r = tex1D( colorCorrectionTex, sample.r ).r;
sample.g = tex1D( colorCorrectionTex, sample.g ).g;
sample.b = tex1D( colorCorrectionTex, sample.b ).b;
// Apply gamma correction
sample.rgb = pow( abs(sample.rgb), g_fOneOverGamma );
return sample;
}

View file

@ -0,0 +1,40 @@
//-----------------------------------------------------------------------------
// 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.hlsl"
#include "../../torque.hlsl"
#include "shadergen:/autogenConditioners.h"
uniform sampler2D inputTex : register(S0);
uniform float brightPassThreshold;
float4 main( PFXVertToPix IN ) : COLOR
{
float4 sample = hdrDecode( tex2D( inputTex, IN.uv0 ) );
// Determine the brightness of this particular pixel.
float lum = hdrLuminance( sample.rgb );
// Write the colour to the bright-pass render target
return ( float4( lum.rrr, 1 ) );
}

View file

@ -0,0 +1,59 @@
//-----------------------------------------------------------------------------
// 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"
#include "../postFx.hlsl"
uniform sampler2D inputTex : register( S0 );
uniform float2 texSize0;
uniform float g_fMinLuminace;
static float2 gTapOffsets[9] =
{
{ -1.0, -1.0 }, { 0.0, -1.0 }, { 1.0, -1.0 },
{ -1.0, 0.0 }, { 0.0, 0.0 }, { 1.0, 0.0 },
{ -1.0, 1.0 }, { 0.0, 1.0 }, { 1.0, 1.0 }
};
float4 main( PFXVertToPix IN ) : COLOR
{
float2 tsize = 1.0 / texSize0;
float3 sample;
float average = 0.0;
for ( int i = 0; i < 9; i++ )
{
// Decode the hdr value.
sample = hdrDecode( tex2D( inputTex, IN.uv0 + ( gTapOffsets[i] * tsize ) ).rgb );
// Get the luminance and add it to the average.
float lum = max( hdrLuminance( sample ), g_fMinLuminace );
average += log( lum );
}
average = exp( average / 9.0 );
return float4( average, 0.0, 0.0, 1.0 );
}

View file

@ -0,0 +1,50 @@
//-----------------------------------------------------------------------------
// 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.hlsl"
uniform sampler2D inputTex : register( S0 );
uniform float2 oneOverTargetSize;
static float2 gTapOffsets[16] =
{
{ -1.5, -1.5 }, { -0.5, -1.5 }, { 0.5, -1.5 }, { 1.5, -1.5 },
{ -1.5, -0.5 }, { -0.5, -0.5 }, { 0.5, -0.5 }, { 1.5, -0.5 },
{ -1.5, 0.5 }, { -0.5, 0.5 }, { 0.5, 0.5 }, { 1.5, 0.5 },
{ -1.5, 1.5 }, { -0.5, 1.5 }, { 0.5, 1.5 }, { 1.5, 1.5 }
};
float4 main( PFXVertToPix IN ) : COLOR
{
float2 pixelSize = oneOverTargetSize;
float average = 0.0;
for ( int i = 0; i < 16; i++ )
{
float lum = tex2D( inputTex, IN.uv0 + ( gTapOffsets[i] * pixelSize ) ).r;
average += lum;
}
return float4( average / 16.0, 0.0, 0.0, 1.0 );
}

View file

@ -0,0 +1,53 @@
//-----------------------------------------------------------------------------
// 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 "shadergen:/autogenConditioners.h"
#include "../postFx.hlsl"
uniform sampler2D backBuffer : register( s0 ); // The original backbuffer.
uniform sampler2D prepassTex : register( s1 ); // The pre-pass depth and normals.
uniform float brightScalar;
static const float3 LUMINANCE_VECTOR = float3(0.3125f, 0.6154f, 0.0721f);
float4 main( PFXVertToPix IN ) : COLOR0
{
float4 col = float4( 0, 0, 0, 1 );
// Get the depth at this pixel.
float depth = prepassUncondition( prepassTex, IN.uv0 ).w;
// If the depth is equal to 1.0, read from the backbuffer
// and perform the exposure calculation on the result.
if ( depth >= 0.999 )
{
col = tex2D( backBuffer, IN.uv0 );
//col = 1 - exp(-120000 * col);
col += dot( col, LUMINANCE_VECTOR ) + 0.0001f;
col *= brightScalar;
}
return col;
}

View file

@ -0,0 +1,88 @@
//-----------------------------------------------------------------------------
// 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.hlsl"
uniform sampler2D frameSampler : register( s0 );
uniform sampler2D backBuffer : register( s1 );
uniform float3 camForward;
uniform float3 lightDirection;
uniform float2 screenSunPos;
uniform float2 oneOverTargetSize;
uniform int numSamples;
uniform float density;
uniform float weight;
uniform float decay;
uniform float exposure;
float4 main( PFXVertToPix IN ) : COLOR0
{
float4 texCoord = float4( IN.uv0.xy, 0, 0 );
// Store initial sample.
half3 color = (half3)tex2D( frameSampler, texCoord.xy ).rgb;
// Store original bb color.
float4 bbCol = tex2D( backBuffer, IN.uv1 );
// Set up illumination decay factor.
half illuminationDecay = 1.0;
float amount = saturate( dot( -lightDirection, camForward ) );
int samples = numSamples * amount;
if ( samples <= 0 )
return bbCol;
// Calculate vector from pixel to light source in screen space.
half2 deltaTexCoord = (half2)( texCoord.xy - screenSunPos );
// Divide by number of samples and scale by control factor.
deltaTexCoord *= 1.0 / (half)samples * density;
// Evaluate summation from Equation 3 NUM_SAMPLES iterations.
for ( int i = 0; i < samples; i++ )
{
// Step sample location along ray.
texCoord.xy -= deltaTexCoord;
// Retrieve sample at new location.
half3 sample = (half3)tex2Dlod( frameSampler, texCoord );
// Apply sample attenuation scale/decay factors.
sample *= illuminationDecay * weight;
// Accumulate combined color.
color += sample;
// Update exponential decay factor.
illuminationDecay *= decay;
}
//return saturate( amount ) * color * Exposure;
//return bbCol * decay;
// Output final color with a further scale control factor.
return saturate( amount ) * float4( color * exposure, 1 ) + bbCol;
}

View file

@ -0,0 +1,78 @@
//-----------------------------------------------------------------------------
// 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.
//-----------------------------------------------------------------------------
// An implementation of "Practical Morphological Anti-Aliasing" from
// GPU Pro 2 by Jorge Jimenez, Belen Masia, Jose I. Echevarria,
// Fernando Navarro, and Diego Gutierrez.
//
// http://www.iryoku.com/mlaa/
uniform sampler2D edgesMap : register(S0);
uniform sampler2D edgesMapL : register(S1);
uniform sampler2D areaMap : register(S2);
#include "./functions.hlsl"
float4 main(float2 texcoord : TEXCOORD0) : COLOR0
{
float4 areas = 0.0;
float2 e = tex2D(edgesMap, texcoord).rg;
[branch]
if (e.g) // Edge at north
{
// Search distances to the left and to the right:
float2 d = float2(SearchXLeft(texcoord), SearchXRight(texcoord));
// Now fetch the crossing edges. Instead of sampling between edgels, we
// sample at -0.25, to be able to discern what value has each edgel:
float4 coords = mad(float4(d.x, -0.25, d.y + 1.0, -0.25),
PIXEL_SIZE.xyxy, texcoord.xyxy);
float e1 = tex2Dlevel0(edgesMapL, coords.xy).r;
float e2 = tex2Dlevel0(edgesMapL, coords.zw).r;
// Ok, we know how this pattern looks like, now it is time for getting
// the actual area:
areas.rg = Area(abs(d), e1, e2);
}
[branch]
if (e.r) // Edge at west
{
// Search distances to the top and to the bottom:
float2 d = float2(SearchYUp(texcoord), SearchYDown(texcoord));
// Now fetch the crossing edges (yet again):
float4 coords = mad(float4(-0.25, d.x, -0.25, d.y + 1.0),
PIXEL_SIZE.xyxy, texcoord.xyxy);
float e1 = tex2Dlevel0(edgesMapL, coords.xy).g;
float e2 = tex2Dlevel0(edgesMapL, coords.zw).g;
// Get the area for this direction:
areas.ba = Area(abs(d), e1, e2);
}
return areas;
}

View file

@ -0,0 +1,72 @@
//-----------------------------------------------------------------------------
// 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.
//-----------------------------------------------------------------------------
// An implementation of "Practical Morphological Anti-Aliasing" from
// GPU Pro 2 by Jorge Jimenez, Belen Masia, Jose I. Echevarria,
// Fernando Navarro, and Diego Gutierrez.
//
// http://www.iryoku.com/mlaa/
#include "shadergen:/autogenConditioners.h"
uniform sampler2D colorMapG : register(S0);
uniform sampler2D prepassMap : register(S1);
uniform float3 lumaCoefficients;
uniform float threshold;
uniform float depthThreshold;
float4 main( float2 texcoord : TEXCOORD0,
float4 offset[2]: TEXCOORD1) : COLOR0
{
// Luma calculation requires gamma-corrected colors (texture 'colorMapG').
//
// Note that there is a lot of overlapped luma calculations; performance
// can be improved if this luma calculation is performed in the main pass,
// which may give you an edge if used in conjunction with a z prepass.
float L = dot(tex2D(colorMapG, texcoord).rgb, lumaCoefficients);
float Lleft = dot(tex2D(colorMapG, offset[0].xy).rgb, lumaCoefficients);
float Ltop = dot(tex2D(colorMapG, offset[0].zw).rgb, lumaCoefficients);
float Lright = dot(tex2D(colorMapG, offset[1].xy).rgb, lumaCoefficients);
float Lbottom = dot(tex2D(colorMapG, offset[1].zw).rgb, lumaCoefficients);
float4 delta = abs(L.xxxx - float4(Lleft, Ltop, Lright, Lbottom));
float4 edges = step(threshold, delta);
// Add depth edges to color edges
float D = prepassUncondition(prepassMap, texcoord).w;
float Dleft = prepassUncondition(prepassMap, offset[0].xy).w;
float Dtop = prepassUncondition(prepassMap, offset[0].zw).w;
float Dright = prepassUncondition(prepassMap, offset[1].xy).w;
float Dbottom = prepassUncondition(prepassMap, offset[1].zw).w;
delta = abs(D.xxxx - float4(Dleft, Dtop, Dright, Dbottom));
edges += step(depthThreshold, delta);
if (dot(edges, 1.0) == 0.0)
discard;
return edges;
}

View file

@ -0,0 +1,145 @@
//-----------------------------------------------------------------------------
// 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.
//-----------------------------------------------------------------------------
// An implementation of "Practical Morphological Anti-Aliasing" from
// GPU Pro 2 by Jorge Jimenez, Belen Masia, Jose I. Echevarria,
// Fernando Navarro, and Diego Gutierrez.
//
// http://www.iryoku.com/mlaa/
uniform float2 texSize0;
#if !defined(PIXEL_SIZE)
#define PIXEL_SIZE (1.0 / texSize0)
#define MAX_SEARCH_STEPS 8
#define MAX_DISTANCE 33
#endif
// Typical Multiply-Add operation to ease translation to assembly code.
float4 mad(float4 m, float4 a, float4 b)
{
#if defined(XBOX)
float4 result;
asm {
mad result, m, a, b
};
return result;
#else
return m * a + b;
#endif
}
// This one just returns the first level of a mip map chain, which allow us to
// avoid the nasty ddx/ddy warnings, even improving the performance a little
// bit.
float4 tex2Dlevel0(sampler2D map, float2 texcoord)
{
return tex2Dlod(map, float4(texcoord, 0.0, 0.0));
}
// Same as above, this eases translation to assembly code;
float4 tex2Doffset(sampler2D map, float2 texcoord, float2 offset)
{
#if defined(XBOX) && MAX_SEARCH_STEPS < 6
float4 result;
float x = offset.x;
float y = offset.y;
asm {
tfetch2D result, texcoord, map, OffsetX = x, OffsetY = y
};
return result;
#else
return tex2Dlevel0(map, texcoord + PIXEL_SIZE * offset);
#endif
}
// Ok, we have the distance and both crossing edges, can you please return
// the float2 blending weights?
float2 Area(float2 distance, float e1, float e2)
{
// * By dividing by areaSize - 1.0 below we are implicitely offsetting to
// always fall inside of a pixel
// * Rounding prevents bilinear access precision problems
float areaSize = MAX_DISTANCE * 5.0;
float2 pixcoord = MAX_DISTANCE * round(4.0 * float2(e1, e2)) + distance;
float2 texcoord = pixcoord / (areaSize - 1.0);
return tex2Dlevel0(areaMap, texcoord).rg;
}
// Search functions for the 2nd pass.
float SearchXLeft(float2 texcoord)
{
// We compare with 0.9 to prevent bilinear access precision problems.
float i;
float e = 0.0;
for (i = -1.5; i > -2.0 * MAX_SEARCH_STEPS; i -= 2.0)
{
e = tex2Doffset(edgesMapL, texcoord, float2(i, 0.0)).g;
[flatten] if (e < 0.9) break;
}
return max(i + 1.5 - 2.0 * e, -2.0 * MAX_SEARCH_STEPS);
}
// Search functions for the 2nd pass.
float SearchXRight(float2 texcoord)
{
float i;
float e = 0.0;
for (i = 1.5; i < 2.0 * MAX_SEARCH_STEPS; i += 2.0)
{
e = tex2Doffset(edgesMapL, texcoord, float2(i, 0.0)).g;
[flatten] if (e < 0.9) break;
}
return min(i - 1.5 + 2.0 * e, 2.0 * MAX_SEARCH_STEPS);
}
// Search functions for the 2nd pass.
float SearchYUp(float2 texcoord)
{
float i;
float e = 0.0;
for (i = -1.5; i > -2.0 * MAX_SEARCH_STEPS; i -= 2.0)
{
e = tex2Doffset(edgesMapL, texcoord, float2(i, 0.0).yx).r;
[flatten] if (e < 0.9) break;
}
return max(i + 1.5 - 2.0 * e, -2.0 * MAX_SEARCH_STEPS);
}
// Search functions for the 2nd pass.
float SearchYDown(float2 texcoord)
{
float i;
float e = 0.0;
for (i = 1.5; i < 2.0 * MAX_SEARCH_STEPS; i += 2.0)
{
e = tex2Doffset(edgesMapL, texcoord, float2(i, 0.0).yx).r;
[flatten] if (e < 0.9) break;
}
return min(i - 1.5 + 2.0 * e, 2.0 * MAX_SEARCH_STEPS);
}

View file

@ -0,0 +1,84 @@
//-----------------------------------------------------------------------------
// 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.
//-----------------------------------------------------------------------------
// An implementation of "Practical Morphological Anti-Aliasing" from
// GPU Pro 2 by Jorge Jimenez, Belen Masia, Jose I. Echevarria,
// Fernando Navarro, and Diego Gutierrez.
//
// http://www.iryoku.com/mlaa/
uniform sampler2D blendMap : register(S0);
uniform sampler2D colorMapL : register(S1);
uniform sampler2D colorMap : register(S2);
// Dummy sampers to please include.
sampler2D areaMap;
sampler2D edgesMapL;
#include "./functions.hlsl"
float4 main( float2 texcoord : TEXCOORD0,
float4 offset[2]: TEXCOORD1 ) : COLOR0
{
// Fetch the blending weights for current pixel:
float4 topLeft = tex2D(blendMap, texcoord);
float bottom = tex2D(blendMap, offset[1].zw).g;
float right = tex2D(blendMap, offset[1].xy).a;
float4 a = float4(topLeft.r, bottom, topLeft.b, right);
// Up to 4 lines can be crossing a pixel (one in each edge). So, we perform
// a weighted average, where the weight of each line is 'a' cubed, which
// favors blending and works well in practice.
float4 w = a * a * a;
// There is some blending weight with a value greater than 0.0?
float sum = dot(w, 1.0);
if (sum < 1e-5)
discard;
float4 color = 0.0;
// Add the contributions of the possible 4 lines that can cross this pixel:
#ifdef BILINEAR_FILTER_TRICK
float4 coords = mad(float4( 0.0, -a.r, 0.0, a.g), PIXEL_SIZE.yyyy, texcoord.xyxy);
color = mad(tex2D(colorMapL, coords.xy), w.r, color);
color = mad(tex2D(colorMapL, coords.zw), w.g, color);
coords = mad(float4(-a.b, 0.0, a.a, 0.0), PIXEL_SIZE.xxxx, texcoord.xyxy);
color = mad(tex2D(colorMapL, coords.xy), w.b, color);
color = mad(tex2D(colorMapL, coords.zw), w.a, color);
#else
float4 C = tex2D(colorMap, texcoord);
float4 Cleft = tex2D(colorMap, offset[0].xy);
float4 Ctop = tex2D(colorMap, offset[0].zw);
float4 Cright = tex2D(colorMap, offset[1].xy);
float4 Cbottom = tex2D(colorMap, offset[1].zw);
color = mad(lerp(C, Ctop, a.r), w.r, color);
color = mad(lerp(C, Cbottom, a.g), w.g, color);
color = mad(lerp(C, Cleft, a.b), w.b, color);
color = mad(lerp(C, Cright, a.a), w.a, color);
#endif
// Normalize the resulting color and we are finished!
return color / sum;
}

View file

@ -0,0 +1,42 @@
//-----------------------------------------------------------------------------
// 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.
//-----------------------------------------------------------------------------
// An implementation of "Practical Morphological Anti-Aliasing" from
// GPU Pro 2 by Jorge Jimenez, Belen Masia, Jose I. Echevarria,
// Fernando Navarro, and Diego Gutierrez.
//
// http://www.iryoku.com/mlaa/
uniform float2 texSize0;
void main( inout float4 position : POSITION0,
inout float2 texcoord : TEXCOORD0,
out float4 offset[2] : TEXCOORD1 )
{
float2 PIXEL_SIZE = 1.0 / texSize0;
texcoord.xy += PIXEL_SIZE * 0.5;
offset[0] = texcoord.xyxy + PIXEL_SIZE.xyxy * float4(-1.0, 0.0, 0.0, -1.0);
offset[1] = texcoord.xyxy + PIXEL_SIZE.xyxy * float4( 1.0, 0.0, 0.0, 1.0);
}

View file

@ -0,0 +1,37 @@
//-----------------------------------------------------------------------------
// 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.
//-----------------------------------------------------------------------------
// An implementation of "Practical Morphological Anti-Aliasing" from
// GPU Pro 2 by Jorge Jimenez, Belen Masia, Jose I. Echevarria,
// Fernando Navarro, and Diego Gutierrez.
//
// http://www.iryoku.com/mlaa/
uniform float2 texSize0;
void main( inout float4 position : POSITION0,
inout float2 texcoord : TEXCOORD0)
{
float2 PIXEL_SIZE = 1.0 / texSize0;
texcoord.xy += PIXEL_SIZE * 0.5;
}

View file

@ -0,0 +1,30 @@
//-----------------------------------------------------------------------------
// 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.hlsl"
uniform sampler2D inputTex : register(S0);
float4 main( PFXVertToPix IN ) : COLOR
{
return tex2D( inputTex, IN.uv0 );
}

View file

@ -0,0 +1,39 @@
//-----------------------------------------------------------------------------
// 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.
//-----------------------------------------------------------------------------
struct PFXVert
{
float4 pos : POSITION;
float2 uv : TEXCOORD0;
float3 wsEyeRay : TEXCOORD1;
};
struct PFXVertToPix
{
float4 hpos : POSITION;
float2 uv0 : TEXCOORD0;
float2 uv1 : TEXCOORD1;
float2 uv2 : TEXCOORD2;
float2 uv3 : TEXCOORD3;
float3 wsEyeRay : TEXCOORD4;
};

View file

@ -0,0 +1,48 @@
//-----------------------------------------------------------------------------
// 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 "./../gl/torque.glsl"
uniform vec4 rtParams0;
uniform vec4 rtParams1;
uniform vec4 rtParams2;
uniform vec4 rtParams3;
varying vec2 uv0;
varying vec2 uv1;
varying vec2 uv2;
varying vec2 uv3;
varying vec3 wsEyeRay;
void main()
{
gl_Position = gl_Vertex;
uv0 = viewportCoordToRenderTarget( gl_MultiTexCoord0.st, rtParams0 );
uv1 = viewportCoordToRenderTarget( gl_MultiTexCoord0.st, rtParams1 );
uv2 = viewportCoordToRenderTarget( gl_MultiTexCoord0.st, rtParams2 );
uv3 = viewportCoordToRenderTarget( gl_MultiTexCoord0.st, rtParams3 );
wsEyeRay = gl_MultiTexCoord1.xyz;
}

View file

@ -0,0 +1,45 @@
//-----------------------------------------------------------------------------
// 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.hlsl"
#include "./../torque.hlsl"
uniform float4 rtParams0;
uniform float4 rtParams1;
uniform float4 rtParams2;
uniform float4 rtParams3;
PFXVertToPix main( PFXVert IN )
{
PFXVertToPix OUT;
OUT.hpos = IN.pos;
OUT.uv0 = viewportCoordToRenderTarget( IN.uv, rtParams0 );
OUT.uv1 = viewportCoordToRenderTarget( IN.uv, rtParams1 );
OUT.uv2 = viewportCoordToRenderTarget( IN.uv, rtParams2 );
OUT.uv3 = viewportCoordToRenderTarget( IN.uv, rtParams3 );
OUT.wsEyeRay = IN.wsEyeRay;
return OUT;
}

View file

@ -0,0 +1,106 @@
//-----------------------------------------------------------------------------
// 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 "shadergen:/autogenConditioners.h"
//#include "./../postFx.hlsl"
uniform sampler2D occludeMap : register(S0);
uniform sampler2D prepassMap : register(S1);
struct VertToPix
{
float4 hpos : POSITION;
float4 uv0 : TEXCOORD0;
float2 uv1 : TEXCOORD1;
float2 uv2 : TEXCOORD2;
float2 uv3 : TEXCOORD3;
float2 uv4 : TEXCOORD4;
float2 uv5 : TEXCOORD5;
float2 uv6 : TEXCOORD6;
float2 uv7 : TEXCOORD7;
};
uniform float blurDepthTol;
uniform float blurNormalTol;
void sample( float2 uv, float weight, float4 centerTap, inout int usedCount, inout float occlusion, inout float total )
{
//return;
float4 tap = prepassUncondition( prepassMap, uv );
if ( abs( tap.a - centerTap.a ) < blurDepthTol )
{
if ( dot( tap.xyz, centerTap.xyz ) > blurNormalTol )
{
usedCount++;
total += weight;
occlusion += tex2D( occludeMap, uv ).r * weight;
}
}
}
float4 main( VertToPix IN ) : COLOR
{
//float4 centerTap;
float4 centerTap = prepassUncondition( prepassMap, IN.uv0.zw );
//return centerTap;
//float centerOcclude = tex2D( occludeMap, IN.uv0.zw ).r;
//return float4( centerOcclude.rrr, 1 );
float4 kernel = float4( 0.175, 0.275, 0.375, 0.475 ); //25f;
float occlusion = 0;
int usedCount = 0;
float total = 0.0;
sample( IN.uv0.xy, kernel.x, centerTap, usedCount, occlusion, total );
sample( IN.uv1, kernel.y, centerTap, usedCount, occlusion, total );
sample( IN.uv2, kernel.z, centerTap, usedCount, occlusion, total );
sample( IN.uv3, kernel.w, centerTap, usedCount, occlusion, total );
sample( IN.uv4, kernel.x, centerTap, usedCount, occlusion, total );
sample( IN.uv5, kernel.y, centerTap, usedCount, occlusion, total );
sample( IN.uv6, kernel.z, centerTap, usedCount, occlusion, total );
sample( IN.uv7, kernel.w, centerTap, usedCount, occlusion, total );
occlusion += tex2D( occludeMap, IN.uv0.zw ).r * 0.5;
total += 0.5;
//occlusion /= 3.0;
//occlusion /= (float)usedCount / 8.0;
occlusion /= total;
return float4( occlusion.rrr, 1 );
//return float4( 0,0,0,occlusion );
//float3 color = tex2D( colorMap, IN.uv0.zw );
//return float4( color, occlusion );
}

View file

@ -0,0 +1,86 @@
//-----------------------------------------------------------------------------
// 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.hlsl"
#include "./../../torque.hlsl"
uniform float2 texSize0;
uniform float4 rtParams0;
uniform float2 oneOverTargetSize;
struct VertToPix
{
float4 hpos : POSITION;
float4 uv0 : TEXCOORD0;
float2 uv1 : TEXCOORD1;
float2 uv2 : TEXCOORD2;
float2 uv3 : TEXCOORD3;
float2 uv4 : TEXCOORD4;
float2 uv5 : TEXCOORD5;
float2 uv6 : TEXCOORD6;
float2 uv7 : TEXCOORD7;
};
VertToPix main( PFXVert IN )
{
VertToPix OUT;
OUT.hpos = IN.pos;
IN.uv = viewportCoordToRenderTarget( IN.uv, rtParams0 );
//float4 step = float4( 3.5, 2.5, 1.5, 0.5 );
//float4 step = float4( 4.0, 3.0, 2.0, 1.0 );
float4 step = float4( 9.0, 5.0, 2.5, 0.5 );
// I don't know why this offset is necessary, but it is.
//IN.uv = IN.uv * oneOverTargetSize;
OUT.uv0.xy = IN.uv + ( ( BLUR_DIR * step.x ) / texSize0 );
OUT.uv1 = IN.uv + ( ( BLUR_DIR * step.y ) / texSize0 );
OUT.uv2 = IN.uv + ( ( BLUR_DIR * step.z ) / texSize0 );
OUT.uv3 = IN.uv + ( ( BLUR_DIR * step.w ) / texSize0 );
OUT.uv4 = IN.uv - ( ( BLUR_DIR * step.x ) / texSize0 );
OUT.uv5 = IN.uv - ( ( BLUR_DIR * step.y ) / texSize0 );
OUT.uv6 = IN.uv - ( ( BLUR_DIR * step.z ) / texSize0 );
OUT.uv7 = IN.uv - ( ( BLUR_DIR * step.w ) / texSize0 );
OUT.uv0.zw = IN.uv;
/*
OUT.uv0 = viewportCoordToRenderTarget( OUT.uv0, rtParams0 );
OUT.uv1 = viewportCoordToRenderTarget( OUT.uv1, rtParams0 );
OUT.uv2 = viewportCoordToRenderTarget( OUT.uv2, rtParams0 );
OUT.uv3 = viewportCoordToRenderTarget( OUT.uv3, rtParams0 );
OUT.uv4 = viewportCoordToRenderTarget( OUT.uv4, rtParams0 );
OUT.uv5 = viewportCoordToRenderTarget( OUT.uv5, rtParams0 );
OUT.uv6 = viewportCoordToRenderTarget( OUT.uv6, rtParams0 );
OUT.uv7 = viewportCoordToRenderTarget( OUT.uv7, rtParams0 );
*/
return OUT;
}

View file

@ -0,0 +1,272 @@
//-----------------------------------------------------------------------------
// 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 "shadergen:/autogenConditioners.h"
#include "./../postFx.hlsl"
#define DOSMALL
#define DOLARGE
uniform sampler2D prepassMap : register(S0);
uniform sampler2D randNormalTex : register(S1);
uniform sampler1D powTable : register(S2);
uniform float2 nearFar;
uniform float2 worldToScreenScale;
uniform float2 texSize0;
uniform float2 texSize1;
uniform float2 targetSize;
// Script-set constants.
uniform float overallStrength;
uniform float sRadius;
uniform float sStrength;
uniform float sDepthMin;
uniform float sDepthMax;
uniform float sDepthPow;
uniform float sNormalTol;
uniform float sNormalPow;
uniform float lRadius;
uniform float lStrength;
uniform float lDepthMin;
uniform float lDepthMax;
uniform float lDepthPow;
uniform float lNormalTol;
uniform float lNormalPow;
#ifndef QUALITY
#define QUALITY 2
#endif
#if QUALITY == 0
#define sSampleCount 4
#define totalSampleCount 12
#elif QUALITY == 1
#define sSampleCount 6
#define totalSampleCount 24
#elif QUALITY == 2
#define sSampleCount 8
#define totalSampleCount 32
#endif
float getOcclusion( float depthDiff, float depthMin, float depthMax, float depthPow,
float normalDiff, float dt, float normalTol, float normalPow )
{
if ( depthDiff < 0.0 )
return 0.0;
float delta = abs( depthDiff );
if ( delta < depthMin || delta > depthMax )
return 0.0;
delta = saturate( delta / depthMax );
if ( dt > 0.0 )
normalDiff *= dt;
else
normalDiff = 1.0;
normalDiff *= 1.0 - ( dt * 0.5 + 0.5 );
return ( 1.0 - tex1D( powTable, delta ).r ) * normalDiff;
}
float4 main( PFXVertToPix IN ) : COLOR
{
float3 ptSphere[32] =
{
float3( 0.295184, 0.077723, 0.068429 ),
float3( -0.271976, -0.365221, -0.838363 ),
float3( 0.547713, 0.467576, 0.488515 ),
float3( 0.662808, -0.031733, -0.584758 ),
float3( -0.025717, 0.218955, -0.657094 ),
float3( -0.310153, -0.365223, -0.370701 ),
float3( -0.101407, -0.006313, -0.747665 ),
float3( -0.769138, 0.360399, -0.086847 ),
float3( -0.271988, -0.275140, -0.905353 ),
float3( 0.096740, -0.566901, 0.700151 ),
float3( 0.562872, -0.735136, -0.094647 ),
float3( 0.379877, 0.359278, 0.190061 ),
float3( 0.519064, -0.023055, 0.405068 ),
float3( -0.301036, 0.114696, -0.088885 ),
float3( -0.282922, 0.598305, 0.487214 ),
float3( -0.181859, 0.251670, -0.679702 ),
float3( -0.191463, -0.635818, -0.512919 ),
float3( -0.293655, 0.427423, 0.078921 ),
float3( -0.267983, 0.680534, -0.132880 ),
float3( 0.139611, 0.319637, 0.477439 ),
float3( -0.352086, 0.311040, 0.653913 ),
float3( 0.321032, 0.805279, 0.487345 ),
float3( 0.073516, 0.820734, -0.414183 ),
float3( -0.155324, 0.589983, -0.411460 ),
float3( 0.335976, 0.170782, -0.527627 ),
float3( 0.463460, -0.355658, -0.167689 ),
float3( 0.222654, 0.596550, -0.769406 ),
float3( 0.922138, -0.042070, 0.147555 ),
float3( -0.727050, -0.329192, 0.369826 ),
float3( -0.090731, 0.533820, 0.463767 ),
float3( -0.323457, -0.876559, -0.238524 ),
float3( -0.663277, -0.372384, -0.342856 )
};
// Sample a random normal for reflecting the
// sphere vector later in our loop.
float4 noiseMapUV = float4( ( IN.uv1 * ( targetSize / texSize1 ) ).xy, 0, 0 );
float3 reflectNormal = normalize( tex2Dlod( randNormalTex, noiseMapUV ).xyz * 2.0 - 1.0 );
//return float4( reflectNormal, 1 );
float4 prepass = prepassUncondition( prepassMap, IN.uv0 );
float3 normal = prepass.xyz;
float depth = prepass.a;
//return float4( ( depth ).xxx, 1 );
// Early out if too far away.
if ( depth > 0.99999999 )
return float4( 0,0,0,0 );
// current fragment coords in screen space
float3 ep = float3( IN.uv0, depth );
float bl;
float3 baseRay, ray, se, occNorm, projRadius;
float normalDiff = 0;
float depthMin, depthMax, dt, depthDiff;
float4 occluderFragment;
int i;
float sOcclusion = 0.0;
float lOcclusion = 0.0;
//------------------------------------------------------------
// Small radius
//------------------------------------------------------------
#ifdef DOSMALL
bl = 0.0;
projRadius.xy = ( float2( sRadius.rr ) / ( depth * nearFar.y ) ) * ( worldToScreenScale / texSize0 );
projRadius.z = sRadius / nearFar.y;
depthMin = projRadius.z * sDepthMin;
depthMax = projRadius.z * sDepthMax;
//float maxr = 1;
//radiusDepth = clamp( radiusDepth, 0.0001, maxr.rrr );
//if ( radiusDepth.x < 1.0 / targetSize.x )
// return color;
//radiusDepth.xyz = 0.0009;
for ( i = 0; i < sSampleCount; i++ )
{
baseRay = reflect( ptSphere[i], reflectNormal );
dt = dot( baseRay.xyz, normal );
baseRay *= sign( dt );
ray = ( projRadius * baseRay.xzy );
ray.y = -ray.y;
se = ep + ray;
occluderFragment = prepassUncondition( prepassMap, se.xy );
depthDiff = se.z - occluderFragment.a;
dt = dot( occluderFragment.xyz, baseRay.xyz );
normalDiff = dot( occluderFragment.xyz, normal );
bl += getOcclusion( depthDiff, depthMin, depthMax, sDepthPow, normalDiff, dt, sNormalTol, sNormalPow );
}
sOcclusion = sStrength * ( bl / (float)sSampleCount );
#endif // DOSMALL
//------------------------------------------------------------
// Large radius
//------------------------------------------------------------
#ifdef DOLARGE
bl = 0.0;
projRadius.xy = ( float2( lRadius.rr ) / ( depth * nearFar.y ) ) * ( worldToScreenScale / texSize0 );
projRadius.z = lRadius / nearFar.y;
depthMin = projRadius.z * lDepthMin;
depthMax = projRadius.z * lDepthMax;
//projRadius.xy = clamp( projRadius.xy, 0.0, 0.01 );
//float maxr = 1;
//radiusDepth = clamp( radiusDepth, 0.0001, maxr.rrr );
//if ( radiusDepth.x < 1.0 / targetSize.x )
// return color;
//radiusDepth.xyz = 0.0009;
for ( i = sSampleCount; i < totalSampleCount; i++ )
{
baseRay = reflect( ptSphere[i], reflectNormal );
dt = dot( baseRay.xyz, normal );
baseRay *= sign( dt );
ray = ( projRadius * baseRay.xzy );
ray.y = -ray.y;
se = ep + ray;
occluderFragment = prepassUncondition( prepassMap, se.xy );
depthDiff = se.z - occluderFragment.a;
normalDiff = dot( occluderFragment.xyz, normal );
dt = dot( occluderFragment.xyz, baseRay.xyz );
bl += getOcclusion( depthDiff, depthMin, depthMax, lDepthPow, normalDiff, dt, lNormalTol, lNormalPow );
}
lOcclusion = lStrength * ( bl / (float)( totalSampleCount - sSampleCount ) );
#endif // DOLARGE
float occlusion = saturate( max( sOcclusion, lOcclusion ) * overallStrength );
// Note black is unoccluded and white is fully occluded. This
// seems backwards, but it makes it simple to deal with the SSAO
// being disabled in the lighting shaders.
return occlusion;
}

View file

@ -0,0 +1,29 @@
//-----------------------------------------------------------------------------
// 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.hlsl"
float4 main( PFXVertToPix IN ) : COLOR
{
float power = pow( max( IN.uv0.x, 0 ), 0.1 );
return float4( power, 0, 0, 1 );
}

View file

@ -0,0 +1,45 @@
//-----------------------------------------------------------------------------
// 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.hlsl"
#include "./../../torque.hlsl"
uniform float4 rtParams0;
uniform float4 rtParams1;
uniform float4 rtParams2;
uniform float4 rtParams3;
PFXVertToPix main( PFXVert IN )
{
PFXVertToPix OUT;
OUT.hpos = IN.pos;
OUT.uv0 = IN.uv; //viewportCoordToRenderTarget( IN.uv, rtParams0 );
OUT.uv1 = IN.uv; //viewportCoordToRenderTarget( IN.uv, rtParams1 );
OUT.uv2 = IN.uv; //viewportCoordToRenderTarget( IN.uv, rtParams2 );
OUT.uv3 = IN.uv; //viewportCoordToRenderTarget( IN.uv, rtParams3 );
OUT.wsEyeRay = IN.wsEyeRay;
return OUT;
}

View file

@ -0,0 +1,138 @@
//-----------------------------------------------------------------------------
// 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 "shadergen:/autogenConditioners.h"
#include "./postFx.hlsl"
#include "../torque.hlsl"
//-----------------------------------------------------------------------------
// Defines
//-----------------------------------------------------------------------------
// oceanFogData
#define FOG_DENSITY waterFogData[0]
#define FOG_DENSITY_OFFSET waterFogData[1]
#define WET_DEPTH waterFogData[2]
#define WET_DARKENING waterFogData[3]
//-----------------------------------------------------------------------------
// Uniforms
//-----------------------------------------------------------------------------
uniform sampler2D prepassTex : register(S0);
uniform sampler2D backbuffer : register(S1);
uniform sampler1D waterDepthGradMap : register(S2);
uniform float3 eyePosWorld;
uniform float3 ambientColor;
uniform float4 waterColor;
uniform float4 waterFogData;
uniform float4 waterFogPlane;
uniform float2 nearFar;
uniform float4 rtParams0;
uniform float waterDepthGradMax;
float4 main( PFXVertToPix IN ) : COLOR
{
//float2 prepassCoord = IN.uv0;
//IN.uv0 = ( IN.uv0.xy * rtParams0.zw ) + rtParams0.xy;
float depth = prepassUncondition( prepassTex, IN.uv0 ).w;
//return float4( depth.rrr, 1 );
// Skip fogging the extreme far plane so that
// the canvas clear color always appears.
//clip( 0.9 - depth );
// We assume that the eye position is below water because
// otherwise this shader/posteffect should not be active.
depth *= nearFar.y;
float3 eyeRay = normalize( IN.wsEyeRay );
float3 rayStart = eyePosWorld;
float3 rayEnd = eyePosWorld + ( eyeRay * depth );
//return float4( rayEnd, 1 );
float4 plane = waterFogPlane; //float4( 0, 0, 1, -waterHeight );
//plane.w -= 0.15;
float startSide = dot( plane.xyz, rayStart ) + plane.w;
if ( startSide > 0 )
{
rayStart.z -= ( startSide );
//return float4( 1, 0, 0, 1 );
}
float3 hitPos;
float3 ray = rayEnd - rayStart;
float rayLen = length( ray );
float3 rayDir = normalize( ray );
float endSide = dot( plane.xyz, rayEnd ) + plane.w;
float planeDist;
if ( endSide < -0.005 )
{
//return float4( 0, 0, 1, 1 );
hitPos = rayEnd;
planeDist = endSide;
}
else
{
//return float4( 0, 0, 0, 0 );
float den = dot( ray, plane.xyz );
// Parallal to the plane, return the endPnt.
//if ( den == 0.0f )
// return endPnt;
float dist = -( dot( plane.xyz, rayStart ) + plane.w ) / den;
if ( dist < 0.0 )
dist = 0.0;
//return float4( 1, 0, 0, 1 );
//return float4( ( dist ).rrr, 1 );
hitPos = lerp( rayStart, rayEnd, dist );
planeDist = dist;
}
float delta = length( hitPos - rayStart );
float fogAmt = 1.0 - saturate( exp( -FOG_DENSITY * ( delta - FOG_DENSITY_OFFSET ) ) );
//return float4( fogAmt.rrr, 1 );
// Calculate the water "base" color based on depth.
float4 fogColor = waterColor * tex1D( waterDepthGradMap, saturate( delta / waterDepthGradMax ) );
// Modulate baseColor by the ambientColor.
fogColor *= float4( ambientColor.rgb, 1 );
float3 inColor = hdrDecode( tex2D( backbuffer, IN.uv0 ).rgb );
inColor.rgb *= 1.0 - saturate( abs( planeDist ) / WET_DEPTH ) * WET_DARKENING;
//return float4( inColor, 1 );
float3 outColor = lerp( inColor, fogColor, fogAmt );
return float4( hdrEncode( outColor ), 1 );
}