I am following the Three Js journey course and in the example using ShaderMaterial, when there is an error in the vertexShader program, the console outputs all the lines of code in the console like the following:
But my console does not display all the lines, it simply states the error:
For anyone else who finds this thread on Google, here is the solution (as of the latest version 0.152.2).
You can change the logging behavior via WebGLRenderer.debug.onShaderError. The default value of null enables Three.js default logging behavior shown here.
If you want to print the full contents of both the vertex and fragment shader, you can read their source via WebGLRenderingContext.getShaderSource( shader: WebGLShader )
For example, this snippet will print each shader’s contents to the console in a neatly collapsed group.
Did anyone ever make the best of both worlds? Is there a public formatter for this? Id like to see what the error is, but not just a snippet of the shader, i need the entire string
You get the “error at line xxx, duplicate whatever” except, by default you dont see the whole string. If you add the onShaderError it turns off that behavior. It would be cool if onShaderError contained that default formatted message.
I’m not sure if they are appropriately exposed but you could try implementing the default error reporting functions from inside that callback… namely getShaderErrors( gl, glVertexShader, 'vertex' ) and renderer.getError()
Edit: it looks like renderer.getProgramInfoLog is the method that gives the errors’ line number