From ce82f40bc4bd03963390d2c95ec688fccc4740b0 Mon Sep 17 00:00:00 2001 From: metamuffin Date: Fri, 24 Jan 2025 16:01:11 +0100 Subject: break things --- client/src/shaders/fragment_pbr.wgsl | 11 +++++++++-- client/src/shaders/vertex_world.wgsl | 4 +++- client/src/shaders/vertex_world_skin.wgsl | 4 +++- 3 files changed, 15 insertions(+), 4 deletions(-) (limited to 'client/src/shaders') diff --git a/client/src/shaders/fragment_pbr.wgsl b/client/src/shaders/fragment_pbr.wgsl index f3ed37e..f3387a1 100644 --- a/client/src/shaders/fragment_pbr.wgsl +++ b/client/src/shaders/fragment_pbr.wgsl @@ -17,7 +17,8 @@ struct VertexOut { @builtin(position) clip: vec4, @location(0) normal: vec3, @location(1) tangent: vec3, - @location(2) texcoord: vec2, + @location(2) view: vec3, + @location(3) texcoord: vec2, } struct Material { @@ -44,9 +45,15 @@ fn main(vo: VertexOut) -> @location(0) vec4 { let normal = tangent_basis * (t_normal.rgb * 2. - 1.); let alpha = t_albedo.a; - let lighting = mix(1., saturate(dot(LIGHT, normal)), 0.9); + + let ambient = 0.1; + let diffuse = saturate(dot(LIGHT, normal)); + let specular = pow(dot(reflect(-LIGHT, normal), vo.view), material.roughness); + + let lighting = ambient + diffuse; // + specular; let color = t_albedo.rgb * lighting; + // let color = vec3(dot(normalize(vo.normal), normalize(vo.view)) * 0.5 + 0.5) ; // TODO better (and faster?) randomness for alpha dither if fract(dot(sin(vo.clip * 123.) * 1213., vec4(3., 2., 1., 4.))) > alpha { diff --git a/client/src/shaders/vertex_world.wgsl b/client/src/shaders/vertex_world.wgsl index 5d69acd..d7bf445 100644 --- a/client/src/shaders/vertex_world.wgsl +++ b/client/src/shaders/vertex_world.wgsl @@ -23,7 +23,8 @@ struct VertexOut { @builtin(position) clip: vec4, @location(0) normal: vec3, @location(1) tangent: vec3, - @location(2) texcoord: vec2, + @location(2) world: vec3, + @location(3) texcoord: vec2, } struct PushConst { @@ -40,6 +41,7 @@ fn main(vi: VertexIn) -> VertexOut { clip, normalize(pc.model_basis * vi.normal), normalize(pc.model_basis * vi.tangent), + vi.position vi.texcoord ); return vo; diff --git a/client/src/shaders/vertex_world_skin.wgsl b/client/src/shaders/vertex_world_skin.wgsl index 288950d..4b45a6f 100644 --- a/client/src/shaders/vertex_world_skin.wgsl +++ b/client/src/shaders/vertex_world_skin.wgsl @@ -25,7 +25,8 @@ struct VertexOut { @builtin(position) clip: vec4, @location(0) normal: vec3, @location(1) tangent: vec3, - @location(2) texcoord: vec2, + @location(2) world: vec3, + @location(3) texcoord: vec2, } struct PushConst { @@ -43,6 +44,7 @@ fn main(vi: VertexIn) -> VertexOut { clip, normalize(pc.model_basis * vi.normal), normalize(pc.model_basis * vi.tangent), + vi.position, vi.texcoord ); return vo; -- cgit v1.2.3-70-g09d2