Help with a very simple pixel shader

Started by
2 comments, last by Kram 14 years, 5 months ago
Hi All, Extending on another question I asked (http://www.gamedev.net/community/forums/topic.asp?topic_id=552442), I began to hack away at an existing pixel shader that I found on the WPFFX project (http://wpffx.codeplex.com/) called RandomCircleRevealTransitionEffect. What I want is, given a texture file (just an image, in this case, cracked ice), grow a circle/blob which slowly reveals the ice texture. I nearly have it working, and here is my pixel shader code:

float progress : register(C0);
float randomSeed : register(C1);
float2 startFromPoint : register(C2);

sampler2D implicitInput : register(s0);
//sampler2D oldInput : register(s1);
sampler2D cloudInput : register(s2);

struct VS_OUTPUT
{
    float4 Position  : POSITION;
    float4 Color     : COLOR0;
    float2 UV        : TEXCOORD0;
};

float4 RandomCircle(float2 uv)
{
	float radius = progress * 0.70710678;
	//float2 fromCenter = uv - float2(0.5,0.5);
	float2 fromCenter = uv - startFromPoint;
	float len = length(fromCenter);

	float2 toUV = normalize(fromCenter);
	float angle = (atan2(toUV.y, toUV.x) + 3.141592) / (2.0 * 3.141592);
	radius += progress * tex2D(cloudInput, float2(angle, frac(randomSeed + progress / 5.0))).r;

	float4 c = tex2D(implicitInput, uv.xy);
	c.a = (len < radius) ? 1.0 : 0;
	c.r = (len < radius) ? c.r : 0;
	c.g = (len < radius) ? c.g : 0;
	c.b = (len < radius) ? c.b : 0;
	return c;
}

float4 main(VS_OUTPUT input) : COLOR0
{
	return RandomCircle(input.UV);
}
But, when I run it over a purple rectangle, for some reason, I cannot see the purple rectangle outside of the growing circle, I would expect that as the texture circle expands, the purple rectangle is slowly overtaken and blended with the ice. If anyone could take a quick look for me as to why this might be? Im sort of very new to pixel shaders! Thanks a heap everyone. [Edited by - Kram on November 5, 2009 6:26:28 PM]
Advertisement
Ok, so I got it working, what I ended up doing was adding another input property as the texture (ice) and changed the logic to either show the current pixel of the implicitInput, or the "revealedTexture":

float progress : register(C0);float randomSeed : register(C1);float2 startFromPoint : register(C2);sampler2D implicitInput : register(s0);sampler2D oldInput : register(s1);sampler2D cloudInput : register(s2);sampler2D revealedTexture : register(s3);struct VS_OUTPUT{    float4 Position  : POSITION;    float4 Color     : COLOR0;    float2 UV        : TEXCOORD0;};float4 RandomCircle(float2 uv){	float radius = progress * 0.70710678;	//float2 fromCenter = uv - float2(0.5,0.5);	float2 fromCenter = uv - startFromPoint;	float len = length(fromCenter);	float2 toUV = normalize(fromCenter);	float angle = (atan2(toUV.y, toUV.x) + 3.141592) / (2.0 * 3.141592);	radius += progress * tex2D(cloudInput, float2(angle, frac(randomSeed + progress / 5.0))).r;		float4 c = tex2D(implicitInput, uv.xy);	if (len < radius) 		c = tex2D(revealedTexture, uv.xy);	return c;}float4 main(VS_OUTPUT input) : COLOR0{	return RandomCircle(input.UV);}
Good to see you got it working, and good on you for posting your results ;)

To keep posted code readable though, you can try wrapping it inside [code] [/code] tags for monospace formatting, or [source] [/source] tags for a scroll-bar and highlighting ;)
Thanks, and done ;)

This topic is closed to new replies.

Advertisement