Shader Transform Update

This commit is contained in:
Josef 2025-04-02 07:44:25 +02:00
parent fb983f7da3
commit 1808c82c51
1 changed files with 35 additions and 0 deletions

View File

@ -52,6 +52,12 @@ vec3 worldToLocalDirection( vec3 _VERTEX, mat4 _MODEL_MATRIX )
return ( mw * vec4( _VERTEX, 1.0 ) ).xyz;
}
vec3 worldToView( vec3 world, mat4 _VIEW_MATRIX )
{
return ( _VIEW_MATRIX * vec4( world, 1.0 ) ).xyz;
}
vec3 worldToViewDirection( vec3 direction, mat4 _VIEW_MATRIX )
{
mat4 mw = _VIEW_MATRIX;
@ -63,6 +69,35 @@ vec3 worldToViewDirection( vec3 direction, mat4 _VIEW_MATRIX )
return ( mw * vec4( direction, 1.0 ) ).xyz;
}
vec3 viewToWorld( vec3 view, mat4 _INV_VIEW_MATRIX )
{
return ( _INV_VIEW_MATRIX * vec4( view, 1.0 ) ).xyz;
}
vec3 viewToWorldDirection( vec3 view, mat4 _INV_VIEW_MATRIX )
{
mat4 mw = _INV_VIEW_MATRIX;
mw[ 3 ][ 0 ] = 0.0;
mw[ 3 ][ 1 ] = 0.0;
mw[ 3 ][ 2 ] = 0.0;
mw[ 3 ][ 3 ] = 1.0;
return ( mw * vec4( view, 1.0 ) ).xyz;
}
vec3 viewToLocal( vec3 view, mat4 _INV_VIEW_MATRIX, mat4 _MODEL_MATRIX )
{
vec3 world = viewToWorld( view, _INV_VIEW_MATRIX );
return worldToLocal( world, _MODEL_MATRIX );
}
vec3 viewToLocalDirection( vec3 view, mat4 _INV_VIEW_MATRIX, mat4 _MODEL_MATRIX )
{
vec3 world = viewToWorldDirection( view, _INV_VIEW_MATRIX );
return worldToLocalDirection( world, _MODEL_MATRIX );
}
vec3 extractScale( mat3 _MODEL_NORMAL_MATRIX )
{
mat3 m = _MODEL_NORMAL_MATRIX;