Shader: Switch type<subtype> to type[subtype]
This commit is contained in:
@@ -21,50 +21,50 @@ const HasUV = (UvLocation >= 0);
|
||||
struct MaterialSettings
|
||||
{
|
||||
AlphaThreshold: f32,
|
||||
DiffuseColor: vec4<f32>
|
||||
DiffuseColor: vec4[f32]
|
||||
}
|
||||
|
||||
[layout(std140)]
|
||||
struct InstanceData
|
||||
{
|
||||
worldMatrix: mat4<f32>,
|
||||
invWorldMatrix: mat4<f32>
|
||||
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>
|
||||
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<MaterialSettings>,
|
||||
[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>,
|
||||
[binding(0)] settings: uniform[MaterialSettings],
|
||||
[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>,
|
||||
[location(1), cond(HasColor)] color: vec4<f32>
|
||||
[location(0), cond(HasUV)] uv: vec2[f32],
|
||||
[location(1), cond(HasColor)] color: vec4[f32]
|
||||
}
|
||||
|
||||
struct FragOut
|
||||
{
|
||||
[location(0)] RenderTarget0: vec4<f32>
|
||||
[location(0)] RenderTarget0: vec4[f32]
|
||||
}
|
||||
|
||||
[entry(frag)]
|
||||
@@ -99,29 +99,29 @@ fn main(input: FragIn) -> FragOut
|
||||
struct VertIn
|
||||
{
|
||||
[location(PosLocation)]
|
||||
pos: vec3<f32>,
|
||||
pos: vec3[f32],
|
||||
|
||||
[cond(HasVertexColor), location(ColorLocation)]
|
||||
color: vec4<f32>,
|
||||
color: vec4[f32],
|
||||
|
||||
[cond(HasUV), location(UvLocation)]
|
||||
uv: vec2<f32>,
|
||||
uv: vec2[f32],
|
||||
|
||||
[cond(Billboard), location(BillboardCenterLocation)]
|
||||
billboardCenter: vec3<f32>,
|
||||
billboardCenter: vec3[f32],
|
||||
|
||||
[cond(Billboard), location(BillboardSizeRotLocation)]
|
||||
billboardSizeRot: vec4<f32>, //< width,height,sin,cos
|
||||
billboardSizeRot: vec4[f32], //< width,height,sin,cos
|
||||
|
||||
[cond(Billboard), location(BillboardColorLocation)]
|
||||
billboardColor: vec4<f32>
|
||||
billboardColor: vec4[f32]
|
||||
}
|
||||
|
||||
struct VertOut
|
||||
{
|
||||
[location(0), cond(HasUV)] uv: vec2<f32>,
|
||||
[location(1), cond(HasColor)] color: vec4<f32>,
|
||||
[builtin(position)] position: vec4<f32>
|
||||
[location(0), cond(HasUV)] uv: vec2[f32],
|
||||
[location(1), cond(HasColor)] color: vec4[f32],
|
||||
[builtin(position)] position: vec4[f32]
|
||||
}
|
||||
|
||||
[entry(vert), cond(Billboard)]
|
||||
@@ -130,27 +130,27 @@ fn billboardMain(input: VertIn) -> VertOut
|
||||
let size = input.billboardSizeRot.xy;
|
||||
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.y * sinCos.y + input.pos.x * sinCos.x
|
||||
);
|
||||
rotatedPosition *= size;
|
||||
|
||||
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 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 vertexPos = input.billboardCenter;
|
||||
vertexPos += cameraRight * rotatedPosition.x;
|
||||
vertexPos += cameraUp * rotatedPosition.y;
|
||||
|
||||
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)
|
||||
output.color = input.billboardColor;
|
||||
|
||||
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;
|
||||
}
|
||||
@@ -159,7 +159,7 @@ fn billboardMain(input: VertIn) -> VertOut
|
||||
fn main(input: VertIn) -> 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)
|
||||
output.color = input.color;
|
||||
|
||||
@@ -1,25 +1,25 @@
|
||||
external
|
||||
{
|
||||
[binding(0)] texture: sampler2D<f32>
|
||||
[binding(0)] texture: sampler2D[f32]
|
||||
}
|
||||
|
||||
struct VertIn
|
||||
{
|
||||
[location(0)] position: vec2<f32>,
|
||||
[location(1)] uv: vec2<f32>
|
||||
[location(0)] position: vec2[f32],
|
||||
[location(1)] uv: vec2[f32]
|
||||
}
|
||||
|
||||
struct VertOut
|
||||
{
|
||||
[builtin(position)] position: vec4<f32>,
|
||||
[location(0)] uv: vec2<f32>
|
||||
[builtin(position)] position: vec4[f32],
|
||||
[location(0)] uv: vec2[f32]
|
||||
}
|
||||
|
||||
[entry(vert)]
|
||||
fn main(vertIn: VertIn) -> 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;
|
||||
|
||||
return output;
|
||||
@@ -27,7 +27,7 @@ fn main(vertIn: VertIn) -> VertOut
|
||||
|
||||
struct FragOut
|
||||
{
|
||||
[location(0)] color: vec4<f32>
|
||||
[location(0)] color: vec4[f32]
|
||||
}
|
||||
|
||||
[entry(frag)]
|
||||
|
||||
@@ -8,44 +8,44 @@ const HasUV = AlphaTest && (HasDiffuseTexture || HasAlphaTexture);
|
||||
struct BasicSettings
|
||||
{
|
||||
AlphaThreshold: f32,
|
||||
DiffuseColor: vec4<f32>
|
||||
DiffuseColor: vec4[f32]
|
||||
}
|
||||
|
||||
[layout(std140)]
|
||||
struct InstanceData
|
||||
{
|
||||
worldMatrix: mat4<f32>,
|
||||
invWorldMatrix: mat4<f32>
|
||||
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>
|
||||
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>,
|
||||
[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>
|
||||
[location(0), cond(HasUV)] uv: vec2[f32]
|
||||
}
|
||||
|
||||
[entry(frag), cond(AlphaTest)]
|
||||
@@ -73,21 +73,21 @@ fn main() {}
|
||||
// Vertex stage
|
||||
struct VertIn
|
||||
{
|
||||
[location(0)] pos: vec3<f32>,
|
||||
[location(1), cond(HasUV)] uv: vec2<f32>
|
||||
[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>
|
||||
[location(0), cond(HasUV)] uv: vec2[f32],
|
||||
[builtin(position)] position: vec4[f32]
|
||||
}
|
||||
|
||||
[entry(vert)]
|
||||
fn main(input: VertIn) -> 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)
|
||||
output.uv = input.uv;
|
||||
|
||||
@@ -36,19 +36,19 @@ struct MaterialSettings
|
||||
{
|
||||
// BasicSettings
|
||||
AlphaThreshold: f32,
|
||||
DiffuseColor: vec4<f32>,
|
||||
DiffuseColor: vec4[f32],
|
||||
|
||||
// PhongSettings
|
||||
AmbientColor: vec3<f32>,
|
||||
SpecularColor: vec3<f32>,
|
||||
AmbientColor: vec3[f32],
|
||||
SpecularColor: vec3[f32],
|
||||
Shininess: f32,
|
||||
}
|
||||
|
||||
[layout(std140)]
|
||||
struct InstanceData
|
||||
{
|
||||
worldMatrix: mat4<f32>,
|
||||
invWorldMatrix: mat4<f32>
|
||||
worldMatrix: mat4[f32],
|
||||
invWorldMatrix: mat4[f32]
|
||||
}
|
||||
|
||||
// TODO: Add enums
|
||||
@@ -60,64 +60,64 @@ const SpotLight = 2;
|
||||
struct Light
|
||||
{
|
||||
type: i32,
|
||||
color: vec4<f32>,
|
||||
factor: vec2<f32>,
|
||||
parameter1: vec4<f32>,
|
||||
parameter2: vec4<f32>,
|
||||
parameter3: vec4<f32>,
|
||||
hasShadowMapping: bool
|
||||
color: vec4[f32],
|
||||
factor: vec2[f32],
|
||||
parameter1: vec4[f32],
|
||||
parameter2: vec4[f32],
|
||||
parameter3: vec4[f32],
|
||||
hasShadowMapping: u32
|
||||
}
|
||||
|
||||
[layout(std140)]
|
||||
struct LightData
|
||||
{
|
||||
lights: [Light; MaxLightCount],
|
||||
lightCount: u32,
|
||||
lights: array[Light, MaxLightCount],
|
||||
lightCount: u32
|
||||
}
|
||||
|
||||
[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>
|
||||
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<MaterialSettings>,
|
||||
[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>,
|
||||
[binding(6)] lightData: uniform<LightData>,
|
||||
[binding(7)] MaterialEmissiveMap: sampler2D<f32>,
|
||||
[binding(8)] MaterialHeightMap: sampler2D<f32>,
|
||||
[binding(9)] MaterialNormalMap: sampler2D<f32>,
|
||||
[binding(10)] MaterialSpecularMap: sampler2D<f32>,
|
||||
[binding(0)] settings: uniform[MaterialSettings],
|
||||
[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],
|
||||
[binding(6)] lightData: uniform[LightData],
|
||||
[binding(7)] MaterialEmissiveMap: sampler2D[f32],
|
||||
[binding(8)] MaterialHeightMap: sampler2D[f32],
|
||||
[binding(9)] MaterialNormalMap: sampler2D[f32],
|
||||
[binding(10)] MaterialSpecularMap: sampler2D[f32],
|
||||
}
|
||||
|
||||
struct VertToFrag
|
||||
{
|
||||
[location(0)] worldPos: vec3<f32>,
|
||||
[location(1), cond(HasUV)] uv: vec2<f32>,
|
||||
[location(2), cond(HasColor)] color: vec4<f32>,
|
||||
[location(3), cond(HasNormal)] normal: vec3<f32>,
|
||||
[location(4), cond(HasNormalMapping)] tbnMatrix: mat3<f32>,
|
||||
[builtin(position)] position: vec4<f32>,
|
||||
[location(0)] worldPos: vec3[f32],
|
||||
[location(1), cond(HasUV)] uv: vec2[f32],
|
||||
[location(2), cond(HasColor)] color: vec4[f32],
|
||||
[location(3), cond(HasNormal)] normal: vec3[f32],
|
||||
[location(4), cond(HasNormalMapping)] tbnMatrix: mat3[f32],
|
||||
[builtin(position)] position: vec4[f32],
|
||||
}
|
||||
|
||||
// Fragment stage
|
||||
struct FragOut
|
||||
{
|
||||
[location(0)] RenderTarget0: vec4<f32>
|
||||
[location(0)] RenderTarget0: vec4[f32]
|
||||
}
|
||||
|
||||
[entry(frag)]
|
||||
@@ -145,15 +145,15 @@ fn main(input: VertToFrag) -> FragOut
|
||||
|
||||
const if (HasNormal)
|
||||
{
|
||||
let lightAmbient = 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 lightAmbient = 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 eyeVec = normalize(viewerData.eyePosition - input.worldPos);
|
||||
|
||||
let normal: vec3<f32>;
|
||||
let normal: vec3[f32];
|
||||
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
|
||||
normal = normalize(input.normal);
|
||||
|
||||
@@ -244,7 +244,7 @@ fn main(input: VertToFrag) -> FragOut
|
||||
let lightColor = lightAmbient + lightDiffuse + lightSpecular;
|
||||
|
||||
let output: FragOut;
|
||||
output.RenderTarget0 = vec4<f32>(lightColor, 1.0) * diffuseColor;
|
||||
output.RenderTarget0 = vec4[f32](lightColor, 1.0) * diffuseColor;
|
||||
return output;
|
||||
}
|
||||
else
|
||||
@@ -259,28 +259,28 @@ fn main(input: VertToFrag) -> FragOut
|
||||
struct VertIn
|
||||
{
|
||||
[location(PosLocation)]
|
||||
pos: vec3<f32>,
|
||||
pos: vec3[f32],
|
||||
|
||||
[cond(HasVertexColor), location(ColorLocation)]
|
||||
color: vec4<f32>,
|
||||
color: vec4[f32],
|
||||
|
||||
[cond(HasUV), location(UvLocation)]
|
||||
uv: vec2<f32>,
|
||||
uv: vec2[f32],
|
||||
|
||||
[cond(HasNormal), location(NormalLocation)]
|
||||
normal: vec3<f32>,
|
||||
normal: vec3[f32],
|
||||
|
||||
[cond(HasTangent), location(TangentLocation)]
|
||||
tangent: vec3<f32>,
|
||||
tangent: vec3[f32],
|
||||
|
||||
[cond(Billboard), location(BillboardCenterLocation)]
|
||||
billboardCenter: vec3<f32>,
|
||||
billboardCenter: vec3[f32],
|
||||
|
||||
[cond(Billboard), location(BillboardSizeRotLocation)]
|
||||
billboardSizeRot: vec4<f32>, //< width,height,sin,cos
|
||||
billboardSizeRot: vec4[f32], //< width,height,sin,cos
|
||||
|
||||
[cond(Billboard), location(BillboardColorLocation)]
|
||||
billboardColor: vec4<f32>
|
||||
billboardColor: vec4[f32]
|
||||
}
|
||||
|
||||
[entry(vert), cond(Billboard)]
|
||||
@@ -289,27 +289,27 @@ fn billboardMain(input: VertIn) -> VertOut
|
||||
let size = input.billboardSizeRot.xy;
|
||||
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.y * sinCos.y + input.pos.x * sinCos.x
|
||||
);
|
||||
rotatedPosition *= size;
|
||||
|
||||
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 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 vertexPos = input.billboardCenter;
|
||||
vertexPos += cameraRight * rotatedPosition.x;
|
||||
vertexPos += cameraUp * rotatedPosition.y;
|
||||
|
||||
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)
|
||||
output.color = input.billboardColor;
|
||||
|
||||
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;
|
||||
}
|
||||
@@ -317,13 +317,13 @@ fn billboardMain(input: VertIn) -> VertOut
|
||||
[entry(vert), cond(!Billboard)]
|
||||
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;
|
||||
output.worldPos = worldPosition.xyz;
|
||||
output.position = viewerData.viewProjMatrix * worldPosition;
|
||||
|
||||
let rotationMatrix = mat3<f32>(instanceData.worldMatrix);
|
||||
let rotationMatrix = mat3[f32](instanceData.worldMatrix);
|
||||
|
||||
const if (HasColor)
|
||||
output.color = input.color;
|
||||
|
||||
@@ -431,7 +431,7 @@ namespace Nz::ShaderAst
|
||||
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;
|
||||
if (vectorComponentCount != targetMatrixType.rowCount)
|
||||
{
|
||||
@@ -1967,7 +1967,7 @@ namespace Nz::ShaderAst
|
||||
{
|
||||
const ExpressionType& type = GetExpressionType(*node.parameters.front());
|
||||
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;
|
||||
break;
|
||||
|
||||
@@ -126,7 +126,7 @@ namespace Nz
|
||||
|
||||
void LangWriter::Append(const ShaderAst::ArrayType& type)
|
||||
{
|
||||
Append("[", type.containedType->type, "; ");
|
||||
Append("array[", type.containedType->type, ", ");
|
||||
|
||||
if (type.length.IsResultingValue())
|
||||
Append(type.length.GetResultingValue());
|
||||
@@ -164,7 +164,7 @@ namespace Nz
|
||||
Append(matrixType.rowCount);
|
||||
}
|
||||
|
||||
Append("<", matrixType.type, ">");
|
||||
Append("[", matrixType.type, "]");
|
||||
}
|
||||
|
||||
void LangWriter::Append(ShaderAst::PrimitiveType type)
|
||||
@@ -192,7 +192,7 @@ namespace Nz
|
||||
case ImageType::Cubemap: Append("Cube"); break;
|
||||
}
|
||||
|
||||
Append("<", samplerType.sampledType, ">");
|
||||
Append("[", samplerType.sampledType, "]");
|
||||
}
|
||||
|
||||
void LangWriter::Append(const ShaderAst::StructType& structType)
|
||||
@@ -203,17 +203,17 @@ namespace Nz
|
||||
|
||||
void LangWriter::Append(const ShaderAst::UniformType& uniformType)
|
||||
{
|
||||
Append("uniform<");
|
||||
Append("uniform[");
|
||||
std::visit([&](auto&& arg)
|
||||
{
|
||||
Append(arg);
|
||||
}, uniformType.containedType);
|
||||
Append(">");
|
||||
Append("]");
|
||||
}
|
||||
|
||||
void LangWriter::Append(const ShaderAst::VectorType& vecType)
|
||||
{
|
||||
Append("vec", vecType.componentCount, "<", vecType.type, ">");
|
||||
Append("vec", vecType.componentCount, "[", vecType.type, "]");
|
||||
}
|
||||
|
||||
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>)
|
||||
Append(std::to_string(arg));
|
||||
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>)
|
||||
Append("vec2<i32>(" + std::to_string(arg.x) + ", " + std::to_string(arg.y) + ")");
|
||||
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>)
|
||||
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>)
|
||||
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>)
|
||||
Append("vec4<i32>(" + std::to_string(arg.x) + ", " + std::to_string(arg.y) + ", " + std::to_string(arg.z) + ", " + std::to_string(arg.w) + ")");
|
||||
else
|
||||
|
||||
@@ -207,7 +207,25 @@ namespace Nz::ShaderLang
|
||||
}
|
||||
|
||||
//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();
|
||||
|
||||
@@ -215,9 +233,9 @@ namespace Nz::ShaderLang
|
||||
matrixType.columnCount = 4;
|
||||
matrixType.rowCount = 4;
|
||||
|
||||
Expect(Advance(), TokenType::LessThan); //< '<'
|
||||
Expect(Advance(), TokenType::OpenSquareBracket); //< [
|
||||
matrixType.type = ParsePrimitiveType();
|
||||
Expect(Advance(), TokenType::GreaterThan); //< '>'
|
||||
Expect(Advance(), TokenType::ClosingSquareBracket); //< ]
|
||||
|
||||
return matrixType;
|
||||
}
|
||||
@@ -229,9 +247,9 @@ namespace Nz::ShaderLang
|
||||
matrixType.columnCount = 3;
|
||||
matrixType.rowCount = 3;
|
||||
|
||||
Expect(Advance(), TokenType::LessThan); //< '<'
|
||||
Expect(Advance(), TokenType::OpenSquareBracket); //< [
|
||||
matrixType.type = ParsePrimitiveType();
|
||||
Expect(Advance(), TokenType::GreaterThan); //< '>'
|
||||
Expect(Advance(), TokenType::ClosingSquareBracket); //< ]
|
||||
|
||||
return matrixType;
|
||||
}
|
||||
@@ -243,9 +261,9 @@ namespace Nz::ShaderLang
|
||||
matrixType.columnCount = 2;
|
||||
matrixType.rowCount = 2;
|
||||
|
||||
Expect(Advance(), TokenType::LessThan); //< '<'
|
||||
Expect(Advance(), TokenType::OpenSquareBracket); //< [
|
||||
matrixType.type = ParsePrimitiveType();
|
||||
Expect(Advance(), TokenType::GreaterThan); //< '>'
|
||||
Expect(Advance(), TokenType::ClosingSquareBracket); //< ]
|
||||
|
||||
return matrixType;
|
||||
}
|
||||
@@ -256,9 +274,9 @@ namespace Nz::ShaderLang
|
||||
ShaderAst::SamplerType samplerType;
|
||||
samplerType.dim = ImageType::E2D;
|
||||
|
||||
Expect(Advance(), TokenType::LessThan); //< '<'
|
||||
Expect(Advance(), TokenType::OpenSquareBracket); //< [
|
||||
samplerType.sampledType = ParsePrimitiveType();
|
||||
Expect(Advance(), TokenType::GreaterThan); //< '>'
|
||||
Expect(Advance(), TokenType::ClosingSquareBracket); //< ]
|
||||
|
||||
return samplerType;
|
||||
}
|
||||
@@ -269,9 +287,9 @@ namespace Nz::ShaderLang
|
||||
ShaderAst::SamplerType samplerType;
|
||||
samplerType.dim = ImageType::Cubemap;
|
||||
|
||||
Expect(Advance(), TokenType::LessThan); //< '<'
|
||||
Expect(Advance(), TokenType::OpenSquareBracket); //< [
|
||||
samplerType.sampledType = ParsePrimitiveType();
|
||||
Expect(Advance(), TokenType::GreaterThan); //< '>'
|
||||
Expect(Advance(), TokenType::ClosingSquareBracket); //< ]
|
||||
|
||||
return samplerType;
|
||||
}
|
||||
@@ -281,9 +299,9 @@ namespace Nz::ShaderLang
|
||||
|
||||
ShaderAst::UniformType uniformType;
|
||||
|
||||
Expect(Advance(), TokenType::LessThan); //< '<'
|
||||
Expect(Advance(), TokenType::OpenSquareBracket); //< [
|
||||
uniformType.containedType = ShaderAst::IdentifierType{ ParseIdentifierAsName() };
|
||||
Expect(Advance(), TokenType::GreaterThan); //< '>'
|
||||
Expect(Advance(), TokenType::ClosingSquareBracket); //< ]
|
||||
|
||||
return uniformType;
|
||||
}
|
||||
@@ -294,9 +312,9 @@ namespace Nz::ShaderLang
|
||||
ShaderAst::VectorType vectorType;
|
||||
vectorType.componentCount = 2;
|
||||
|
||||
Expect(Advance(), TokenType::LessThan); //< '<'
|
||||
Expect(Advance(), TokenType::OpenSquareBracket); //< [
|
||||
vectorType.type = ParsePrimitiveType();
|
||||
Expect(Advance(), TokenType::GreaterThan); //< '>'
|
||||
Expect(Advance(), TokenType::ClosingSquareBracket); //< ]
|
||||
|
||||
return vectorType;
|
||||
}
|
||||
@@ -307,9 +325,9 @@ namespace Nz::ShaderLang
|
||||
ShaderAst::VectorType vectorType;
|
||||
vectorType.componentCount = 3;
|
||||
|
||||
Expect(Advance(), TokenType::LessThan); //< '<'
|
||||
Expect(Advance(), TokenType::OpenSquareBracket); //< [
|
||||
vectorType.type = ParsePrimitiveType();
|
||||
Expect(Advance(), TokenType::GreaterThan); //< '>'
|
||||
Expect(Advance(), TokenType::ClosingSquareBracket); //< ]
|
||||
|
||||
return vectorType;
|
||||
}
|
||||
@@ -320,9 +338,9 @@ namespace Nz::ShaderLang
|
||||
ShaderAst::VectorType vectorType;
|
||||
vectorType.componentCount = 4;
|
||||
|
||||
Expect(Advance(), TokenType::LessThan); //< '<'
|
||||
Expect(Advance(), TokenType::OpenSquareBracket); //< [
|
||||
vectorType.type = ParsePrimitiveType();
|
||||
Expect(Advance(), TokenType::GreaterThan); //< '>'
|
||||
Expect(Advance(), TokenType::ClosingSquareBracket); //< ]
|
||||
|
||||
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()
|
||||
{
|
||||
const Token& identifierToken = Expect(Advance(), TokenType::Identifier);
|
||||
@@ -1402,9 +1402,6 @@ namespace Nz::ShaderLang
|
||||
return ShaderAst::NoType{};
|
||||
}
|
||||
|
||||
if (Peek().type == TokenType::OpenSquareBracket)
|
||||
return ParseArrayType();
|
||||
|
||||
const Token& identifierToken = Expect(Peek(), TokenType::Identifier);
|
||||
const std::string& identifier = std::get<std::string>(identifierToken.data);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user