pygfx.renderers.wgpu.NoisePass

class pygfx.renderers.wgpu.NoisePass(noise=0.1)

Bases: EffectPass

An effect pass that adds noise.

uniform_type = {'noise': '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        {$ include 'pygfx.noise.wgsl' $}\n\n        @fragment\n        fn fs_main(varyings: Varyings) -> @location(0) vec4<f32> {\n            let texCoord = varyings.texCoord;\n            let texIndex = vec2i(varyings.position.xy);\n            let noise = random(texCoord.x * texCoord.y * u_effect.time);\n            let color = textureLoad(colorTex, texIndex, 0);\n            return color + noise * u_effect.noise;\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 noise

The strength of the noise.

Examples

Post processing effects 1

Post processing effects 1

Post processing effects 2

Post processing effects 2