source: GTP/trunk/App/Demos/Illum/Shark3D/version164x12u/IllumDemo/src/res/levelutil/shader/prog/ogl_glsl/include_stddef_ogl_glsl_vs1x0.s3d_shadercode @ 2196

Revision 2196, 5.2 KB checked in by szirmay, 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@ifndef STDDEF_OGL_GLSL_SC
15@define STDDEF_OGL_GLSL_SC
16
17///////////////////////////////////////////////////////////////////////////////
18
19// default to 4 for bone transformation w/o bone subcriptions
20@ifndef S3D_MATBONE_CNT
21@define S3D_MATBONE_CNT 4
22@endif
23
24@ifdef S3D_USE_BONESUBSCR   
25
26@define S3D_BONE_TRANSF_SUBSCR(matBoneFinal, matBone, boneWgh, boneSubscr) \
27    matBoneFinal \
28        = boneWgh.x * matBone[int(boneSubscr.x)] \
29        + boneWgh.y * matBone[int(boneSubscr.y)] \
30        + boneWgh.z * matBone[int(boneSubscr.z)] \
31        + boneWgh.w * matBone[int(boneSubscr.w)];
32
33@define S3D_BONE_DECL_STD(boneWgh, boneSubscr) \
34        attribute vec4 boneWgh; \
35        attribute vec4 boneSubscr;
36
37@define S3D_MATBONE_DECL_STD(matBone) \
38        uniform mat4 matBone[S3D_MATBONE_CNT];
39
40@define S3D_BONE_TRANSF_STD(matBoneFinal, matBone, boneWgh, boneSubscr) \
41        mat4 matBoneFinal; \
42        S3D_BONE_TRANSF_SUBSCR(matBoneFinal, matBone, boneWgh, boneSubscr)
43       
44@else
45
46@ifdef S3D_USE_BONEWGH
47
48@define S3D_BONE_TRANSF_WGH(matBoneFinal, matBone, boneWgh) \
49    matBoneFinal \
50        = boneWgh.x * matBone[0] \
51        + boneWgh.y * matBone[1] \
52        + boneWgh.z * matBone[2] \
53        + boneWgh.w * matBone[3];
54
55@define S3D_BONE_DECL_STD(boneWgh, boneSubscr) \
56        attribute vec4 boneWgh;
57
58@define S3D_MATBONE_DECL_STD(matBone) \
59        uniform mat4 matBone[S3D_MATBONE_CNT];
60
61@define S3D_BONE_TRANSF_STD(matBoneFinal, matBone, boneWgh, boneSubscr) \
62        mat4 matBoneFinal; \
63        S3D_BONE_TRANSF_WGH(matBoneFinal, matBone, boneWgh)
64       
65@else
66
67@define S3D_BONE_DECL_STD(boneWgh, boneSubscr)
68
69@define S3D_MATBONE_DECL_STD(matBone)
70
71@define S3D_BONE_TRANSF_STD(matBoneFinal, matBone, boneWgh, boneSubscr) \
72        mat4 matBoneFinal = gl_ModelViewMatrix
73
74@endif
75
76@endif
77
78///////////////////////////////////////////////////////////////////////////////
79
80float s3d_calcLightRangeFac(float dist, vec4 posRange)
81{
82    float lightRsqRange = 1.0 / (posRange.w * posRange.w);
83    float rangeFac = max(1.0 - dist * dist * lightRsqRange, 0.0);
84    return rangeFac;
85}
86
87float s3d_calcLightRangeFac(float dist, float quadraticAtten)
88{
89    float lightRsqRange = quadraticAtten * 0.25;
90    float rangeFac = max(1.0 - dist * dist * lightRsqRange, 0.0);
91    return rangeFac;
92}
93
94///////////////////////////////////////////////////////////////////////////////
95
96struct s3d_ColPair
97{
98   vec4 diffuse;
99   vec4 specular;
100};
101
102@define s3d_calcPointLightTermImpl( \
103        result, camToVertView, normalView, mtrlPower, \
104        lightPos, lightAmbient, lightDiffuse, lightSpecular, quadraticAtten) \
105{ \
106    vec3 vertToLightDirView = normalize(lightPos.xyz - camToVertView.xyz); \
107    float normalDotVertToLightDir = dot(normalView, vertToLightDirView); \
108    vec3 camToVertDirView = normalize(camToVertView.xyz); \
109    vec3 HalfDirView = normalize(vertToLightDirView - camToVertDirView); \
110    float normalDotHalfDir= dot(normalView, HalfDirView); \
111\
112    float dist = length(lightPos.xyz - camToVertView.xyz); \
113    float rangeFac = s3d_calcLightRangeFac(dist, quadraticAtten); \
114    float specular = pow(max(0.0, normalDotHalfDir), mtrlPower) * rangeFac; \
115\
116    result.diffuse = lightAmbient * rangeFac; \
117    float diffuse = normalDotVertToLightDir * rangeFac; \
118    result.diffuse += lightDiffuse * diffuse; \
119    result.specular = lightSpecular * specular; \
120}
121
122@define s3d_calcPointLightTerm( \
123        result, camToVertView, normalView, mtrlPower, light, lightProd) \
124{ \
125    s3d_calcPointLightTermImpl( \
126            result, camToVertView, normalView, mtrlPower, light.position, \
127            lightProd.ambient, lightProd.diffuse, \
128            lightProd.specular, light.quadraticAttenuation); \
129}
130
131///////////////////////////////////////////////////////////////////////////////
132
133void s3d_calcBump(
134    out vec3 diffuseDirSurf, out vec3 specularDirSurf,
135    vec3 normalView, vec3 vertToLightDirView, vec3 halfDirView,
136    vec3 tangentUView, vec3 tangentVView)
137{
138    diffuseDirSurf.x = dot(tangentUView, vertToLightDirView);
139    diffuseDirSurf.y = dot(tangentVView, vertToLightDirView);
140    diffuseDirSurf.z = dot(normalView, vertToLightDirView);
141
142    specularDirSurf.x = dot(tangentUView, halfDirView);
143    specularDirSurf.y = dot(tangentVView, halfDirView);
144    specularDirSurf.z = dot(normalView, halfDirView);
145}
146
147///////////////////////////////////////////////////////////////////////////////
148
149vec3 s3d_uncomprNormal(vec3 comprNormal)
150{
151@ifdef S3D_COMPR_NORMAL
152    return comprNormal / 127.5 - 1;
153@else
154    return comprNormal;
155@endif   
156}
157
158///////////////////////////////////////////////////////////////////////////////
159
160@endif // STDDEF_OGL_GLSL_SC
Note: See TracBrowser for help on using the repository browser.