| 1 | //--------------------------------------------------------------------------- |
|---|
| 2 | //These materials/shaders are part of the NEW InstanceManager implementation |
|---|
| 3 | //Written by Matias N. Goldberg ("dark_sylinc") |
|---|
| 4 | //--------------------------------------------------------------------------- |
|---|
| 5 | |
|---|
| 6 | //This shader is not instancing related, but is used in the Instancing tests for lighting |
|---|
| 7 | //consistency (i.e. the ground) |
|---|
| 8 | |
|---|
| 9 | //--------------------------------------------- |
|---|
| 10 | //Vertex Shader Input |
|---|
| 11 | //--------------------------------------------- |
|---|
| 12 | struct VS_INPUT |
|---|
| 13 | { |
|---|
| 14 | float4 Position : POSITION; |
|---|
| 15 | float3 Normal : NORMAL; |
|---|
| 16 | float2 uv0 : TEXCOORD0; |
|---|
| 17 | }; |
|---|
| 18 | |
|---|
| 19 | #include "InstancingVertexInterpolators.cg" |
|---|
| 20 | |
|---|
| 21 | //--------------------------------------------- |
|---|
| 22 | //Main Vertex Shader |
|---|
| 23 | //--------------------------------------------- |
|---|
| 24 | VS_OUTPUT main_vs( in VS_INPUT input, |
|---|
| 25 | uniform float4x4 viewProjMatrix, |
|---|
| 26 | uniform float4x4 worldMatrix |
|---|
| 27 | |
|---|
| 28 | #if defined( DEPTH_SHADOWCASTER ) || defined( DEPTH_SHADOWRECEIVER ) |
|---|
| 29 | , uniform float4 depthRange |
|---|
| 30 | #endif |
|---|
| 31 | #ifdef DEPTH_SHADOWRECEIVER |
|---|
| 32 | , uniform float4x4 texViewProjMatrix |
|---|
| 33 | #endif |
|---|
| 34 | ) |
|---|
| 35 | { |
|---|
| 36 | VS_OUTPUT output; |
|---|
| 37 | |
|---|
| 38 | float4 worldPos = mul( worldMatrix, input.Position ); |
|---|
| 39 | float3 worldNorm = mul( (float3x3)(worldMatrix), input.Normal ); |
|---|
| 40 | |
|---|
| 41 | //Transform the position |
|---|
| 42 | output.Position = mul( viewProjMatrix, worldPos ); |
|---|
| 43 | |
|---|
| 44 | #ifdef DEPTH_SHADOWCASTER |
|---|
| 45 | output.ps.unused = float3( 0 ); |
|---|
| 46 | output.ps.depth = (output.Position.z - depthRange.x + SHADOW_BIAS) * depthRange.w; |
|---|
| 47 | #else |
|---|
| 48 | output.ps.uv0 = input.uv0; |
|---|
| 49 | |
|---|
| 50 | //Pass Normal and position for Blinn Phong lighting |
|---|
| 51 | output.ps.Normal = worldNorm; |
|---|
| 52 | output.ps.vPos = worldPos.xyz; |
|---|
| 53 | |
|---|
| 54 | #ifdef DEPTH_SHADOWRECEIVER |
|---|
| 55 | // Calculate the position of vertex in light space to do shadows |
|---|
| 56 | output.ps.lightSpacePos = mul( texViewProjMatrix, worldPos ); |
|---|
| 57 | // make linear |
|---|
| 58 | output.ps.lightSpacePos.z = (output.ps.lightSpacePos.z - depthRange.x) * depthRange.w; |
|---|
| 59 | #endif |
|---|
| 60 | #endif |
|---|
| 61 | |
|---|
| 62 | return output; |
|---|
| 63 | } |
|---|