Jump to content
  • Advertisement
Sign in to follow this  
Archie2112

SSAO - Question

This topic is 3797 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! [Edited by - Archie2112 on July 19, 2008 10:58:30 PM]

Share this post


Link to post
Share on other sites
Advertisement
Sorry I can't be much help, but I think people will find your post much easier to read if you put it between [source][/source] tags. A list of tags for the forum can be found here. Just a suggestion that I hope helps readers who can help more willing to.

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!