User Tag List

Results 1 to 3 of 3

Thread: Modifying depth within a pixel shader?

  1. #1
    Clicker Fusion 2.5 DeveloperAndroid Export ModuleHTML5 Export ModuleiOS Export ModuleSWF Export Module
    UltimateWalrus's Avatar
    Join Date
    Jul 2006
    Posts
    824
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Modifying depth within a pixel shader?

    Hello,

    I'm trying to achieve an effect similar to this video, an isometric game where pixel positions are stored and used for lighting and occlusion. I'm getting close, but I can't figure out how to do the occlusion as it requires me to modify the depth of individual pixels.

    I've made a simple shader to try and test this, but I can't seem to get any response out of it. I know changing depth with a pixel shader is tough to do, and I'm guessing I need to be setting something up correctly in the pass, but everything I've tried hasn't worked so far. My sprites still sort according to MMF's object order rather than the values I give for fDepth.

    Code:
    // Global variables
    sampler2D Tex0;
    float fDepth;
    
    struct PS_OUTPUT
    {
    	float4 Color : COLOR0;
    	float Depth : DEPTH0;
    };
    
    PS_OUTPUT ps_main(float4 Position : POSITION, float2 TexCoord : TEXCOORD0 )
    {
        // Output pixel
        PS_OUTPUT Out;
    
        Out.Color = tex2D(Tex0, TexCoord);
        Out.Depth = fDepth;
        
        return Out;
    }
    
    // Effect technique
    technique tech_main
    {
        pass P0
        {
    	ZEnable = TRUE;
    	ZWriteEnable = TRUE;
    	ZFunc = GreaterEqual;
    
            // shaders
            VertexShader = NULL;
            PixelShader  = compile ps_2_0 ps_main();
        }  
    }
    Any ideas/suggestions?

    Thanks,
    Sebastian

  2. #2
    Clicker Fusion 2.5 DeveloperFusion 2.5+ DLCAndroid Export ModuleSWF Export ModuleUnicode Add-on
    Looki's Avatar
    Join Date
    Aug 2006
    Location
    Karlsruhe, Germany
    Posts
    3,741
    Mentioned
    5 Post(s)
    Tagged
    1 Thread(s)
    I doubt MMF allocates a depth buffer in the first place, so you're probably out of luck. Care to elaborate what exactly that screenshot represents? The lighting looks quite nice, but I have no idea how exactly this shader is involved there.

  3. #3
    Clicker Fusion 2.5 DeveloperAndroid Export ModuleHTML5 Export ModuleiOS Export ModuleSWF Export Module
    UltimateWalrus's Avatar
    Join Date
    Jul 2006
    Posts
    824
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks Looki. The shader code I provided was just an attempt at changing the depth of a pixel. The screenshot was generated using a shader for each tile with normal mapping to get diffuse, and height mapping to derive pixel positions and smooth the attenuation of the light.

    You are probably right that MMF2 doesn't even allocate a depth buffer. If that's the case then I am most likely out of luck, unless I can figure out some way to roll my own depth culling using multiple passes, which may or may not be possible.

    I'm curious about multiple passes as well for another project I'm working on, though. I started another thread since it's a bit of a tangent to the topic of this one.

    Thanks,
    Sebastian

Similar Threads

  1. Tilemap Pixel Shader (aka "texture atlas" shader)
    By MuddyMole in forum Hardware Accelerated Runtime
    Replies: 3
    Last Post: 10th May 2013, 08:21 PM
  2. Can any one get the pixel shader to wok?
    By SEELE in forum Multimedia Fusion 2 - Technical Support
    Replies: 4
    Last Post: 11th August 2008, 01:28 PM
  3. Sub-Pixel Positioning Pixel Shader
    By LazyCoder in forum Hardware Accelerated Runtime
    Replies: 15
    Last Post: 16th March 2008, 11:24 AM
  4. Pixel Shader Help
    By LazyCoder in forum Hardware Accelerated Runtime
    Replies: 15
    Last Post: 11th January 2008, 06:21 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •