summaryrefslogtreecommitdiff
path: root/client/src/shaders/fragment_pbr.wgsl
diff options
context:
space:
mode:
Diffstat (limited to 'client/src/shaders/fragment_pbr.wgsl')
-rw-r--r--client/src/shaders/fragment_pbr.wgsl19
1 files changed, 10 insertions, 9 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 {