-
Notifications
You must be signed in to change notification settings - Fork 0
/
fragmentWriteGBuffers.wgsl
33 lines (27 loc) · 1013 Bytes
/
fragmentWriteGBuffers.wgsl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
override paraboloid: bool = false;
struct GBufferOutput {
@location(0) normal : vec4<f32>,
// Textures: diffuse color, reflectivity color, smoothness, emissive etc. could go here
@location(1) albedo : vec4<f32>,
}
@fragment
fn main(
@location(0) fragNormal: vec3<f32>,
@location(1) fragUV : vec2<f32>,
@location(2) zvalue : f32,
@location(3) color_reflectivity : vec4<f32>,
) -> GBufferOutput {
if (paraboloid && zvalue < -0.05) { // Some margin.
discard;
}
// faking some kind of checkerboard texture
let uv = floor(10.0 * fragUV);
let c = 0.5 + 0.5 * ((uv.x + uv.y) - 2.0 * floor((uv.x + uv.y) / 2.0));
let albedo = vec3(c, c, c) * color_reflectivity.rgb;
let reflectivity = color_reflectivity.a;
let normal = normalize(fragNormal);
var output : GBufferOutput;
output.normal = vec4(normal, zvalue); // 放物面逆変換用に、wにzvalueを入れておく
output.albedo = vec4(albedo, reflectivity);
return output;
}