Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: data/branches/Shader_HS18/programs/Cg/HWBasicInstancing.cg @ 12294

Last change on this file since 12294 was 12115, checked in by wiesep, 6 years ago

Changed folder structure, deletet some unused files and cleaned up code

File size: 2.0 KB
Line 
1//---------------------------------------------------------------------------
2//These materials/shaders are part of the NEW InstanceManager implementation
3//Written by Matias N. Goldberg ("dark_sylinc")
4//---------------------------------------------------------------------------
5
6//---------------------------------------------
7//Vertex Shader Input
8//---------------------------------------------
9struct VS_INPUT
10{
11        float4 Position :       POSITION;
12        float3 Normal   :       NORMAL;
13        float3 Tangent  :       TANGENT;
14        float2 uv0              :       TEXCOORD0;
15
16        float4 mat14    :       TEXCOORD1;
17        float4 mat24    :       TEXCOORD2;
18        float4 mat34    :       TEXCOORD3;
19};
20
21#include "InstancingVertexInterpolators.cg"
22
23//---------------------------------------------
24//Main Vertex Shader
25//---------------------------------------------
26VS_OUTPUT main_vs( in VS_INPUT input,
27                                   uniform float4x4 viewProjMatrix
28
29#if defined( DEPTH_SHADOWCASTER ) || defined( DEPTH_SHADOWRECEIVER )
30                                ,  uniform float4 depthRange
31#endif
32#ifdef DEPTH_SHADOWRECEIVER
33                                ,  uniform float4x4 texViewProjMatrix
34#endif
35                                )
36{
37        VS_OUTPUT output;
38
39        float3x4 worldMatrix;
40        worldMatrix[0] = input.mat14;
41        worldMatrix[1] = input.mat24;
42        worldMatrix[2] = input.mat34;
43
44        float4 worldPos = float4( mul( worldMatrix, input.Position ).xyz, 1.0f );
45        float3 worldNorm= mul( (float3x3)(worldMatrix), input.Normal );
46
47        //Transform the position
48        output.Position         = mul( viewProjMatrix, worldPos );
49
50#ifdef DEPTH_SHADOWCASTER
51        output.ps.unused        = float3( 0 );
52        output.ps.depth         = (output.Position.z - depthRange.x + SHADOW_BIAS) * depthRange.w;
53#else
54        output.ps.uv0           = input.uv0;
55
56        //Pass Normal and position for Blinn Phong lighting
57        output.ps.Normal        = normalize(worldNorm);
58        output.ps.vPos          = worldPos.xyz;
59       
60        #ifdef DEPTH_SHADOWRECEIVER
61                // Calculate the position of vertex in light space to do shadows
62                output.ps.lightSpacePos = mul( texViewProjMatrix, worldPos );
63                // make linear
64                output.ps.lightSpacePos.z = (output.ps.lightSpacePos.z - depthRange.x) * depthRange.w;
65        #endif
66#endif
67
68        return output;
69}
Note: See TracBrowser for help on using the repository browser.