79 lines
1.7 KiB
Plaintext
79 lines
1.7 KiB
Plaintext
option HasDiffuseTexture: bool = false;
|
|
option HasAlphaTexture: bool = false;
|
|
option AlphaTest: bool = false;
|
|
|
|
[layout(std140)]
|
|
struct BasicSettings
|
|
{
|
|
AlphaThreshold: f32,
|
|
DiffuseColor: vec4<f32>
|
|
}
|
|
|
|
[layout(std140)]
|
|
struct InstanceData
|
|
{
|
|
worldMatrix: mat4<f32>,
|
|
invWorldMatrix: mat4<f32>
|
|
}
|
|
|
|
[layout(std140)]
|
|
struct ViewerData
|
|
{
|
|
projectionMatrix: mat4<f32>,
|
|
invProjectionMatrix: mat4<f32>,
|
|
viewMatrix: mat4<f32>,
|
|
invViewMatrix: mat4<f32>,
|
|
viewProjMatrix: mat4<f32>,
|
|
invViewProjMatrix: mat4<f32>,
|
|
renderTargetSize: vec2<f32>,
|
|
invRenderTargetSize: vec2<f32>,
|
|
eyePosition: vec3<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>,
|
|
}
|
|
|
|
struct InputData
|
|
{
|
|
[location(0)] normal: vec3<f32>,
|
|
[location(1)] uv: vec2<f32>,
|
|
[location(2)] pos: vec3<f32>
|
|
}
|
|
|
|
struct OutputData
|
|
{
|
|
[location(0)] diffuseMap: vec4<f32>,
|
|
[location(1)] normalMap: vec4<f32>,
|
|
[location(2)] positionMap: vec4<f32>
|
|
}
|
|
|
|
[entry(frag)]
|
|
fn main(input: InputData) -> OutputData
|
|
{
|
|
let diffuseColor = settings.DiffuseColor;
|
|
const if (HasDiffuseTexture)
|
|
diffuseColor *= MaterialDiffuseMap.Sample(input.uv);
|
|
|
|
const if (HasAlphaTexture)
|
|
diffuseColor.w *= MaterialAlphaMap.Sample(input.uv).x;
|
|
|
|
const if (AlphaTest)
|
|
{
|
|
if (diffuseColor.w < settings.AlphaThreshold)
|
|
discard;
|
|
}
|
|
|
|
let output: OutputData;
|
|
output.diffuseMap = diffuseColor;
|
|
output.normalMap = vec4<f32>((vec3<f32>(1.0, 1.0, 1.0) + input.normal) * 0.5, 1.0);
|
|
output.positionMap = vec4<f32>(input.pos, 1.0);
|
|
return output;
|
|
}
|