-
Notifications
You must be signed in to change notification settings - Fork 0
/
vertexWriteGBuffers.wgsl
56 lines (51 loc) · 1.66 KB
/
vertexWriteGBuffers.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
override paraboloid: bool = false;
override viewDirection: f32 = 1.0;
struct Camera {
viewProjectionMatrix : mat4x4<f32>,
invViewProjectionMatrix : mat4x4<f32>,
}
@group(0) @binding(0) var<uniform> camera : Camera;
struct Model {
modelMatrix : mat4x4<f32>,
}
@group(1) @binding(0) var<uniform> model : Model;
struct Material {
color_reflectivity: vec4<f32>, // rgb, a=specular.
}
@group(2) @binding(0) var<uniform> material: Material;
struct VertexOutput {
@builtin(position) Position : vec4<f32>,
@location(0) fragNormal: vec3<f32>, // normal in world space
@location(1) fragUV: vec2<f32>,
@location(2) zvalue: f32,
@location(3) color_reflectivity : vec4<f32>,
}
@vertex
fn main(
@location(0) position : vec3<f32>,
@location(1) normal : vec3<f32>,
@location(2) uv : vec2<f32>,
@location(3) color : vec3<f32>,
) -> VertexOutput {
var output : VertexOutput;
let worldPosition = (model.modelMatrix * vec4(position, 1.0)).xyz;
var vpPosition = camera.viewProjectionMatrix * vec4(worldPosition, 1.0);
var zvalue = 0.0;
var fragNormal = normalize((model.modelMatrix * vec4(normal, 0.0)).xyz);
if (paraboloid) {
// 放物面変換
let shadowZ = length(vpPosition.xyz);
var d = vpPosition.xyz / shadowZ;
d.z *= viewDirection;
let dd = d.xy / (d.z + 1.0);
vpPosition = vec4(dd, shadowZ, 1);
zvalue = d.z;
fragNormal.z *= viewDirection;
}
output.Position = vpPosition;
output.fragNormal = fragNormal;
output.fragUV = uv;
output.zvalue = zvalue;
output.color_reflectivity = vec4(color, material.color_reflectivity.a);
return output;
}