|
发表于 2010-5-12 20:16:00
|
显示全部楼层
Re:请问如何实现折射效果
float4 PSmain(float3 pos: TEXCOORD0, float3 normal: TEXCOORD1, float3 vVec: TEXCOORD2) : COLOR {
pos.x += waveSpeed * time_0_X;
pos.y += noiseSpeed * time_0_X;
float4 noisy = tex3D(Noise, pos);
// Signed noise
float3 bump = 2 * noisy - 1;
bump.xz *= 0.15;
// Make sure the normal always points upwards
bump.y = 0.8 * abs(bump.y) + 0.2;
// Offset the surface normal with the bump
bump = normalize(normal + bump);
// Find the reflection vector
float3 reflVec = reflect(vVec, bump);
float4 refl = texCUBE(Skybox, reflVec);
float lrp = 1 - dot(-normalize(vVec), bump);
// Interpolate between the water color and reflection
float temp = 0.0;
temp = sin(time_0_X);
temp = abs(temp);
refl.x += temp*0.5;
return lerp(waterColor, refl, saturate(fadeBias + pow(lrp, fadeExp)));
} |
|