Image space ambient occlusion or Screen space ambient occlusion, based on http://www.shalinor.com/code.html and http://rgba.scenesp.org/iq/computer/articles/ssao/ssao.htm
gpgpu forums
code for copy paste ... but more instructions...maybe change g_cKernelSize to 8 or 12...
//-----------------------------------------------------------------------------
// File: PP_SSAO.fx
//
// Desc: Effect file for image post-processing sample. This effect contains
// a single technique with a pixel shader that calculates simple SSAO
// uses full screen depth and normals
//-----------------------------------------------------------------------------
texture Albedo; // Here are normals
texture NormalMap; // Here is depth
//--------------------------------------------------------------------------------------
// Texture samplers
//--------------------------------------------------------------------------------------
sampler AlbedoSampler = sampler_state {
Texture = (Albedo);
MipFilter = LINEAR;
MinFilter = LINEAR;
MagFilter = LINEAR;
ADDRESSU = WRAP;
ADDRESSV = WRAP;
};
sampler NormalMapSampler = sampler_state {
Texture = (NormalMap);
MipFilter = NONE;
MinFilter = LINEAR;
MagFilter = LINEAR;
ADDRESSU = WRAP;
ADDRESSV = WRAP;
};
static const int g_cKernelSize = 24;
float2 PixelKernel[g_cKernelSize ] = {
{-0.326212f, -0.405805f},
{-0.840144f, -0.07358f},
{-0.695914f, 0.457137f},
{-0.203345f, 0.620716f},
{ 0.96234f, -0.194983f},
{ 0.473434f, -0.480026f},
{-0.519456f, 0.767022f},
{ 0.185461f, -0.893124f},
{ 0.507431f, 0.064425f},
{ 0.89642f, 0.412458f},
{-0.32194f, -0.932615f},
{-0.791559f, -0.597705f},
{ 0.326212f, -0.405805f},
{ 0.840144f, -0.07358f},
{ 0.695914f, 0.457137f},
{ 0.203345f, 0.620716f},
{-0.96234f, -0.194983f},
{-0.473434f, -0.480026f},
{ 0.519456f, 0.767022f},
{-0.185461f, -0.893124f},
{-0.507431f, 0.064425f},
{-0.89642f, 0.412458f},
{ 0.32194f, -0.932615f},
{ 0.791559f, -0.597705f}
};
float2 TexelKernel[g_cKernelSize]
< convertpixelstotexels512 = "PixelKernel">;
//float3 Settings (AOCreaseValues - Range, Bias, Averager, Unused)
float4 Settings = { 0.4196,-0.2510,4.8471,3.0627 };
float4 SettingsB = { 25.8824,1.0000,1.0000,1.0000 };
float4 PostProcessPS( float2 Tex : TEXCOORD0 ) : COLOR0
{
// Get center sample
float UVlr = 1/256;
float2 centeredUV = Tex;
float3 centerPos = tex2D(AlbedoSampler, centeredUV).xyz; // normals
float3 centerNormal = tex2D(NormalMapSampler, centeredUV).xyz; // depth
float4 totalGI = 1.0f;
float GI = 0.0f;
// Run through all taps
for (int i = 0; i < sampleuv =" centeredUV" samplepos =" tex2D(AlbedoSampler," tocenter =" samplePos" distance =" length(toCenter);" centercontrib =" saturate((dot(toCenter,centerNormal)" rangeattenuation =" 1-saturate(distance" totalgi =" float4(GI,GI,GI,1.0f);" vertexshader =" null;" pixelshader =" compile" zenable =" false;">
Ni komentarjev:
Objavite komentar