Jump to content
  • Advertisement
Sign in to follow this  
Kram

Help with a very simple pixel shader

This topic is 3177 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
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);
}

Share this post


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

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!