Accessing previous frames

Hi,

I’m new to shaders, just started messing about and I wondered if it is possible to access the color a pixel had in a previous frame ?

not directly in the shader. but you can store your older frames in a Queue (Texture) and input them as additional textures to the shader.

maybe that is what the ddx() and ddy() functions are for. i never quite understood their purpose and it is hard to find documentation on them.

gregsn should be able to tell us something about those and if they are related…

Offcourse, a queue, why didn’t I think of that? Thanks,
I’m just starting out with this stuff, so I hope you don’t mind the stupid questions.

Actually ddx() returns the partial derivative of x with respect to the screen-space x coordinate. No idea what that means tho :)
You can find some good reference docs on HLSL here:

dx9_graphics_reference_hlsl_intrinsic_functions

Can anybody tell me how to access a pixel directly tho? I mean the pixelshader function goes through all pixels on stage right? But say I want it to compare to pixels, like the current pixel with a pixel that’s on the other side of the screen, how can I do that? Or is stuff like that only possible with a matrix?

you can access the pixels of a through the tex2d function. this function will give you the rgba value of a texture at a given xy coordinate.

basically you do not need a matrix to do that. you can calculate x and y coordinates with any formula you like. of course matrices were invented to simplify things for people knowing how to use them :)

Thanks for all you help.
I’m actually making a all purposes color range keying shader. I want to give the ability to blur the edges eventualy, so I’ll get to matrices then, for now I’ll leave them to people knowing how to use them :)
But I also want to implement a minimum area sort of thing, to eliminate stray keyed pixels, if that makes sense. Havent had any chance to work on it today, hopefuly i’ll be able to get back to it tomorrow.

Could you tell me how I can do that? I mean access a pixel with tex2d? I’ve been trying out some stuff but I’m not getting there.

Am I correct in my earlier assumption that a pixelshaders goes through all the pixels on the screen and applies whatever stuff you have in there on all pixels? If so, how do I know what the coordinates of the pixel thats currently being processed are?

Can I do that with tex2d? I’ve tried stuff like
tex2D(Sampler, In.Tex).x; but it doesn’t seem to do much.

It’s kinda hard debugging these shaders without any way of passing variables back to vvvv without using the output.

I think I figured it out.

Dunno how I came up with that tex2d thing, as Oschatz already pointed out, tex2d is for finding info on a specific pixel of a texture.

To find the x and y of the current pixel passing through the pixelshader, use In.texcd.x and y. Offcourse you have to declare texcd as a texturecoord in the vertex shader and include it in your output to the pixelshader.

Can somebody who actually knows what he’s doing confirm this?

Am I correct in my earlier assumption that a pixelshaders
goes through all the pixels on the screen and applies whatever
stuff you have in there on all pixels?

to be precise, pixelshaders loop through all pixels on each triangle.

in each iteration you get the coordinates, texturecoordinates and colors of the the three corners interpolated to the current position in the triangle.