source: GTP/trunk/App/Demos/Geom/Shark3D/clod_head_demo_win32/src/res/levelutil/shader/prog/ogl_glsl/bump_ogl_glsl_fs1x0.s3d_shadercode @ 2236

Revision 2236, 6.3 KB checked in by gumbau, 17 years ago (diff)
Line 
1///////////////////////////////////////////////////////////////////////////////
2//
3//      ##  ######
4//       ######  ###
5//  ## ###############        Shark 3D Engine (www.shark3d.com)
6//   ########## # # #
7//    ########                Copyright (c) 1996-2006 Spinor GmbH.
8//   ######### # # #          All rights reserved.
9//  ##   ##########
10//      ##
11//
12///////////////////////////////////////////////////////////////////////////////
13
14@include "levelutil/shader/prog/ogl_glsl/" \
15        "include_shmap_filter_ogl_glsl_vs1x0.s3d_shadercode_run"
16
17///////////////////////////////////////////////////////////////////////////////
18
19@define S3D_NORMALIZE(v) (v)
20
21///////////////////////////////////////////////////////////////////////////////
22
23uniform sampler2D tex0;
24uniform sampler2D normalSamp;
25
26///////////////////////////////////////////////////////////////////////////////
27
28@ifdef S3D_LIGHT_BRIGHT
29uniform sampler2D lightBrightSamp;
30@endif
31@ifdef S3D_LIGHT_PROJ
32uniform sampler2D lightProjSamp;
33@endif
34@ifdef S3D_LIGHT_SHMAP
35uniform sampler2D lightShmapSamp;
36@endif
37
38///////////////////////////////////////////////////////////////////////////////
39
40uniform vec4 lightAmbient;
41uniform vec4 lightDiffuse;
42uniform vec4 lightSpecular;
43
44@ifdef S3D_LIGHT_SHMAP
45uniform vec4 lightShmapSize;
46uniform vec4 lightShmapRcpSize;
47@endif
48
49@ifdef S3D_LIGHT_BRIGHT
50uniform vec4 lightBrightRcpSize;
51@endif
52
53///////////////////////////////////////////////////////////////////////////////
54
55@define S3D_INTENS_DISCARD_TRESHOLD 0.001
56@define S3D_BRIGHT_EPS 0.01
57
58///////////////////////////////////////////////////////////////////////////////
59
60void main(void)
61{
62@ifdef S3D_GEOMETRIC_SHADOW
63    // Geometric shadow
64    if(gl_TexCoord[1].z < 0.0)
65        discard;
66@endif
67
68@ifdef S3D_LIGHT_SHMAP
69    vec3 clipVal = gl_TexCoord[2].www
70            - abs(2.0 * gl_TexCoord[2].xyz - gl_TexCoord[2].www);
71    if(clipVal.x < 0.0 || clipVal.y < 0.0 || clipVal.z < 0.0)
72        discard;
73@endif
74
75@ifdef S3D_LIGHT_BRIGHT
76@ifdef S3D_LIGHT_BRIGHT_CARE
77    vec4 brightVecMain = texture2Dproj(lightBrightSamp, input.lightBrightCoord);
78    float brightIdent = frac(100 * input.secPosScr.z / input.secPosScr.w);
79    float brightDeltaMain = abs(brightVecMain.w - brightIdent);
80    float brightVal = brightVecMain.x;
81    if(brightDeltaMain > S3D_BRIGHT_EPS)
82    {
83        float2 brightOffs = lightBrightRcpSize.xy * input.lightBrightCoord.w;
84        vec4 brightCoordX = vec4(
85                input.lightBrightCoord.xy + brightOffs, input.lightBrightCoord.zw);
86        vec4 brightCoordY = vec4(
87                input.lightBrightCoord.xy - brightOffs, input.lightBrightCoord.zw);
88        vec4 brightCoordZ = brightCoordX;
89        brightCoordZ.y = brightCoordY.y;
90        vec4 brightCoordW = brightCoordY;
91        brightCoordW.y = brightCoordX.y;
92        vec4 brightVecX = texture2Dproj(lightBrightSamp, brightCoordX);
93        vec4 brightVecY = texture2Dproj(lightBrightSamp, brightCoordY);
94        vec4 brightVecZ = texture2Dproj(lightBrightSamp, brightCoordZ);
95        vec4 brightVecW = texture2Dproj(lightBrightSamp, brightCoordW);
96        brightVal = min(brightVecMain.x,
97                        min(min(brightVecX.x, brightVecY.x),
98                            min(brightVecZ.x, brightVecW.x)));
99    }
100@else   
101    // Lookup brightness:
102    float brightVal = texture2DProj(lightBrightSamp, gl_TexCoord[5]).x;
103@endif   
104    // Exit if no light:
105    if(brightVal <= S3D_INTENS_DISCARD_TRESHOLD)
106        discard;
107@endif
108   
109@ifdef S3D_LIGHT_SHMAP
110    // Shadow map:
111    float shmapVal = s3d_shmapFilter(
112            lightShmapSamp, gl_TexCoord[6],
113            lightShmapSize, lightShmapRcpSize);
114    if(shmapVal <= S3D_INTENS_DISCARD_TRESHOLD)
115        discard;
116@endif
117
118    // Texture coordinates:
119    vec2 mainTexCoord = gl_TexCoord[0].xy;
120@ifdef S3D_PARALLAX_MAPPING
121    vec3 camToVertSurfNrm = normalize(gl_TexCoord[4].xyz);
122    float height = texture2D(normalSamp, mainTexCoord).a;
123    vec2 offset = S3D_PARALLAX_SCALE * (S3D_PARALLAX_BIAS - height)
124            * camToVertSurfNrm.xy;
125    mainTexCoord = mainTexCoord + offset;
126@endif
127
128    // Texture lookups:
129    vec4 texCol = texture2D(tex0, mainTexCoord.xy);
130    vec4 rawNormalView = texture2D(normalSamp, mainTexCoord.xy);
131    vec3 normalView = (rawNormalView.xyz - 0.5) * 2.0;
132
133    // Calculate range-factor from scaled surface-to-light vector:
134    float rangeFac =
135        max(1.0 - dot(gl_TexCoord[3].xyz, gl_TexCoord[3].xyz), 0.0);
136
137    // Diffuse direction:
138    vec3 diffuseDirSurfNrm = S3D_NORMALIZE(gl_TexCoord[1].xyz);
139
140    // Calculate diffuse:   
141    vec4 diffuse = vec4(lightDiffuse.xyz * rangeFac, lightDiffuse.w);
142    diffuse += lightAmbient;
143    float diffDot = dot(normalView, diffuseDirSurfNrm);
144#ifdef S3D_MILD
145    float diffFac = clamp(lerp(diffDot, 1, S3D_MILD), 0.0, 1.0);
146#else
147    float diffFac = clamp(diffDot, 0.0, 1.0);
148#endif
149    diffuse *= diffFac;
150   
151    // Calculate specular:
152    vec4 specular = vec4(lightSpecular.xyz * rangeFac, lightSpecular.w);
153    // ATI workaround: Don't use x component of gl_TexCoord[2]:
154    vec3 specularDirSurfNrm = S3D_NORMALIZE(gl_TexCoord[2].yzw);
155    float specDot = dot(normalView, specularDirSurfNrm);
156    float specFac = clamp(pow(clamp(specDot, 0.0, 1.0),
157            S3D_SPECULAR_EXP, 0.0, 1.0);
158    specular *= specFac;
159
160    vec4 outCol;
161    outCol.rgb = clamp(diffuse.rgb * texCol.rgb
162            + specular.rgb * texCol.a, 0.0, 1.0);
163    // Preserve original opacity from texture.
164    outCol.a = texCol.a;
165
166@ifdef S3D_GEOMETRIC_SHADOW
167    // Geometric shadow
168    float geomShadow = clamp(diffuseDirSurfNrm.z * 4.0, 0.0, 1.0);
169    outCol.rgb = clamp(outCol.rgb * geomShadow, 0.0, 1.0);
170@endif
171
172@ifdef S3D_LIGHT_BRIGHT
173    // Correct brightness:
174    // The smoothing algorithm generates higher brightness gradients
175    // near 0 and 1 due to sticking to 0 and 1.
176    // This is approximately compensated by using a quadratic function
177    // near 0 and 1.
178    brightVal = 2.0 * brightVal * brightVal * (1.5 - brightVal);
179
180    // Apply brightness:
181    outCol.rgb = outCol.rgb * brightVal;
182@endif
183
184@ifdef S3D_LIGHT_SHMAP
185    outCol *= shmapVal;
186@endif
187
188    gl_FragColor = outCol;
189}
190
191///////////////////////////////////////////////////////////////////////////////
Note: See TracBrowser for help on using the repository browser.