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