patriciogonzalezvivo / glslViewer

Console-based GLSL Sandbox for 2D/3D shaders
BSD 3-Clause "New" or "Revised" License
4.72k stars 350 forks source link

Launch with file that doesn't have .frag extension #352

Open danielchasehooper opened 12 months ago

danielchasehooper commented 12 months ago

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

patriciogonzalezvivo commented 12 months ago

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
danielchasehooper commented 12 months ago

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.