You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: Sources/Rendering/WebGPU/README.md
+40Lines changed: 40 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -128,3 +128,43 @@ Note that none of the classes in the WebGPU directory are meant to be accessed d
128
128
The volume renderer in WebGPU starts in the ForwardPass, which if it detects volumes invokes a volume pass. The volume pass requests bounding boxes from all volumes and renders them, along with the opaque polygonal depth buffer to create min and max ray depth textures. These textures are bounds for each fragment's ray casting. Then the VolumePassFSQ gets invoked with these two bounding textures to actually perfom the ray casting of the voxels between the min and max.
129
129
130
130
The ray casting is done for all volumes at once and the VolumePassFSQ class is where all the complexity and work is done.
131
+
132
+
133
+
## Zbuffer implementation and calculations
134
+
135
+
The depth buffer is stored as a 32bit float and ranges from 1.0 to 0.0. The distance to the near clipping plane is by far the largest factor determining the accuracy of the zbuffer. The farther out you can place the near plane the better. See https://zero-radiance.github.io/post/z-buffer/ for a more detailed analysis of why we use this approach.
136
+
137
+
### Orthographic
138
+
139
+
For orthographic projections the zbuffer ranges from 1.0 at the near plane to 0.0 at the far plane. The depth value in both the vertex and fragment shader is given as
140
+
141
+
```position.z = (zVC + f)/(f - n)```
142
+
143
+
within the fragment shader you can get the z value (in view coordinates)
144
+
145
+
```zVC = position.z * (far - near) - far```
146
+
147
+
The depth valus are linear in depth.
148
+
149
+
### Perspective
150
+
151
+
For perspective we use a reverse infinite far clip projection which ranges from 1.0 at the near plane to 0.0 at infinity. The depth value in the vertex shader is
152
+
153
+
```position.z = near```
154
+
```position.w = -zVC```
155
+
156
+
and in the fragment after division by w as
157
+
158
+
```position.z = -near / zVC```
159
+
160
+
within the shader you can get the z value (in view coordinates)
161
+
162
+
```zVC = -near / position.z```
163
+
164
+
The depth values are not linear in depth.
165
+
166
+
You can offset geometry by a factor cF ranging from 0.0 to 1.0 using the following forumla
0 commit comments