source: GTP/trunk/App/Demos/Illum/Shark3D/version164x12u/IllumDemo/bin/res/levelutil/shader/prog/d3d9_hlsl/bump_d3d9_hlsl_vs1x1.s3d_shadercode_run @ 2196

Revision 2196, 3.7 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#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;
55S3D_MATBONE_DECL_STD(matBone)
56
57const float4 lightCenRange;
58#ifdef S3D_LIGHT_BRIGHT
59const float4x4 lightBrightMat;
60#endif
61#ifdef S3D_LIGHT_PROJ
62const float4x4 lightProjMat;
63#endif
64#ifdef S3D_LIGHT_SHMAP
65const float4x4 lightShmapMat;
66#endif
67
68///////////////////////////////////////////////////////////////////////////////
69// Vertexshader
70// Profile: 1x1
71
72VS_OUTPUT main(VS_INPUT input)
73{
74    VS_OUTPUT output = (VS_OUTPUT)0;
75
76    float4x4 matBoneFinal;
77    S3D_BONE_TRANSF_STD(
78            matBoneFinal, matBone, input.boneWgh, input.boneSubscr);
79    // Transform vectors by matBoneFinal
80    float4 posView = mul(input.posObj, matBoneFinal);
81    float3 normalView = mul(input.normalObj, matBoneFinal).xyz;
82    float3 tangentUObj = input.tangentUObj.xyz;
83    float3 tangentVObj = input.tangentVObj.xyz;
84    float3 tangentUView = mul(tangentUObj, matBoneFinal);
85    float3 tangentVView = mul(tangentVObj, matBoneFinal);
86
87    output.posScr = mul(posView, projMat);
88    output.mainTexCoord = input.mainTexCoord;
89
90    output.fog = posView.z / posView.w;
91
92    float3 camToVertView = posView.xyz;
93    float3 vertToLightView = lightCenRange - camToVertView;   
94    float3 vertToLightDirView = normalize(vertToLightView);
95    float3 halfDirView = vertToLightDirView - camToVertView;
96    s3d_calcBump(
97            output.diffuseDirSurf, output.specularDirSurf, normalView,
98            vertToLightDirView, halfDirView, tangentUView, tangentVView);
99    // Lightrange-factor: 1 - (lightpos - surfacepos)^2 / range^2
100    output.scaledSurfToLight = vertToLightView / lightCenRange.w;
101
102#ifdef S3D_PARALLAX_MAPPING
103    output.camToVertSurf.x = dot(tangentUView, camToVertView);
104    output.camToVertSurf.y = dot(tangentVView, camToVertView);
105    output.camToVertSurf.z = dot(normalView, camToVertView);
106#endif
107
108#ifdef S3D_LIGHT_BRIGHT
109    output.lightBrightCoord = mul(posView, lightBrightMat);
110    output.secPosScr = output.posScr;
111#endif
112
113#ifdef S3D_LIGHT_PROJ
114    output.lightProjCoord = mul(posView, lightProjMat);
115#endif   
116#ifdef S3D_LIGHT_SHMAP
117    output.lightShmapCoord = mul(posView, lightShmapMat);
118#endif
119
120    return output;
121}
122
123///////////////////////////////////////////////////////////////////////////////
Note: See TracBrowser for help on using the repository browser.