patriciogonzalezvivo/glslViewer

Launch with file that doesn't have .frag extension

danielchasehooper opened this issue · 2 comments

we have some existing shaders in our repo that don't have the .frag extension that we would like to view in glslviewer, is there a way to launch it from the command line without cping to a tmp file with the .frag extension? When you do this you don't get hot reloading for the original file

hi @danielchasehooper! For context we use .frag or .fs to distinguish fragment shaders from vertex shader (.vert or .vs). Files with .glsl extensions are a bit ambiguous, that's why usually you see them when they are part of libraries like on https://lygia.xyz.

Solution, you could create file pairs that include the .glsl counter part. For example:

shader.glsl

uniform vec2 u_resolution;
uniform float u_time;
void main() {
   vec4 color = vec4(0.0,0.0,0.0,1.0);
   vec2 uv = gl_FragCoord.xy/u_resolution;
   ...
   gl_FragColor = color;
}

shader.frag

#include "shader.glsl"

This way:

  1. you don't have duplicate files
  2. glslViewer can track the changes of the original .glsl file
  3. the .frag pairs can be easily generated programatically

we don't use the glsl extension, #include doesn't seem to work if the file doesn't have a glsl extension

It'd be useful if glslviewer had something like a --frag param so that you can launch it like so:
glslviewer --frag shaderFileName and it works with any extension.