aboutsummaryrefslogtreecommitdiff
path: root/samples/VolumetricLightingTest/shaders/scene_VS.hlsl
blob: 630b87c80d2dd1d274e5a99536b3afba542047a6 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
// This code contains NVIDIA Confidential Information and is disclosed 
// under the Mutual Non-Disclosure Agreement. 
// 
// Notice 
// ALL NVIDIA DESIGN SPECIFICATIONS AND CODE ("MATERIALS") ARE PROVIDED "AS IS" NVIDIA MAKES 
// NO REPRESENTATIONS, WARRANTIES, EXPRESSED, IMPLIED, STATUTORY, OR OTHERWISE WITH RESPECT TO 
// THE MATERIALS, AND EXPRESSLY DISCLAIMS ANY IMPLIED WARRANTIES OF NONINFRINGEMENT, 
// MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. 
// 
// NVIDIA Corporation assumes no responsibility for the consequences of use of such 
// information or for any infringement of patents or other rights of third parties that may 
// result from its use. No license is granted by implication or otherwise under any patent 
// or patent rights of NVIDIA Corporation. No third party distribution is allowed unless 
// expressly authorized by NVIDIA.  Details are subject to change without notice. 
// This code supersedes and replaces all information previously supplied. 
// NVIDIA Corporation products are not authorized for use as critical 
// components in life support devices or systems without express written approval of 
// NVIDIA Corporation. 
// 
// Copyright (c) 2003 - 2016 NVIDIA Corporation. All rights reserved.
//
// NVIDIA Corporation and its licensors retain all intellectual property and proprietary
// rights in and to this software and related documentation and any modifications thereto.
// Any use, reproduction, disclosure or distribution of this software and related
// documentation without an express license agreement from NVIDIA Corporation is
// strictly prohibited.
//

/*
Define the shader permutations for code generation
%% MUX_BEGIN %%
%% MUX_END %%
*/

////////////////////////////////////////////////////////////////////////////////
// Constant Buffers

cbuffer CameraCB : register( b0 )
{
    column_major float4x4 c_mViewProj   : packoffset(c0);
    float3 c_vEyePos                    : packoffset(c4);
    float c_fZNear                      : packoffset(c5);
    float c_fZFar                       : packoffset(c5.y);
};

cbuffer ObjectCB : register( b1 )
{
    column_major float4x4 c_mObject : packoffset(c0);
    float3 c_vObjectColor : packoffset(c4);
};

cbuffer LightCB : register( b2 )
{
    column_major float4x4 c_mLightViewProj  : packoffset(c0);
    float3 c_vLightDirection                : packoffset(c4);
    float c_fLightFalloffCosTheta           : packoffset(c4.w);
    float3 c_vLightPos                      : packoffset(c5);
    float c_fLightFalloffPower              : packoffset(c5.w);
    float3 c_vLightColor                    : packoffset(c6);
    float4 c_vLightAttenuationFactors       : packoffset(c7);
    float c_fLightZNear                     : packoffset(c8);
    float c_fLightZNFar                     : packoffset(c8.y);
    float3 c_vSigmaExtinction               : packoffset(c9);
};

////////////////////////////////////////////////////////////////////////////////
// IO Structures

struct VS_OUTPUT
{
    float4 ScreenP : SV_POSITION;
    float4 P : TEXCOORD0;
    float3 N : NORMAL0;
};

////////////////////////////////////////////////////////////////////////////////
// Vertex Shader

VS_OUTPUT main( uint id : SV_VERTEXID )
{
    VS_OUTPUT output;

    // Faces
    // +X, +Y, +Z, -X, -Y, -Z
    // Vertices
    // 0 ---15
    // |   / |
    // |  /  |
    // | /   |
    // 24--- 3
    
    uint face_idx = id / 6;
    uint vtx_idx = id % 6;
    float3 P;
    P.x = ((vtx_idx % 3) == 2) ? -1 : 1;
    P.y = ((vtx_idx % 3) == 1) ? -1 : 1;
    P.z = 0;
    if ((face_idx % 3) == 0)
        P.yzx = P.xyz;
    else if ((face_idx % 3) == 1)
        P.xzy = P.xyz;
    // else if ((face_idx % 3) == 2)
    //    P.xyz = P.xyz;
    P *= ((vtx_idx / 3) == 0) ? 1 : -1;
    
    float3 N;
    N.x = ((face_idx % 3) == 0) ? 1 : 0;
    N.y = ((face_idx % 3) == 1) ? 1 : 0;
    N.z = ((face_idx % 3) == 2) ? 1 : 0;
    N *= ((face_idx / 3) == 0) ? 1 : -1;
    P += N;

    output.P = mul(c_mObject, float4(P, 1));
    output.ScreenP = mul(c_mViewProj, output.P);
    output.N = mul(c_mObject, float4(N, 0)).xyz;
    return output;
}