Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/archive/skybox/Media/materials/programs/Ocean2HLSL_Cg.frag @ 11183

Last change on this file since 11183 was 390, checked in by landauf, 17 years ago

added materials

File size: 3.0 KB
Line 
1/*********************************************************************NVMH3****
2Copyright NVIDIA Corporation 2003
3TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW, THIS SOFTWARE IS PROVIDED
4*AS IS* AND NVIDIA AND ITS SUPPLIERS DISCLAIM ALL WARRANTIES, EITHER EXPRESS
5OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY
6AND FITNESS FOR A PARTICULAR PURPOSE.  IN NO EVENT SHALL NVIDIA OR ITS SUPPLIERS
7BE LIABLE FOR ANY SPECIAL, INCIDENTAL, INDIRECT, OR CONSEQUENTIAL DAMAGES
8WHATSOEVER (INCLUDING, WITHOUT LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS,
9BUSINESS INTERRUPTION, LOSS OF BUSINESS INFORMATION, OR ANY OTHER PECUNIARY LOSS)
10ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF NVIDIA HAS
11BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
12
13
14Comments:
15        Simple ocean shader with animated bump map and geometric waves
16        Based partly on "Effective Water Simulation From Physical Models", GPU Gems
17
1811 Aug 05: heavily modified by Jeff Doyle (nfz) for Ogre
19
20******************************************************************************/
21
22
23
24struct v2f {
25        float4 Position  : POSITION;  // in clip space
26        float3 rotMatrix1 : TEXCOORD0; // first row of the 3x3 transform from tangent to obj space
27        float3 rotMatrix2 : TEXCOORD1; // second row of the 3x3 transform from tangent to obj space
28        float3 rotMatrix3 : TEXCOORD2; // third row of the 3x3 transform from tangent to obj space
29
30        float2 bumpCoord0 : TEXCOORD3;
31        float2 bumpCoord1 : TEXCOORD4;
32        float2 bumpCoord2 : TEXCOORD5;
33
34        float3 eyeVector  : TEXCOORD6;
35};
36
37
38float4 main(v2f IN,
39                        uniform sampler2D NormalMap,
40                        uniform samplerCUBE EnvironmentMap,
41                        uniform float4 deepColor,
42                        uniform float4 shallowColor,
43                        uniform float4 reflectionColor,
44                        uniform float reflectionAmount,
45                        uniform float reflectionBlur,
46                        uniform float waterAmount,
47                        uniform float fresnelPower,
48                        uniform float fresnelBias,
49                        uniform float hdrMultiplier
50                        ) : COLOR
51{
52        // sum normal maps
53        // sample from 3 different points so no texture repetition is noticeable
54    float4 t0 = tex2D(NormalMap, IN.bumpCoord0) * 2.0 - 1.0;
55    float4 t1 = tex2D(NormalMap, IN.bumpCoord1) * 2.0 - 1.0;
56    float4 t2 = tex2D(NormalMap, IN.bumpCoord2) * 2.0 - 1.0;
57    float3 N = t0.xyz + t1.xyz + t2.xyz;
58
59    float3x3 m; // tangent to world matrix
60    m[0] = IN.rotMatrix1;
61    m[1] = IN.rotMatrix2;
62    m[2] = IN.rotMatrix3;
63
64    N = normalize( mul( N, m ) );
65
66        // reflection
67    float3 E = normalize(IN.eyeVector);
68    float4 R;
69    R.xyz = reflect(E, N);
70    // Ogre conversion for cube map lookup
71    R.z = -R.z;
72    R.w = reflectionBlur;
73    float4 reflection = texCUBEbias(EnvironmentMap, R);
74    // cheap hdr effect
75    reflection.rgb *= (reflection.r + reflection.g + reflection.b) * hdrMultiplier;
76
77        // fresnel
78    float facing = 1.0 - max(dot(-E, N), 0);
79    float fresnel = saturate(fresnelBias + pow(facing, fresnelPower));
80
81    float4 waterColor = lerp(shallowColor, deepColor, facing) * waterAmount;
82
83    reflection = lerp(waterColor,  reflection * reflectionColor, fresnel) * reflectionAmount;
84    return waterColor + reflection;
85}
Note: See TracBrowser for help on using the repository browser.