pygfx.renderers.wgpu.FogPass
- class pygfx.renderers.wgpu.FogPass(color='#fff', power=1.0)
Bases:
EffectPassAn effect pass that adds fog to the full image, using the depth buffer.
- USES_DEPTH = True
Overloadable class attribute to state whether bindings to the depth buffer are needed.
- uniform_type = {'color': '4xf4', 'power': 'f4', 'time': 'f4'}
Overloadable class attribute that defines the structure of the uniform struct.
In a subclass you should use something like this:
uniform_type = dict( EffectPass.uniform_type, color="4xf4", strength="f4", )
- wgsl = '\n @fragment\n fn fs_main(varyings: Varyings) -> @location(0) vec4<f32> {\n let texIndex = vec2i(varyings.position.xy);\n let raw_depth = textureLoad(depthTex, texIndex, 0);\n let depth = pow(raw_depth, u_effect.power);\n\n let color = textureLoad(colorTex, texIndex, 0);\n let depth_color = u_effect.color;\n\n return mix(color, depth_color, depth);\n }\n '
Overloadable class attribute that contains the WGSL shading code for the fragment shader.
Use the following template:
@fragment fn fs_main(varyings: Varyings) -> @location(0) vec4<f32> { // Available variables: // colorTex - the texture containing the rendered image, or the previous effect pass. // depthTex - the texture containing the renderd depth values. // texSampler - a sampler to use for the above. // varyings.position - the position in physical pixels (a vec4f). // varyings.texCoord - the coordinate in the textures (a vec2f). // u_effect.time - the current time in seconds, changes each frame. // u_effect.xx - whatever uniforms you added. // Calculate the pixel index, e.g. if you want to use textureLoad(). let texIndex = vec2i(varyings.position.xy); // To simply copy the image: return textureSample(colorTex, texSampler, varyings.texCoord); }
- property color
The color of the fog.
- property power
The power to apply to the depth value. Using a value < 1 brings the range more towards the camera.