Sign in to follow this  
gwycon

Pixel Shader 2.0 iterated input

Recommended Posts

gwycon    100
Hi, Fairly new to the topic of pixel shaders. I have been doing some fairly simple experiments in Silverlight 3 using pixel shader version 2.0. I am trying to program a Mandelbrot set demo using pixel shaders but the main restriction using ps 2.0 is the limited instruction set. One way around this I have seen mentioned is to iterate each pixels (final colour) value a low number of times to stay within the allowed instruction set number. And then render this, before taking the output in again to do more iterations starting from the previous output. Could anyone explain a little more about how this could work. At the moment due to my limited shader programming experience I am finding it hard to understand what gets inputted to the shader the first time it is called and subsequent calls. I mean if a shader is modifying a pixel colour (based on its current value) then when the shader is called again on the next render cycle the shader only changes the pixel colour once and not on every pass? For example I have this very simple pixel shader:
sampler2D implicitInput : register(s0);

float4 MainPS(float2 uv : TEXCOORD) : COLOR
{

float4 src = tex2D(implicitInput, uv);

float4 tmp = src;
tmp.g -= 0.1;
tmp.b -= 0.1;
tmp.r = src.r;
tmp.a = src.a;

return tmp;
}
The purpose here is to decrement the green and blue colours every render pass, but leave the red and alpha the same. However the shader code is only applied to the image once and not iteratively as I would have hoped. Any help or insights would be highly appreciated. David

Share this post


Link to post
Share on other sites
gwycon    100
Hi, Yes I read elsewhere that there would have to be multiple (just 2?) render targets. But as I am new to shaders I am not sure how to set this up and swap them from within the shader?

Share this post


Link to post
Share on other sites
MJP    19786
Quote:
Original post by gwycon
Hi, Yes I read elsewhere that there would have to be multiple (just 2?) render targets. But as I am new to shaders I am not sure how to set this up and swap them from within the shader?


Yes, you would need at minimum two render targets so that you could render to one and read from another. It's called "ping-ponging".

Setting up render targets and input textures isn't done in the shader itself, it's done in the application code. I don't know anything about Silverlight, so unfortunately I can't tell you how to do it or whether it's even possible.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this