-
-
Notifications
You must be signed in to change notification settings - Fork 35.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WebGLRenderer: Remove material condition for unconditional uniforms. #26467
Conversation
📦 Bundle sizeFull ESM build, minified and gzipped.
🌳 Bundle size after tree-shakingMinimal build including a renderer, camera, empty scene, and dependencies.
|
Do you mind demonstrating with a fiddle what use case is currently not possible? This will make it easier to understand the issue and how the PR fixes it. |
I'm modify const point = new BufferGeometry().setFromPoints([new Vector3(10, 10, 10)])
const material = new PointsMaterial({
color: 0xff0000,
size: 5,
sizeAttenuation: false,
})
const points = new Points(point, material)
scene.add(points)
material.onBeforeCompile = (shader) => {
shader.vertexShader = shader.vertexShader.replace('#include <worldpos_vertex>', /* glsl */`
vec4 worldPosition = modelMatrix * vec4(transformed, 1.0);
// Some manipulations in world space, for example multiply global Y to 0.1
worldPosition.y *= 0.1;
gl_Position = projectionMatrix * modelViewMatrix * inverse(modelMatrix) * worldPosition; // WORK
gl_Position = projectionMatrix * viewMatrix * worldPosition; // NOT WORK
`)
} If I use classic way gl_Position = projectionMatrix * viewMatrix * worldPosition; to convert worldPosition to screenPosition, shader not working, because I know that gl_Position = projectionMatrix * modelViewMatrix * inverse(modelMatrix) * worldPosition; and this work correctly. But this is weird, counterintuitive, and not optimal. My fix removes the material check before passing |
I agree it's a bit unfortunate in context of Would you be okay to make this change just for the view matrix but not for the other two uniforms? There is a section called |
I think all this uniforms must be load unconditional. This declare in global prefixVertex in uniform mat4 modelMatrix;
uniform mat4 modelViewMatrix;
uniform mat4 projectionMatrix;
uniform mat4 viewMatrix;
uniform mat3 normalMatrix;
uniform vec3 cameraPosition;
uniform bool isOrthographic;
ps. |
Just because they are declared does not mean a uniform update is required. Sorry, I have to think about this change since we want to avoid uniform updates whenever possible. I would be okay to update the view matrix because it is listed in the documentation but not with the other ones. |
All these matrices, except About three.js/src/renderers/webgl/WebGLUniforms.js Lines 1095 to 1101 in 39305cf
And load to GPU only if needed |
You are right I have actually missed
Since the uniform is always defined in the scaffold, the uniform is always present in the map and thus would be updated. However, it still might not be evaluated in the shader (e.g. for depth and normal materials). In this context, executing the update is wasted resources. |
One could consider to define |
Уes, I understand you, then it really needs to avoid updating. I think I should return the orthographic update as it was, but I can comment todo or open the issue with your note about transferring |
Update comment.
Description
WebGLRenderer load default (unconditional) uniforms for not all built-in materials. This uniforms declare in
common
shader chunk and include for all built-in materials. Also material has onBeforeCompile callback witchIf I completely legally modify built-in materials, I want to get access to default unconditional uniforms.
In WebGLRenderer before load some uniforms set conditional that check material type, and for some material not provide some uniforms. I am remove this conditionals.
This doesn't affect performance much, but will make the behavior more predictable.