Jump to content
  • Advertisement
Sign in to follow this  
Archie2112

SSAO Question

This topic is 3681 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello. I've tried to toon an edge detection shader into an SSAO shader using the shader example by JKLint. However the shader still turns into an edge detector and just gives everythingn an outline. Here is the shader...
texture depthTexture;
float4x4 matWorldViewProj;
float2 camerarange=float2(0.1f,800.f);

sampler RT = sampler_state
{
   Texture = < depthTexture>;
};

struct toonVSOUT
{
    float4 Pos         : POSITION;
    float2 Tex           :TEXCOORD0;
};

toonVSOUT toonVS(float4 Pos : POSITION,  float2 inTex : TEXCOORD)
{
    toonVSOUT Out;

   Pos.xy = sign(Pos.xy);
  
 Out.Pos  = float4(Pos.xy, 0.0, 1.0);


    Out.Tex.x = 0.5 *( 1 + Pos.x);
    Out.Tex.y = 0.5 *( 1 - Pos.y);

    return Out;

}

const float1 off = 1.0 /1024; //size of depth texture

struct PS_OUTPUT
{
   float4 Color    : COLOR0;
};

struct PS_INPUT
{
   float2 TexCoord : TEXCOORD0;
};
float readDepth(float2 coord)
{
    return (2.0 * camerarange.x) / (camerarange.y + camerarange.x - tex2D( RT, coord ).x * (camerarange.y - camerarange.x));    
}

float4 psToon2( PS_INPUT In): COLOR
{


float depth = readDepth( In.TexCoord );
float d;
float ao = 0.0;
float aoMultiplier=1000.0;
float depthTolerance = 0.001;

   // Sample neighbor pixels
     d=readDepth( In.TexCoord + float2(-off, -off)).r;
     ao+=max(0.0,d-depth-depthTolerance) * aoMultiplier;
   
     d=readDepth( In.TexCoord + float2( off*2,   -off)).r;
     ao+=max(0.0,d-depth-depthTolerance) * aoMultiplier;

    d=readDepth( In.TexCoord + float2( off, -off)).r;
    ao+=max(0.0,d-depth-depthTolerance) * aoMultiplier;

    d=readDepth( In.TexCoord + float2(-off,  off*2)).r;
    ao+=max(0.0,d-depth-depthTolerance) * aoMultiplier;

    d=readDepth( In.TexCoord + float2( off,  off*2)).r;
    ao+=max(0.0,d-depth-depthTolerance) * aoMultiplier;

    d=readDepth(  In.TexCoord + float2(-off,  off)).r;
    ao+=max(0.0,d-depth-depthTolerance) * aoMultiplier;

    ao/=6;
    ao=min(ao,0.5);

    return float4(1.0-ao,1.0-ao,1.0-ao,0);

}

technique toon2
{

    pass p0
    {
               cullmode = none;
                zenable = false;
//      alpharef = 16;
//       alphafunc = less;
//       alphatestenable=true;

               VertexShader = compile vs_1_1 toonVS();
                PixelShader  = compile ps_2_0 psToon2(); 
    }

}



Does anyone have an idea as to what I'm doing wrong? Thanks!

Share this post


Link to post
Share on other sites
Advertisement
All that shader does is check some depth differences, which will obviously result in a type of edge detection. So, you're not doing anything wrong, it's just what the shader does. Check out this page for a nice base for SSAO.

Share this post


Link to post
Share on other sites
Quote:
Original post by Archie2112
Thanks I'll try to follow that example. It's the cg to hlsl that confuses me though. But thanks again.


CG's syntax is identical to HLSL. You can directly pass the CG source as HLSL.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!