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

Revision 2236, 3.6 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 \
15    <levelutil/shader/prog/d3d9_hlsl/include_stddef_d3d9_hlsl.s3d_shadercode_run>
16
17///////////////////////////////////////////////////////////////////////////////
18
19struct VS_INPUT
20{
21    float4 posObj: POSITION;
22    float3 normalObj: NORMAL;
23    S3D_BONE_DECL_STD(boneWgh, boneSubscr)
24    float2 mainTexCoord: TEXCOORD0;
25    float3 tangentUObj: TEXCOORD1;
26    float3 tangentVObj: TEXCOORD2;
27};
28
29struct VS_OUTPUT
30{
31    float4 posScr: POSITION;
32    float2 mainTexCoord: TEXCOORD0;
33    float3 diffuseDirSurf: TEXCOORD1;
34    float3 specularDirSurf: TEXCOORD2;
35    float3 scaledSurfToLight: TEXCOORD3;
36#ifdef S3D_PARALLAX_MAPPING
37    float3 camToVertSurf: TEXCOORD4;
38#endif
39#ifdef S3D_LIGHT_BRIGHT
40    float4 lightBrightCoord: TEXCOORD5;
41    float4 secPosScr: TEXCOORD6;
42#endif
43#ifdef S3D_LIGHT_PROJ
44    float4 lightProjCoord: TEXCOORD5;
45#endif
46#ifdef S3D_LIGHT_SHMAP
47    float4 lightShmapCoord: TEXCOORD6;
48#endif
49    float fog: FOG;
50};
51
52///////////////////////////////////////////////////////////////////////////////
53
54const float4x4 projMat;
55const float4x4 lightBrightMat;
56
57S3D_MATBONE_DECL_STD(matBone)
58
59const float4 lightCenRange;
60const float4x4 lightProjMat;
61const float4x4 lightShmapMat;
62
63///////////////////////////////////////////////////////////////////////////////
64// Vertexshader
65// Profile: 1x1
66
67VS_OUTPUT main(VS_INPUT input)
68{
69    VS_OUTPUT output = (VS_OUTPUT)0;
70
71    float4x4 matBoneFinal;
72    S3D_BONE_TRANSF_STD(
73            matBoneFinal, matBone, input.boneWgh, input.boneSubscr);
74    // Transform vectors by matBoneFinal
75    float4 posView = mul(input.posObj, matBoneFinal);
76    float3 normalView = mul(input.normalObj, matBoneFinal).xyz;
77    float3 tangentUObj = input.tangentUObj.xyz;
78    float3 tangentVObj = input.tangentVObj.xyz;
79    float3 tangentUView = mul(tangentUObj, matBoneFinal);
80    float3 tangentVView = mul(tangentVObj, matBoneFinal);
81
82    output.posScr = mul(posView, projMat);
83    output.mainTexCoord = input.mainTexCoord;
84
85    output.fog = posView.z / posView.w;
86
87#ifdef S3D_LIGHT_PROJ
88    output.lightProjCoord = mul(posView, lightProjMat);
89#endif   
90#ifdef S3D_LIGHT_SHMAP
91    output.lightShmapCoord = mul(posView, lightShmapMat);
92#endif
93
94    float3 camToVertView = posView.xyz;
95    float3 vertToLightView = lightCenRange - camToVertView;
96   
97    // Lightrange-factor: 1 - (lightpos - surfacepos)^2 / range^2
98    output.scaledSurfToLight = vertToLightView / lightCenRange.w;
99
100#ifdef S3D_PARALLAX_MAPPING
101    output.camToVertSurf.x = dot(tangentUView, camToVertView);
102    output.camToVertSurf.y = dot(tangentVView, camToVertView);
103    output.camToVertSurf.z = dot(normalView, camToVertView);
104#endif
105
106    float3 vertToLightDirView = normalize(vertToLightView);
107    float3 halfDirView = vertToLightDirView - camToVertView;
108    s3d_calcBump(
109            output.diffuseDirSurf, output.specularDirSurf, normalView,
110            vertToLightDirView, halfDirView, tangentUView, tangentVView);
111
112#ifdef S3D_LIGHT_BRIGHT
113    output.lightBrightCoord = mul(posView, lightBrightMat);
114    output.secPosScr = output.posScr;
115#endif
116
117    return output;
118}
119
120///////////////////////////////////////////////////////////////////////////////
Note: See TracBrowser for help on using the repository browser.