summaryrefslogtreecommitdiffstats
path: root/Projects/Asteroids/src/asteroid_vs_diligent.hlsl
blob: fa29aba7208b91049fe2a67af324df02400ec175 (plain)
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
#include "shader_common.h"

struct AsteroidData
{
	float4x4 World;
	float4 SurfaceColor;

	float DeepColorR;
    float DeepColorG;
    float DeepColorB;
	uint TextureIndex;
};

#ifdef BINDLESS

cbuffer DrawConstantBuffer
{
    float4x4 ViewProjection;
}
StructuredBuffer<AsteroidData> g_Data;

#else

cbuffer DrawConstantBuffer
{
    float4x4 ViewProjection;
    AsteroidData g_Data;
};

#endif

float linstep(float min, float max, float s)
{
    return saturate((s - min) / (max - min));
}


void asteroid_vs_diligent(in float3 in_pos      : ATTRIB0,
                          in float3 in_normal   : ATTRIB1,
#ifdef BINDLESS           
                          in uint   AsteroidId  : ATTRIB2, // SV_InstanceId is not affected by BaseInstance
#endif                    
                          out float4 position   : SV_Position,
                          out VSOut vs_output)
{
#ifdef BINDLESS
    AsteroidData Data = g_Data[AsteroidId];
#else
    AsteroidData Data = g_Data;
#endif

    float3 positionWorld = mul(Data.World, float4(in_pos, 1.0f)).xyz;
    position = mul(ViewProjection, float4(positionWorld, 1.0f));

    vs_output.positionModel = in_pos;
    vs_output.normalWorld = mul(Data.World, float4(in_normal, 0.0f)).xyz; // No non-uniform scaling
    
    float depth = linstep(0.5f, 0.7f, length(in_pos.xyz));
    vs_output.albedo = lerp( float3(Data.DeepColorR, Data.DeepColorG, Data.DeepColorB), Data.SurfaceColor.xyz, depth);

    vs_output.textureId = Data.TextureIndex;
}