Fixed Imgui and light scissor clipping issues. Closes #651

This commit is contained in:
Robert Beckebans 2023-10-13 16:08:35 +02:00
parent 8b1bc6d8cd
commit f408fcad38
4 changed files with 32 additions and 28 deletions

View file

@ -389,7 +389,8 @@ void idGuiModel::EmitImGui( ImDrawData* drawData )
mat = ( const idMaterial* )pcmd->TextureId;
}
idScreenRect clipRect = { static_cast<short>( pcmd->ClipRect.x ), static_cast<short>( pcmd->ClipRect.y ), static_cast<short>( pcmd->ClipRect.z ), static_cast<short>( pcmd->ClipRect.w ) };
// RB: (0, 0) starts in the upper left corner compared to GL!
idScreenRect clipRect = { static_cast<short>( pcmd->ClipRect.x ), static_cast<short>( pcmd->ClipRect.y ), static_cast<short>( pcmd->ClipRect.z ), static_cast<short>( pcmd->ClipRect.w ), 0.0f, 1.0f };
idDrawVert* verts = AllocTris( numVerts, indexBufferOffset, numIndexes, mat, tr.currentGLState, STEREO_DEPTH_TYPE_NONE, clipRect );
if( verts == NULL )

View file

@ -495,13 +495,11 @@ void idRenderBackend::DrawElementsWithCounters( const drawSurf_t* surf, bool sha
1.0f };
state.viewport.addViewport( viewport );
#if 0
if( !context.scissor.IsEmpty() )
{
state.viewport.addScissorRect( nvrhi::Rect( context.scissor.x1, context.scissor.x2, context.scissor.y1, context.scissor.y2 ) );
}
else
#endif
{
state.viewport.addScissorRect( nvrhi::Rect( viewport ) );
}
@ -1681,7 +1679,6 @@ idRenderBackend::GL_Scissor
*/
void idRenderBackend::GL_Scissor( int x /* left*/, int y /* bottom */, int w, int h )
{
// TODO Check if this is right.
context.scissor.Clear();
context.scissor.AddPoint( x, y );
context.scissor.AddPoint( x + w, y + h );

View file

@ -545,8 +545,11 @@ void idRenderBackend::ResetViewportAndScissorToDefaultCamera( const viewDef_t* _
_viewDef->viewport.y2 + 1 - _viewDef->viewport.y1 );
// the scissor may be smaller than the viewport for subviews
// RB: (0, 0) starts in the upper left corner compared to OpenGL!
// convert light scissor to from GL coordinates to DX
GL_Scissor( viewDef->viewport.x1 + _viewDef->scissor.x1,
viewDef->viewport.y1 + _viewDef->scissor.y1,
viewDef->viewport.y2 - _viewDef->scissor.y2,
_viewDef->scissor.x2 + 1 - _viewDef->scissor.x1,
_viewDef->scissor.y2 + 1 - _viewDef->scissor.y1 );
@ -1525,8 +1528,10 @@ void idRenderBackend::RenderInteractions( const drawSurf_t* surfList, const view
// change the scissor if needed, it will be constant across all the surfaces lit by the light
if( !currentScissor.Equals( vLight->scissorRect ) && r_useScissor.GetBool() )
{
// RB: (0, 0) starts in the upper left corner compared to OpenGL!
// convert light scissor to from GL coordinates to DX
GL_Scissor( viewDef->viewport.x1 + vLight->scissorRect.x1,
viewDef->viewport.y1 + vLight->scissorRect.y1,
viewDef->viewport.y2 - vLight->scissorRect.y2,
vLight->scissorRect.x2 + 1 - vLight->scissorRect.x1,
vLight->scissorRect.y2 + 1 - vLight->scissorRect.y1 );
@ -3971,6 +3976,8 @@ int idRenderBackend::DrawShaderPasses( const drawSurf_t* const* const drawSurfs,
// change the scissor if needed
if( !currentScissor.Equals( surf->scissorRect ) && r_useScissor.GetBool() )
{
// RB: (0, 0) starts in the upper left corner compared to GL!
// this is only used by the Imgui scissors which start at the top left corner
GL_Scissor( viewDef->viewport.x1 + surf->scissorRect.x1,
viewDef->viewport.y1 + surf->scissorRect.y1,
surf->scissorRect.x2 + 1 - surf->scissorRect.x1,
@ -4328,9 +4335,10 @@ void idRenderBackend::T_BlendLight( const drawSurf_t* drawSurfs, const viewLight
if( !currentScissor.Equals( drawSurf->scissorRect ) && r_useScissor.GetBool() )
{
// change the scissor
// RB: (0, 0) starts in the upper left corner compared to OpenGL!
// convert light scissor to from GL coordinates to DX
GL_Scissor( viewDef->viewport.x1 + drawSurf->scissorRect.x1,
viewDef->viewport.y1 + drawSurf->scissorRect.y1,
viewDef->viewport.y2 - drawSurf->scissorRect.y2,
drawSurf->scissorRect.x2 + 1 - drawSurf->scissorRect.x1,
drawSurf->scissorRect.y2 + 1 - drawSurf->scissorRect.y1 );
@ -4457,9 +4465,10 @@ void idRenderBackend::T_BasicFog( const drawSurf_t* drawSurfs, const idPlane fog
if( !currentScissor.Equals( drawSurf->scissorRect ) && r_useScissor.GetBool() )
{
// change the scissor
// RB: (0, 0) starts in the upper left corner compared to OpenGL!
// convert light scissor to from GL coordinates to DX
GL_Scissor( viewDef->viewport.x1 + drawSurf->scissorRect.x1,
viewDef->viewport.y1 + drawSurf->scissorRect.y1,
viewDef->viewport.y2 - drawSurf->scissorRect.y2,
drawSurf->scissorRect.x2 + 1 - drawSurf->scissorRect.x1,
drawSurf->scissorRect.y2 + 1 - drawSurf->scissorRect.y1 );

View file

@ -817,21 +817,17 @@ void LightEditor::Draw()
idAngles angles( 0, 0, 90 );
idMat3 rotate = angles.ToMat3();
idMat3 scaleMatrix = mat3_identity;
scaleMatrix[0][0] = 4;
scaleMatrix[1][1] = 4;
scaleMatrix[2][2] = 4;
scaleMatrix[0][0] = 16;
scaleMatrix[1][1] = 16;
scaleMatrix[2][2] = 16;
//idMat4 gridMatrix( scaleMatrix * rotate, vec3_origin );
//ImGuizmo::DrawGrid( cameraView, cameraProjection, gridMatrix.ToFloatPtr(), 100.f );
idMat4 gridMatrix( scaleMatrix * rotate, vec3_origin );
ImGuizmo::DrawGrid( cameraView, cameraProjection, gridMatrix.ToFloatPtr(), 100.f );
//idMat3 scaleMatrix = mat3_identity;
scaleMatrix[0][0] = 1;
scaleMatrix[1][1] = 1;
scaleMatrix[2][2] = 1;
idMat4 objectMatrix( scaleMatrix, cur.origin );
//idMat4 objectMatrix( scaleMatrix, cur.origin );
//ImGuizmo::DrawCubes( cameraView, cameraProjection, objectMatrix.Transpose().ToFloatPtr(), 1 );
ImGuizmo::DrawCubes( cameraView, cameraProjection, objectMatrix.Transpose().ToFloatPtr(), 1 );
ImGuizmo::OPERATION mCurrentGizmoOperation( ImGuizmo::TRANSLATE );
@ -846,9 +842,10 @@ void LightEditor::Draw()
}
//if( ImGui::IsKeyPressed( ImGuiKey_S ) )
//{
// mCurrentGizmoOperation = ImGuizmo::SCALE;
//}
if( io.KeysDown[K_S] )
{
mCurrentGizmoOperation = ImGuizmo::SCALE;
}
ImGuizmo::MODE mCurrentGizmoMode( ImGuizmo::LOCAL );
bool useSnap = false;
@ -858,7 +855,11 @@ void LightEditor::Draw()
bool boundSizing = false;
bool boundSizingSnap = false;
idMat4 manipMatrix = objectMatrix.Transpose();
scaleMatrix[0][0] = 16;
scaleMatrix[1][1] = 16;
scaleMatrix[2][2] = 16;
idMat4 gizmoMatrix( scaleMatrix, cur.origin );
idMat4 manipMatrix = gizmoMatrix.Transpose();
ImGuizmo::Manipulate( cameraView, cameraProjection, mCurrentGizmoOperation, mCurrentGizmoMode, manipMatrix.ToFloatPtr(), NULL, useSnap ? &snap[0] : NULL, boundSizing ? bounds : NULL, boundSizingSnap ? boundsSnap : NULL );
if( ImGuizmo::IsUsing() )
@ -868,10 +869,6 @@ void LightEditor::Draw()
cur.origin.z = manipMatrix[3].z;
}
//float camDistance = 8.f;
//float viewManipulateRight = io.DisplaySize.x;
//float viewManipulateTop = 0;
ImGui::Separator();
ImGui::Text( "X: %f Y: %f", io.MousePos.x, io.MousePos.y );