Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified resources/shaders/compiled/NormalsPixel.spv
Binary file not shown.
Binary file modified resources/shaders/compiled/PPEndPixel.spv
Binary file not shown.
Binary file modified resources/shaders/compiled/PPFxaaPixel.spv
Binary file not shown.
Binary file modified resources/shaders/compiled/PPNoisePixel.spv
Binary file not shown.
Binary file modified resources/shaders/compiled/PPOutlinePixel.spv
Binary file not shown.
Binary file modified resources/shaders/compiled/ParticlePixel.spv
Binary file not shown.
Binary file modified resources/shaders/compiled/ParticleVertex.spv
Binary file not shown.
Binary file modified resources/shaders/compiled/PointShadowMapPixel.spv
Binary file not shown.
Binary file modified resources/shaders/compiled/PointShadowMapSkinnedVertex.spv
Binary file not shown.
Binary file modified resources/shaders/compiled/PointShadowMapVertex.spv
Binary file not shown.
Binary file modified resources/shaders/compiled/PostProcessVertex.spv
Binary file not shown.
Binary file modified resources/shaders/compiled/SkyboxPixel.spv
Binary file not shown.
Binary file modified resources/shaders/compiled/SkyboxVertex.spv
Binary file not shown.
Binary file modified resources/shaders/compiled/ToonPixel.spv
Binary file not shown.
Binary file modified resources/shaders/compiled/ToonSkinnedVertex.spv
Binary file not shown.
Binary file modified resources/shaders/compiled/ToonVertex.spv
Binary file not shown.
Binary file modified resources/shaders/compiled/UniShadowMapSkinnedVertex.spv
Binary file not shown.
Binary file modified resources/shaders/compiled/UniShadowMapVertex.spv
Binary file not shown.
Binary file modified resources/shaders/compiled/WireframePixel.spv
Binary file not shown.
Binary file modified resources/shaders/compiled/WireframeVertex.spv
Binary file not shown.
22 changes: 11 additions & 11 deletions resources/shaders/source/Normals.psh
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ struct PSInput
float4 Pos : SV_POSITION;
float3 Normal : NORMAL;
float2 UV : TEX_COORD;
uint MaterialIndex;
float4 WorldPos;
uint MaterialIndex : MAT_INDEX;
float4 WorldPos : WORLD_POS;
};

struct PSOutput
Expand All @@ -20,16 +20,14 @@ SamplerState Textures_sampler; // By convention, texture samplers must use the

StructuredBuffer<MaterialData> Materials : register(t1);

const float Epsilon = 1e-10;

float3 RGBtoHSV(in float3 RGB)
float3 RGBtoHSV(in float3 RGB, float epsilon)
{
float4 P = (RGB.g < RGB.b) ? float4(RGB.bg, -1.0, 2.0/3.0) : float4(RGB.gb, 0.0, -1.0/3.0);
float4 Q = (RGB.r < P.x) ? float4(P.xyw, RGB.r) : float4(RGB.r, P.yzx);
float C = Q.x - min(Q.w, Q.y);
float H = abs((Q.w - Q.y) / (6.0 * C + Epsilon) + Q.z);
float H = abs((Q.w - Q.y) / (6.0 * C + epsilon) + Q.z);
float3 HCV = float3(H, C, Q.x);
float S = HCV.y / (HCV.z + Epsilon);
float S = HCV.y / (HCV.z + epsilon);
return float3(HCV.x, S, HCV.z);
}

Expand All @@ -45,22 +43,24 @@ float3 HSVtoRGB(in float3 HSV)

void main(in PSInput PSIn, out PSOutput PSOut)
{
const float Epsilon = 1e-10;

float4 Color;
float3 viewDir = normalize(cameraPosition - PSIn.WorldPos);
float3 viewDir = normalize(cameraPosition - PSIn.WorldPos.xyz);

if (Materials[PSIn.MaterialIndex].useTextureNormals)
{
uint normalIndex = Materials[PSIn.MaterialIndex].normalTexIndex;
float3 textureNormals = normalize(Textures[normalIndex].Sample(Textures_sampler, PSIn.UV));
Color = float4(normalize(textureNormals.xyz * float3(2.0) - float3(1.0)), 1.0f);
float3 textureNormals = normalize(Textures[normalIndex].Sample(Textures_sampler, PSIn.UV)).xyz;
Color = float4(normalize(textureNormals.xyz * float3(2.0, 2.0, 2.0) - float3(1.0, 1.0, 1.0)), 1.0f);
}
else
{
float3 vertexNormals = normalize(PSIn.Normal);
Color = float4(vertexNormals, 1.0f);
}

float3 colHsv = RGBtoHSV(float3(Color.r, Color.g, Color.b));
float3 colHsv = RGBtoHSV(float3(Color.r, Color.g, Color.b), Epsilon);
colHsv.y *= Materials[PSIn.MaterialIndex].normalIntensity;
Color.rgb = HSVtoRGB(colHsv.rgb);

Expand Down
36 changes: 18 additions & 18 deletions resources/shaders/source/PPFxaa.psh
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ void main(in PSInput PSIn, out PSOutput PSOut)
colorTex.GetDimensions(screenWidth, screenHeight);
float2 texelSize = float2(1.0 / screenWidth, 1.0 / screenHeight);

/***********************
/ Get edge luminance
/***********************/
//
// Get edge luminance
//
// Get luminance for four texels in a cross shape surrounding the current texel
float curLuma = RgbToLuma(colorTex.Sample(smplr, PSIn.UV).rgb);
float downLuma = RgbToLuma(colorTex.Sample(smplr, PSIn.UV + (float2( 0, -1) * texelSize)).rgb);
Expand Down Expand Up @@ -75,9 +75,9 @@ void main(in PSInput PSIn, out PSOutput PSOut)
float rightCornerLuma = LRLuma + URLuma;
float upCornerLuma = URLuma + ULLuma;

/**********************
/ Get edge orientation
/**********************/
//
// Get edge orientation
//
// Get an estimated gradient along the horizontal and vertical axes.
float edgeHoriz = abs(-2.0 * leftLuma + leftCornerLuma) + abs(-2.0 * curLuma + downUpLuma) * 2.0 + abs(-2.0 * rightLuma + rightCornerLuma);
float edgeVert = abs(-2.0 * upLuma + upCornerLuma) + abs(-2.0 * curLuma + leftRightLuma) * 2.0 + abs(-2.0 * downLuma + downCornerLuma);
Expand All @@ -95,9 +95,9 @@ void main(in PSInput PSIn, out PSOutput PSOut)
bool isGradient1Steepest = abs(gradient1) >= abs(gradient2);
float scaledGradient = 0.25 * max(abs(gradient1), abs(gradient2));

/******************************
/ Average luma values at edge
/******************************/
//
// Average luma values at edge
//
float stepLength = isHorizontalEdge ? texelSize.y : texelSize.x;
float localAvgLuma = 0.0;

Expand All @@ -123,9 +123,9 @@ void main(in PSInput PSIn, out PSOutput PSOut)
currentUV.x += stepLength * 0.5;
}

/************************
/ Explore bounds of edge
/************************/
//
// Explore bounds of edge
//
float2 offset = isHorizontalEdge ? float2(texelSize.x, 0.0) : float2(0.0, texelSize.y);
float2 newUV1 = currentUV - offset;
float2 newUV2 = currentUV + offset;
Expand Down Expand Up @@ -187,9 +187,9 @@ void main(in PSInput PSIn, out PSOutput PSOut)
}
}

/*****************
/ Estimate offset
/*****************/
//
// Estimate offset
//
float distance1 = isHorizontalEdge ? (PSIn.UV.x - newUV1.x) : (PSIn.UV.y - newUV1.y);
float distance2 = isHorizontalEdge ? (newUV2.x - PSIn.UV.x) : (newUV2.y - PSIn.UV.y);

Expand All @@ -206,9 +206,9 @@ void main(in PSInput PSIn, out PSOutput PSOut)
bool correctVariation = ((isDirection1 ? endLuma1 : endLuma2) < 0.0) != isCurLumaSmaller;
float finalOffset = correctVariation ? pixelOffset : 0.0;

/***********************
/ Subpixel antialiasing
/***********************/
//
// Subpixel antialiasing
//
// Get full weighted luminance average over 3x3 neighborhood
float iterationsF = float(Iterations);
float averageLuma = (1.0 / iterationsF) * (2.0 * (downUpLuma + leftRightLuma) + leftCornerLuma + rightCornerLuma);
Expand Down
6 changes: 3 additions & 3 deletions resources/shaders/source/PPNoise.psh
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,15 @@ void main(in PSInput PSIn, out PSOutput PSOut)
SamplerState smplr = ColorSinks_sampler;
Texture2D sceneColorTex = PostProcessSinks[0];
Texture2D noiseTex = Textures[noiseTexIndex];
float3 sceneColor = sceneColorTex.Sample(smplr, PSIn.UV);
float3 noiseColor = noiseTex.Sample(smplr, PSIn.UV * noiseTexTiling);
float3 sceneColor = sceneColorTex.Sample(smplr, PSIn.UV).xyz;
float3 noiseColor = noiseTex.Sample(smplr, PSIn.UV * noiseTexTiling).xyz;

// Gradient for mask
float3 gradient = lerp(gradientStart, gradientEnd, PSIn.UV.y);
float4 gradientApplied = float4(lerp(sceneColor, sceneColor + gradient, gradientAmount), 1.0f);

// Noise
float3 luma = RgbToLuma(gradientApplied);
float3 luma = RgbToLuma(gradientApplied.xyz);
float3 noiseApplied = lerp(sceneColor, sceneColor + noiseColor, (1-luma.r) * noiseTexAmount);

PSOut.Color = float4(noiseApplied, 1.0f);
Expand Down
10 changes: 5 additions & 5 deletions resources/shaders/source/PPOutline.psh
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ float SampleNormalizeDepth(Texture2D tex, SamplerState smplr, float2 uv)
{
float rawDepth = tex.Sample(smplr, uv).r;
float3 ndc = float3(uv * 2.0 - 1.0, rawDepth);
float4 view = cameraInvProjection * float4(ndc, 1.0);
float4 view = mul(float4(ndc, 1.0), cameraInvProjection);
view.xyz /= view.w;
float linearDepth = -view.z;
return (linearDepth - nearClip) / (farClip - nearClip);
Expand Down Expand Up @@ -64,10 +64,10 @@ float OutlineDepth(Texture2D depthTex, float viewDirDepthOffset, SamplerState sm
float OutlineNormals(Texture2D normalsTex, float intensity, SamplerState smplr, float2 LLUV, float2 URUV, float2 LRUV, float2 ULUV)
{
// Sample normals texture at four corners
float3 normalsLL = normalsTex.Sample(smplr, LLUV);
float3 normalsUR = normalsTex.Sample(smplr, URUV);
float3 normalsLR = normalsTex.Sample(smplr, LRUV);
float3 normalsUL = normalsTex.Sample(smplr, ULUV);
float3 normalsLL = normalsTex.Sample(smplr, LLUV).xyz;
float3 normalsUR = normalsTex.Sample(smplr, URUV).xyz;
float3 normalsLR = normalsTex.Sample(smplr, LRUV).xyz;
float3 normalsUL = normalsTex.Sample(smplr, ULUV).xyz;

// Get the difference between the diagonals
float3 normalsDiagDif0 = (normalsUR - normalsLL) * intensity;
Expand Down
8 changes: 4 additions & 4 deletions resources/shaders/source/Particle.psh
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
struct PSInput
{
float4 Pos : SV_POSITION;
float2 UV : TEX_COORD;
float4 Color;
uint TextureIndex;
float4 Pos : SV_POSITION;
float2 UV : TEX_COORD;
float4 Color : COLOR;
uint TextureIndex : TEX_INDEX;
};

struct PSOutput
Expand Down
8 changes: 4 additions & 4 deletions resources/shaders/source/Particle.vsh
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@

struct VSInput
{
float3 Pos : ATTRIB0;
float2 UV : ATTRIB1;
float3 Pos : POSITION;
float2 UV : TEXCOORD0;
};

struct PSOutput
{
float4 Pos : SV_POSITION;
float2 UV : TEX_COORD;
float4 Color;
uint TextureIndex;
float4 Color : COLOR;
uint TextureIndex : TEX_INDEX;
};

StructuredBuffer<ParticleData> Particles;
Expand Down
4 changes: 2 additions & 2 deletions resources/shaders/source/PointShadowMap.psh
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

struct PSInput
{
float4 Pos : SV_POSITION;
float4 WorldPos;
float4 Pos : SV_POSITION;
float4 WorldPos : WORLD_POS;
};

struct PSOutput
Expand Down
6 changes: 3 additions & 3 deletions resources/shaders/source/PointShadowMap.vsh
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@

struct VSInput
{
float3 Pos : ATTRIB0;
float3 Pos : ATTRIB0;
};

struct PSInput
{
float4 Pos : SV_POSITION;
float4 WorldPos;
float4 Pos : SV_POSITION;
float4 WorldPos : WORLD_POS;
};

StructuredBuffer<TransformData> Transforms;
Expand Down
4 changes: 2 additions & 2 deletions resources/shaders/source/PointShadowMapSkinned.vsh
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ struct VSInput

struct PSInput
{
float4 Pos : SV_POSITION;
float4 WorldPos;
float4 Pos : SV_POSITION;
float4 WorldPos : WORLD_POS;
};

StructuredBuffer<TransformData> Transforms;
Expand Down
4 changes: 2 additions & 2 deletions resources/shaders/source/Skybox.psh
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ SamplerState Textures_sampler; // By convention, texture samplers must use the

struct PSInput
{
float4 Pos : SV_POSITION;
float3 UVW;
float4 Pos : SV_POSITION;
float3 UVW : U_V_W;
};

struct PSOutput
Expand Down
4 changes: 2 additions & 2 deletions resources/shaders/source/Skybox.vsh
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ struct VSInput

struct PSInput
{
float4 Pos : SV_POSITION;
float3 UVW;
float4 Pos : SV_POSITION;
float3 UVW : U_V_W;
};

static float4x4 localModelMatrix = float4x4(
Expand Down
30 changes: 15 additions & 15 deletions resources/shaders/source/Toon.psh
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ struct PSInput
float4 Pos : SV_POSITION;
float3 Normal : NORMAL;
float2 UV : TEX_COORD;
uint MaterialIndex;
float4 WorldPos;
float3 LocalPos;
float3 ViewDir;
uint MaterialIndex : MAT_INDEX;
float4 WorldPos : WORLD_POS;
float3 LocalPos : LOCAL_POS;
float3 ViewDir : VIEW_DIR;
};

struct PSOutput
Expand All @@ -22,8 +22,6 @@ SamplerState Textures_sampler; // By convention, texture samplers must use the

StructuredBuffer<MaterialData> Materials : register(t1);

const float Epsilon = 1e-10;

float Band(float lightAmount)
{
if (lightAmount * 100 < 0.05f)
Expand All @@ -39,8 +37,8 @@ void main(in PSInput PSIn, out PSOutput PSOut)
MaterialData material = Materials[PSIn.MaterialIndex];

// Get texture colors
uint TexIndex = material.diffuseTexIndex;
uint NormalIndex = material.normalTexIndex;
uint TexIndex = NonUniformResourceIndex(material.diffuseTexIndex);
uint NormalIndex = NonUniformResourceIndex(material.normalTexIndex);
float4 Diffuse = Textures[TexIndex].Sample(Textures_sampler, PSIn.UV);
float4 Normals = Textures[NormalIndex].Sample(Textures_sampler, PSIn.UV);

Expand Down Expand Up @@ -83,7 +81,7 @@ void main(in PSInput PSIn, out PSOutput PSOut)
float3 normals = PSIn.Normal;
if (material.useTextureNormals)
{
normals = normalize(Normals.xyz * float3(2.0) - float3(1.0));
normals = normalize(Normals.xyz * float3(2.0, 2.0, 2.0) - float3(1.0, 1.0, 1.0));
}

float3 result = 0.0f;
Expand Down Expand Up @@ -112,27 +110,29 @@ void main(in PSInput PSIn, out PSOutput PSOut)

// Calculate shadow factor
float shadowFactor = 1.0f;
TextureCube pointDepthTex;
Texture2D uniDepthTex;
if (Lights[i].castsShadows)
{
if (Lights[i].type == 1)
{
TextureCube depthTex = PointShadowMapSinks[pointShadowMapIndex];
float rawShadow = PointShadowCalculation(PSIn.WorldPos, Lights[i].position, depthTex, PSIn.Normal);
pointDepthTex = PointShadowMapSinks[pointShadowMapIndex];
float rawShadow = PointShadowCalculation(PSIn.WorldPos, Lights[i].position, pointDepthTex, PSIn.Normal);
shadowFactor += (rawShadow);
pointShadowMapIndex++;
}
else
{
Texture2D depthTex = UniShadowMapSinks[uniShadowMapIndex];
float rawShadow = UniShadowCalculation(Lights[i].type == 0, mul(mul(PSIn.WorldPos, LightMatrices[Lights[i].lightMatrixIndex].viewProjection), biasMat), depthTex);
uniDepthTex = UniShadowMapSinks[uniShadowMapIndex];
float rawShadow = UniShadowCalculation(Lights[i].type == 0, mul(mul(PSIn.WorldPos, LightMatrices[Lights[i].lightMatrixIndex].viewProjection), biasMat), uniDepthTex);
shadowFactor += (rawShadow);
uniShadowMapIndex++;
}
}

shadowFactor = min((1-shadowFactor) + 1.0f, 1.0f);
diffuseAmt = max(diffuseAmt * shadowFactor, 0.0f);
specularAmt = max(diffuseAmt * shadowFactor, 0.0f);
specularAmt = max(specularAmt * shadowFactor, 0.0f);

// Apply lighting influences and shadows
result += ((diffuseAmt * influence.diffuseColor * color.rgb) + (specularAmt * influence.specularColor * color.rgb ));
Expand All @@ -142,7 +142,7 @@ void main(in PSInput PSIn, out PSOutput PSOut)
if (material.useHatchTexture)
{
// Get hatching texture and tiling property
uint hatchTexIndex = material.hatchTexIndex;
uint hatchTexIndex = NonUniformResourceIndex(material.hatchTexIndex);
float hatchTiling = material.hatchTiling;
float hatchLight = Textures[hatchTexIndex].Sample(Textures_sampler, PSIn.UV * hatchTiling).r;
float hatchMedium = Textures[hatchTexIndex].Sample(Textures_sampler, PSIn.UV * hatchTiling).g;
Expand Down
8 changes: 4 additions & 4 deletions resources/shaders/source/Toon.vsh
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ struct PSInput
float4 Pos : SV_POSITION;
float3 Normal : NORMAL;
float2 UV : TEX_COORD;
uint MaterialIndex;
float4 WorldPos;
float3 LocalPos;
uint MaterialIndex : MAT_INDEX;
float4 WorldPos : WORLD_POS;
float3 LocalPos : LOCAL_POS;
};

StructuredBuffer<TransformData> Transforms;
Expand All @@ -28,7 +28,7 @@ void main(in VSInput VSIn, uint InstanceID : SV_InstanceID, out PSInput PSIn)
float4 TransformedPos = mul(float4(VSIn.Pos, 1.0), Transforms[transformIndex].model);
PSIn.Pos = mul(TransformedPos, cameraViewProjection);
PSIn.UV = VSIn.UV;
PSIn.Normal = normalize( mul(float4(VSIn.Normal, 0.0), Transforms[transformIndex].model));
PSIn.Normal = normalize( mul(float4(VSIn.Normal, 0.0), Transforms[transformIndex].model)).xyz;
PSIn.WorldPos = TransformedPos;
PSIn.LocalPos = VSIn.Pos.xyz;
PSIn.MaterialIndex = materialIndex;
Expand Down
Loading