When an object is black due to divide by zero in the shader (which apparently does not throw any error, interesting), physical blur from transmission through semi-rough physical material is incorrect:
However when an object is explicitly black, it works fine:
Should (can) this be fixed within Three.js?
I think the best way to handle it is probably to validate the parameters given before compiling/updating the shader, assuming this was a built in material you were using. Since you can’t really throw an error from within a shader.
What were the parameters you passed to this material that triggered a divide by zero?
Yeah, validating on the JS side seems like the way to go, or some default values in place of 0
s.
The black box behind the transparent one has a custom ShaderMaterial
(arguably not enough checking on the JS side for proper values), and in the shader does this:
...
vec2 uv = fragCoord / iResolution.xy;
gl_FragColor = vec4(0.5 + 0.5 * cos(iTime + uv.xyx + vec3(0,2,4)), 1.0);
where iResolution.xy
is 0,0
when the box is black.