Sign in to follow this  
ColinS

Sine Wave and Texture animation

Recommended Posts

ColinS    100
I'm working on a project for school where my teacher wants me to make a textured grid that also can be able to animate a radial and directional sine wave. I was able to make the sine waves earlier so I then changed up the code a bit to texture it, however, now when I call the sine wave function nothing happens. I'm trying to do this all in an .fx file. This is what I have so far:
uniform extern float4x4 gWVP;
uniform extern float gTime;
uniform extern texture gWaterTex0;
uniform extern texture gWaterTex1;
uniform extern float2  gTexOffset0;
uniform extern float2  gTexOffset1;

//Water Texture One
sampler WaterS0 = sampler_state
{
	Texture = <gWaterTex0>;
	MinFilter = Anisotropic;
	MagFilter = LINEAR;
	MipFilter = LINEAR;
	MaxAnisotropy = 8;
	AddressU  = WRAP;
    AddressV  = WRAP;
};
 
//Water Texture Two
sampler WaterS1 = sampler_state
{
	Texture = <gWaterTex1>;
	MinFilter = Anisotropic;
	MagFilter = LINEAR;
	MipFilter = LINEAR;
	MaxAnisotropy = 8;
	AddressU  = WRAP;
    AddressV  = WRAP;
};

struct OutputVS
{
    float4 posH : POSITION0;
    float2 tex0 : TEXCOORD0;
    float2 tex1 : TEXCOORD1;
};

//Directional Sine Wave
float SumOfDirectionalSineWaves(float x, float z)
{
	float d = x + z;
	
	float sum = 0.0f;

	sum += 0.8 *sin( 1.0 * d - gTime * 1.0 + 0.0 );
		
	return sum;
}

//Radial Sine Wave
//float SumOfRadialSineWaves(float x, float z)
//{
	//float d = sqrt(x*x + z*z);
	
	//float sum = 0.0f;

	//sum += 0.8 *sin( 1.0 * d - gTime * 1.0 + 0.0 );
		
	//return sum;
//}

OutputVS WaterVS(float3 posL : POSITION0, float2 tex0: TEXCOORD0)
{
    // Zero out our output.
	OutputVS outVS = (OutputVS)0;
	
	
	posL.y = SumOfDirectionalSineWaves(posL.x, posL.z);

	// Transform to homogeneous clip space.
	outVS.posH = mul(float4(posL, 1.0f), gWVP);
	
	// Pass on texture coordinates to be interpolated in rasterization.
	outVS.tex0 = tex0 + gTexOffset0;
	outVS.tex1 = tex0 + gTexOffset1;
	
	// Done--return the output.
    return outVS;
}

float4 WaterPS(float4 c : COLOR0, float2 tex0 : TEXCOORD0, float2 tex1 : TEXCOORD1) : COLOR
{
	float3 c0 = tex2D(WaterS0, tex0).rgb;
	float3 c1 = tex2D(WaterS1, tex1).rgb;
	float3 blue = float3(0.0f, 0.0f, 1.0f);
    return float4(c0+c1+blue, 1.0f);
}

technique WaterTech
{
    pass P0
    {
        vertexShader = compile vs_2_0 WaterVS();
        pixelShader  = compile ps_2_0 WaterPS();

    }
}
I've looked everywhere for an answer and can't find anything. Any help is appreciated.

Share this post


Link to post
Share on other sites

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