Skip to content

WebGLNodesHandler: Add missing fogDensity uniform. - #35250

Merged
sunag merged 1 commit into
mrdoob:devfrom
subashc2023:webglnodes-fog-exp2
Oct 28, 2026
Merged

sunag merged 1 commit into
mrdoob:devfrom
subashc2023:webglnodes-fog-exp2

Conversation

@subashc2023

@subashc2023 subashc2023 commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

Related issue: -

Description

With WebGLNodesHandler, a node material in a scene with FogExp2 throws on its first render:

TypeError: Cannot set properties of undefined (setting 'value')

WebGLRenderer refreshes the classic fog uniforms of every material with fog set to true, the default for node materials, and for FogExp2 it writes fogDensity (WebGLMaterials.js). The handler declares fogColor, fogNear and fogFar for this, but not fogDensity. The node shader already supports FogExp2, so the uniform is the only thing missing.

import * as THREE from 'three/webgpu';
import { WebGLRenderer } from 'three';
import { WebGLNodesHandler } from 'three/addons/tsl/WebGLNodesHandler.js';

const renderer = new WebGLRenderer();
renderer.setNodesHandler( new WebGLNodesHandler() );

const scene = new THREE.Scene();
scene.fog = new THREE.FogExp2( 0x806050, 0.15 ); // THREE.Fog works
scene.add( new THREE.Mesh( new THREE.SphereGeometry(), new THREE.MeshStandardNodeMaterial() ) );

const camera = new THREE.PerspectiveCamera();
camera.position.z = 4;

renderer.render( scene, camera ); // TypeError before this PR

Tested on dev by switching webgl_tsl_shadowmap to FogExp2. Without this PR, every frame throws the error above and nothing renders. With it, the fog renders. With the example's own Fog, nothing changes.

Before:

webglnodes-fog-exp2-before

After:

webglnodes-fog-exp2-after

@sunag sunag added this to the r187 milestone Oct 28, 2026
@sunag
sunag merged commit b46cb82 into mrdoob:dev Oct 28, 2026
9 checks passed
@subashc2023
subashc2023 deleted the webglnodes-fog-exp2 branch October 29, 2026 21:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants