source: OGRE/trunk/ogrenew/Samples/Media/materials/programs/Ocean2HLSL_Cg.frag @ 692

Revision 692, 3.0 KB checked in by mattausch, 19 years ago (diff)

adding ogre 1.2 and dependencies

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 waterAmount,
46                        uniform float fresnelPower,
47                        uniform float fresnelBias,
48                        uniform float hdrMultiplier
49                        ) : COLOR
50{
51        // sum normal maps
52        // sample from 3 different points so no texture repetition is noticeable
53    float4 t0 = tex2D(NormalMap, IN.bumpCoord0) * 2.0 - 1.0;
54    float4 t1 = tex2D(NormalMap, IN.bumpCoord1) * 2.0 - 1.0;
55    float4 t2 = tex2D(NormalMap, IN.bumpCoord2) * 2.0 - 1.0;
56    float3 N = t0.xyz + t1.xyz + t2.xyz;
57
58    float3x3 m; // tangent to world matrix
59    m[0] = IN.rotMatrix1;
60    m[1] = IN.rotMatrix2;
61    m[2] = IN.rotMatrix3;
62   
63    N = normalize( mul( N, m ) );
64
65        // reflection
66    float3 E = normalize(IN.eyeVector);
67    float3 R = reflect(E, N);
68    // Ogre conversion for cube map lookup
69    R.z = -R.z;
70
71    float4 reflection = texCUBE(EnvironmentMap, R);
72    // cheap hdr effect
73    reflection.rgb *= (reflection.r + reflection.g + reflection.b) * hdrMultiplier;
74
75        // fresnel
76    float facing = 1.0 - max(dot(-E, N), 0);
77    float fresnel = saturate(fresnelBias + pow(facing, fresnelPower));
78
79    float4 waterColor = lerp(shallowColor, deepColor, facing) * waterAmount;
80   
81    reflection = lerp(waterColor,  reflection * reflectionColor, fresnel) * reflectionAmount;
82    return waterColor + reflection;
83}
Note: See TracBrowser for help on using the repository browser.