|

楼主 |
发表于 2007-12-27 09:53:00
|
显示全部楼层
Re:用shader进行渲染怎么做alpha,谢谢!
//------------------------
// vs
float4x4 matWorldViewProj;
float4 layer_speed = {0.68753, 0.52, 0.7534, 1};
float time_0_X;
struct VS_OUTPUT
{
float4 Pos : POSITION;
float2 TexCoord0 : TEXCOORD0;
float2 TexCoord1 : TEXCOORD1;
float2 TexCoord2 : TEXCOORD2;
float2 TexCoord3 : TEXCOORD3;
};
VS_OUTPUT vs_main (float3 vPosition: POSITION, float2 vTexCoord0 : TEXCOORD0)
{
VS_OUTPUT Out = (VS_OUTPUT) 0;
// Align quad with the screen
Out.Pos = mul( float4(vPosition, 1), matWorldViewProj );
//Out.Pos = float4 (vPosition.x, vPosition.y, 0.0f, 1.0f);
// Output TexCoord0 directly
Out.TexCoord0 = vTexCoord0;
// Base texture coordinates plus scaled time
Out.TexCoord1.x = vTexCoord0.x;
Out.TexCoord1.y = vTexCoord0.y + layer_speed.x * time_0_X;
// Base texture coordinates plus scaled time
Out.TexCoord2.x = vTexCoord0.x;
Out.TexCoord2.y = vTexCoord0.y + layer_speed.y * time_0_X;
// Base texture coordinates plus scaled time
Out.TexCoord3.x = vTexCoord0.x;
Out.TexCoord3.y = vTexCoord0.y + layer_speed.z * time_0_X;
return Out;
}
//-------------------------
// ps
float distortion_amount2 = 0.0723;
float distortion_amount1 = 0.091;
float distortion_amount0 = 0.123;
float4 height_attenuation = {0.44, 0.29, 0, 1};
texture tex_base;
texture tex_distortion;
texture tex_opacity;
sampler fire_base = sampler_state
{
Texture = <tex_base>;
MinFilter = Point;
MagFilter = Point;
MipFilter = None;
AddressU = Wrap;
AddressV = Wrap;
};
sampler fire_distortion = sampler_state
{
Texture = <tex_distortion>;
MinFilter = Point;
MagFilter = Point;
MipFilter = None;
AddressU = Wrap;
AddressV = Wrap;
};
sampler fire_opacity = sampler_state
{
Texture = <tex_opacity>;
MinFilter = Point;
MagFilter = Point;
MipFilter = None;
AddressU = Wrap;
AddressV = Wrap;
};
// Bias and double a value to take it from 0..1 range to -1..1 range
float4 bx2(float x)
{
return 2.0f * x - 1.0f;
}
float4 ps_main (float2 tc0 : TEXCOORD0, float2 tc1 : TEXCOORD1,
float2 tc2 : TEXCOORD2, float2 tc3 : TEXCOORD3) : COLOR
{
// Sample noise map three times with different texture coordinates
float4 noise0 = tex2D(fire_distortion, tc1);
float4 noise1 = tex2D(fire_distortion, tc2);
float4 noise2 = tex2D(fire_distortion, tc3);
// Weighted sum of signed noise
float2 noiseSum = bx2(noise0.r) * distortion_amount0 + bx2(noise1.r) * distortion_amount1 + bx2(noise2.r) * distortion_amount2;
// Perturb base coordinates in direction of noiseSum as function of height (y)
float2 perturbedBaseCoords = saturate(tc0 + noiseSum * (tc0.y * height_attenuation.x + height_attenuation.y));
// Sample base and opacity maps with perturbed coordinates
float4 base = tex2D(fire_base, perturbedBaseCoords);
float4 opacity = tex2D(fire_opacity, tc0);
//return float4(1, 1,1,1);
base.a = 0;
return base * opacity;
}
technique my_tech
{
pass Fire
{
//PixelShader = NULL;
//Texture[0] = NULL;
// enable alpha blending
/*AlphaBlendEnable = TRUE;
AlphaTestEnable = TRUE;
SrcBlend = SRCCOLOR;
DestBlend = INVSRCCOLOR;*/
// set up texture stage states to use the diffuse color
//ColorOp[0] = SELECTARG2;
//ColorArg2[0] = DIFFUSE;
//AlphaOp[0] = SELECTARG2;
//AlphaArg2[0] = DIFFUSE;
//ColorOp[1] = DISABLE;
//AlphaOp[1] = DISABLE;
CullMode = None;
VertexShader = compile vs_2_0 vs_main();
PixelShader = compile ps_2_0 ps_main();
}
} |
|