Code: Select all
float noiseScale;
float morphRate;
float bubbleRate;
float bubbleScale;
float time_0_X;
float scale;
float bias;
sampler Flame : register(s0);
sampler Noise : register(s1);
float4x4 mWorldViewProj; // World * View * Projection transformation
float4x4 mInvWorld; // Inverted world matrix
float4x4 mTransWorld; // Transposed world matrix
float3 mLightPos; // Light position
float4 mLightColor; // Light color
// Vertex shader output structure
struct VS_OUTPUT
{
float4 Position : POSITION; // vertex position
float4 Diffuse : COLOR0; // vertex diffuse color
float2 TexCoord : TEXCOORD0; // tex coords
};
VS_OUTPUT vertexMain( in float4 vPosition : POSITION,
in float3 vNormal : NORMAL,
float2 texCoord : TEXCOORD0 )
{
VS_OUTPUT Output;
// transform position to clip space
Output.Position = mul(vPosition, mWorldViewProj);
// transform normal
float3 normal = mul(vNormal, mInvWorld);
// renormalize normal
normal = normalize(normal);
// position in world coodinates
float3 worldpos = mul(mTransWorld, vPosition);
// calculate light vector, vtxpos - lightpos
float3 lightVector = worldpos - mLightPos;
// normalize light vector
lightVector = normalize(lightVector);
// calculate light color
float3 tmp = dot(-lightVector, normal);
tmp = lit(tmp.x, tmp.y, 1.0);
tmp = mLightColor * tmp.y;
Output.Diffuse = float4(tmp.x, tmp.y, tmp.z, 0);
Output.TexCoord = texCoord;
return Output;
}
// We use noise as our base texture. Then we use more noisy to
// bubble in that noise. Both the base noise and bubble noise is
// animated, though the bubbling at a higher rate.
float4 pixelMain(float2 pos: TEXCOORD0) : COLOR
{
// Bubble coords
float3 coord;
coord.xy = pos * bubbleScale;
coord.z = bubbleRate * time_0_X;
// Sample noise for x and y
float noiseX = tex3D(Noise, coord).r - 0.5;
float noiseY = tex3D(Noise, coord + 0.5).r - 0.5;
// Offset our base noise with the bubble noise
coord.x = pos.x + noiseX * noiseScale;
coord.y = pos.y + noiseY * noiseScale;
coord.z = time_0_X * morphRate;
// Sample the base noise
float base = tex3D(Noise, coord).r;
// Assign a firey color from the base noise
return tex1D(Flame, scale * base + bias);
}
Is there way that I can pass the 128 pieces of Noise Map to the shader? Or letting the shader know which pieces I need this time?
Or any other suggestion that I can solve this problem??
Thank you very much.