Add u_invModelView uniform to shader and documentation (#3421)

This commit is contained in:
Luigi Malomo
2025-04-12 01:54:42 +02:00
committed by GitHub
parent 01dc8c59b4
commit c8f237a39b
12 changed files with 31 additions and 0 deletions

View File

@@ -3398,6 +3398,7 @@ public static class bgfx
/// - `u_model mat4[BGFX_CONFIG_MAX_BONES]` - array of model matrices.
/// - `u_modelView mat4` - concatenated model view matrix, only first
/// model matrix from array is used.
/// - `u_invModelView mat4` - inverted concatenated model view matrix.
/// - `u_modelViewProj mat4` - concatenated model view projection matrix.
/// - `u_alphaRef float` - alpha reference value for alpha test.
/// </summary>

View File

@@ -3353,6 +3353,7 @@ public static partial class bgfx
/// - `u_model mat4[BGFX_CONFIG_MAX_BONES]` - array of model matrices.
/// - `u_modelView mat4` - concatenated model view matrix, only first
/// model matrix from array is used.
/// - `u_invModelView mat4` - inverted concatenated model view matrix.
/// - `u_modelViewProj mat4` - concatenated model view projection matrix.
/// - `u_alphaRef float` - alpha reference value for alpha test.
/// </summary>

View File

@@ -2807,6 +2807,7 @@ mixin(joinFnBinds((){
* - `u_model mat4[BGFX_CONFIG_MAX_BONES]` - array of model matrices.
* - `u_modelView mat4` - concatenated model view matrix, only first
* model matrix from array is used.
* - `u_invModelView mat4` - inverted concatenated model view matrix.
* - `u_modelViewProj mat4` - concatenated model view projection matrix.
* - `u_alphaRef float` - alpha reference value for alpha test.
Params:

View File

@@ -2731,6 +2731,7 @@ extern fn bgfx_destroy_frame_buffer(_handle: FrameBufferHandle) void;
/// - `u_model mat4[BGFX_CONFIG_MAX_BONES]` - array of model matrices.
/// - `u_modelView mat4` - concatenated model view matrix, only first
/// model matrix from array is used.
/// - `u_invModelView mat4` - inverted concatenated model view matrix.
/// - `u_modelViewProj mat4` - concatenated model view projection matrix.
/// - `u_alphaRef float` - alpha reference value for alpha test.
/// <param name="_name">Uniform name in shader.</param>

View File

@@ -128,6 +128,7 @@ Predefined Uniforms
mat4 u_invViewProj Transform clip-to-world space.
mat4[N] u_model Transform local-to-world space array.
mat4 u_modelView Transform local-to-view space.
mat4 u_invModelView Transform view-to-local space.
mat4 u_modelViewProj Transform local-to-clip space.
float u_alphaRef | The reference value to which incoming alpha
| values are compared.

View File

@@ -3244,6 +3244,7 @@ namespace bgfx
/// - `u_model mat4[BGFX_CONFIG_MAX_BONES]` - array of model matrices.
/// - `u_modelView mat4` - concatenated model view matrix, only first
/// model matrix from array is used.
// - `u_invModelView mat4` - inverted model view matrix.
/// - `u_modelViewProj mat4` - concatenated model view projection matrix.
/// - `u_alphaRef float` - alpha reference value for alpha test.
///

View File

@@ -2167,6 +2167,7 @@ BGFX_C_API void bgfx_destroy_frame_buffer(bgfx_frame_buffer_handle_t _handle);
* - `u_modelView mat4` - concatenated model view matrix, only first
* model matrix from array is used.
* - `u_modelViewProj mat4` - concatenated model view projection matrix.
* - `u_invModelView mat4` - inverted concatenated model view matrix.
* - `u_alphaRef float` - alpha reference value for alpha test.
*
* @param[in] _name Uniform name in shader.

View File

@@ -1954,6 +1954,7 @@ func.destroy { cname = "destroy_frame_buffer" }
--- - `u_model mat4[BGFX_CONFIG_MAX_BONES]` - array of model matrices.
--- - `u_modelView mat4` - concatenated model view matrix, only first
--- model matrix from array is used.
--- - `u_invModelView mat4` - inverted concatenated model view matrix.
--- - `u_modelViewProj mat4` - concatenated model view projection matrix.
--- - `u_alphaRef float` - alpha reference value for alpha test.
---

View File

@@ -982,6 +982,7 @@ namespace bgfx
"u_invViewProj",
"u_model",
"u_modelView",
"u_invModelView",
"u_modelViewProj",
"u_alphaRef4",
};

View File

@@ -843,6 +843,7 @@ namespace bgfx
InvViewProj,
Model,
ModelView,
InvModelView,
ModelViewProj,
AlphaRef,
Count

View File

@@ -721,6 +721,7 @@ uniform mat4 u_viewProj;
uniform mat4 u_invViewProj;
uniform mat4 u_model[BGFX_CONFIG_MAX_BONES];
uniform mat4 u_modelView;
uniform mat4 u_invModelView;
uniform mat4 u_modelViewProj;
uniform vec4 u_alphaRef4;
#define u_alphaRef u_alphaRef4.x

View File

@@ -244,6 +244,26 @@ namespace bgfx
}
break;
case PredefinedUniform::InvModelView:
{
Matrix4 modelView;
Matrix4 invModelView;
const Matrix4& model = frameCache.m_matrixCache.m_cache[_draw.m_startMatrix];
bx::model4x4_mul(&modelView.un.f4x4
, &model.un.f4x4
, &m_view[_view].un.f4x4
);
bx::float4x4_inverse(&invModelView.un.f4x4
, &modelView.un.f4x4
);
_renderer->setShaderUniform4x4f(flags
, predefined.m_loc
, invModelView.un.val
, bx::uint32_min(mtxRegs, predefined.m_count)
);
}
break;
case PredefinedUniform::ModelViewProj:
{
Matrix4 modelViewProj;