Sign in to follow this  

Help with a very simple pixel shader

This topic is 2964 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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]

Share this post


Link to post
Share on other sites
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);
}

Share this post


Link to post
Share on other sites

This topic is 2964 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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