Moved shaders to new directory
This commit is contained in:
parent
0b3f8340e3
commit
99b226237a
1244 changed files with 0 additions and 0 deletions
53
shaders/hlsl/shadowmappingomni/cubemapdisplay.frag
Normal file
53
shaders/hlsl/shadowmappingomni/cubemapdisplay.frag
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
// Copyright 2020 Google LLC
|
||||
|
||||
TextureCube shadowCubeMapTexture : register(t1);
|
||||
SamplerState shadowCubeMapSampler : register(s1);
|
||||
|
||||
float4 main([[vk::location(0)]] float2 inUV : TEXCOORD0) : SV_TARGET
|
||||
{
|
||||
float4 outFragColor = float4(0, 0, 0, 0);
|
||||
outFragColor.rgb = float3(0.05, 0.05, 0.05);
|
||||
|
||||
float3 samplePos = float3(0, 0, 0);
|
||||
|
||||
// Crude statement to visualize different cube map faces based on UV coordinates
|
||||
int x = int(floor(inUV.x / 0.25f));
|
||||
int y = int(floor(inUV.y / (1.0 / 3.0)));
|
||||
if (y == 1) {
|
||||
float2 uv = float2(inUV.x * 4.0f, (inUV.y - 1.0/3.0) * 3.0);
|
||||
uv = 2.0 * float2(uv.x - float(x) * 1.0, uv.y) - 1.0;
|
||||
switch (x) {
|
||||
case 0: // NEGATIVE_X
|
||||
samplePos = float3(-1.0f, uv.y, uv.x);
|
||||
break;
|
||||
case 1: // POSITIVE_Z
|
||||
samplePos = float3(uv.x, uv.y, 1.0f);
|
||||
break;
|
||||
case 2: // POSITIVE_X
|
||||
samplePos = float3(1.0, uv.y, -uv.x);
|
||||
break;
|
||||
case 3: // NEGATIVE_Z
|
||||
samplePos = float3(-uv.x, uv.y, -1.0f);
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
if (x == 1) {
|
||||
float2 uv = float2((inUV.x - 0.25) * 4.0, (inUV.y - float(y) / 3.0) * 3.0);
|
||||
uv = 2.0 * uv - 1.0;
|
||||
switch (y) {
|
||||
case 0: // NEGATIVE_Y
|
||||
samplePos = float3(uv.x, -1.0f, uv.y);
|
||||
break;
|
||||
case 2: // POSITIVE_Y
|
||||
samplePos = float3(uv.x, 1.0f, -uv.y);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ((samplePos.x != 0.0f) && (samplePos.y != 0.0f)) {
|
||||
float dist = length(shadowCubeMapTexture.Sample(shadowCubeMapSampler, samplePos).xyz) * 0.005;
|
||||
outFragColor = float4(dist.xxx, 1.0);
|
||||
}
|
||||
return outFragColor;
|
||||
}
|
||||
BIN
shaders/hlsl/shadowmappingomni/cubemapdisplay.frag.spv
Normal file
BIN
shaders/hlsl/shadowmappingomni/cubemapdisplay.frag.spv
Normal file
Binary file not shown.
25
shaders/hlsl/shadowmappingomni/cubemapdisplay.vert
Normal file
25
shaders/hlsl/shadowmappingomni/cubemapdisplay.vert
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
// Copyright 2020 Google LLC
|
||||
|
||||
struct UBO
|
||||
{
|
||||
float4x4 projection;
|
||||
float4x4 view;
|
||||
float4x4 model;
|
||||
};
|
||||
|
||||
cbuffer ubo : register(b0) { UBO ubo; }
|
||||
|
||||
struct VSOutput
|
||||
{
|
||||
float4 Pos : SV_POSITION;
|
||||
[[vk::location(0)]] float2 UV : TEXCOORD0;
|
||||
};
|
||||
|
||||
VSOutput main(uint VertexIndex : SV_VertexID)
|
||||
{
|
||||
VSOutput output = (VSOutput)0;
|
||||
output.UV = float2((VertexIndex << 1) & 2, VertexIndex & 2);
|
||||
output.Pos = float4(output.UV.xy * 2.0f - 1.0f, 0.0f, 1.0f);
|
||||
return output;
|
||||
}
|
||||
|
||||
BIN
shaders/hlsl/shadowmappingomni/cubemapdisplay.vert.spv
Normal file
BIN
shaders/hlsl/shadowmappingomni/cubemapdisplay.vert.spv
Normal file
Binary file not shown.
14
shaders/hlsl/shadowmappingomni/offscreen.frag
Normal file
14
shaders/hlsl/shadowmappingomni/offscreen.frag
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
// Copyright 2020 Google LLC
|
||||
|
||||
struct VSOutput
|
||||
{
|
||||
[[vk::location(0)]] float4 Pos : POSITION0;
|
||||
[[vk::location(1)]] float3 LightPos : POSITION1;
|
||||
};
|
||||
|
||||
float main(VSOutput input) : SV_TARGET
|
||||
{
|
||||
// Store distance to light as 32 bit float value
|
||||
float3 lightVec = input.Pos.xyz - input.LightPos;
|
||||
return length(lightVec);
|
||||
}
|
||||
BIN
shaders/hlsl/shadowmappingomni/offscreen.frag.spv
Normal file
BIN
shaders/hlsl/shadowmappingomni/offscreen.frag.spv
Normal file
Binary file not shown.
34
shaders/hlsl/shadowmappingomni/offscreen.vert
Normal file
34
shaders/hlsl/shadowmappingomni/offscreen.vert
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
// Copyright 2020 Google LLC
|
||||
|
||||
struct VSOutput
|
||||
{
|
||||
float4 Pos : SV_POSITION;
|
||||
[[vk::location(0)]] float4 WorldPos : POSITION0;
|
||||
[[vk::location(1)]] float3 LightPos : POSITION1;
|
||||
};
|
||||
|
||||
struct UBO
|
||||
{
|
||||
float4x4 projection;
|
||||
float4x4 view;
|
||||
float4x4 model;
|
||||
float4 lightPos;
|
||||
};
|
||||
|
||||
cbuffer ubo : register(b0) { UBO ubo; }
|
||||
|
||||
struct PushConsts
|
||||
{
|
||||
float4x4 view;
|
||||
};
|
||||
[[vk::push_constant]] PushConsts pushConsts;
|
||||
|
||||
VSOutput main([[vk::location(0)]] float3 Pos : POSITION0)
|
||||
{
|
||||
VSOutput output = (VSOutput)0;
|
||||
output.Pos = mul(ubo.projection, mul(pushConsts.view, mul(ubo.model, float4(Pos, 1.0))));
|
||||
|
||||
output.WorldPos = float4(Pos, 1.0);
|
||||
output.LightPos = ubo.lightPos.xyz;
|
||||
return output;
|
||||
}
|
||||
BIN
shaders/hlsl/shadowmappingomni/offscreen.vert.spv
Normal file
BIN
shaders/hlsl/shadowmappingomni/offscreen.vert.spv
Normal file
Binary file not shown.
43
shaders/hlsl/shadowmappingomni/scene.frag
Normal file
43
shaders/hlsl/shadowmappingomni/scene.frag
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
// Copyright 2020 Google LLC
|
||||
|
||||
TextureCube shadowCubeMapTexture : register(t1);
|
||||
SamplerState shadowCubeMapSampler : register(s1);
|
||||
|
||||
struct VSOutput
|
||||
{
|
||||
[[vk::location(0)]] float3 Normal : NORMAL0;
|
||||
[[vk::location(1)]] float3 Color : COLOR0;
|
||||
[[vk::location(2)]] float3 EyePos : POSITION0;
|
||||
[[vk::location(3)]] float3 LightVec : TEXCOORD2;
|
||||
[[vk::location(4)]] float3 WorldPos : POSITION1;
|
||||
[[vk::location(5)]] float3 LightPos : POSITION2;
|
||||
};
|
||||
|
||||
#define EPSILON 0.15
|
||||
#define SHADOW_OPACITY 0.5
|
||||
|
||||
float4 main(VSOutput input) : SV_TARGET
|
||||
{
|
||||
// Lighting
|
||||
float3 N = normalize(input.Normal);
|
||||
float3 L = normalize(float3(1.0, 1.0, 1.0));
|
||||
|
||||
float3 Eye = normalize(-input.EyePos);
|
||||
float3 Reflected = normalize(reflect(-input.LightVec, input.Normal));
|
||||
|
||||
float4 IAmbient = float4(float3(0.05, 0.05, 0.05), 1.0);
|
||||
float4 IDiffuse = float4(1.0, 1.0, 1.0, 1.0) * max(dot(input.Normal, input.LightVec), 0.0);
|
||||
|
||||
float4 outFragColor = float4(IAmbient + IDiffuse * float4(input.Color, 1.0));
|
||||
|
||||
// Shadow
|
||||
float3 lightVec = input.WorldPos - input.LightPos;
|
||||
float sampledDist = shadowCubeMapTexture.Sample(shadowCubeMapSampler, lightVec).r;
|
||||
float dist = length(lightVec);
|
||||
|
||||
// Check if fragment is in shadow
|
||||
float shadow = (dist <= sampledDist + EPSILON) ? 1.0 : SHADOW_OPACITY;
|
||||
|
||||
outFragColor.rgb *= shadow;
|
||||
return outFragColor;
|
||||
}
|
||||
BIN
shaders/hlsl/shadowmappingomni/scene.frag.spv
Normal file
BIN
shaders/hlsl/shadowmappingomni/scene.frag.spv
Normal file
Binary file not shown.
45
shaders/hlsl/shadowmappingomni/scene.vert
Normal file
45
shaders/hlsl/shadowmappingomni/scene.vert
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
// Copyright 2020 Google LLC
|
||||
|
||||
struct VSInput
|
||||
{
|
||||
[[vk::location(0)]] float3 Pos : POSITION0;
|
||||
[[vk::location(1)]] float3 Color : COLOR0;
|
||||
[[vk::location(2)]] float3 Normal : NORMAL0;
|
||||
};
|
||||
|
||||
struct UBO
|
||||
{
|
||||
float4x4 projection;
|
||||
float4x4 view;
|
||||
float4x4 model;
|
||||
float4 lightPos;
|
||||
};
|
||||
|
||||
cbuffer ubo : register(b0) { UBO ubo; }
|
||||
|
||||
struct VSOutput
|
||||
{
|
||||
float4 Pos : SV_POSITION;
|
||||
[[vk::location(0)]] float3 Normal : NORMAL0;
|
||||
[[vk::location(1)]] float3 Color : COLOR0;
|
||||
[[vk::location(2)]] float3 EyePos : POSITION0;
|
||||
[[vk::location(3)]] float3 LightVec : TEXCOORD2;
|
||||
[[vk::location(4)]] float3 WorldPos : POSITION1;
|
||||
[[vk::location(5)]] float3 LightPos : POSITION2;
|
||||
};
|
||||
|
||||
VSOutput main(VSInput input)
|
||||
{
|
||||
VSOutput output = (VSOutput)0;
|
||||
output.Color = input.Color;
|
||||
output.Normal = input.Normal;
|
||||
|
||||
output.Pos = mul(ubo.projection, mul(ubo.view, mul(ubo.model, float4(input.Pos.xyz, 1.0))));
|
||||
output.EyePos = mul(ubo.model, float4(input.Pos, 1.0f)).xyz;
|
||||
output.LightVec = normalize(ubo.lightPos.xyz - input.Pos.xyz);
|
||||
output.WorldPos = input.Pos;
|
||||
|
||||
output.LightPos = ubo.lightPos.xyz;
|
||||
return output;
|
||||
}
|
||||
|
||||
BIN
shaders/hlsl/shadowmappingomni/scene.vert.spv
Normal file
BIN
shaders/hlsl/shadowmappingomni/scene.vert.spv
Normal file
Binary file not shown.
Loading…
Add table
Add a link
Reference in a new issue