Commit: b7d5d9608e1a0e91b8e037c5253ed1350d7b63d0
Parent: 8aeba1450218830aadfd7b9d08841e02b957561d
Author: Randy Palamar
Date:   Mon, 26 May 2025 21:28:58 -0600
swizzle texture_coordinate in vertex shader instead of fragment
Diffstat:
2 files changed, 6 insertions(+), 5 deletions(-)
diff --git a/common.c b/common.c
@@ -408,6 +408,7 @@ init_viewer(ViewerContext *ctx)
 	"layout(location = " str(MODEL_RENDER_VIEW_MATRIX_LOC)   ") uniform mat4  u_view;\n"
 	"layout(location = " str(MODEL_RENDER_PROJ_MATRIX_LOC)   ") uniform mat4  u_projection;\n"
 	"layout(location = " str(MODEL_RENDER_CLIP_FRACTION_LOC) ") uniform float u_clip_fraction = 1;\n"
+	"layout(location = " str(MODEL_RENDER_SWIZZLE_LOC)       ") uniform bool  u_swizzle;\n"
 	"\n"
 	"\n"
 	"void main()\n"
@@ -415,7 +416,8 @@ init_viewer(ViewerContext *ctx)
 	"\tvec3 pos = v_position;\n"
 	"\tf_orig_texture_coordinate = (v_position + 1) / 2;\n"
 	"\tif (v_position.y == -1) pos.x = clamp(v_position.x, -u_clip_fraction, u_clip_fraction);\n"
-	"\tf_texture_coordinate = (pos + 1) / 2;\n"
+	"\tvec3 tex_coord = (pos + 1) / 2;\n"
+	"\tf_texture_coordinate = u_swizzle? tex_coord.xzy : tex_coord;\n"
 	//"\tf_normal    = normalize(mat3(u_model) * v_normal);\n"
 	"\tf_normal    = v_normal;\n"
 	"\tgl_Position = u_projection * u_view * u_model * vec4(pos, 1);\n"
@@ -433,7 +435,7 @@ init_viewer(ViewerContext *ctx)
 	"layout(location = " str(MODEL_RENDER_LOG_SCALE_LOC)     ") uniform bool  u_log_scale;\n"
 	"layout(location = " str(MODEL_RENDER_BB_COLOUR_LOC)     ") uniform vec4  u_bb_colour   = vec4(" str(BOUNDING_BOX_COLOUR) ");\n"
 	"layout(location = " str(MODEL_RENDER_BB_FRACTION_LOC)   ") uniform float u_bb_fraction = " str(BOUNDING_BOX_FRACTION) ";\n"
-	"layout(location = " str(MODEL_RENDER_SWIZZLE_LOC)       ") uniform bool u_swizzle;\n\n"
+	"\n"
 	"layout(binding = 0) uniform sampler3D u_texture;\n"
 	"\n#line 1\n");
 
diff --git a/render_model.frag.glsl b/render_model.frag.glsl
@@ -20,8 +20,7 @@ bool bounding_box_test(vec3 coord, float p)
 
 void main()
 {
-	vec3 tex_coord = u_swizzle? texture_coordinate.xzy : texture_coordinate;
-	float smp = length(texture(u_texture, tex_coord).xy);
+	float smp = length(texture(u_texture, texture_coordinate).xy);
 	float threshold_val = pow(10.0f, u_threshold / 20.0f);
 	smp = clamp(smp, 0.0f, threshold_val);
 	smp = smp / threshold_val;
@@ -39,7 +38,7 @@ void main()
 		out_colour = vec4(smp, smp, smp, 1);
 	}
 
-	//out_colour = vec4(textureQueryLod(u_texture, tex_coord).y, 0, 0, 1);
+	//out_colour = vec4(textureQueryLod(u_texture, texture_coordinate).y, 0, 0, 1);
 	//out_colour = vec4(abs(normal), 1);
 	//out_colour = vec4(1, 1, 1, smp);
 	//out_colour = vec4(smp * abs(normal), 1);