84 lines
1.7 KiB
Plaintext
84 lines
1.7 KiB
Plaintext
[nzsl_version("1.0")]
|
|
module DepthMaterial;
|
|
|
|
import InstanceData from Engine.InstanceData;
|
|
import ViewerData from Engine.ViewerData;
|
|
|
|
option HasDiffuseTexture: bool = false;
|
|
option HasAlphaTexture: bool = false;
|
|
option AlphaTest: bool = false;
|
|
|
|
const HasUV = AlphaTest && (HasDiffuseTexture || HasAlphaTexture);
|
|
|
|
[layout(std140)]
|
|
struct BasicSettings
|
|
{
|
|
AlphaThreshold: f32,
|
|
DiffuseColor: vec4[f32]
|
|
}
|
|
|
|
external
|
|
{
|
|
[binding(0)] settings: uniform[BasicSettings],
|
|
[binding(1)] MaterialDiffuseMap: sampler2D[f32],
|
|
[binding(2)] MaterialAlphaMap: sampler2D[f32],
|
|
[binding(3)] TextureOverlay: sampler2D[f32],
|
|
[binding(4)] instanceData: uniform[InstanceData],
|
|
[binding(5)] viewerData: uniform[ViewerData],
|
|
}
|
|
|
|
// Fragment stage
|
|
struct FragIn
|
|
{
|
|
[location(0), cond(HasUV)] uv: vec2[f32]
|
|
}
|
|
|
|
[entry(frag), cond(AlphaTest)]
|
|
fn main(input: FragIn)
|
|
{
|
|
let alpha = settings.DiffuseColor.a;
|
|
|
|
const if (HasUV)
|
|
alpha *= TextureOverlay.Sample(input.uv).a;
|
|
|
|
const if (HasDiffuseTexture)
|
|
alpha *= MaterialDiffuseMap.Sample(input.uv).a;
|
|
|
|
const if (HasAlphaTexture)
|
|
alpha *= MaterialAlphaMap.Sample(input.uv).x;
|
|
|
|
if (alpha < settings.AlphaThreshold)
|
|
discard;
|
|
}
|
|
|
|
// Dummy fragment shader (TODO: Add a way to delete stage?)
|
|
[entry(frag), cond(!AlphaTest)]
|
|
fn main() {}
|
|
|
|
// Vertex stage
|
|
struct VertIn
|
|
{
|
|
[location(0)] pos: vec3[f32],
|
|
[location(1), cond(HasUV)] uv: vec2[f32]
|
|
}
|
|
|
|
struct VertOut
|
|
{
|
|
[location(0), cond(HasUV)] uv: vec2[f32],
|
|
[builtin(position)] position: vec4[f32]
|
|
}
|
|
|
|
[entry(vert)]
|
|
fn main(input: VertIn) -> VertOut
|
|
{
|
|
let worldPosition = instanceData.worldMatrix * vec4[f32](input.pos, 1.0);
|
|
|
|
let output: VertOut;
|
|
output.position = viewerData.viewProjMatrix * worldPosition;
|
|
|
|
const if (HasUV)
|
|
output.uv = input.uv;
|
|
|
|
return output;
|
|
}
|