Skip to content

Commit

Permalink
[render] more explicative uintABGRToVec4Color shaders common function
Browse files Browse the repository at this point in the history
  • Loading branch information
alemuntoni committed Feb 8, 2025
1 parent 7136190 commit f30aefd
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ void main()
light = computeLight(u_lightDir, u_lightColor, normal);
}

color = uintToVec4Color(floatBitsToUint(u_userPointColorFloat));
color = uintABGRToVec4Color(floatBitsToUint(u_userPointColorFloat));

if (bool(drawMode0 & VCL_MRS_POINTS_COLOR_VERTEX)) {
color = v_color;
Expand Down Expand Up @@ -118,7 +118,7 @@ void main()
}

/***** compute color ******/
color = uintToVec4Color(floatBitsToUint(u_userSurfaceColorFloat));
color = uintABGRToVec4Color(floatBitsToUint(u_userSurfaceColorFloat));

if (bool(drawMode0 & VCL_MRS_SURF_COLOR_VERTEX)) {
color = v_color;
Expand All @@ -127,7 +127,7 @@ void main()
color = u_meshColor;
}
if (bool(drawMode0 & VCL_MRS_SURF_COLOR_FACE)) {
color = uintToVec4Color(primitiveColors[gl_PrimitiveID]);
color = uintABGRToVec4Color(primitiveColors[gl_PrimitiveID]);
}
if (bool(drawMode0 & VCL_MRS_SURF_TEX_VERTEX)) {
color = getColorFromTexture(0, v_texcoord0);
Expand All @@ -142,7 +142,7 @@ void main()
light = computeLight(u_lightDir, u_lightColor, normal);
}

color = uintToVec4Color(floatBitsToUint(u_userWireframeColorFloat));
color = uintABGRToVec4Color(floatBitsToUint(u_userWireframeColorFloat));

if (bool(drawMode0 & VCL_MRS_WIREFRAME_COLOR_VERT)) {
color = v_color;
Expand Down Expand Up @@ -175,7 +175,7 @@ void main()
}

/***** compute color ******/
color = uintToVec4Color(floatBitsToUint(u_userEdgesColorFloat));
color = uintABGRToVec4Color(floatBitsToUint(u_userEdgesColorFloat));

if (bool(drawMode1 & VCL_MRS_EDGES_COLOR_VERTEX)) {
color = v_color;
Expand All @@ -184,7 +184,7 @@ void main()
color = u_meshColor;
}
if (bool(drawMode1 & VCL_MRS_EDGES_COLOR_EDGE)) {
color = uintToVec4Color(primitiveColors[gl_PrimitiveID]);
color = uintABGRToVec4Color(primitiveColors[gl_PrimitiveID]);
}
depthOffset = 0.00005;
}
Expand Down
7 changes: 6 additions & 1 deletion vclib/render/shaders/vclib/bgfx/shaders_common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,12 @@
#include <bgfx_shader.sh>
#include <bgfx_compute.sh>

vec4 uintToVec4Color(uint color)
/**
* @brief Convert an uint color in ABGR format to a vec4 float color.
* @param[in] color: The input color.
* @return The output color.
*/
vec4 uintABGRToVec4Color(uint color)
{
return vec4(
float(color & uint(0x000000FF)) / 255.0,
Expand Down

0 comments on commit f30aefd

Please sign in to comment.