diff options
author | metamuffin <metamuffin@disroot.org> | 2025-01-24 18:25:25 +0100 |
---|---|---|
committer | metamuffin <metamuffin@disroot.org> | 2025-01-24 18:25:25 +0100 |
commit | b4aaaae52b3b746a5e1ef8a98151c627f2787e38 (patch) | |
tree | 397eee51c86670f46947d94838c36f57c320f3d7 /client/src/shaders | |
parent | ce82f40bc4bd03963390d2c95ec688fccc4740b0 (diff) | |
download | weareserver-b4aaaae52b3b746a5e1ef8a98151c627f2787e38.tar weareserver-b4aaaae52b3b746a5e1ef8a98151c627f2787e38.tar.bz2 weareserver-b4aaaae52b3b746a5e1ef8a98151c627f2787e38.tar.zst |
fix things up but no light
Diffstat (limited to 'client/src/shaders')
-rw-r--r-- | client/src/shaders/fragment_pbr.wgsl | 19 | ||||
-rw-r--r-- | client/src/shaders/vertex_world.wgsl | 16 | ||||
-rw-r--r-- | client/src/shaders/vertex_world_skin.wgsl | 14 |
3 files changed, 25 insertions, 24 deletions
diff --git a/client/src/shaders/fragment_pbr.wgsl b/client/src/shaders/fragment_pbr.wgsl index f3387a1..60d7737 100644 --- a/client/src/shaders/fragment_pbr.wgsl +++ b/client/src/shaders/fragment_pbr.wgsl @@ -17,8 +17,8 @@ struct VertexOut { @builtin(position) clip: vec4<f32>, @location(0) normal: vec3<f32>, @location(1) tangent: vec3<f32>, - @location(2) view: vec3<f32>, - @location(3) texcoord: vec2<f32>, + @location(2) texcoord: vec2<f32>, + @location(3) position: vec3<f32>, } struct Material { @@ -34,8 +34,6 @@ struct Material { @group(1) @binding(1) var tex_normal_sampler: sampler; @group(2) @binding(0) var<uniform> material: Material; -const LIGHT: vec3<f32> = vec3(0.64, 0.64, 0.64); - @fragment fn main(vo: VertexOut) -> @location(0) vec4<f32> { let t_albedo = textureSample(tex_albedo, tex_albedo_sampler, vo.texcoord); @@ -44,16 +42,19 @@ fn main(vo: VertexOut) -> @location(0) vec4<f32> { let tangent_basis = mat3x3(vo.tangent, cross(vo.tangent, vo.normal), vo.normal); let normal = tangent_basis * (t_normal.rgb * 2. - 1.); - let alpha = t_albedo.a; + let light = vec3(0., 0., 0.); + let view = normalize(-vo.position); let ambient = 0.1; - let diffuse = saturate(dot(LIGHT, normal)); - let specular = pow(dot(reflect(-LIGHT, normal), vo.view), material.roughness); + let diffuse = saturate(dot(light, normal)) * 0.7; + let specular = pow(saturate(dot(reflect(-light, normal), view)), 2.); - let lighting = ambient + diffuse; // + specular; + 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) ; + // let color = vec3(dot(normal, view) * 0.5 + 0.5) ; + // let color = view * 0.5 + 0.5; + let alpha = t_albedo.a; // 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 d7bf445..e185289 100644 --- a/client/src/shaders/vertex_world.wgsl +++ b/client/src/shaders/vertex_world.wgsl @@ -23,26 +23,26 @@ struct VertexOut { @builtin(position) clip: vec4<f32>, @location(0) normal: vec3<f32>, @location(1) tangent: vec3<f32>, - @location(2) world: vec3<f32>, - @location(3) texcoord: vec2<f32>, + @location(2) texcoord: vec2<f32>, + @location(3) position: vec3<f32>, } struct PushConst { + modelviewproject: mat4x4<f32>, modelview: mat4x4<f32>, - model_basis: mat3x3<f32>, } var<push_constant> pc: PushConst; @vertex fn main(vi: VertexIn) -> VertexOut { - let clip = pc.modelview * vec4(vi.position, 1.); + let clip = pc.modelviewproject * vec4(vi.position, 1.); let vo = VertexOut( clip, - normalize(pc.model_basis * vi.normal), - normalize(pc.model_basis * vi.tangent), - vi.position - vi.texcoord + normalize((pc.modelview * vec4(vi.normal, 0.)).xyz), + normalize((pc.modelview * vec4(vi.tangent, 0.)).xyz), + vi.texcoord, + (pc.modelview * vec4(vi.position, 1.)).xyz, ); return vo; } diff --git a/client/src/shaders/vertex_world_skin.wgsl b/client/src/shaders/vertex_world_skin.wgsl index 4b45a6f..633f06b 100644 --- a/client/src/shaders/vertex_world_skin.wgsl +++ b/client/src/shaders/vertex_world_skin.wgsl @@ -25,13 +25,13 @@ struct VertexOut { @builtin(position) clip: vec4<f32>, @location(0) normal: vec3<f32>, @location(1) tangent: vec3<f32>, - @location(2) world: vec3<f32>, - @location(3) texcoord: vec2<f32>, + @location(2) texcoord: vec2<f32>, + @location(3) position: vec3<f32>, } struct PushConst { + modelviewproject: mat4x4<f32>, modelview: mat4x4<f32>, - model_basis: mat3x3<f32>, } @group(3) @binding(0) var<uniform> joints: array<mat4x4<f32>, 128>; @@ -42,10 +42,10 @@ fn main(vi: VertexIn) -> VertexOut { let clip = pc.modelview * vec4(vi.position, 1.); let vo = VertexOut( clip, - normalize(pc.model_basis * vi.normal), - normalize(pc.model_basis * vi.tangent), - vi.position, - vi.texcoord + normalize((pc.modelview * vec4(vi.normal, 0.)).xyz), + normalize((pc.modelview * vec4(vi.tangent, 0.)).xyz), + vi.texcoord, + (pc.modelview * vec4(vi.position, 1.)).xyz, ); return vo; } |