Shader: Switch type<subtype> to type[subtype]

This commit is contained in:
Jérôme Leclercq 2022-01-26 19:24:46 +01:00
parent 29a01e975c
commit e6951d54a5
27 changed files with 506 additions and 510 deletions

View File

@ -1,44 +1,44 @@
[layout(std140)] [layout(std140)]
struct ViewerData struct ViewerData
{ {
projectionMatrix: mat4<f32>, projectionMatrix: mat4[f32],
invProjectionMatrix: mat4<f32>, invProjectionMatrix: mat4[f32],
viewMatrix: mat4<f32>, viewMatrix: mat4[f32],
invViewMatrix: mat4<f32>, invViewMatrix: mat4[f32],
viewProjMatrix: mat4<f32>, viewProjMatrix: mat4[f32],
invViewProjMatrix: mat4<f32>, invViewProjMatrix: mat4[f32],
renderTargetSize: vec2<f32>, renderTargetSize: vec2[f32],
invRenderTargetSize: vec2<f32>, invRenderTargetSize: vec2[f32],
eyePosition: vec3<f32> eyePosition: vec3[f32]
} }
external external
{ {
[set(0), binding(0)] viewerData: uniform<ViewerData>, [set(0), binding(0)] viewerData: uniform[ViewerData],
[set(0), binding(1)] colorTexture: sampler2D<f32>, [set(0), binding(1)] colorTexture: sampler2D[f32],
} }
struct FragIn struct FragIn
{ {
[builtin(fragcoord)] fragcoord: vec4<f32>, [builtin(fragcoord)] fragcoord: vec4[f32],
[location(0)] uv: vec2<f32> [location(0)] uv: vec2[f32]
} }
struct FragOut struct FragOut
{ {
[location(0)] color: vec4<f32> [location(0)] color: vec4[f32]
} }
struct VertIn struct VertIn
{ {
[location(0)] pos: vec2<f32>, [location(0)] pos: vec2[f32],
[location(1)] uv: vec2<f32> [location(1)] uv: vec2[f32]
} }
struct VertOut struct VertOut
{ {
[builtin(position)] position: vec4<f32>, [builtin(position)] position: vec4[f32],
[location(0)] uv: vec2<f32> [location(0)] uv: vec2[f32]
} }
[entry(frag)] [entry(frag)]
@ -50,19 +50,19 @@ fn main(input: FragIn) -> FragOut
let color = colorTexture.Sample(input.uv).rgb; let color = colorTexture.Sample(input.uv).rgb;
color *= BrightMiddleGrey / BrightLuminance; color *= BrightMiddleGrey / BrightLuminance;
color *= vec3<f32>(1.0, 1.0, 1.0) + (color / (BrightThreshold*BrightThreshold)); color *= vec3[f32](1.0, 1.0, 1.0) + (color / (BrightThreshold*BrightThreshold));
color -= vec3<f32>(0.5, 0.5, 0.5); color -= vec3[f32](0.5, 0.5, 0.5);
color /= vec3<f32>(1.0, 1.0, 1.0) + color;*/ color /= vec3[f32](1.0, 1.0, 1.0) + color;*/
let output: FragOut; let output: FragOut;
//output.color = vec4<f32>(max(color, vec3<f32>(0.0, 0.0, 0.0)), 1.0); //output.color = vec4[f32](max(color, vec3[f32](0.0, 0.0, 0.0)), 1.0);
let color = colorTexture.Sample(input.uv).rgb; let color = colorTexture.Sample(input.uv).rgb;
let brightness = dot(color, vec3<f32>(0.2126, 0.7152, 0.0722)); let brightness = dot(color, vec3[f32](0.2126, 0.7152, 0.0722));
if (brightness > 1.0) if (brightness > 1.0)
output.color = vec4<f32>(color, 1.0); output.color = vec4[f32](color, 1.0);
else else
output.color = vec4<f32>(0.0, 0.0, 0.0, 1.0); output.color = vec4[f32](0.0, 0.0, 0.0, 1.0);
return output; return output;
} }
@ -71,7 +71,7 @@ fn main(input: FragIn) -> FragOut
fn main(input: VertIn) -> VertOut fn main(input: VertIn) -> VertOut
{ {
let output: VertOut; let output: VertOut;
output.position = vec4<f32>(input.pos, 0.0, 1.0); output.position = vec4[f32](input.pos, 0.0, 1.0);
output.uv = input.uv; output.uv = input.uv;
return output; return output;

View File

@ -1,44 +1,44 @@
[layout(std140)] [layout(std140)]
struct ViewerData struct ViewerData
{ {
projectionMatrix: mat4<f32>, projectionMatrix: mat4[f32],
invProjectionMatrix: mat4<f32>, invProjectionMatrix: mat4[f32],
viewMatrix: mat4<f32>, viewMatrix: mat4[f32],
invViewMatrix: mat4<f32>, invViewMatrix: mat4[f32],
viewProjMatrix: mat4<f32>, viewProjMatrix: mat4[f32],
invViewProjMatrix: mat4<f32>, invViewProjMatrix: mat4[f32],
renderTargetSize: vec2<f32>, renderTargetSize: vec2[f32],
invRenderTargetSize: vec2<f32>, invRenderTargetSize: vec2[f32],
eyePosition: vec3<f32> eyePosition: vec3[f32]
} }
external external
{ {
[set(0), binding(0)] viewerData: uniform<ViewerData>, [set(0), binding(0)] viewerData: uniform[ViewerData],
//[set(0), binding(1)] colorTexture: sampler2D<f32>, //[set(0), binding(1)] colorTexture: sampler2D[f32],
[set(0), binding(2)] bloomTexture: sampler2D<f32>, [set(0), binding(2)] bloomTexture: sampler2D[f32],
} }
struct FragIn struct FragIn
{ {
[location(0)] uv: vec2<f32> [location(0)] uv: vec2[f32]
} }
struct FragOut struct FragOut
{ {
[location(0)] color: vec4<f32> [location(0)] color: vec4[f32]
} }
struct VertIn struct VertIn
{ {
[location(0)] pos: vec2<f32>, [location(0)] pos: vec2[f32],
[location(1)] uv: vec2<f32>, [location(1)] uv: vec2[f32],
} }
struct VertOut struct VertOut
{ {
[location(0)] uv: vec2<f32>, [location(0)] uv: vec2[f32],
[builtin(position)] position: vec4<f32> [builtin(position)] position: vec4[f32]
} }
[entry(frag)] [entry(frag)]
@ -54,7 +54,7 @@ fn main(input: FragIn) -> FragOut
fn main(input: VertIn) -> VertOut fn main(input: VertIn) -> VertOut
{ {
let output: VertOut; let output: VertOut;
output.position = vec4<f32>(input.pos, 0.0, 1.0); output.position = vec4[f32](input.pos, 0.0, 1.0);
output.uv = input.uv; output.uv = input.uv;
return output; return output;

View File

@ -6,52 +6,52 @@ option AlphaTest: bool = false;
struct BasicSettings struct BasicSettings
{ {
AlphaThreshold: f32, AlphaThreshold: f32,
DiffuseColor: vec4<f32> DiffuseColor: vec4[f32]
} }
[layout(std140)] [layout(std140)]
struct InstanceData struct InstanceData
{ {
worldMatrix: mat4<f32>, worldMatrix: mat4[f32],
invWorldMatrix: mat4<f32> invWorldMatrix: mat4[f32]
} }
[layout(std140)] [layout(std140)]
struct ViewerData struct ViewerData
{ {
projectionMatrix: mat4<f32>, projectionMatrix: mat4[f32],
invProjectionMatrix: mat4<f32>, invProjectionMatrix: mat4[f32],
viewMatrix: mat4<f32>, viewMatrix: mat4[f32],
invViewMatrix: mat4<f32>, invViewMatrix: mat4[f32],
viewProjMatrix: mat4<f32>, viewProjMatrix: mat4[f32],
invViewProjMatrix: mat4<f32>, invViewProjMatrix: mat4[f32],
renderTargetSize: vec2<f32>, renderTargetSize: vec2[f32],
invRenderTargetSize: vec2<f32>, invRenderTargetSize: vec2[f32],
eyePosition: vec3<f32> eyePosition: vec3[f32]
} }
external external
{ {
[binding(0)] settings: uniform<BasicSettings>, [binding(0)] settings: uniform[BasicSettings],
[binding(1)] MaterialDiffuseMap: sampler2D<f32>, [binding(1)] MaterialDiffuseMap: sampler2D[f32],
[binding(2)] MaterialAlphaMap: sampler2D<f32>, [binding(2)] MaterialAlphaMap: sampler2D[f32],
[binding(3)] TextureOverlay: sampler2D<f32>, [binding(3)] TextureOverlay: sampler2D[f32],
[binding(4)] instanceData: uniform<InstanceData>, [binding(4)] instanceData: uniform[InstanceData],
[binding(5)] viewerData: uniform<ViewerData>, [binding(5)] viewerData: uniform[ViewerData],
} }
struct InputData struct InputData
{ {
[location(0)] normal: vec3<f32>, [location(0)] normal: vec3[f32],
[location(1)] uv: vec2<f32>, [location(1)] uv: vec2[f32],
[location(2)] pos: vec3<f32> [location(2)] pos: vec3[f32]
} }
struct OutputData struct OutputData
{ {
[location(0)] diffuseMap: vec4<f32>, [location(0)] diffuseMap: vec4[f32],
[location(1)] normalMap: vec4<f32>, [location(1)] normalMap: vec4[f32],
[location(2)] positionMap: vec4<f32> [location(2)] positionMap: vec4[f32]
} }
[entry(frag)] [entry(frag)]
@ -72,7 +72,7 @@ fn main(input: InputData) -> OutputData
let output: OutputData; let output: OutputData;
output.diffuseMap = diffuseColor; output.diffuseMap = diffuseColor;
output.normalMap = vec4<f32>((vec3<f32>(1.0, 1.0, 1.0) + input.normal) * 0.5, 1.0); 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); output.positionMap = vec4[f32](input.pos, 1.0);
return output; return output;
} }

View File

@ -2,61 +2,61 @@
struct BasicSettings struct BasicSettings
{ {
AlphaThreshold: f32, AlphaThreshold: f32,
DiffuseColor: vec4<f32> DiffuseColor: vec4[f32]
} }
[layout(std140)] [layout(std140)]
struct InstanceData struct InstanceData
{ {
worldMatrix: mat4<f32>, worldMatrix: mat4[f32],
invWorldMatrix: mat4<f32> invWorldMatrix: mat4[f32]
} }
[layout(std140)] [layout(std140)]
struct ViewerData struct ViewerData
{ {
projectionMatrix: mat4<f32>, projectionMatrix: mat4[f32],
invProjectionMatrix: mat4<f32>, invProjectionMatrix: mat4[f32],
viewMatrix: mat4<f32>, viewMatrix: mat4[f32],
invViewMatrix: mat4<f32>, invViewMatrix: mat4[f32],
viewProjMatrix: mat4<f32>, viewProjMatrix: mat4[f32],
invViewProjMatrix: mat4<f32>, invViewProjMatrix: mat4[f32],
renderTargetSize: vec2<f32>, renderTargetSize: vec2[f32],
invRenderTargetSize: vec2<f32>, invRenderTargetSize: vec2[f32],
eyePosition: vec3<f32> eyePosition: vec3[f32]
} }
external external
{ {
[binding(0)] settings: uniform<BasicSettings>, [binding(0)] settings: uniform[BasicSettings],
[binding(4)] instanceData: uniform<InstanceData>, [binding(4)] instanceData: uniform[InstanceData],
[binding(5)] viewerData: uniform<ViewerData>, [binding(5)] viewerData: uniform[ViewerData],
} }
struct InputData struct InputData
{ {
[location(0)] pos: vec3<f32>, [location(0)] pos: vec3[f32],
[location(1)] normal: vec3<f32>, [location(1)] normal: vec3[f32],
[location(2)] uv: vec2<f32> [location(2)] uv: vec2[f32]
} }
struct OutputData struct OutputData
{ {
[location(0)] normal: vec3<f32>, [location(0)] normal: vec3[f32],
[location(1)] uv: vec2<f32>, [location(1)] uv: vec2[f32],
[location(2)] pos: vec3<f32>, [location(2)] pos: vec3[f32],
[builtin(position)] position: vec4<f32> [builtin(position)] position: vec4[f32]
} }
[entry(vert)] [entry(vert)]
fn main(input: InputData) -> OutputData fn main(input: InputData) -> OutputData
{ {
let worldPos = instanceData.worldMatrix * vec4<f32>(input.pos, 1.0); let worldPos = instanceData.worldMatrix * vec4[f32](input.pos, 1.0);
let output: OutputData; let output: OutputData;
output.uv = input.uv; output.uv = input.uv;
output.normal = input.normal; output.normal = input.normal;
output.pos = worldPos.xyz; output.pos = worldPos.xyz;
output.position = viewerData.viewProjMatrix * instanceData.worldMatrix * vec4<f32>(input.pos, 1.0); output.position = viewerData.viewProjMatrix * instanceData.worldMatrix * vec4[f32](input.pos, 1.0);
return output; return output;
} }

View File

@ -1,28 +1,28 @@
external external
{ {
[binding(0)] colorTexture: sampler2D<f32> [binding(0)] colorTexture: sampler2D[f32]
} }
struct FragIn struct FragIn
{ {
[location(0)] uv: vec2<f32> [location(0)] uv: vec2[f32]
} }
struct FragOut struct FragOut
{ {
[location(0)] color: vec4<f32> [location(0)] color: vec4[f32]
} }
struct VertIn struct VertIn
{ {
[location(0)] pos: vec2<f32>, [location(0)] pos: vec2[f32],
[location(1)] uv: vec2<f32> [location(1)] uv: vec2[f32]
} }
struct VertOut struct VertOut
{ {
[location(0)] vertUV: vec2<f32>, [location(0)] vertUV: vec2[f32],
[builtin(position)] position: vec4<f32> [builtin(position)] position: vec4[f32]
} }
[entry(frag)] [entry(frag)]
@ -32,7 +32,7 @@ fn main(input: FragIn) -> FragOut
let output: FragOut; let output: FragOut;
output.color = colorTexture.Sample(input.uv); output.color = colorTexture.Sample(input.uv);
//output.color = pow(colorTexture.Sample(input.uv), vec4<f32>(1.0 / gamma, 1.0 / gamma, 1.0 / gamma, 1.0)); //output.color = pow(colorTexture.Sample(input.uv), vec4[f32](1.0 / gamma, 1.0 / gamma, 1.0 / gamma, 1.0));
return output; return output;
} }
@ -40,7 +40,7 @@ fn main(input: FragIn) -> FragOut
fn main(input: VertIn) -> VertOut fn main(input: VertIn) -> VertOut
{ {
let output: VertOut; let output: VertOut;
output.position = vec4<f32>(input.pos, 0.0, 1.0); output.position = vec4[f32](input.pos, 0.0, 1.0);
output.vertUV = input.uv; output.vertUV = input.uv;
return output; return output;
} }

View File

@ -1,51 +1,51 @@
[layout(std140)] [layout(std140)]
struct ViewerData struct ViewerData
{ {
projectionMatrix: mat4<f32>, projectionMatrix: mat4[f32],
invProjectionMatrix: mat4<f32>, invProjectionMatrix: mat4[f32],
viewMatrix: mat4<f32>, viewMatrix: mat4[f32],
invViewMatrix: mat4<f32>, invViewMatrix: mat4[f32],
viewProjMatrix: mat4<f32>, viewProjMatrix: mat4[f32],
invViewProjMatrix: mat4<f32>, invViewProjMatrix: mat4[f32],
renderTargetSize: vec2<f32>, renderTargetSize: vec2[f32],
invRenderTargetSize: vec2<f32>, invRenderTargetSize: vec2[f32],
eyePosition: vec3<f32> eyePosition: vec3[f32]
} }
[layout(std140)] [layout(std140)]
struct BlurData struct BlurData
{ {
direction: vec2<f32>, direction: vec2[f32],
sizeFactor: f32 sizeFactor: f32
} }
external external
{ {
[set(0), binding(0)] viewerData: uniform<ViewerData>, [set(0), binding(0)] viewerData: uniform[ViewerData],
[set(0), binding(1)] colorTexture: sampler2D<f32>, [set(0), binding(1)] colorTexture: sampler2D[f32],
[set(0), binding(2)] blurData: uniform<BlurData> [set(0), binding(2)] blurData: uniform[BlurData]
} }
struct FragIn struct FragIn
{ {
[location(0)] uv: vec2<f32> [location(0)] uv: vec2[f32]
} }
struct FragOut struct FragOut
{ {
[location(0)] color: vec4<f32> [location(0)] color: vec4[f32]
} }
struct VertIn struct VertIn
{ {
[location(0)] pos: vec2<f32>, [location(0)] pos: vec2[f32],
[location(1)] uv: vec2<f32>, [location(1)] uv: vec2[f32],
} }
struct VertOut struct VertOut
{ {
[location(0)] uv: vec2<f32>, [location(0)] uv: vec2[f32],
[builtin(position)] position: vec4<f32> [builtin(position)] position: vec4[f32]
} }
[entry(frag)] [entry(frag)]
@ -62,7 +62,7 @@ fn main(input: FragIn) -> FragOut
color += colorTexture.Sample(input.uv - blurData.direction * 3.2307692308 * invTargetSize).rgb * 0.0702702703; color += colorTexture.Sample(input.uv - blurData.direction * 3.2307692308 * invTargetSize).rgb * 0.0702702703;
let output: FragOut; let output: FragOut;
output.color = vec4<f32>(color, 1.0); output.color = vec4[f32](color, 1.0);
return output; return output;
} }
@ -71,7 +71,7 @@ fn main(input: FragIn) -> FragOut
fn main(input: VertIn) -> VertOut fn main(input: VertIn) -> VertOut
{ {
let output: VertOut; let output: VertOut;
output.position = vec4<f32>(input.pos, 0.0, 1.0); output.position = vec4[f32](input.pos, 0.0, 1.0);
output.uv = input.uv; output.uv = input.uv;
return output; return output;

View File

@ -1,15 +1,15 @@
[layout(std140)] [layout(std140)]
struct ViewerData struct ViewerData
{ {
projectionMatrix: mat4<f32>, projectionMatrix: mat4[f32],
invProjectionMatrix: mat4<f32>, invProjectionMatrix: mat4[f32],
viewMatrix: mat4<f32>, viewMatrix: mat4[f32],
invViewMatrix: mat4<f32>, invViewMatrix: mat4[f32],
viewProjMatrix: mat4<f32>, viewProjMatrix: mat4[f32],
invViewProjMatrix: mat4<f32>, invViewProjMatrix: mat4[f32],
renderTargetSize: vec2<f32>, renderTargetSize: vec2[f32],
invRenderTargetSize: vec2<f32>, invRenderTargetSize: vec2[f32],
eyePosition: vec3<f32> eyePosition: vec3[f32]
} }
[layout(std140)] [layout(std140)]
@ -19,38 +19,38 @@ struct Settings
decay: f32, decay: f32,
density: f32, density: f32,
weight: f32, weight: f32,
lightPosition: vec2<f32>, //< TODO: Switch to world position lightPosition: vec2[f32], //< TODO: Switch to world position
} }
const SampleCount: i32 = 200; const SampleCount: i32 = 200;
external external
{ {
[set(0), binding(0)] viewerData: uniform<ViewerData>, [set(0), binding(0)] viewerData: uniform[ViewerData],
[set(0), binding(1)] settings: uniform<Settings>, [set(0), binding(1)] settings: uniform[Settings],
[set(0), binding(2)] occluderTexture: sampler2D<f32> [set(0), binding(2)] occluderTexture: sampler2D[f32]
} }
struct FragIn struct FragIn
{ {
[location(0)] uv: vec2<f32> [location(0)] uv: vec2[f32]
} }
struct FragOut struct FragOut
{ {
[location(0)] color: vec4<f32> [location(0)] color: vec4[f32]
} }
struct VertIn struct VertIn
{ {
[location(0)] pos: vec2<f32>, [location(0)] pos: vec2[f32],
[location(1)] uv: vec2<f32> [location(1)] uv: vec2[f32]
} }
struct VertOut struct VertOut
{ {
[builtin(position)] position: vec4<f32>, [builtin(position)] position: vec4[f32],
[location(0)] uv: vec2<f32> [location(0)] uv: vec2[f32]
} }
[entry(frag)] [entry(frag)]
@ -62,7 +62,7 @@ fn main(input: FragIn) -> FragOut
let uv = input.uv; let uv = input.uv;
let outputColor = vec4<f32>(0.0, 0.0, 0.0, 1.0); let outputColor = vec4[f32](0.0, 0.0, 0.0, 1.0);
for i in 0 -> SampleCount for i in 0 -> SampleCount
{ {
@ -85,7 +85,7 @@ fn main(input: FragIn) -> FragOut
fn main(input: VertIn) -> VertOut fn main(input: VertIn) -> VertOut
{ {
let output: VertOut; let output: VertOut;
output.position = vec4<f32>(input.pos, 0.0, 1.0); output.position = vec4[f32](input.pos, 0.0, 1.0);
output.uv = input.uv; output.uv = input.uv;
return output; return output;

View File

@ -1,8 +1,8 @@
[layout(std140)] [layout(std140)]
struct PointLight struct PointLight
{ {
color: vec3<f32>, color: vec3[f32],
position: vec3<f32>, position: vec3[f32],
radius: f32, radius: f32,
invRadius: f32, invRadius: f32,
@ -11,11 +11,11 @@ struct PointLight
[layout(std140)] [layout(std140)]
struct SpotLight struct SpotLight
{ {
transformMatrix: mat4<f32>, transformMatrix: mat4[f32],
color: vec3<f32>, color: vec3[f32],
position: vec3<f32>, position: vec3[f32],
direction: vec3<f32>, direction: vec3[f32],
radius: f32, radius: f32,
invRadius: f32, invRadius: f32,
@ -27,63 +27,63 @@ struct SpotLight
[layout(std140)] [layout(std140)]
struct ViewerData struct ViewerData
{ {
projectionMatrix: mat4<f32>, projectionMatrix: mat4[f32],
invProjectionMatrix: mat4<f32>, invProjectionMatrix: mat4[f32],
viewMatrix: mat4<f32>, viewMatrix: mat4[f32],
invViewMatrix: mat4<f32>, invViewMatrix: mat4[f32],
viewProjMatrix: mat4<f32>, viewProjMatrix: mat4[f32],
invViewProjMatrix: mat4<f32>, invViewProjMatrix: mat4[f32],
renderTargetSize: vec2<f32>, renderTargetSize: vec2[f32],
invRenderTargetSize: vec2<f32>, invRenderTargetSize: vec2[f32],
eyePosition: vec3<f32> eyePosition: vec3[f32]
} }
[set(0)] [set(0)]
external external
{ {
[binding(0)] viewerData: uniform<ViewerData>, [binding(0)] viewerData: uniform[ViewerData],
[binding(1)] colorTexture: sampler2D<f32>, [binding(1)] colorTexture: sampler2D[f32],
[binding(2)] normalTexture: sampler2D<f32>, [binding(2)] normalTexture: sampler2D[f32],
[binding(3)] positionTexture: sampler2D<f32>, [binding(3)] positionTexture: sampler2D[f32],
} }
[set(1)] [set(1)]
external external
{ {
[binding(0)] lightParameters: uniform<SpotLight>, [binding(0)] lightParameters: uniform[SpotLight],
} }
struct FragIn struct FragIn
{ {
[builtin(fragcoord)] fragcoord: vec4<f32> [builtin(fragcoord)] fragcoord: vec4[f32]
} }
struct FragOut struct FragOut
{ {
[location(0)] color: vec4<f32> [location(0)] color: vec4[f32]
} }
struct VertIn struct VertIn
{ {
[location(0)] pos: vec3<f32> [location(0)] pos: vec3[f32]
} }
struct VertOut struct VertOut
{ {
[builtin(position)] position: vec4<f32> [builtin(position)] position: vec4[f32]
} }
[entry(frag)] [entry(frag)]
fn main(input: FragIn) -> FragOut fn main(input: FragIn) -> FragOut
{ {
let fragcoord = input.fragcoord.xy * viewerData.invRenderTargetSize; let fragcoord = input.fragcoord.xy * viewerData.invRenderTargetSize;
let normal = normalTexture.Sample(fragcoord).xyz * 2.0 - vec3<f32>(1.0, 1.0, 1.0); let normal = normalTexture.Sample(fragcoord).xyz * 2.0 - vec3[f32](1.0, 1.0, 1.0);
let position = positionTexture.Sample(fragcoord).xyz; let position = positionTexture.Sample(fragcoord).xyz;
let attenuation = compute_attenuation(position, normal); let attenuation = compute_attenuation(position, normal);
let output: FragOut; let output: FragOut;
output.color = vec4<f32>(lightParameters.color, 1.0) * attenuation * colorTexture.Sample(fragcoord); output.color = vec4[f32](lightParameters.color, 1.0) * attenuation * colorTexture.Sample(fragcoord);
return output; return output;
} }
@ -92,12 +92,12 @@ fn main(input: FragIn) -> FragOut
fn main(input: VertIn) -> VertOut fn main(input: VertIn) -> VertOut
{ {
let output: VertOut; let output: VertOut;
output.position = viewerData.projectionMatrix * viewerData.viewMatrix * lightParameters.transformMatrix * vec4<f32>(input.pos, 1.0); output.position = viewerData.projectionMatrix * viewerData.viewMatrix * lightParameters.transformMatrix * vec4[f32](input.pos, 1.0);
return output; return output;
} }
fn compute_attenuation(worldPos: vec3<f32>, normal: vec3<f32>) -> f32 fn compute_attenuation(worldPos: vec3[f32], normal: vec3[f32]) -> f32
{ {
let distance = length(lightParameters.position - worldPos); let distance = length(lightParameters.position - worldPos);

View File

@ -1,32 +1,32 @@
[layout(std140)] [layout(std140)]
struct ViewerData struct ViewerData
{ {
projectionMatrix: mat4<f32>, projectionMatrix: mat4[f32],
invProjectionMatrix: mat4<f32>, invProjectionMatrix: mat4[f32],
viewMatrix: mat4<f32>, viewMatrix: mat4[f32],
invViewMatrix: mat4<f32>, invViewMatrix: mat4[f32],
viewProjMatrix: mat4<f32>, viewProjMatrix: mat4[f32],
invViewProjMatrix: mat4<f32>, invViewProjMatrix: mat4[f32],
renderTargetSize: vec2<f32>, renderTargetSize: vec2[f32],
invRenderTargetSize: vec2<f32>, invRenderTargetSize: vec2[f32],
eyePosition: vec3<f32> eyePosition: vec3[f32]
} }
external external
{ {
[binding(0)] viewerData: uniform<ViewerData>, [binding(0)] viewerData: uniform[ViewerData],
[binding(1)] skybox: samplerCube<f32> [binding(1)] skybox: samplerCube[f32]
} }
struct VertOut struct VertOut
{ {
[location(0)] uvw: vec3<f32>, [location(0)] uvw: vec3[f32],
[builtin(position)] position: vec4<f32> [builtin(position)] position: vec4[f32]
} }
struct FragOut struct FragOut
{ {
[location(0)] color: vec4<f32>, [location(0)] color: vec4[f32],
[builtin(fragdepth)] depth: f32 [builtin(fragdepth)] depth: f32
} }
@ -43,7 +43,7 @@ fn main(input: VertOut) -> FragOut
struct VertIn struct VertIn
{ {
[location(0)] position: vec3<f32> [location(0)] position: vec3[f32]
} }
[entry(vert)] [entry(vert)]
@ -51,10 +51,10 @@ fn main(input: VertIn) -> VertOut
{ {
// Set translation part to zero // Set translation part to zero
let rotationMat = viewerData.viewMatrix; let rotationMat = viewerData.viewMatrix;
rotationMat[3].xyz = vec3<f32>(0.0, 0.0, 0.0); rotationMat[3].xyz = vec3[f32](0.0, 0.0, 0.0);
let output: VertOut; let output: VertOut;
output.position = viewerData.projectionMatrix * rotationMat * vec4<f32>(input.position, 1.0); output.position = viewerData.projectionMatrix * rotationMat * vec4[f32](input.position, 1.0);
output.uvw = input.position.xyz; output.uvw = input.position.xyz;
return output; return output;

View File

@ -1,43 +1,43 @@
[layout(std140)] [layout(std140)]
struct ViewerData struct ViewerData
{ {
projectionMatrix: mat4<f32>, projectionMatrix: mat4[f32],
invProjectionMatrix: mat4<f32>, invProjectionMatrix: mat4[f32],
viewMatrix: mat4<f32>, viewMatrix: mat4[f32],
invViewMatrix: mat4<f32>, invViewMatrix: mat4[f32],
viewProjMatrix: mat4<f32>, viewProjMatrix: mat4[f32],
invViewProjMatrix: mat4<f32>, invViewProjMatrix: mat4[f32],
renderTargetSize: vec2<f32>, renderTargetSize: vec2[f32],
invRenderTargetSize: vec2<f32>, invRenderTargetSize: vec2[f32],
eyePosition: vec3<f32> eyePosition: vec3[f32]
} }
external external
{ {
[set(0), binding(0)] viewerData: uniform<ViewerData>, [set(0), binding(0)] viewerData: uniform[ViewerData],
[set(0), binding(1)] inputTexture: sampler2D<f32> [set(0), binding(1)] inputTexture: sampler2D[f32]
} }
struct FragIn struct FragIn
{ {
[location(0)] uv: vec2<f32>, [location(0)] uv: vec2[f32],
} }
struct FragOut struct FragOut
{ {
[location(0)] color: vec4<f32> [location(0)] color: vec4[f32]
} }
struct VertIn struct VertIn
{ {
[location(0)] pos: vec2<f32>, [location(0)] pos: vec2[f32],
[location(1)] uv: vec2<f32>, [location(1)] uv: vec2[f32],
} }
struct VertOut struct VertOut
{ {
[location(0)] uv: vec2<f32>, [location(0)] uv: vec2[f32],
[builtin(position)] position: vec4<f32> [builtin(position)] position: vec4[f32]
} }
[entry(frag)] [entry(frag)]
@ -48,10 +48,10 @@ fn main(input: FragIn) -> FragOut
let hdrColor = inputTexture.Sample(input.uv).rgb; let hdrColor = inputTexture.Sample(input.uv).rgb;
// reinhard tone mapping // reinhard tone mapping
let mapped = vec3<f32>(1.0, 1.0, 1.0) - exp(-hdrColor * exposure); let mapped = vec3[f32](1.0, 1.0, 1.0) - exp(-hdrColor * exposure);
let output: FragOut; let output: FragOut;
output.color = vec4<f32>(mapped, 1.0); output.color = vec4[f32](mapped, 1.0);
return output; return output;
} }
@ -60,7 +60,7 @@ fn main(input: FragIn) -> FragOut
fn main(input: VertIn) -> VertOut fn main(input: VertIn) -> VertOut
{ {
let output: VertOut; let output: VertOut;
output.position = vec4<f32>(input.pos, 0.0, 1.0); output.position = vec4[f32](input.pos, 0.0, 1.0);
output.uv = input.uv; output.uv = input.uv;
return output; return output;

View File

@ -17,8 +17,8 @@ constexpr std::size_t BloomSubdivisionCount = 5;
[layout(std140)] [layout(std140)]
struct PointLight struct PointLight
{ {
color: vec3<f32>, color: vec3[f32],
position: vec3<f32>, position: vec3[f32],
constant: f32, constant: f32,
linear: f32, linear: f32,
@ -28,9 +28,9 @@ struct PointLight
[layout(std140)] [layout(std140)]
struct SpotLight struct SpotLight
{ {
color: vec3<f32>, color: vec3[f32],
position: vec3<f32>, position: vec3[f32],
direction: vec3<f32>, direction: vec3[f32],
constant: f32, constant: f32,
linear: f32, linear: f32,
@ -299,9 +299,9 @@ int main()
[layout(std140)] [layout(std140)]
struct SpotLight struct SpotLight
{ {
color: vec3<f32>, color: vec3[f32],
position: vec3<f32>, position: vec3[f32],
direction: vec3<f32>, direction: vec3[f32],
constant: f32, constant: f32,
linear: f32, linear: f32,

View File

@ -17,50 +17,50 @@ option red: bool = false;
[layout(std140)] [layout(std140)]
struct Data struct Data
{ {
projectionMatrix: mat4<f32>, projectionMatrix: mat4[f32],
worldMatrix: mat4<f32>, worldMatrix: mat4[f32],
viewMatrix: mat4<f32> viewMatrix: mat4[f32]
} }
[set(0)] [set(0)]
external external
{ {
[binding(0)] viewerData: uniform<Data>, [binding(0)] viewerData: uniform[Data],
} }
[set(1)] [set(1)]
external external
{ {
[binding(0)] tex: sampler2D<f32> [binding(0)] tex: sampler2D[f32]
} }
struct VertIn struct VertIn
{ {
[location(0)] position: vec3<f32>, [location(0)] position: vec3[f32],
[location(1)] normal: vec3<f32>, [location(1)] normal: vec3[f32],
[location(2)] uv: vec2<f32> [location(2)] uv: vec2[f32]
} }
struct VertOut struct VertOut
{ {
[builtin(position)] position: vec4<f32>, [builtin(position)] position: vec4[f32],
[location(0)] normal: vec3<f32>, [location(0)] normal: vec3[f32],
[location(1)] uv: vec2<f32> [location(1)] uv: vec2[f32]
} }
struct FragOut struct FragOut
{ {
[location(0)] color: vec4<f32> [location(0)] color: vec4[f32]
} }
[entry(frag)] [entry(frag)]
fn main(fragIn: VertOut) -> FragOut fn main(fragIn: VertOut) -> FragOut
{ {
let lightDir = vec3<f32>(0.0, 0.707, 0.707); let lightDir = vec3[f32](0.0, 0.707, 0.707);
let lightFactor = dot(fragIn.normal, lightDir); let lightFactor = dot(fragIn.normal, lightDir);
let fragOut: FragOut; let fragOut: FragOut;
fragOut.color = lightFactor * tex.Sample(fragIn.uv) * const_select(red, vec4<f32>(1.0, 0.0, 0.0, 1.0), vec4<f32>(1.0, 1.0, 1.0, 1.0)); fragOut.color = lightFactor * tex.Sample(fragIn.uv) * const_select(red, vec4[f32](1.0, 0.0, 0.0, 1.0), vec4[f32](1.0, 1.0, 1.0, 1.0));
return fragOut; return fragOut;
} }
@ -69,7 +69,7 @@ fn main(fragIn: VertOut) -> FragOut
fn main(vertIn: VertIn) -> VertOut fn main(vertIn: VertIn) -> VertOut
{ {
let vertOut: VertOut; let vertOut: VertOut;
vertOut.position = viewerData.projectionMatrix * viewerData.viewMatrix * viewerData.worldMatrix * vec4<f32>(vertIn.position, 1.0); vertOut.position = viewerData.projectionMatrix * viewerData.viewMatrix * viewerData.worldMatrix * vec4[f32](vertIn.position, 1.0);
vertOut.normal = vertIn.normal; vertOut.normal = vertIn.normal;
vertOut.uv = vertIn.uv; vertOut.uv = vertIn.uv;

View File

@ -113,7 +113,6 @@ namespace Nz::ShaderLang
ShaderAst::ExpressionPtr ParsePrimaryExpression(); ShaderAst::ExpressionPtr ParsePrimaryExpression();
ShaderAst::ExpressionPtr ParseVariableAssignation(); ShaderAst::ExpressionPtr ParseVariableAssignation();
ShaderAst::ExpressionType ParseArrayType();
ShaderAst::AttributeType ParseIdentifierAsAttributeType(); ShaderAst::AttributeType ParseIdentifierAsAttributeType();
const std::string& ParseIdentifierAsName(); const std::string& ParseIdentifierAsName();
ShaderAst::PrimitiveType ParsePrimitiveType(); ShaderAst::PrimitiveType ParsePrimitiveType();

View File

@ -21,50 +21,50 @@ const HasUV = (UvLocation >= 0);
struct MaterialSettings struct MaterialSettings
{ {
AlphaThreshold: f32, AlphaThreshold: f32,
DiffuseColor: vec4<f32> DiffuseColor: vec4[f32]
} }
[layout(std140)] [layout(std140)]
struct InstanceData struct InstanceData
{ {
worldMatrix: mat4<f32>, worldMatrix: mat4[f32],
invWorldMatrix: mat4<f32> invWorldMatrix: mat4[f32]
} }
[layout(std140)] [layout(std140)]
struct ViewerData struct ViewerData
{ {
projectionMatrix: mat4<f32>, projectionMatrix: mat4[f32],
invProjectionMatrix: mat4<f32>, invProjectionMatrix: mat4[f32],
viewMatrix: mat4<f32>, viewMatrix: mat4[f32],
invViewMatrix: mat4<f32>, invViewMatrix: mat4[f32],
viewProjMatrix: mat4<f32>, viewProjMatrix: mat4[f32],
invViewProjMatrix: mat4<f32>, invViewProjMatrix: mat4[f32],
renderTargetSize: vec2<f32>, renderTargetSize: vec2[f32],
invRenderTargetSize: vec2<f32>, invRenderTargetSize: vec2[f32],
eyePosition: vec3<f32> eyePosition: vec3[f32]
} }
external external
{ {
[binding(0)] settings: uniform<MaterialSettings>, [binding(0)] settings: uniform[MaterialSettings],
[binding(1)] MaterialDiffuseMap: sampler2D<f32>, [binding(1)] MaterialDiffuseMap: sampler2D[f32],
[binding(2)] MaterialAlphaMap: sampler2D<f32>, [binding(2)] MaterialAlphaMap: sampler2D[f32],
[binding(3)] TextureOverlay: sampler2D<f32>, [binding(3)] TextureOverlay: sampler2D[f32],
[binding(4)] instanceData: uniform<InstanceData>, [binding(4)] instanceData: uniform[InstanceData],
[binding(5)] viewerData: uniform<ViewerData>, [binding(5)] viewerData: uniform[ViewerData],
} }
// Fragment stage // Fragment stage
struct FragIn struct FragIn
{ {
[location(0), cond(HasUV)] uv: vec2<f32>, [location(0), cond(HasUV)] uv: vec2[f32],
[location(1), cond(HasColor)] color: vec4<f32> [location(1), cond(HasColor)] color: vec4[f32]
} }
struct FragOut struct FragOut
{ {
[location(0)] RenderTarget0: vec4<f32> [location(0)] RenderTarget0: vec4[f32]
} }
[entry(frag)] [entry(frag)]
@ -99,29 +99,29 @@ fn main(input: FragIn) -> FragOut
struct VertIn struct VertIn
{ {
[location(PosLocation)] [location(PosLocation)]
pos: vec3<f32>, pos: vec3[f32],
[cond(HasVertexColor), location(ColorLocation)] [cond(HasVertexColor), location(ColorLocation)]
color: vec4<f32>, color: vec4[f32],
[cond(HasUV), location(UvLocation)] [cond(HasUV), location(UvLocation)]
uv: vec2<f32>, uv: vec2[f32],
[cond(Billboard), location(BillboardCenterLocation)] [cond(Billboard), location(BillboardCenterLocation)]
billboardCenter: vec3<f32>, billboardCenter: vec3[f32],
[cond(Billboard), location(BillboardSizeRotLocation)] [cond(Billboard), location(BillboardSizeRotLocation)]
billboardSizeRot: vec4<f32>, //< width,height,sin,cos billboardSizeRot: vec4[f32], //< width,height,sin,cos
[cond(Billboard), location(BillboardColorLocation)] [cond(Billboard), location(BillboardColorLocation)]
billboardColor: vec4<f32> billboardColor: vec4[f32]
} }
struct VertOut struct VertOut
{ {
[location(0), cond(HasUV)] uv: vec2<f32>, [location(0), cond(HasUV)] uv: vec2[f32],
[location(1), cond(HasColor)] color: vec4<f32>, [location(1), cond(HasColor)] color: vec4[f32],
[builtin(position)] position: vec4<f32> [builtin(position)] position: vec4[f32]
} }
[entry(vert), cond(Billboard)] [entry(vert), cond(Billboard)]
@ -130,27 +130,27 @@ 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;
let rotatedPosition = vec2<f32>( let rotatedPosition = vec2[f32](
input.pos.x * sinCos.y - input.pos.y * sinCos.x, input.pos.x * sinCos.y - input.pos.y * sinCos.x,
input.pos.y * sinCos.y + input.pos.x * sinCos.x input.pos.y * sinCos.y + input.pos.x * sinCos.x
); );
rotatedPosition *= size; rotatedPosition *= size;
let cameraRight = vec3<f32>(viewerData.viewMatrix[0][0], viewerData.viewMatrix[1][0], viewerData.viewMatrix[2][0]); let cameraRight = vec3[f32](viewerData.viewMatrix[0][0], viewerData.viewMatrix[1][0], viewerData.viewMatrix[2][0]);
let cameraUp = vec3<f32>(viewerData.viewMatrix[0][1], viewerData.viewMatrix[1][1], viewerData.viewMatrix[2][1]); let cameraUp = vec3[f32](viewerData.viewMatrix[0][1], viewerData.viewMatrix[1][1], viewerData.viewMatrix[2][1]);
let vertexPos = input.billboardCenter; let vertexPos = input.billboardCenter;
vertexPos += cameraRight * rotatedPosition.x; vertexPos += cameraRight * rotatedPosition.x;
vertexPos += cameraUp * rotatedPosition.y; vertexPos += cameraUp * rotatedPosition.y;
let output: VertOut; 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)
output.color = input.billboardColor; output.color = input.billboardColor;
const if (HasUV) const if (HasUV)
output.uv = input.pos.xy + vec2<f32>(0.5, 0.5); output.uv = input.pos.xy + vec2[f32](0.5, 0.5);
return output; return output;
} }
@ -159,7 +159,7 @@ fn billboardMain(input: VertIn) -> VertOut
fn main(input: VertIn) -> VertOut fn main(input: VertIn) -> VertOut
{ {
let output: VertOut; let output: VertOut;
output.position = viewerData.viewProjMatrix * instanceData.worldMatrix * vec4<f32>(input.pos, 1.0); output.position = viewerData.viewProjMatrix * instanceData.worldMatrix * vec4[f32](input.pos, 1.0);
const if (HasColor) const if (HasColor)
output.color = input.color; output.color = input.color;

View File

@ -1,25 +1,25 @@
external external
{ {
[binding(0)] texture: sampler2D<f32> [binding(0)] texture: sampler2D[f32]
} }
struct VertIn struct VertIn
{ {
[location(0)] position: vec2<f32>, [location(0)] position: vec2[f32],
[location(1)] uv: vec2<f32> [location(1)] uv: vec2[f32]
} }
struct VertOut struct VertOut
{ {
[builtin(position)] position: vec4<f32>, [builtin(position)] position: vec4[f32],
[location(0)] uv: vec2<f32> [location(0)] uv: vec2[f32]
} }
[entry(vert)] [entry(vert)]
fn main(vertIn: VertIn) -> VertOut fn main(vertIn: VertIn) -> VertOut
{ {
let output: VertOut; let output: VertOut;
output.position = vec4<f32>(vertIn.position, 0.0, 1.0); output.position = vec4[f32](vertIn.position, 0.0, 1.0);
output.uv = vertIn.uv; output.uv = vertIn.uv;
return output; return output;
@ -27,7 +27,7 @@ fn main(vertIn: VertIn) -> VertOut
struct FragOut struct FragOut
{ {
[location(0)] color: vec4<f32> [location(0)] color: vec4[f32]
} }
[entry(frag)] [entry(frag)]

View File

@ -8,44 +8,44 @@ const HasUV = AlphaTest && (HasDiffuseTexture || HasAlphaTexture);
struct BasicSettings struct BasicSettings
{ {
AlphaThreshold: f32, AlphaThreshold: f32,
DiffuseColor: vec4<f32> DiffuseColor: vec4[f32]
} }
[layout(std140)] [layout(std140)]
struct InstanceData struct InstanceData
{ {
worldMatrix: mat4<f32>, worldMatrix: mat4[f32],
invWorldMatrix: mat4<f32> invWorldMatrix: mat4[f32]
} }
[layout(std140)] [layout(std140)]
struct ViewerData struct ViewerData
{ {
projectionMatrix: mat4<f32>, projectionMatrix: mat4[f32],
invProjectionMatrix: mat4<f32>, invProjectionMatrix: mat4[f32],
viewMatrix: mat4<f32>, viewMatrix: mat4[f32],
invViewMatrix: mat4<f32>, invViewMatrix: mat4[f32],
viewProjMatrix: mat4<f32>, viewProjMatrix: mat4[f32],
invViewProjMatrix: mat4<f32>, invViewProjMatrix: mat4[f32],
renderTargetSize: vec2<f32>, renderTargetSize: vec2[f32],
invRenderTargetSize: vec2<f32>, invRenderTargetSize: vec2[f32],
eyePosition: vec3<f32> eyePosition: vec3[f32]
} }
external external
{ {
[binding(0)] settings: uniform<BasicSettings>, [binding(0)] settings: uniform[BasicSettings],
[binding(1)] MaterialDiffuseMap: sampler2D<f32>, [binding(1)] MaterialDiffuseMap: sampler2D[f32],
[binding(2)] MaterialAlphaMap: sampler2D<f32>, [binding(2)] MaterialAlphaMap: sampler2D[f32],
[binding(3)] TextureOverlay: sampler2D<f32>, [binding(3)] TextureOverlay: sampler2D[f32],
[binding(4)] instanceData: uniform<InstanceData>, [binding(4)] instanceData: uniform[InstanceData],
[binding(5)] viewerData: uniform<ViewerData>, [binding(5)] viewerData: uniform[ViewerData],
} }
// Fragment stage // Fragment stage
struct FragIn struct FragIn
{ {
[location(0), cond(HasUV)] uv: vec2<f32> [location(0), cond(HasUV)] uv: vec2[f32]
} }
[entry(frag), cond(AlphaTest)] [entry(frag), cond(AlphaTest)]
@ -73,21 +73,21 @@ fn main() {}
// Vertex stage // Vertex stage
struct VertIn struct VertIn
{ {
[location(0)] pos: vec3<f32>, [location(0)] pos: vec3[f32],
[location(1), cond(HasUV)] uv: vec2<f32> [location(1), cond(HasUV)] uv: vec2[f32]
} }
struct VertOut struct VertOut
{ {
[location(0), cond(HasUV)] uv: vec2<f32>, [location(0), cond(HasUV)] uv: vec2[f32],
[builtin(position)] position: vec4<f32> [builtin(position)] position: vec4[f32]
} }
[entry(vert)] [entry(vert)]
fn main(input: VertIn) -> VertOut fn main(input: VertIn) -> VertOut
{ {
let output: VertOut; let output: VertOut;
output.position = viewerData.viewProjMatrix * instanceData.worldMatrix * vec4<f32>(input.pos, 1.0); output.position = viewerData.viewProjMatrix * instanceData.worldMatrix * vec4[f32](input.pos, 1.0);
const if (HasUV) const if (HasUV)
output.uv = input.uv; output.uv = input.uv;

View File

@ -36,19 +36,19 @@ struct MaterialSettings
{ {
// BasicSettings // BasicSettings
AlphaThreshold: f32, AlphaThreshold: f32,
DiffuseColor: vec4<f32>, DiffuseColor: vec4[f32],
// PhongSettings // PhongSettings
AmbientColor: vec3<f32>, AmbientColor: vec3[f32],
SpecularColor: vec3<f32>, SpecularColor: vec3[f32],
Shininess: f32, Shininess: f32,
} }
[layout(std140)] [layout(std140)]
struct InstanceData struct InstanceData
{ {
worldMatrix: mat4<f32>, worldMatrix: mat4[f32],
invWorldMatrix: mat4<f32> invWorldMatrix: mat4[f32]
} }
// TODO: Add enums // TODO: Add enums
@ -60,64 +60,64 @@ const SpotLight = 2;
struct Light struct Light
{ {
type: i32, type: i32,
color: vec4<f32>, color: vec4[f32],
factor: vec2<f32>, factor: vec2[f32],
parameter1: vec4<f32>, parameter1: vec4[f32],
parameter2: vec4<f32>, parameter2: vec4[f32],
parameter3: vec4<f32>, parameter3: vec4[f32],
hasShadowMapping: bool hasShadowMapping: u32
} }
[layout(std140)] [layout(std140)]
struct LightData struct LightData
{ {
lights: [Light; MaxLightCount], lights: array[Light, MaxLightCount],
lightCount: u32, lightCount: u32
} }
[layout(std140)] [layout(std140)]
struct ViewerData struct ViewerData
{ {
projectionMatrix: mat4<f32>, projectionMatrix: mat4[f32],
invProjectionMatrix: mat4<f32>, invProjectionMatrix: mat4[f32],
viewMatrix: mat4<f32>, viewMatrix: mat4[f32],
invViewMatrix: mat4<f32>, invViewMatrix: mat4[f32],
viewProjMatrix: mat4<f32>, viewProjMatrix: mat4[f32],
invViewProjMatrix: mat4<f32>, invViewProjMatrix: mat4[f32],
renderTargetSize: vec2<f32>, renderTargetSize: vec2[f32],
invRenderTargetSize: vec2<f32>, invRenderTargetSize: vec2[f32],
eyePosition: vec3<f32> eyePosition: vec3[f32]
} }
external external
{ {
[binding(0)] settings: uniform<MaterialSettings>, [binding(0)] settings: uniform[MaterialSettings],
[binding(1)] MaterialDiffuseMap: sampler2D<f32>, [binding(1)] MaterialDiffuseMap: sampler2D[f32],
[binding(2)] MaterialAlphaMap: sampler2D<f32>, [binding(2)] MaterialAlphaMap: sampler2D[f32],
[binding(3)] TextureOverlay: sampler2D<f32>, [binding(3)] TextureOverlay: sampler2D[f32],
[binding(4)] instanceData: uniform<InstanceData>, [binding(4)] instanceData: uniform[InstanceData],
[binding(5)] viewerData: uniform<ViewerData>, [binding(5)] viewerData: uniform[ViewerData],
[binding(6)] lightData: uniform<LightData>, [binding(6)] lightData: uniform[LightData],
[binding(7)] MaterialEmissiveMap: sampler2D<f32>, [binding(7)] MaterialEmissiveMap: sampler2D[f32],
[binding(8)] MaterialHeightMap: sampler2D<f32>, [binding(8)] MaterialHeightMap: sampler2D[f32],
[binding(9)] MaterialNormalMap: sampler2D<f32>, [binding(9)] MaterialNormalMap: sampler2D[f32],
[binding(10)] MaterialSpecularMap: sampler2D<f32>, [binding(10)] MaterialSpecularMap: sampler2D[f32],
} }
struct VertToFrag struct VertToFrag
{ {
[location(0)] worldPos: vec3<f32>, [location(0)] worldPos: vec3[f32],
[location(1), cond(HasUV)] uv: vec2<f32>, [location(1), cond(HasUV)] uv: vec2[f32],
[location(2), cond(HasColor)] color: vec4<f32>, [location(2), cond(HasColor)] color: vec4[f32],
[location(3), cond(HasNormal)] normal: vec3<f32>, [location(3), cond(HasNormal)] normal: vec3[f32],
[location(4), cond(HasNormalMapping)] tbnMatrix: mat3<f32>, [location(4), cond(HasNormalMapping)] tbnMatrix: mat3[f32],
[builtin(position)] position: vec4<f32>, [builtin(position)] position: vec4[f32],
} }
// Fragment stage // Fragment stage
struct FragOut struct FragOut
{ {
[location(0)] RenderTarget0: vec4<f32> [location(0)] RenderTarget0: vec4[f32]
} }
[entry(frag)] [entry(frag)]
@ -145,15 +145,15 @@ fn main(input: VertToFrag) -> FragOut
const if (HasNormal) const if (HasNormal)
{ {
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);
let eyeVec = normalize(viewerData.eyePosition - input.worldPos); let eyeVec = normalize(viewerData.eyePosition - input.worldPos);
let normal: vec3<f32>; let normal: vec3[f32];
const if (HasNormalMapping) const if (HasNormalMapping)
normal = normalize(input.tbnMatrix * (MaterialNormalMap.Sample(input.uv).xyz * 2.0 - vec3<f32>(1.0, 1.0, 1.0))); normal = normalize(input.tbnMatrix * (MaterialNormalMap.Sample(input.uv).xyz * 2.0 - vec3[f32](1.0, 1.0, 1.0)));
else else
normal = normalize(input.normal); normal = normalize(input.normal);
@ -244,7 +244,7 @@ fn main(input: VertToFrag) -> FragOut
let lightColor = lightAmbient + lightDiffuse + lightSpecular; let lightColor = lightAmbient + lightDiffuse + lightSpecular;
let output: FragOut; let output: FragOut;
output.RenderTarget0 = vec4<f32>(lightColor, 1.0) * diffuseColor; output.RenderTarget0 = vec4[f32](lightColor, 1.0) * diffuseColor;
return output; return output;
} }
else else
@ -259,28 +259,28 @@ fn main(input: VertToFrag) -> FragOut
struct VertIn struct VertIn
{ {
[location(PosLocation)] [location(PosLocation)]
pos: vec3<f32>, pos: vec3[f32],
[cond(HasVertexColor), location(ColorLocation)] [cond(HasVertexColor), location(ColorLocation)]
color: vec4<f32>, color: vec4[f32],
[cond(HasUV), location(UvLocation)] [cond(HasUV), location(UvLocation)]
uv: vec2<f32>, uv: vec2[f32],
[cond(HasNormal), location(NormalLocation)] [cond(HasNormal), location(NormalLocation)]
normal: vec3<f32>, normal: vec3[f32],
[cond(HasTangent), location(TangentLocation)] [cond(HasTangent), location(TangentLocation)]
tangent: vec3<f32>, tangent: vec3[f32],
[cond(Billboard), location(BillboardCenterLocation)] [cond(Billboard), location(BillboardCenterLocation)]
billboardCenter: vec3<f32>, billboardCenter: vec3[f32],
[cond(Billboard), location(BillboardSizeRotLocation)] [cond(Billboard), location(BillboardSizeRotLocation)]
billboardSizeRot: vec4<f32>, //< width,height,sin,cos billboardSizeRot: vec4[f32], //< width,height,sin,cos
[cond(Billboard), location(BillboardColorLocation)] [cond(Billboard), location(BillboardColorLocation)]
billboardColor: vec4<f32> billboardColor: vec4[f32]
} }
[entry(vert), cond(Billboard)] [entry(vert), cond(Billboard)]
@ -289,27 +289,27 @@ 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;
let rotatedPosition = vec2<f32>( let rotatedPosition = vec2[f32](
input.pos.x * sinCos.y - input.pos.y * sinCos.x, input.pos.x * sinCos.y - input.pos.y * sinCos.x,
input.pos.y * sinCos.y + input.pos.x * sinCos.x input.pos.y * sinCos.y + input.pos.x * sinCos.x
); );
rotatedPosition *= size; rotatedPosition *= size;
let cameraRight = vec3<f32>(viewerData.viewMatrix[0][0], viewerData.viewMatrix[1][0], viewerData.viewMatrix[2][0]); let cameraRight = vec3[f32](viewerData.viewMatrix[0][0], viewerData.viewMatrix[1][0], viewerData.viewMatrix[2][0]);
let cameraUp = vec3<f32>(viewerData.viewMatrix[0][1], viewerData.viewMatrix[1][1], viewerData.viewMatrix[2][1]); let cameraUp = vec3[f32](viewerData.viewMatrix[0][1], viewerData.viewMatrix[1][1], viewerData.viewMatrix[2][1]);
let vertexPos = input.billboardCenter; let vertexPos = input.billboardCenter;
vertexPos += cameraRight * rotatedPosition.x; vertexPos += cameraRight * rotatedPosition.x;
vertexPos += cameraUp * rotatedPosition.y; vertexPos += cameraUp * rotatedPosition.y;
let output: VertToFrag; let output: VertToFrag;
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)
output.color = input.billboardColor; output.color = input.billboardColor;
const if (HasUV) const if (HasUV)
output.uv = input.pos.xy + vec2<f32>(0.5, 0.5); output.uv = input.pos.xy + vec2[f32](0.5, 0.5);
return output; return output;
} }
@ -317,13 +317,13 @@ fn billboardMain(input: VertIn) -> VertOut
[entry(vert), cond(!Billboard)] [entry(vert), cond(!Billboard)]
fn main(input: VertIn) -> VertToFrag fn main(input: VertIn) -> VertToFrag
{ {
let worldPosition = instanceData.worldMatrix * vec4<f32>(input.pos, 1.0); let worldPosition = instanceData.worldMatrix * vec4[f32](input.pos, 1.0);
let output: VertToFrag; let output: VertToFrag;
output.worldPos = worldPosition.xyz; output.worldPos = worldPosition.xyz;
output.position = viewerData.viewProjMatrix * worldPosition; output.position = viewerData.viewProjMatrix * worldPosition;
let rotationMatrix = mat3<f32>(instanceData.worldMatrix); let rotationMatrix = mat3[f32](instanceData.worldMatrix);
const if (HasColor) const if (HasColor)
output.color = input.color; output.color = input.color;

View File

@ -431,7 +431,7 @@ namespace Nz::ShaderAst
vectorComponentCount = std::get<VectorType>(GetExpressionType(*vectorExpr)).componentCount; vectorComponentCount = std::get<VectorType>(GetExpressionType(*vectorExpr)).componentCount;
} }
// cast expression (turn fromMatrix[i] to vec3<f32>(fromMatrix[i])) // cast expression (turn fromMatrix[i] to vec3[f32](fromMatrix[i]))
ExpressionPtr castExpr; ExpressionPtr castExpr;
if (vectorComponentCount != targetMatrixType.rowCount) if (vectorComponentCount != targetMatrixType.rowCount)
{ {
@ -1967,7 +1967,7 @@ namespace Nz::ShaderAst
{ {
const ExpressionType& type = GetExpressionType(*node.parameters.front()); const ExpressionType& type = GetExpressionType(*node.parameters.front());
if (type != ExpressionType{ VectorType{ 3, PrimitiveType::Float32 } }) if (type != ExpressionType{ VectorType{ 3, PrimitiveType::Float32 } })
throw AstError{ "CrossProduct only works with vec3<f32> expressions" }; throw AstError{ "CrossProduct only works with vec3[f32] expressions" };
node.cachedExpressionType = type; node.cachedExpressionType = type;
break; break;

View File

@ -126,7 +126,7 @@ namespace Nz
void LangWriter::Append(const ShaderAst::ArrayType& type) void LangWriter::Append(const ShaderAst::ArrayType& type)
{ {
Append("[", type.containedType->type, "; "); Append("array[", type.containedType->type, ", ");
if (type.length.IsResultingValue()) if (type.length.IsResultingValue())
Append(type.length.GetResultingValue()); Append(type.length.GetResultingValue());
@ -164,7 +164,7 @@ namespace Nz
Append(matrixType.rowCount); Append(matrixType.rowCount);
} }
Append("<", matrixType.type, ">"); Append("[", matrixType.type, "]");
} }
void LangWriter::Append(ShaderAst::PrimitiveType type) void LangWriter::Append(ShaderAst::PrimitiveType type)
@ -192,7 +192,7 @@ namespace Nz
case ImageType::Cubemap: Append("Cube"); break; case ImageType::Cubemap: Append("Cube"); break;
} }
Append("<", samplerType.sampledType, ">"); Append("[", samplerType.sampledType, "]");
} }
void LangWriter::Append(const ShaderAst::StructType& structType) void LangWriter::Append(const ShaderAst::StructType& structType)
@ -203,17 +203,17 @@ namespace Nz
void LangWriter::Append(const ShaderAst::UniformType& uniformType) void LangWriter::Append(const ShaderAst::UniformType& uniformType)
{ {
Append("uniform<"); Append("uniform[");
std::visit([&](auto&& arg) std::visit([&](auto&& arg)
{ {
Append(arg); Append(arg);
}, uniformType.containedType); }, uniformType.containedType);
Append(">"); Append("]");
} }
void LangWriter::Append(const ShaderAst::VectorType& vecType) void LangWriter::Append(const ShaderAst::VectorType& vecType)
{ {
Append("vec", vecType.componentCount, "<", vecType.type, ">"); Append("vec", vecType.componentCount, "[", vecType.type, "]");
} }
void LangWriter::Append(ShaderAst::NoType) void LangWriter::Append(ShaderAst::NoType)
@ -732,15 +732,15 @@ namespace Nz
else if constexpr (std::is_same_v<T, float> || std::is_same_v<T, Int32> || std::is_same_v<T, UInt32>) else if constexpr (std::is_same_v<T, float> || std::is_same_v<T, Int32> || std::is_same_v<T, UInt32>)
Append(std::to_string(arg)); Append(std::to_string(arg));
else if constexpr (std::is_same_v<T, Vector2f>) else if constexpr (std::is_same_v<T, Vector2f>)
Append("vec2<f32>(" + std::to_string(arg.x) + ", " + std::to_string(arg.y) + ")"); Append("vec2[f32](" + std::to_string(arg.x) + ", " + std::to_string(arg.y) + ")");
else if constexpr (std::is_same_v<T, Vector2i32>) else if constexpr (std::is_same_v<T, Vector2i32>)
Append("vec2<i32>(" + std::to_string(arg.x) + ", " + std::to_string(arg.y) + ")"); Append("vec2<i32>(" + std::to_string(arg.x) + ", " + std::to_string(arg.y) + ")");
else if constexpr (std::is_same_v<T, Vector3f>) else if constexpr (std::is_same_v<T, Vector3f>)
Append("vec3<f32>(" + std::to_string(arg.x) + ", " + std::to_string(arg.y) + ", " + std::to_string(arg.z) + ")"); Append("vec3[f32](" + std::to_string(arg.x) + ", " + std::to_string(arg.y) + ", " + std::to_string(arg.z) + ")");
else if constexpr (std::is_same_v<T, Vector3i32>) else if constexpr (std::is_same_v<T, Vector3i32>)
Append("vec3<i32>(" + std::to_string(arg.x) + ", " + std::to_string(arg.y) + ", " + std::to_string(arg.z) + ")"); Append("vec3<i32>(" + std::to_string(arg.x) + ", " + std::to_string(arg.y) + ", " + std::to_string(arg.z) + ")");
else if constexpr (std::is_same_v<T, Vector4f>) else if constexpr (std::is_same_v<T, Vector4f>)
Append("vec4<f32>(" + std::to_string(arg.x) + ", " + std::to_string(arg.y) + ", " + std::to_string(arg.z) + ", " + std::to_string(arg.w) + ")"); Append("vec4[f32](" + std::to_string(arg.x) + ", " + std::to_string(arg.y) + ", " + std::to_string(arg.z) + ", " + std::to_string(arg.w) + ")");
else if constexpr (std::is_same_v<T, Vector4i32>) else if constexpr (std::is_same_v<T, Vector4i32>)
Append("vec4<i32>(" + std::to_string(arg.x) + ", " + std::to_string(arg.y) + ", " + std::to_string(arg.z) + ", " + std::to_string(arg.w) + ")"); Append("vec4<i32>(" + std::to_string(arg.x) + ", " + std::to_string(arg.y) + ", " + std::to_string(arg.z) + ", " + std::to_string(arg.w) + ")");
else else

View File

@ -207,7 +207,25 @@ namespace Nz::ShaderLang
} }
//FIXME: Handle this better //FIXME: Handle this better
if (identifier == "mat4") if (identifier == "array")
{
Consume();
Expect(Advance(), TokenType::OpenSquareBracket); //< [
ShaderAst::ArrayType arrayType;
arrayType.containedType = std::make_unique<ShaderAst::ContainedType>();
arrayType.containedType->type = ParseType();
Expect(Advance(), TokenType::Comma); //< ,
arrayType.length = ParseExpression();
Expect(Advance(), TokenType::ClosingSquareBracket); //< ]
return arrayType;
}
else if (identifier == "mat4")
{ {
Consume(); Consume();
@ -215,9 +233,9 @@ namespace Nz::ShaderLang
matrixType.columnCount = 4; matrixType.columnCount = 4;
matrixType.rowCount = 4; matrixType.rowCount = 4;
Expect(Advance(), TokenType::LessThan); //< '<' Expect(Advance(), TokenType::OpenSquareBracket); //< [
matrixType.type = ParsePrimitiveType(); matrixType.type = ParsePrimitiveType();
Expect(Advance(), TokenType::GreaterThan); //< '>' Expect(Advance(), TokenType::ClosingSquareBracket); //< ]
return matrixType; return matrixType;
} }
@ -229,9 +247,9 @@ namespace Nz::ShaderLang
matrixType.columnCount = 3; matrixType.columnCount = 3;
matrixType.rowCount = 3; matrixType.rowCount = 3;
Expect(Advance(), TokenType::LessThan); //< '<' Expect(Advance(), TokenType::OpenSquareBracket); //< [
matrixType.type = ParsePrimitiveType(); matrixType.type = ParsePrimitiveType();
Expect(Advance(), TokenType::GreaterThan); //< '>' Expect(Advance(), TokenType::ClosingSquareBracket); //< ]
return matrixType; return matrixType;
} }
@ -243,9 +261,9 @@ namespace Nz::ShaderLang
matrixType.columnCount = 2; matrixType.columnCount = 2;
matrixType.rowCount = 2; matrixType.rowCount = 2;
Expect(Advance(), TokenType::LessThan); //< '<' Expect(Advance(), TokenType::OpenSquareBracket); //< [
matrixType.type = ParsePrimitiveType(); matrixType.type = ParsePrimitiveType();
Expect(Advance(), TokenType::GreaterThan); //< '>' Expect(Advance(), TokenType::ClosingSquareBracket); //< ]
return matrixType; return matrixType;
} }
@ -256,9 +274,9 @@ namespace Nz::ShaderLang
ShaderAst::SamplerType samplerType; ShaderAst::SamplerType samplerType;
samplerType.dim = ImageType::E2D; samplerType.dim = ImageType::E2D;
Expect(Advance(), TokenType::LessThan); //< '<' Expect(Advance(), TokenType::OpenSquareBracket); //< [
samplerType.sampledType = ParsePrimitiveType(); samplerType.sampledType = ParsePrimitiveType();
Expect(Advance(), TokenType::GreaterThan); //< '>' Expect(Advance(), TokenType::ClosingSquareBracket); //< ]
return samplerType; return samplerType;
} }
@ -269,9 +287,9 @@ namespace Nz::ShaderLang
ShaderAst::SamplerType samplerType; ShaderAst::SamplerType samplerType;
samplerType.dim = ImageType::Cubemap; samplerType.dim = ImageType::Cubemap;
Expect(Advance(), TokenType::LessThan); //< '<' Expect(Advance(), TokenType::OpenSquareBracket); //< [
samplerType.sampledType = ParsePrimitiveType(); samplerType.sampledType = ParsePrimitiveType();
Expect(Advance(), TokenType::GreaterThan); //< '>' Expect(Advance(), TokenType::ClosingSquareBracket); //< ]
return samplerType; return samplerType;
} }
@ -281,9 +299,9 @@ namespace Nz::ShaderLang
ShaderAst::UniformType uniformType; ShaderAst::UniformType uniformType;
Expect(Advance(), TokenType::LessThan); //< '<' Expect(Advance(), TokenType::OpenSquareBracket); //< [
uniformType.containedType = ShaderAst::IdentifierType{ ParseIdentifierAsName() }; uniformType.containedType = ShaderAst::IdentifierType{ ParseIdentifierAsName() };
Expect(Advance(), TokenType::GreaterThan); //< '>' Expect(Advance(), TokenType::ClosingSquareBracket); //< ]
return uniformType; return uniformType;
} }
@ -294,9 +312,9 @@ namespace Nz::ShaderLang
ShaderAst::VectorType vectorType; ShaderAst::VectorType vectorType;
vectorType.componentCount = 2; vectorType.componentCount = 2;
Expect(Advance(), TokenType::LessThan); //< '<' Expect(Advance(), TokenType::OpenSquareBracket); //< [
vectorType.type = ParsePrimitiveType(); vectorType.type = ParsePrimitiveType();
Expect(Advance(), TokenType::GreaterThan); //< '>' Expect(Advance(), TokenType::ClosingSquareBracket); //< ]
return vectorType; return vectorType;
} }
@ -307,9 +325,9 @@ namespace Nz::ShaderLang
ShaderAst::VectorType vectorType; ShaderAst::VectorType vectorType;
vectorType.componentCount = 3; vectorType.componentCount = 3;
Expect(Advance(), TokenType::LessThan); //< '<' Expect(Advance(), TokenType::OpenSquareBracket); //< [
vectorType.type = ParsePrimitiveType(); vectorType.type = ParsePrimitiveType();
Expect(Advance(), TokenType::GreaterThan); //< '>' Expect(Advance(), TokenType::ClosingSquareBracket); //< ]
return vectorType; return vectorType;
} }
@ -320,9 +338,9 @@ namespace Nz::ShaderLang
ShaderAst::VectorType vectorType; ShaderAst::VectorType vectorType;
vectorType.componentCount = 4; vectorType.componentCount = 4;
Expect(Advance(), TokenType::LessThan); //< '<' Expect(Advance(), TokenType::OpenSquareBracket); //< [
vectorType.type = ParsePrimitiveType(); vectorType.type = ParsePrimitiveType();
Expect(Advance(), TokenType::GreaterThan); //< '>' Expect(Advance(), TokenType::ClosingSquareBracket); //< ]
return vectorType; return vectorType;
} }
@ -1337,24 +1355,6 @@ namespace Nz::ShaderLang
} }
} }
ShaderAst::ExpressionType Parser::ParseArrayType()
{
ShaderAst::ArrayType arrayType;
Expect(Advance(), TokenType::OpenSquareBracket);
arrayType.containedType = std::make_unique<ShaderAst::ContainedType>();
arrayType.containedType->type = ParseType();
Expect(Advance(), TokenType::Semicolon);
arrayType.length = ParseExpression();
Expect(Advance(), TokenType::ClosingSquareBracket);
return arrayType;
}
ShaderAst::AttributeType Parser::ParseIdentifierAsAttributeType() ShaderAst::AttributeType Parser::ParseIdentifierAsAttributeType()
{ {
const Token& identifierToken = Expect(Advance(), TokenType::Identifier); const Token& identifierToken = Expect(Advance(), TokenType::Identifier);
@ -1402,9 +1402,6 @@ namespace Nz::ShaderLang
return ShaderAst::NoType{}; return ShaderAst::NoType{};
} }
if (Peek().type == TokenType::OpenSquareBracket)
return ParseArrayType();
const Token& identifierToken = Expect(Peek(), TokenType::Identifier); const Token& identifierToken = Expect(Peek(), TokenType::Identifier);
const std::string& identifier = std::get<std::string>(identifierToken.data); const std::string& identifier = std::get<std::string>(identifierToken.data);

View File

@ -13,7 +13,7 @@ TEST_CASE("structure member access", "[Shader]")
std::string_view nzslSource = R"( std::string_view nzslSource = R"(
struct innerStruct struct innerStruct
{ {
field: vec3<f32> field: vec3[f32]
} }
struct outerStruct struct outerStruct
@ -23,7 +23,7 @@ struct outerStruct
external external
{ {
[set(0), binding(0)] ubo: uniform<outerStruct> [set(0), binding(0)] ubo: uniform[outerStruct]
} }
)"; )";

View File

@ -18,7 +18,7 @@ struct inputStruct
external external
{ {
[set(0), binding(0)] data: uniform<inputStruct> [set(0), binding(0)] data: uniform[inputStruct]
} }
[entry(frag)] [entry(frag)]
@ -97,7 +97,7 @@ struct inputStruct
external external
{ {
[set(0), binding(0)] data: uniform<inputStruct> [set(0), binding(0)] data: uniform[inputStruct]
} }
[entry(frag)] [entry(frag)]
@ -161,7 +161,7 @@ struct inputStruct
external external
{ {
[set(0), binding(0)] data: uniform<inputStruct> [set(0), binding(0)] data: uniform[inputStruct]
} }
[entry(frag)] [entry(frag)]

View File

@ -37,7 +37,7 @@ struct inputStruct
external external
{ {
[set(0), binding(0)] data: uniform<inputStruct> [set(0), binding(0)] data: uniform[inputStruct]
} }
[entry(frag)] [entry(frag)]
@ -73,7 +73,7 @@ struct inputStruct
external external
{ {
[set(0), binding(0)] data: uniform<inputStruct> [set(0), binding(0)] data: uniform[inputStruct]
} }
[entry(frag)] [entry(frag)]
@ -97,7 +97,7 @@ struct inputStruct
external external
{ {
[set(0), binding(0)] data: uniform<inputStruct> [set(0), binding(0)] data: uniform[inputStruct]
} }
[entry(frag)] [entry(frag)]
@ -118,18 +118,18 @@ const LightCount = 3;
[layout(std140)] [layout(std140)]
struct Light struct Light
{ {
color: vec4<f32> color: vec4[f32]
} }
[layout(std140)] [layout(std140)]
struct LightData struct LightData
{ {
lights: [Light; LightCount] lights: array[Light, LightCount]
} }
external external
{ {
[set(0), binding(0)] data: uniform<LightData> [set(0), binding(0)] data: uniform[LightData]
} }
[entry(frag)] [entry(frag)]
@ -152,7 +152,7 @@ fn main()
[entry(frag)] [entry(frag)]
fn main() fn main()
{ {
let color: vec4<f32> = (0.000000).xxxx; let color: vec4[f32] = (0.000000).xxxx;
let i: i32 = 0; let i: i32 = 0;
color += data.lights[i].color; color += data.lights[i].color;
let i: i32 = 2; let i: i32 = 2;
@ -175,18 +175,18 @@ const LightCount = 3;
[layout(std140)] [layout(std140)]
struct Light struct Light
{ {
color: vec4<f32> color: vec4[f32]
} }
[layout(std140)] [layout(std140)]
struct LightData struct LightData
{ {
lights: [Light; LightCount] lights: array[Light, LightCount]
} }
external external
{ {
[set(0), binding(0)] data: uniform<LightData> [set(0), binding(0)] data: uniform[LightData]
} }
[entry(frag)] [entry(frag)]
@ -209,7 +209,7 @@ fn main()
[entry(frag)] [entry(frag)]
fn main() fn main()
{ {
let color: vec4<f32> = (0.000000).xxxx; let color: vec4[f32] = (0.000000).xxxx;
let light: Light = data.lights[0]; let light: Light = data.lights[0];
color += light.color; color += light.color;
let light: Light = data.lights[1]; let light: Light = data.lights[1];

View File

@ -18,7 +18,7 @@ struct inputStruct
external external
{ {
[set(0), binding(0)] data: uniform<inputStruct> [set(0), binding(0)] data: uniform[inputStruct]
} }
[entry(frag)] [entry(frag)]
@ -250,12 +250,12 @@ OpFunctionEnd)");
std::string_view nzslSource = R"( std::string_view nzslSource = R"(
struct inputStruct struct inputStruct
{ {
value: [f32; 10] value: array[f32, 10]
} }
external external
{ {
[set(0), binding(0)] data: uniform<inputStruct> [set(0), binding(0)] data: uniform[inputStruct]
} }
[entry(frag)] [entry(frag)]

View File

@ -42,13 +42,13 @@ fn main()
[entry(frag)] [entry(frag)]
fn main() fn main()
{ {
let output = vec4<f32>(8.0, 2.0, -7.0, 0.0) * (7.0 + 5.0) * 2.0 / 4.0; let output = vec4[f32](8.0, 2.0, -7.0, 0.0) * (7.0 + 5.0) * 2.0 / 4.0;
} }
)", R"( )", R"(
[entry(frag)] [entry(frag)]
fn main() fn main()
{ {
let output: vec4<f32> = vec4<f32>(48.000000, 12.000000, -42.000000, 0.000000); let output: vec4[f32] = vec4[f32](48.000000, 12.000000, -42.000000, 0.000000);
)"); )");
} }
@ -149,7 +149,7 @@ fn main()
[entry(frag)] [entry(frag)]
fn main() fn main()
{ {
let value = vec3<f32>(3.0, 0.0, 1.0).z; let value = vec3[f32](3.0, 0.0, 1.0).z;
} }
)", R"( )", R"(
[entry(frag)] [entry(frag)]
@ -172,7 +172,7 @@ fn main()
[entry(frag)] [entry(frag)]
fn main() fn main()
{ {
let value: vec4<f32> = vec4<f32>(42.000000, 42.000000, 42.000000, 42.000000); let value: vec4[f32] = vec4[f32](42.000000, 42.000000, 42.000000, 42.000000);
} }
)"); )");
} }
@ -183,13 +183,13 @@ fn main()
[entry(frag)] [entry(frag)]
fn main() fn main()
{ {
let value = vec4<f32>(3.0, 0.0, 1.0, 2.0).yzwx; let value = vec4[f32](3.0, 0.0, 1.0, 2.0).yzwx;
} }
)", R"( )", R"(
[entry(frag)] [entry(frag)]
fn main() fn main()
{ {
let value: vec4<f32> = vec4<f32>(0.000000, 1.000000, 2.000000, 3.000000); let value: vec4[f32] = vec4[f32](0.000000, 1.000000, 2.000000, 3.000000);
} }
)"); )");
} }
@ -200,13 +200,13 @@ fn main()
[entry(frag)] [entry(frag)]
fn main() fn main()
{ {
let value = vec4<f32>(3.0, 0.0, 1.0, 2.0).zzxx; let value = vec4[f32](3.0, 0.0, 1.0, 2.0).zzxx;
} }
)", R"( )", R"(
[entry(frag)] [entry(frag)]
fn main() fn main()
{ {
let value: vec4<f32> = vec4<f32>(1.000000, 1.000000, 3.000000, 3.000000); let value: vec4[f32] = vec4[f32](1.000000, 1.000000, 3.000000, 3.000000);
} }
)"); )");
} }
@ -217,13 +217,13 @@ fn main()
[entry(frag)] [entry(frag)]
fn main() fn main()
{ {
let value = vec4<f32>(0.0, 1.0, 2.0, 3.0).xyz.yz.y.x.xxxx; let value = vec4[f32](0.0, 1.0, 2.0, 3.0).xyz.yz.y.x.xxxx;
} }
)", R"( )", R"(
[entry(frag)] [entry(frag)]
fn main() fn main()
{ {
let value: vec4<f32> = vec4<f32>(2.000000, 2.000000, 2.000000, 2.000000); let value: vec4[f32] = vec4[f32](2.000000, 2.000000, 2.000000, 2.000000);
} }
)"); )");
} }
@ -233,12 +233,12 @@ fn main()
ExpectOptimization(R"( ExpectOptimization(R"(
struct inputStruct struct inputStruct
{ {
value: vec4<f32> value: vec4[f32]
} }
external external
{ {
[set(0), binding(0)] data: uniform<inputStruct> [set(0), binding(0)] data: uniform[inputStruct]
} }
[entry(frag)] [entry(frag)]
@ -250,7 +250,7 @@ fn main()
[entry(frag)] [entry(frag)]
fn main() fn main()
{ {
let value: vec4<f32> = data.value.zzzz; let value: vec4[f32] = data.value.zzzz;
} }
)"); )");
} }

View File

@ -19,7 +19,7 @@ struct inputStruct
external external
{ {
[set(0), binding(0)] data: uniform<inputStruct> [set(0), binding(0)] data: uniform[inputStruct]
} }
[entry(frag)] [entry(frag)]
@ -84,12 +84,12 @@ fn main()
std::string_view nzslSource = R"( std::string_view nzslSource = R"(
struct inputStruct struct inputStruct
{ {
value: [f32; 10] value: array[f32, 10]
} }
external external
{ {
[set(0), binding(0)] data: uniform<inputStruct> [set(0), binding(0)] data: uniform[inputStruct]
} }
[entry(frag)] [entry(frag)]
@ -131,49 +131,49 @@ fn main()
WHEN("removing matrix casts") WHEN("removing matrix casts")
{ {
std::string_view nzslSource = R"( std::string_view nzslSource = R"(
fn testMat2ToMat2(input: mat2<f32>) -> mat2<f32> fn testMat2ToMat2(input: mat2[f32]) -> mat2[f32]
{ {
return mat2<f32>(input); return mat2[f32](input);
} }
fn testMat2ToMat3(input: mat2<f32>) -> mat3<f32> fn testMat2ToMat3(input: mat2[f32]) -> mat3[f32]
{ {
return mat3<f32>(input); return mat3[f32](input);
} }
fn testMat2ToMat4(input: mat2<f32>) -> mat4<f32> fn testMat2ToMat4(input: mat2[f32]) -> mat4[f32]
{ {
return mat4<f32>(input); return mat4[f32](input);
} }
fn testMat3ToMat2(input: mat3<f32>) -> mat2<f32> fn testMat3ToMat2(input: mat3[f32]) -> mat2[f32]
{ {
return mat2<f32>(input); return mat2[f32](input);
} }
fn testMat3ToMat3(input: mat3<f32>) -> mat3<f32> fn testMat3ToMat3(input: mat3[f32]) -> mat3[f32]
{ {
return mat3<f32>(input); return mat3[f32](input);
} }
fn testMat3ToMat4(input: mat3<f32>) -> mat4<f32> fn testMat3ToMat4(input: mat3[f32]) -> mat4[f32]
{ {
return mat4<f32>(input); return mat4[f32](input);
} }
fn testMat4ToMat2(input: mat4<f32>) -> mat2<f32> fn testMat4ToMat2(input: mat4[f32]) -> mat2[f32]
{ {
return mat2<f32>(input); return mat2[f32](input);
} }
fn testMat4ToMat3(input: mat4<f32>) -> mat3<f32> fn testMat4ToMat3(input: mat4[f32]) -> mat3[f32]
{ {
return mat3<f32>(input); return mat3[f32](input);
} }
fn testMat4ToMat4(input: mat4<f32>) -> mat4<f32> fn testMat4ToMat4(input: mat4[f32]) -> mat4[f32]
{ {
return mat4<f32>(input); return mat4[f32](input);
} }
)"; )";
@ -185,71 +185,71 @@ fn testMat4ToMat4(input: mat4<f32>) -> mat4<f32>
REQUIRE_NOTHROW(shader = Nz::ShaderAst::Sanitize(*shader, options)); REQUIRE_NOTHROW(shader = Nz::ShaderAst::Sanitize(*shader, options));
ExpectNZSL(*shader, R"( ExpectNZSL(*shader, R"(
fn testMat2ToMat2(input: mat2<f32>) -> mat2<f32> fn testMat2ToMat2(input: mat2[f32]) -> mat2[f32]
{ {
return input; return input;
} }
fn testMat2ToMat3(input: mat2<f32>) -> mat3<f32> fn testMat2ToMat3(input: mat2[f32]) -> mat3[f32]
{ {
let temp: mat3<f32>; let temp: mat3[f32];
temp[0] = vec3<f32>(input[0], 0.000000); temp[0] = vec3[f32](input[0], 0.000000);
temp[1] = vec3<f32>(input[1], 0.000000); temp[1] = vec3[f32](input[1], 0.000000);
temp[2] = vec3<f32>(input[2], 1.000000); temp[2] = vec3[f32](input[2], 1.000000);
return temp; return temp;
} }
fn testMat2ToMat4(input: mat2<f32>) -> mat4<f32> fn testMat2ToMat4(input: mat2[f32]) -> mat4[f32]
{ {
let temp: mat4<f32>; let temp: mat4[f32];
temp[0] = vec4<f32>(input[0], 0.000000, 0.000000); temp[0] = vec4[f32](input[0], 0.000000, 0.000000);
temp[1] = vec4<f32>(input[1], 0.000000, 0.000000); temp[1] = vec4[f32](input[1], 0.000000, 0.000000);
temp[2] = vec4<f32>(input[2], 1.000000, 0.000000); temp[2] = vec4[f32](input[2], 1.000000, 0.000000);
temp[3] = vec4<f32>(input[3], 0.000000, 1.000000); temp[3] = vec4[f32](input[3], 0.000000, 1.000000);
return temp; return temp;
} }
fn testMat3ToMat2(input: mat3<f32>) -> mat2<f32> fn testMat3ToMat2(input: mat3[f32]) -> mat2[f32]
{ {
let temp: mat2<f32>; let temp: mat2[f32];
temp[0] = input[0].xy; temp[0] = input[0].xy;
temp[1] = input[1].xy; temp[1] = input[1].xy;
return temp; return temp;
} }
fn testMat3ToMat3(input: mat3<f32>) -> mat3<f32> fn testMat3ToMat3(input: mat3[f32]) -> mat3[f32]
{ {
return input; return input;
} }
fn testMat3ToMat4(input: mat3<f32>) -> mat4<f32> fn testMat3ToMat4(input: mat3[f32]) -> mat4[f32]
{ {
let temp: mat4<f32>; let temp: mat4[f32];
temp[0] = vec4<f32>(input[0], 0.000000); temp[0] = vec4[f32](input[0], 0.000000);
temp[1] = vec4<f32>(input[1], 0.000000); temp[1] = vec4[f32](input[1], 0.000000);
temp[2] = vec4<f32>(input[2], 0.000000); temp[2] = vec4[f32](input[2], 0.000000);
temp[3] = vec4<f32>(input[3], 1.000000); temp[3] = vec4[f32](input[3], 1.000000);
return temp; return temp;
} }
fn testMat4ToMat2(input: mat4<f32>) -> mat2<f32> fn testMat4ToMat2(input: mat4[f32]) -> mat2[f32]
{ {
let temp: mat2<f32>; let temp: mat2[f32];
temp[0] = input[0].xy; temp[0] = input[0].xy;
temp[1] = input[1].xy; temp[1] = input[1].xy;
return temp; return temp;
} }
fn testMat4ToMat3(input: mat4<f32>) -> mat3<f32> fn testMat4ToMat3(input: mat4[f32]) -> mat3[f32]
{ {
let temp: mat3<f32>; let temp: mat3[f32];
temp[0] = input[0].xyz; temp[0] = input[0].xyz;
temp[1] = input[1].xyz; temp[1] = input[1].xyz;
temp[2] = input[2].xyz; temp[2] = input[2].xyz;
return temp; return temp;
} }
fn testMat4ToMat4(input: mat4<f32>) -> mat4<f32> fn testMat4ToMat4(input: mat4[f32]) -> mat4[f32]
{ {
return input; return input;
} }

View File

@ -16,7 +16,7 @@ TEST_CASE("swizzle", "[Shader]")
[entry(frag)] [entry(frag)]
fn main() fn main()
{ {
let vec = vec4<f32>(0.0, 1.0, 2.0, 3.0); let vec = vec4[f32](0.0, 1.0, 2.0, 3.0);
let value = vec.xyz; let value = vec.xyz;
} }
)"; )";
@ -35,8 +35,8 @@ void main()
[entry(frag)] [entry(frag)]
fn main() fn main()
{ {
let vec: vec4<f32> = vec4<f32>(0.000000, 1.000000, 2.000000, 3.000000); let vec: vec4[f32] = vec4[f32](0.000000, 1.000000, 2.000000, 3.000000);
let value: vec3<f32> = vec.xyz; let value: vec3[f32] = vec.xyz;
} }
)"); )");
@ -60,8 +60,8 @@ OpFunctionEnd)");
[entry(frag)] [entry(frag)]
fn main() fn main()
{ {
let vec = vec4<f32>(0.0, 0.0, 0.0, 0.0); let vec = vec4[f32](0.0, 0.0, 0.0, 0.0);
vec.yzw = vec3<f32>(1.0, 2.0, 3.0); vec.yzw = vec3[f32](1.0, 2.0, 3.0);
} }
)"; )";
@ -79,8 +79,8 @@ void main()
[entry(frag)] [entry(frag)]
fn main() fn main()
{ {
let vec: vec4<f32> = vec4<f32>(0.000000, 0.000000, 0.000000, 0.000000); let vec: vec4[f32] = vec4[f32](0.000000, 0.000000, 0.000000, 0.000000);
vec.yzw = vec3<f32>(1.000000, 2.000000, 3.000000); vec.yzw = vec3[f32](1.000000, 2.000000, 3.000000);
} }
)"); )");
@ -127,7 +127,7 @@ void main()
fn main() fn main()
{ {
let value: f32 = 42.000000; let value: f32 = 42.000000;
let vec: vec3<f32> = value.xxx; let vec: vec3[f32] = value.xxx;
} }
)"); )");
@ -171,8 +171,8 @@ void main()
[entry(frag)] [entry(frag)]
fn main() fn main()
{ {
let vec: vec3<f32> = (max(2.000000, 1.000000)).xxx; let vec: vec3[f32] = (max(2.000000, 1.000000)).xxx;
let vec2: vec3<f32> = (min(2.000000, 1.000000)).xxx; let vec2: vec3[f32] = (min(2.000000, 1.000000)).xxx;
} }
)"); )");
@ -200,7 +200,7 @@ OpFunctionEnd)");
[entry(frag)] [entry(frag)]
fn main() fn main()
{ {
let vec = vec4<f32>(0.0, 1.0, 2.0, 3.0); let vec = vec4[f32](0.0, 1.0, 2.0, 3.0);
let value = vec.xyz.yz.y.x.xxxx; let value = vec.xyz.yz.y.x.xxxx;
} }
)"; )";
@ -219,8 +219,8 @@ void main()
[entry(frag)] [entry(frag)]
fn main() fn main()
{ {
let vec: vec4<f32> = vec4<f32>(0.000000, 1.000000, 2.000000, 3.000000); let vec: vec4[f32] = vec4[f32](0.000000, 1.000000, 2.000000, 3.000000);
let value: vec4<f32> = vec.xyz.yz.y.x.xxxx; let value: vec4[f32] = vec.xyz.yz.y.x.xxxx;
} }
)"); )");
@ -247,9 +247,9 @@ OpFunctionEnd)");
[entry(frag)] [entry(frag)]
fn main() fn main()
{ {
let vec = vec4<f32>(0.0, 1.0, 2.0, 3.0); let vec = vec4[f32](0.0, 1.0, 2.0, 3.0);
vec.wyxz.bra.ts.x = 0.0; vec.wyxz.bra.ts.x = 0.0;
vec.zyxw.ar.xy.yx = vec2<f32>(1.0, 0.0); vec.zyxw.ar.xy.yx = vec2[f32](1.0, 0.0);
} }
)"; )";
@ -268,9 +268,9 @@ void main()
[entry(frag)] [entry(frag)]
fn main() fn main()
{ {
let vec: vec4<f32> = vec4<f32>(0.000000, 1.000000, 2.000000, 3.000000); let vec: vec4[f32] = vec4[f32](0.000000, 1.000000, 2.000000, 3.000000);
vec.wyxz.zxw.yx.x = 0.000000; vec.wyxz.zxw.yx.x = 0.000000;
vec.zyxw.wx.xy.yx = vec2<f32>(1.000000, 0.000000); vec.zyxw.wx.xy.yx = vec2[f32](1.000000, 0.000000);
} }
)"); )");