# Framedifference

i’m wondering if its possible to compare the pixels of two frames with a pixelshader. sort of a shaderversion of framedifference…any hint?

2 texture variable and a wait command…mmmm…dunno where to start

thats easy, make a shader with two texture inputs. at the first input is your current frame, at the second the last frame (use a Queue (EX9.Texture) for delay).

greets

right, got the difference of the two textures, queue node is a good hint…just thought there might be a shader function/trick like queue

float4 difference(vs2ps In): COLOR
{
float4 Reference = tex2D(Samp2, In.TexCd);
float4 Subtrahend = tex2D(Samp, In.TexCd);
float4 Difference = (Reference-Subtrahend);

return Difference;
}

ok difference doesn’t work. the result is just plain black although multiplication has an effect. what is the missing bit?

its the alpha channel i think, its one in most cases so you subtract 1 by 1 = 0, try:

float4 difference(vs2ps In): COLOR
{
float4 Reference = tex2D(Samp2, In.TexCd);
float4 Subtrahend = tex2D(Samp, In.TexCd);
Reference.rgb -= Subtrahend.rgb;

return Reference;
}

works like a charm…

thanks mr. tonfilm :)

yea !
just to explain the a -= b sign, it means a = a - b. there are:

a += b
a -= b
a *= b
a /= b

yeah i understood that bit… like in c or java

ah, so its for some other readers ;)

hehe…i didn’t want to be cocky ;)

another general question: is it possible to analyze pixels and translate the values to position (3D) data with a shader…like the typical pipet technique?

because when looking at the order vertexshader --> pixelshader… it seems like impossible or am i wrong?

the only thing you can get out of a pixelshader is a texture (if you draw it in a renderer and use a DX9Texture node). and there comes pipet again, or you have a card with shader model 3.0 to be able to do texture lookups in the vertex shader.

… and, what about freeframe ? there is a AsVideo (EX9.Texture) node !