Highlight shaders when hovering over list item
spite opened this issue · 7 comments
It probably has to do with replacing gl_FragColor.rgb *= vec3( 1., 0., 1. ); in the last step of the fragment shader, but I can't figure out a way that:
a) works with any structure of shader - probably requires some interesting regExp
b) won't interfere with the shader source update mechanism (how to distinguish user-type changs from that change) - may be creating a parallel shader for that?
Maybe something like this psuedo-code?
shaderSource.replace('main()', 'internalMain()');
shaderSource.append('void main() { internalMain(); gl_FragColor.r = 1.0; }');
Obviously the replace would need to be more robust than that, but this way you preserve all of the original fragment shader logic. Other candidates for the frag color change would be inverting or swizzling color channels.
That's a good one!
Exactly, checking for a more precise "main()" to prevent changing functions that might be named "{whatever}main()", and that should work!
Let's give it a try and then figure out if there needs to be some caching to prevent continuous re-attaching and re-linking of programs.
Ok, it worked :)
This is definitely going to be a problem with heavy shaders that take longer to compile, but we'll cross that bridge when we come to it.
For now, when version 1.0.2 gets updated in the Chrome Store, there's already color hinting of the program is hovered.
I've tried it with several programs, including your Q3 BSP viewer, and it works as expected :)
Here's a video showing the result https://www.youtube.com/watch?v=vUgUWq5Twdw
Very nice! Glad it works!
Thanks for the suggestion, it really did the trick. I would probably have ended looking for the closing brace of the main() and adding the color modifier. Kudos!
Still not working. There's some issues and it destroys shaders.
The highlighting system -and the toggling visibility system, which is based on the same idea-, is working. If the shader breaks it's because the live-replacing mechanism of the extension is still not good enough. Closing this ticket.