Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: data/branches/Shader_HS18/programs/Cg/oceanHLSL_Cg.frag @ 12181

Last change on this file since 12181 was 12115, checked in by wiesep, 6 years ago

Changed folder structure, deletet some unused files and cleaned up code

File size: 1.4 KB
Line 
1// oceanHLSL_Cg.frag
2// fragment program for Ocean water simulation
3// 04 Aug 2005
4// adapted for Ogre by nfz
5// original shader source from Render Monkey 1.6 Reflections Refractions.rfx
6// can be used in both Cg and HLSL compilers
7
8// 06 Aug 2005: moved uvw calculation from fragment program into vertex program
9
10float4 main(  float4 Pos:    POSITION,
11  float3 uvw: TEXCOORD0, float3 normal: TEXCOORD1, float3 vVec: TEXCOORD2,
12        uniform float fadeBias,
13        uniform float fadeExp,
14        uniform float4 waterColor,
15        uniform sampler3D Noise,
16        uniform samplerCUBE skyBox
17
18) : COLOR
19{
20
21   float3 noisy = tex3D(Noise, uvw).xyz;
22
23   // convert to Signed noise
24   float3 bump = 2 * noisy - 1;
25   bump.xz *= 0.15;
26   // Make sure the normal always points upwards
27   // note that Ogres y axis is vertical (RM Z axis is vertical)
28   bump.y = 0.8 * abs(bump.y) + 0.2;
29   // Offset the surface normal with the bump
30   bump = normalize(normal + bump);
31
32   // Find the reflection vector
33   float3 normView = normalize(vVec);
34   float3 reflVec = reflect(normView, bump);
35   // Ogre has z flipped for cubemaps
36   reflVec.z = -reflVec.z;
37   float4 refl = texCUBE(skyBox, reflVec);
38
39   // set up for fresnel calc
40   float lrp = 1 - dot(-normView, bump);
41   
42   // Interpolate between the water color and reflection for fresnel effect
43   return lerp(waterColor, refl, saturate(fadeBias + pow(lrp, fadeExp)));
44
45}
Note: See TracBrowser for help on using the repository browser.