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 |
|
---|
19 | struct VS_INPUT
|
---|
20 | {
|
---|
21 | float4 posObj: POSITION;
|
---|
22 | float3 normalObj: NORMAL;
|
---|
23 | float2 texCoord0: TEXCOORD0;
|
---|
24 | float2 color: COLOR0;
|
---|
25 | };
|
---|
26 |
|
---|
27 | struct VS_OUTPUT
|
---|
28 | {
|
---|
29 | float4 posScr: POSITION;
|
---|
30 | float2 mainTexCoord: TEXCOORD0;
|
---|
31 | float3 diffuse: TEXCOORD1;
|
---|
32 | float3 specular: TEXCOORD2;
|
---|
33 | #ifdef S3D_LIGHT_PROJ
|
---|
34 | float4 lightProjCoord: TEXCOORD3;
|
---|
35 | #endif
|
---|
36 | #ifdef S3D_LIGHT_SHMAP
|
---|
37 | float4 lightShmapCoord: TEXCOORD4;
|
---|
38 | #endif
|
---|
39 | float fog: FOG;
|
---|
40 | };
|
---|
41 |
|
---|
42 | ///////////////////////////////////////////////////////////////////////////////
|
---|
43 |
|
---|
44 | const float4x4 projMat;
|
---|
45 | const float4x4 matView;
|
---|
46 |
|
---|
47 | const float4 lightCenRange;
|
---|
48 | #ifdef S3D_LIGHT_PROJ
|
---|
49 | const float4x4 lightProjMat;
|
---|
50 | #endif
|
---|
51 | #ifdef S3D_LIGHT_SHMAP
|
---|
52 | const float4x4 lightShmapMat;
|
---|
53 | #endif
|
---|
54 |
|
---|
55 | ///////////////////////////////////////////////////////////////////////////////
|
---|
56 | // Vertexshader
|
---|
57 | // Profile: 1x1
|
---|
58 |
|
---|
59 | VS_OUTPUT main(VS_INPUT input)
|
---|
60 | {
|
---|
61 | VS_OUTPUT output = (VS_OUTPUT)0;
|
---|
62 |
|
---|
63 | float4 posView = mul(input.posObj, matView);
|
---|
64 | float3 normalView = mul(input.normalObj, matView).xyz;
|
---|
65 |
|
---|
66 | output.posScr = mul(posView, projMat);
|
---|
67 | output.fog = posView.z / posView.w;
|
---|
68 |
|
---|
69 | float3 camToVertView = posView.xyz;
|
---|
70 | float3 vertToLightView = lightCenRange - camToVertView;
|
---|
71 | float3 vertToLightDirView = normalize(vertToLightView);
|
---|
72 | float3 halfDirView = vertToLightDirView - camToVertView;
|
---|
73 | // Lightrange-factor: 1 - (lightpos - surfacepos)^2 / range^2
|
---|
74 | float3 scaledSurfToLight = vertToLightView / lightCenRange.w;
|
---|
75 |
|
---|
76 | output.mainTexCoord = input.texCoord0;
|
---|
77 | output.diffuse = clamp(dot(vertToLightDirView, input.normalObj), 0.0, 1.0) + clamp(-dot(vertToLightDirView, input.normalObj), 0.0, 1.0);
|
---|
78 | output.specular = pow(saturate(dot(reflect(-normalize(camToVertView), input.normalObj), vertToLightDirView)), S3D_SPECULAR_EXP);
|
---|
79 |
|
---|
80 | #ifdef S3D_LIGHT_PROJ
|
---|
81 | output.lightProjCoord = mul(posView, lightProjMat);
|
---|
82 | #endif
|
---|
83 | #ifdef S3D_LIGHT_SHMAP
|
---|
84 | output.lightShmapCoord = mul(posView, lightShmapMat);
|
---|
85 | #endif
|
---|
86 |
|
---|
87 | return output;
|
---|
88 | }
|
---|
89 |
|
---|
90 | ///////////////////////////////////////////////////////////////////////////////
|
---|