I feel like I can’t be alone in this. I’m constantly modifying the standard shaders with onBeforeCompile
. I frequently have to look at the raw GLSL to see what variables are available where. It’s not uncommon to have to go in to the THREE source, uncomment the console.log
// console.log( '*VERTEX*', vertexGlsl );
// console.log( '*FRAGMENT*', fragmentGlsl );
and then reload the modules and such. It’s a pain to do this. Am I missing something here? Is there a better workflow?
Seems like something like a shader.debug flag to log this out would be really helpful.
I do this,
console.log(mesh.material.vertexShader)
console.log(mesh.material.fragmentShader)
E.g.,
I’ve used a very rude method in the past. I introduce a deliberate error in the beginning of the shader, and its raw code gets vomited in the console:
material.onBeforeCompile = shader => {
shader.vertexShader =
'fail\n'+ // this causes the shader to fail compilatio n
shader.vertexShader.replace(
'#include <project_vertex>',
`
vec4 mvPosition = vec4( transformed, 1.0 );
vec3 limits = vec3(0.6, 0.75, 1.0);
...and so on...
`
);
}
and then I get this in the console (the fail
appears in line 63):
1 Like
@seanwasere This only shows the GLSL template structure, not the actual GLSL code.
@PavelBoytchev I’ve definitely thought about this. In my case, it only shows the 10 or so lines around the error location.
In Chomium-based browser click on the “Show more” link at the end of the dump (see line 157)
In Firefox click on the second gray triangle at the top of the dump:
That’s not the case in my situation unfortunately. I’d like to not have to switch browsers here either.
Just tried some of the ideas from SO and they worked (my attempt ):
Source of ideas:
Fennec
February 28, 2025, 11:11pm
9
Thanks to @manthrax , I use this three-shaderlib-skim to check the raw definitions.
2 Likes
There is actually a shader debug hook that can get you more info.
I use this in an automated shader workflow I made:
let onShaderError = {
fn: () => {}
}
let triageShader = (gl, shader) => {
return {
status: gl.getShaderParameter(shader, gl.COMPILE_STATUS),
errors: gl.getShaderInfoLog(shader),
source: gl.getShaderSource(shader)
}
}
renderer.debug.onShaderError = (gl, program, glVertexShader, glFragmentShader) => {
let errorInfo = {
vs: triageShader(gl, glVertexShader),
fs: triageShader(gl, glFragmentShader),
gl,
program,
glVertexShader,
glFragmentShader
}
onShaderError.fn(errorInfo)
}
2 Likes