Graphics: Update material shaders
This commit is contained in:
parent
3b61face6f
commit
b7aca4b22a
|
|
@ -89,6 +89,10 @@ namespace Nz
|
||||||
#include <Nazara/Graphics/Resources/Shaders/Modules/Math/CookTorrancePBR.nzslb.h>
|
#include <Nazara/Graphics/Resources/Shaders/Modules/Math/CookTorrancePBR.nzslb.h>
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const UInt8 r_mathDepthModule[] = {
|
||||||
|
#include <Nazara/Graphics/Resources/Shaders/Modules/Math/Depth.nzslb.h>
|
||||||
|
};
|
||||||
|
|
||||||
// Passes
|
// Passes
|
||||||
const UInt8 r_gammaCorrectionPass[] = {
|
const UInt8 r_gammaCorrectionPass[] = {
|
||||||
#include <Nazara/Graphics/Resources/Shaders/Passes/GammaCorrection.nzslb.h>
|
#include <Nazara/Graphics/Resources/Shaders/Passes/GammaCorrection.nzslb.h>
|
||||||
|
|
@ -487,6 +491,7 @@ namespace Nz
|
||||||
RegisterEmbedShaderModule(r_mathColorModule);
|
RegisterEmbedShaderModule(r_mathColorModule);
|
||||||
RegisterEmbedShaderModule(r_mathConstantsModule);
|
RegisterEmbedShaderModule(r_mathConstantsModule);
|
||||||
RegisterEmbedShaderModule(r_mathCookTorrancePBRModule);
|
RegisterEmbedShaderModule(r_mathCookTorrancePBRModule);
|
||||||
|
RegisterEmbedShaderModule(r_mathDepthModule);
|
||||||
RegisterEmbedShaderModule(r_phongMaterialShader);
|
RegisterEmbedShaderModule(r_phongMaterialShader);
|
||||||
RegisterEmbedShaderModule(r_physicallyBasedMaterialShader);
|
RegisterEmbedShaderModule(r_physicallyBasedMaterialShader);
|
||||||
RegisterEmbedShaderModule(r_skinningDataModule);
|
RegisterEmbedShaderModule(r_skinningDataModule);
|
||||||
|
|
|
||||||
|
|
@ -72,7 +72,7 @@ external
|
||||||
[tag("SkeletalData")] skeletalData: uniform[SkeletalData]
|
[tag("SkeletalData")] skeletalData: uniform[SkeletalData]
|
||||||
}
|
}
|
||||||
|
|
||||||
struct VertToFrag
|
struct VertOut
|
||||||
{
|
{
|
||||||
[location(0)] worldPos: vec3[f32],
|
[location(0)] worldPos: vec3[f32],
|
||||||
[location(1), cond(HasUV)] uv: vec2[f32],
|
[location(1), cond(HasUV)] uv: vec2[f32],
|
||||||
|
|
@ -87,7 +87,7 @@ struct FragOut
|
||||||
[builtin(frag_depth), cond(DistanceDepth)] fragdepth: f32
|
[builtin(frag_depth), cond(DistanceDepth)] fragdepth: f32
|
||||||
}
|
}
|
||||||
|
|
||||||
fn ComputeColor(input: VertToFrag) -> vec4[f32]
|
fn ComputeColor(input: VertOut) -> vec4[f32]
|
||||||
{
|
{
|
||||||
let color = settings.BaseColor;
|
let color = settings.BaseColor;
|
||||||
|
|
||||||
|
|
@ -103,19 +103,20 @@ fn ComputeColor(input: VertToFrag) -> vec4[f32]
|
||||||
const if (HasAlphaTexture)
|
const if (HasAlphaTexture)
|
||||||
color.w *= MaterialAlphaMap.Sample(input.uv).x;
|
color.w *= MaterialAlphaMap.Sample(input.uv).x;
|
||||||
|
|
||||||
return color;
|
|
||||||
}
|
|
||||||
|
|
||||||
[entry(frag), cond(!DepthPass || AlphaTest)]
|
|
||||||
fn main(input: VertToFrag) -> FragOut
|
|
||||||
{
|
|
||||||
let color = ComputeColor(input);
|
|
||||||
const if (AlphaTest)
|
const if (AlphaTest)
|
||||||
{
|
{
|
||||||
if (color.w < settings.AlphaThreshold)
|
if (color.w < settings.AlphaThreshold)
|
||||||
discard;
|
discard;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return color;
|
||||||
|
}
|
||||||
|
|
||||||
|
[entry(frag), cond(!DepthPass || AlphaTest)]
|
||||||
|
fn FragMain(input: VertOut) -> FragOut
|
||||||
|
{
|
||||||
|
let color = ComputeColor(input);
|
||||||
|
|
||||||
let output: FragOut;
|
let output: FragOut;
|
||||||
output.RenderTarget0 = color;
|
output.RenderTarget0 = color;
|
||||||
return output;
|
return output;
|
||||||
|
|
@ -124,14 +125,9 @@ fn main(input: VertToFrag) -> FragOut
|
||||||
// Shadow passes entries
|
// Shadow passes entries
|
||||||
[entry(frag), cond(DepthPass && DistanceDepth)]
|
[entry(frag), cond(DepthPass && DistanceDepth)]
|
||||||
[depth_write(replace)]
|
[depth_write(replace)]
|
||||||
fn main(input: VertToFrag) -> FragOut
|
fn FragDepthDist(input: VertOut) -> FragOut
|
||||||
{
|
{
|
||||||
let color = ComputeColor(input);
|
let color = ComputeColor(input);
|
||||||
const if (AlphaTest)
|
|
||||||
{
|
|
||||||
if (color.w < settings.AlphaThreshold)
|
|
||||||
discard;
|
|
||||||
}
|
|
||||||
|
|
||||||
let output: FragOut;
|
let output: FragOut;
|
||||||
output.RenderTarget0 = color;
|
output.RenderTarget0 = color;
|
||||||
|
|
@ -143,11 +139,9 @@ fn main(input: VertToFrag) -> FragOut
|
||||||
}
|
}
|
||||||
|
|
||||||
[entry(frag), cond(DepthPass && AlphaTest && !DistanceDepth)]
|
[entry(frag), cond(DepthPass && AlphaTest && !DistanceDepth)]
|
||||||
fn main(input: VertToFrag) -> FragOut
|
fn FragDepth(input: VertOut) -> FragOut
|
||||||
{
|
{
|
||||||
let color = ComputeColor(input);
|
let color = ComputeColor(input);
|
||||||
if (color.w < settings.AlphaThreshold)
|
|
||||||
discard;
|
|
||||||
|
|
||||||
let output: FragOut;
|
let output: FragOut;
|
||||||
output.RenderTarget0 = color;
|
output.RenderTarget0 = color;
|
||||||
|
|
@ -155,7 +149,7 @@ fn main(input: VertToFrag) -> FragOut
|
||||||
}
|
}
|
||||||
|
|
||||||
[entry(frag), cond(DepthPass && !AlphaTest && !DistanceDepth)]
|
[entry(frag), cond(DepthPass && !AlphaTest && !DistanceDepth)]
|
||||||
fn main() {} //< dummy
|
fn FragDepthNoAlpha() {} //< dummy
|
||||||
|
|
||||||
// Vertex stage
|
// Vertex stage
|
||||||
struct VertIn
|
struct VertIn
|
||||||
|
|
@ -189,7 +183,7 @@ struct VertIn
|
||||||
}
|
}
|
||||||
|
|
||||||
[entry(vert), cond(Billboard)]
|
[entry(vert), cond(Billboard)]
|
||||||
fn billboardMain(input: VertIn) -> VertToFrag
|
fn VertBillboard(input: VertIn) -> VertOut
|
||||||
{
|
{
|
||||||
let size = input.billboardSizeRot.xy;
|
let size = input.billboardSizeRot.xy;
|
||||||
let sinCos = input.billboardSizeRot.zw;
|
let sinCos = input.billboardSizeRot.zw;
|
||||||
|
|
@ -209,7 +203,7 @@ fn billboardMain(input: VertIn) -> VertToFrag
|
||||||
|
|
||||||
let worldPosition = instanceData.worldMatrix * vec4[f32](vertexPos, 1.0);
|
let worldPosition = instanceData.worldMatrix * vec4[f32](vertexPos, 1.0);
|
||||||
|
|
||||||
let output: VertToFrag;
|
let output: VertOut;
|
||||||
output.worldPos = worldPosition.xyz;
|
output.worldPos = worldPosition.xyz;
|
||||||
output.position = viewerData.viewProjMatrix * worldPosition;
|
output.position = viewerData.viewProjMatrix * worldPosition;
|
||||||
|
|
||||||
|
|
@ -223,7 +217,7 @@ fn billboardMain(input: VertIn) -> VertToFrag
|
||||||
}
|
}
|
||||||
|
|
||||||
[entry(vert), cond(!Billboard)]
|
[entry(vert), cond(!Billboard)]
|
||||||
fn main(input: VertIn) -> VertToFrag
|
fn VertMain(input: VertIn) -> VertOut
|
||||||
{
|
{
|
||||||
let pos: vec3[f32];
|
let pos: vec3[f32];
|
||||||
|
|
||||||
|
|
@ -251,7 +245,7 @@ fn main(input: VertIn) -> VertToFrag
|
||||||
|
|
||||||
let worldPosition = instanceData.worldMatrix * vec4[f32](pos, 1.0);
|
let worldPosition = instanceData.worldMatrix * vec4[f32](pos, 1.0);
|
||||||
|
|
||||||
let output: VertToFrag;
|
let output: VertOut;
|
||||||
output.worldPos = worldPosition.xyz;
|
output.worldPos = worldPosition.xyz;
|
||||||
output.position = viewerData.viewProjMatrix * worldPosition;
|
output.position = viewerData.viewProjMatrix * worldPosition;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,8 @@
|
||||||
|
[nzsl_version("1.0")]
|
||||||
|
module Math.Depth;
|
||||||
|
|
||||||
|
[export]
|
||||||
|
fn LinearizeDepth(depth: f32, zNear: f32, zFar: f32) -> f32
|
||||||
|
{
|
||||||
|
return zNear * zFar / (zFar + depth * (zNear - zFar));
|
||||||
|
}
|
||||||
|
|
@ -111,7 +111,7 @@ external
|
||||||
[tag("ShadowMapsSpot")] shadowMapsSpot: array[depth_sampler2D[f32], MaxLightCount],
|
[tag("ShadowMapsSpot")] shadowMapsSpot: array[depth_sampler2D[f32], MaxLightCount],
|
||||||
}
|
}
|
||||||
|
|
||||||
struct VertToFrag
|
struct VertOut
|
||||||
{
|
{
|
||||||
[location(0)] worldPos: vec3[f32],
|
[location(0)] worldPos: vec3[f32],
|
||||||
[location(1), cond(HasUV)] uv: vec2[f32],
|
[location(1), cond(HasUV)] uv: vec2[f32],
|
||||||
|
|
@ -129,21 +129,7 @@ struct FragOut
|
||||||
[builtin(frag_depth), cond(DistanceDepth)] fragdepth: f32,
|
[builtin(frag_depth), cond(DistanceDepth)] fragdepth: f32,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn LinearizeDepth(depth: f32, zNear: f32, zFar: f32) -> f32
|
fn ComputeColor(input: VertOut) -> vec4[f32]
|
||||||
{
|
|
||||||
return zNear * zFar / (zFar + depth * (zNear - zFar));
|
|
||||||
}
|
|
||||||
|
|
||||||
// http://the-witness.net/news/2013/09/shadow-mapping-summary-part-1/
|
|
||||||
fn GetSlopeScaledBias(normal: vec3[f32], lightDir: vec3[f32]) -> f32
|
|
||||||
{
|
|
||||||
let cosAlpha = clamp(dot(normal, lightDir), 0.0, 1.0);
|
|
||||||
let sinAlpha = sqrt(1.0 - cosAlpha * cosAlpha); // sin(acos(L*N))
|
|
||||||
let tanAlpha = sinAlpha / cosAlpha; // tan(acos(L*N))
|
|
||||||
return tanAlpha;
|
|
||||||
}
|
|
||||||
|
|
||||||
fn ComputeColor(input: VertToFrag) -> vec4[f32]
|
|
||||||
{
|
{
|
||||||
let color = settings.BaseColor;
|
let color = settings.BaseColor;
|
||||||
|
|
||||||
|
|
@ -159,21 +145,18 @@ fn ComputeColor(input: VertToFrag) -> vec4[f32]
|
||||||
const if (HasAlphaTexture)
|
const if (HasAlphaTexture)
|
||||||
color.w *= MaterialAlphaMap.Sample(input.uv).x;
|
color.w *= MaterialAlphaMap.Sample(input.uv).x;
|
||||||
|
|
||||||
return color;
|
|
||||||
}
|
|
||||||
|
|
||||||
[entry(frag), cond(!DepthPass)]
|
|
||||||
fn main(input: VertToFrag) -> FragOut
|
|
||||||
{
|
|
||||||
let color = ComputeColor(input);
|
|
||||||
const if (AlphaTest)
|
const if (AlphaTest)
|
||||||
{
|
{
|
||||||
if (color.w < settings.AlphaThreshold)
|
if (color.w < settings.AlphaThreshold)
|
||||||
discard;
|
discard;
|
||||||
}
|
}
|
||||||
|
|
||||||
const if (HasLighting)
|
return color;
|
||||||
{
|
}
|
||||||
|
|
||||||
|
[cond(HasLighting)]
|
||||||
|
fn ComputeLighting(color: vec3[f32], input: VertOut) -> vec3[f32]
|
||||||
|
{
|
||||||
let lightAmbient = vec3[f32](0.0, 0.0, 0.0);
|
let lightAmbient = vec3[f32](0.0, 0.0, 0.0);
|
||||||
let lightDiffuse = vec3[f32](0.0, 0.0, 0.0);
|
let lightDiffuse = vec3[f32](0.0, 0.0, 0.0);
|
||||||
let lightSpecular = vec3[f32](0.0, 0.0, 0.0);
|
let lightSpecular = vec3[f32](0.0, 0.0, 0.0);
|
||||||
|
|
@ -265,9 +248,16 @@ fn main(input: VertToFrag) -> FragOut
|
||||||
lightSpecular *= MaterialSpecularMap.Sample(input.uv).rgb;
|
lightSpecular *= MaterialSpecularMap.Sample(input.uv).rgb;
|
||||||
|
|
||||||
let lightColor = lightAmbient + lightDiffuse + lightSpecular;
|
let lightColor = lightAmbient + lightDiffuse + lightSpecular;
|
||||||
|
return color * lightColor;
|
||||||
|
}
|
||||||
|
|
||||||
color.rgb *= lightColor;
|
[entry(frag), cond(!DepthPass)]
|
||||||
}
|
fn FragMain(input: VertOut) -> FragOut
|
||||||
|
{
|
||||||
|
let color = ComputeColor(input);
|
||||||
|
|
||||||
|
const if (HasLighting)
|
||||||
|
color.rgb = ComputeLighting(color.rgb, input);
|
||||||
|
|
||||||
let output: FragOut;
|
let output: FragOut;
|
||||||
output.RenderTarget0 = color;
|
output.RenderTarget0 = color;
|
||||||
|
|
@ -278,14 +268,9 @@ fn main(input: VertToFrag) -> FragOut
|
||||||
// Shadow passes entries
|
// Shadow passes entries
|
||||||
[entry(frag), cond(DepthPass && DistanceDepth)]
|
[entry(frag), cond(DepthPass && DistanceDepth)]
|
||||||
[depth_write(replace)]
|
[depth_write(replace)]
|
||||||
fn main(input: VertToFrag) -> FragOut
|
fn FragDepthDist(input: VertOut) -> FragOut
|
||||||
{
|
{
|
||||||
let color = ComputeColor(input);
|
let color = ComputeColor(input);
|
||||||
const if (AlphaTest)
|
|
||||||
{
|
|
||||||
if (color.w < settings.AlphaThreshold)
|
|
||||||
discard;
|
|
||||||
}
|
|
||||||
|
|
||||||
let output: FragOut;
|
let output: FragOut;
|
||||||
output.RenderTarget0 = color;
|
output.RenderTarget0 = color;
|
||||||
|
|
@ -297,11 +282,9 @@ fn main(input: VertToFrag) -> FragOut
|
||||||
}
|
}
|
||||||
|
|
||||||
[entry(frag), cond(DepthPass && AlphaTest && !DistanceDepth)]
|
[entry(frag), cond(DepthPass && AlphaTest && !DistanceDepth)]
|
||||||
fn main(input: VertToFrag) -> FragOut
|
fn FragDepth(input: VertOut) -> FragOut
|
||||||
{
|
{
|
||||||
let color = ComputeColor(input);
|
let color = ComputeColor(input);
|
||||||
if (color.w < settings.AlphaThreshold)
|
|
||||||
discard;
|
|
||||||
|
|
||||||
let output: FragOut;
|
let output: FragOut;
|
||||||
output.RenderTarget0 = color;
|
output.RenderTarget0 = color;
|
||||||
|
|
@ -309,7 +292,7 @@ fn main(input: VertToFrag) -> FragOut
|
||||||
}
|
}
|
||||||
|
|
||||||
[entry(frag), cond(DepthPass && !AlphaTest && !DistanceDepth)]
|
[entry(frag), cond(DepthPass && !AlphaTest && !DistanceDepth)]
|
||||||
fn main() {} //< dummy
|
fn FragDepthNoAlpha() {} //< dummy
|
||||||
|
|
||||||
// Vertex stage
|
// Vertex stage
|
||||||
struct VertIn
|
struct VertIn
|
||||||
|
|
@ -346,7 +329,7 @@ struct VertIn
|
||||||
}
|
}
|
||||||
|
|
||||||
[entry(vert), cond(Billboard)]
|
[entry(vert), cond(Billboard)]
|
||||||
fn billboardMain(input: VertIn) -> VertToFrag
|
fn billboardMain(input: VertIn) -> VertOut
|
||||||
{
|
{
|
||||||
let size = input.billboardSizeRot.xy;
|
let size = input.billboardSizeRot.xy;
|
||||||
let sinCos = input.billboardSizeRot.zw;
|
let sinCos = input.billboardSizeRot.zw;
|
||||||
|
|
@ -364,7 +347,7 @@ fn billboardMain(input: VertIn) -> VertToFrag
|
||||||
vertexPos += cameraRight * rotatedPosition.x;
|
vertexPos += cameraRight * rotatedPosition.x;
|
||||||
vertexPos += cameraUp * rotatedPosition.y;
|
vertexPos += cameraUp * rotatedPosition.y;
|
||||||
|
|
||||||
let output: VertToFrag;
|
let output: VertOut;
|
||||||
output.position = viewerData.viewProjMatrix * instanceData.worldMatrix * vec4[f32](vertexPos, 1.0);
|
output.position = viewerData.viewProjMatrix * instanceData.worldMatrix * vec4[f32](vertexPos, 1.0);
|
||||||
|
|
||||||
const if (HasColor)
|
const if (HasColor)
|
||||||
|
|
@ -377,7 +360,7 @@ fn billboardMain(input: VertIn) -> VertToFrag
|
||||||
}
|
}
|
||||||
|
|
||||||
[entry(vert), cond(!Billboard)]
|
[entry(vert), cond(!Billboard)]
|
||||||
fn main(input: VertIn) -> VertToFrag
|
fn main(input: VertIn) -> VertOut
|
||||||
{
|
{
|
||||||
let pos: vec3[f32];
|
let pos: vec3[f32];
|
||||||
const if (HasNormal) let normal: vec3[f32];
|
const if (HasNormal) let normal: vec3[f32];
|
||||||
|
|
@ -419,7 +402,7 @@ fn main(input: VertIn) -> VertToFrag
|
||||||
|
|
||||||
let worldPosition = instanceData.worldMatrix * vec4[f32](pos, 1.0);
|
let worldPosition = instanceData.worldMatrix * vec4[f32](pos, 1.0);
|
||||||
|
|
||||||
let output: VertToFrag;
|
let output: VertOut;
|
||||||
output.worldPos = worldPosition.xyz;
|
output.worldPos = worldPosition.xyz;
|
||||||
output.position = viewerData.viewProjMatrix * worldPosition;
|
output.position = viewerData.viewProjMatrix * worldPosition;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -104,7 +104,8 @@ external
|
||||||
[tag("ShadowMapsSpot")] shadowMapsSpot: array[depth_sampler2D[f32], MaxLightCount],
|
[tag("ShadowMapsSpot")] shadowMapsSpot: array[depth_sampler2D[f32], MaxLightCount],
|
||||||
}
|
}
|
||||||
|
|
||||||
struct VertToFrag
|
[export]
|
||||||
|
struct VertOut
|
||||||
{
|
{
|
||||||
[location(0)] worldPos: vec3[f32],
|
[location(0)] worldPos: vec3[f32],
|
||||||
[location(1), cond(HasUV)] uv: vec2[f32],
|
[location(1), cond(HasUV)] uv: vec2[f32],
|
||||||
|
|
@ -124,7 +125,8 @@ struct FragOut
|
||||||
[builtin(frag_depth), cond(DistanceDepth)] fragdepth: f32,
|
[builtin(frag_depth), cond(DistanceDepth)] fragdepth: f32,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn ComputeColor(input: VertToFrag) -> vec4[f32]
|
[export]
|
||||||
|
fn ComputeColor(input: VertOut) -> vec4[f32]
|
||||||
{
|
{
|
||||||
let color = settings.BaseColor;
|
let color = settings.BaseColor;
|
||||||
|
|
||||||
|
|
@ -140,21 +142,18 @@ fn ComputeColor(input: VertToFrag) -> vec4[f32]
|
||||||
const if (HasAlphaTexture)
|
const if (HasAlphaTexture)
|
||||||
color.w *= MaterialAlphaMap.Sample(input.uv).x;
|
color.w *= MaterialAlphaMap.Sample(input.uv).x;
|
||||||
|
|
||||||
return color;
|
|
||||||
}
|
|
||||||
|
|
||||||
[entry(frag), cond(!DepthPass)]
|
|
||||||
fn main(input: VertToFrag) -> FragOut
|
|
||||||
{
|
|
||||||
let color = ComputeColor(input);
|
|
||||||
const if (AlphaTest)
|
const if (AlphaTest)
|
||||||
{
|
{
|
||||||
if (color.w < settings.AlphaThreshold)
|
if (color.w < settings.AlphaThreshold)
|
||||||
discard;
|
discard;
|
||||||
}
|
}
|
||||||
|
|
||||||
const if (HasNormal && !DepthPass)
|
return color;
|
||||||
{
|
}
|
||||||
|
|
||||||
|
[export, cond(HasNormal)]
|
||||||
|
fn ComputeLighting(color: vec3[f32], input: VertOut) -> vec3[f32]
|
||||||
|
{
|
||||||
let lightRadiance = vec3[f32](0.0, 0.0, 0.0);
|
let lightRadiance = vec3[f32](0.0, 0.0, 0.0);
|
||||||
|
|
||||||
let eyeVec = normalize(viewerData.eyePosition - input.worldPos);
|
let eyeVec = normalize(viewerData.eyePosition - input.worldPos);
|
||||||
|
|
@ -243,33 +242,32 @@ fn main(input: VertToFrag) -> FragOut
|
||||||
|
|
||||||
let ambient = (0.0001).rrr * albedo;
|
let ambient = (0.0001).rrr * albedo;
|
||||||
|
|
||||||
let color = ambient + lightRadiance * color.rgb;
|
let finalColor = ambient + lightRadiance * color;
|
||||||
color = color / (color + vec3[f32](1.0, 1.0, 1.0));
|
finalColor = finalColor / (finalColor + vec3[f32](1.0, 1.0, 1.0));
|
||||||
color = pow(color, (1.0 / 2.2).xxx);
|
finalColor = pow(finalColor, (1.0 / 2.2).xxx); //< WTF?
|
||||||
|
|
||||||
|
return finalColor;
|
||||||
|
}
|
||||||
|
|
||||||
|
[export, entry(frag), cond(!DepthPass)]
|
||||||
|
fn FragMain(input: VertOut) -> FragOut
|
||||||
|
{
|
||||||
|
let color = ComputeColor(input);
|
||||||
|
|
||||||
|
const if (HasNormal)
|
||||||
|
color.rgb = ComputeLighting(color.rgb, input);
|
||||||
|
|
||||||
let output: FragOut;
|
|
||||||
output.RenderTarget0 = vec4[f32](color, 1.0);
|
|
||||||
return output;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
let output: FragOut;
|
let output: FragOut;
|
||||||
output.RenderTarget0 = color;
|
output.RenderTarget0 = color;
|
||||||
return output;
|
return output;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Shadow passes entries
|
// Shadow passes entries
|
||||||
[entry(frag), cond(DepthPass && DistanceDepth)]
|
[entry(frag), cond(DepthPass && DistanceDepth)]
|
||||||
[depth_write(replace)]
|
[depth_write(replace)]
|
||||||
fn main(input: VertToFrag) -> FragOut
|
fn FragDepthDist(input: VertOut) -> FragOut
|
||||||
{
|
{
|
||||||
let color = ComputeColor(input);
|
let color = ComputeColor(input);
|
||||||
const if (AlphaTest)
|
|
||||||
{
|
|
||||||
if (color.w < settings.AlphaThreshold)
|
|
||||||
discard;
|
|
||||||
}
|
|
||||||
|
|
||||||
let output: FragOut;
|
let output: FragOut;
|
||||||
output.RenderTarget0 = color;
|
output.RenderTarget0 = color;
|
||||||
|
|
@ -281,11 +279,9 @@ fn main(input: VertToFrag) -> FragOut
|
||||||
}
|
}
|
||||||
|
|
||||||
[entry(frag), cond(DepthPass && AlphaTest && !DistanceDepth)]
|
[entry(frag), cond(DepthPass && AlphaTest && !DistanceDepth)]
|
||||||
fn main(input: VertToFrag) -> FragOut
|
fn FragDepth(input: VertOut) -> FragOut
|
||||||
{
|
{
|
||||||
let color = ComputeColor(input);
|
let color = ComputeColor(input);
|
||||||
if (color.w < settings.AlphaThreshold)
|
|
||||||
discard;
|
|
||||||
|
|
||||||
let output: FragOut;
|
let output: FragOut;
|
||||||
output.RenderTarget0 = color;
|
output.RenderTarget0 = color;
|
||||||
|
|
@ -293,7 +289,7 @@ fn main(input: VertToFrag) -> FragOut
|
||||||
}
|
}
|
||||||
|
|
||||||
[entry(frag), cond(DepthPass && !AlphaTest && !DistanceDepth)]
|
[entry(frag), cond(DepthPass && !AlphaTest && !DistanceDepth)]
|
||||||
fn main() {} //< dummy
|
fn FragDepthNoAlpha() {} //< dummy
|
||||||
|
|
||||||
// Vertex stage
|
// Vertex stage
|
||||||
struct VertIn
|
struct VertIn
|
||||||
|
|
@ -330,7 +326,7 @@ struct VertIn
|
||||||
}
|
}
|
||||||
|
|
||||||
[entry(vert), cond(Billboard)]
|
[entry(vert), cond(Billboard)]
|
||||||
fn billboardMain(input: VertIn) -> VertToFrag
|
fn VertBillboard(input: VertIn) -> VertOut
|
||||||
{
|
{
|
||||||
let size = input.billboardSizeRot.xy;
|
let size = input.billboardSizeRot.xy;
|
||||||
let sinCos = input.billboardSizeRot.zw;
|
let sinCos = input.billboardSizeRot.zw;
|
||||||
|
|
@ -348,7 +344,7 @@ fn billboardMain(input: VertIn) -> VertToFrag
|
||||||
vertexPos += cameraRight * rotatedPosition.x;
|
vertexPos += cameraRight * rotatedPosition.x;
|
||||||
vertexPos += cameraUp * rotatedPosition.y;
|
vertexPos += cameraUp * rotatedPosition.y;
|
||||||
|
|
||||||
let output: VertToFrag;
|
let output: VertOut;
|
||||||
output.position = viewerData.viewProjMatrix * instanceData.worldMatrix * vec4[f32](vertexPos, 1.0);
|
output.position = viewerData.viewProjMatrix * instanceData.worldMatrix * vec4[f32](vertexPos, 1.0);
|
||||||
|
|
||||||
const if (HasColor)
|
const if (HasColor)
|
||||||
|
|
@ -361,7 +357,7 @@ fn billboardMain(input: VertIn) -> VertToFrag
|
||||||
}
|
}
|
||||||
|
|
||||||
[entry(vert), cond(!Billboard)]
|
[entry(vert), cond(!Billboard)]
|
||||||
fn main(input: VertIn) -> VertToFrag
|
fn VertMain(input: VertIn) -> VertOut
|
||||||
{
|
{
|
||||||
let pos: vec3[f32];
|
let pos: vec3[f32];
|
||||||
const if (HasNormal) let normal: vec3[f32];
|
const if (HasNormal) let normal: vec3[f32];
|
||||||
|
|
@ -403,7 +399,7 @@ fn main(input: VertIn) -> VertToFrag
|
||||||
|
|
||||||
let worldPosition = instanceData.worldMatrix * vec4[f32](pos, 1.0);
|
let worldPosition = instanceData.worldMatrix * vec4[f32](pos, 1.0);
|
||||||
|
|
||||||
let output: VertToFrag;
|
let output: VertOut;
|
||||||
output.worldPos = worldPosition.xyz;
|
output.worldPos = worldPosition.xyz;
|
||||||
output.position = viewerData.viewProjMatrix * worldPosition;
|
output.position = viewerData.viewProjMatrix * worldPosition;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -170,9 +170,11 @@ namespace Nz
|
||||||
m_states = states;
|
m_states = states;
|
||||||
m_states.sanitized = true; //< Shader is always sanitized (because of keywords)
|
m_states.sanitized = true; //< Shader is always sanitized (because of keywords)
|
||||||
|
|
||||||
#ifdef NAZARA_PLATFORM_WEB
|
/*
|
||||||
m_states.optimize = true; //< Always remove unused code with emscripten (prevents errors on draw calls when no buffer is bound on a unused binding)
|
Always remove dead code with OpenGL (prevents errors on draw calls when no buffer is bound on a unused binding),
|
||||||
#endif
|
also prevents compilation failure because of functions using discard in a vertex shader
|
||||||
|
*/
|
||||||
|
m_states.optimize = true;
|
||||||
|
|
||||||
nzsl::Ast::SanitizeVisitor::Options options = nzsl::GlslWriter::GetSanitizeOptions();
|
nzsl::Ast::SanitizeVisitor::Options options = nzsl::GlslWriter::GetSanitizeOptions();
|
||||||
options.optionValues = states.optionValues;
|
options.optionValues = states.optionValues;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue