From 291c5c75b66c047ccde527a8b76fb115b1038db2 Mon Sep 17 00:00:00 2001 From: marauder2k7 Date: Wed, 4 Dec 2024 23:45:32 +0000 Subject: [PATCH 1/4] Update guiMaterialPreview.cpp use mSaveFrustm to keep states between object switches --- Engine/source/T3D/guiMaterialPreview.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Engine/source/T3D/guiMaterialPreview.cpp b/Engine/source/T3D/guiMaterialPreview.cpp index 4d5bf78fc..0efa10aa8 100644 --- a/Engine/source/T3D/guiMaterialPreview.cpp +++ b/Engine/source/T3D/guiMaterialPreview.cpp @@ -369,7 +369,8 @@ void GuiMaterialPreview::renderWorld(const RectI &updateRect) F32 left, right, top, bottom, nearPlane, farPlane; bool isOrtho; GFX->getFrustum( &left, &right, &bottom, &top, &nearPlane, &farPlane, &isOrtho); - Frustum frust( isOrtho, left, right, bottom, top, nearPlane, farPlane, MatrixF::Identity ); + mSaveFrustum = Frustum( isOrtho, left, right, bottom, top, nearPlane, farPlane, MatrixF::Identity ); + mSaveFrustum.setTransform(MatrixF::Identity); FogData savedFogData = gClientSceneGraph->getFogData(); gClientSceneGraph->setFogData( FogData() ); // no fog in preview window @@ -382,7 +383,7 @@ void GuiMaterialPreview::renderWorld(const RectI &updateRect) ( gClientSceneGraph, SPT_Diffuse, - SceneCameraState( GFX->getViewport(), frust, GFX->getWorldMatrix(), GFX->getProjectionMatrix() ), + SceneCameraState( GFX->getViewport(), mSaveFrustum, GFX->getWorldMatrix(), GFX->getProjectionMatrix() ), renderPass, true ); From e7a7935bd400baf2eb31d610eee365522208d9fc Mon Sep 17 00:00:00 2001 From: marauder2k7 Date: Wed, 4 Dec 2024 23:59:43 +0000 Subject: [PATCH 2/4] Update guiMaterialPreview.cpp more "fixes" --- Engine/source/T3D/guiMaterialPreview.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Engine/source/T3D/guiMaterialPreview.cpp b/Engine/source/T3D/guiMaterialPreview.cpp index 0efa10aa8..e5ada8e25 100644 --- a/Engine/source/T3D/guiMaterialPreview.cpp +++ b/Engine/source/T3D/guiMaterialPreview.cpp @@ -372,6 +372,9 @@ void GuiMaterialPreview::renderWorld(const RectI &updateRect) mSaveFrustum = Frustum( isOrtho, left, right, bottom, top, nearPlane, farPlane, MatrixF::Identity ); mSaveFrustum.setTransform(MatrixF::Identity); + mSaveProjection = GFX->getProjectionMatrix(); + mSaveWorldToScreenScale = GFX->getWorldToScreenScale(); + FogData savedFogData = gClientSceneGraph->getFogData(); gClientSceneGraph->setFogData( FogData() ); // no fog in preview window From a92b9d0e2defbf81dc85904555fdb4bc7b561e79 Mon Sep 17 00:00:00 2001 From: marauder2k7 Date: Thu, 5 Dec 2024 00:17:44 +0000 Subject: [PATCH 3/4] code review with az changes per review, frustum wasnt dirty... i like it dirty --- Engine/source/T3D/guiMaterialPreview.cpp | 33 +++++++++++++++++++++++- Engine/source/T3D/guiMaterialPreview.h | 2 +- Engine/source/math/util/frustum.cpp | 1 + 3 files changed, 34 insertions(+), 2 deletions(-) diff --git a/Engine/source/T3D/guiMaterialPreview.cpp b/Engine/source/T3D/guiMaterialPreview.cpp index e5ada8e25..096490629 100644 --- a/Engine/source/T3D/guiMaterialPreview.cpp +++ b/Engine/source/T3D/guiMaterialPreview.cpp @@ -35,6 +35,7 @@ #include "scene/sceneRenderState.h" #include "renderInstance/renderProbeMgr.h" #include "T3D/lighting/skylight.h" +#include "gfx/gfxDrawUtil.h" // GuiMaterialPreview GuiMaterialPreview::GuiMaterialPreview() @@ -370,7 +371,6 @@ void GuiMaterialPreview::renderWorld(const RectI &updateRect) bool isOrtho; GFX->getFrustum( &left, &right, &bottom, &top, &nearPlane, &farPlane, &isOrtho); mSaveFrustum = Frustum( isOrtho, left, right, bottom, top, nearPlane, farPlane, MatrixF::Identity ); - mSaveFrustum.setTransform(MatrixF::Identity); mSaveProjection = GFX->getProjectionMatrix(); mSaveWorldToScreenScale = GFX->getWorldToScreenScale(); @@ -426,12 +426,43 @@ void GuiMaterialPreview::renderWorld(const RectI &updateRect) renderPass->renderPass( &state ); + if (mMouseState == MovingLight) + { + renderSunDirection(); + } + gClientSceneGraph->setFogData( savedFogData ); // restore fog setting // Make sure to remove our fake sun LIGHTMGR->unregisterAllLights(); } +void GuiMaterialPreview::renderSunDirection() const +{ + // Render four arrows aiming in the direction of the sun's light + ColorI color = LinearColorF(mFakeSun->getColor()).toColorI(); + F32 length = mModel->getShape()->mBounds.len() * 0.8f; + + // Get the sun's vectors + Point3F fwd = mFakeSun->getTransform().getForwardVector(); + Point3F up = mFakeSun->getTransform().getUpVector() * length / 8; + Point3F right = mFakeSun->getTransform().getRightVector() * length / 8; + + // Calculate the start and end points of the first arrow (bottom left) + Point3F start = mModel->getShape()->center - fwd * length - up / 2 - right / 2; + Point3F end = mModel->getShape()->center - fwd * length / 3 - up / 2 - right / 2; + + GFXStateBlockDesc desc; + desc.setZReadWrite(true, true); + + GFXDrawUtil* drawUtil = GFX->getDrawUtil(); + + drawUtil->drawArrow(desc, start, end, color); + drawUtil->drawArrow(desc, start + up, end + up, color); + drawUtil->drawArrow(desc, start + right, end + right, color); + drawUtil->drawArrow(desc, start + up + right, end + up + right, color); +} + // Make sure the orbit distance is within the acceptable range. void GuiMaterialPreview::setOrbitDistance(F32 distance) { diff --git a/Engine/source/T3D/guiMaterialPreview.h b/Engine/source/T3D/guiMaterialPreview.h index 2bf702019..3acafeb14 100644 --- a/Engine/source/T3D/guiMaterialPreview.h +++ b/Engine/source/T3D/guiMaterialPreview.h @@ -75,7 +75,7 @@ protected: Point2I mLastMousePoint; LightInfo* mFakeSun; - + void renderSunDirection() const; public: bool onWake() override; diff --git a/Engine/source/math/util/frustum.cpp b/Engine/source/math/util/frustum.cpp index 2ac1824b7..632d7cded 100644 --- a/Engine/source/math/util/frustum.cpp +++ b/Engine/source/math/util/frustum.cpp @@ -81,6 +81,7 @@ Frustum::Frustum( bool isOrtho, mProjectionOffset.zero(); mProjectionOffsetMatrix.identity(); + mDirty = true; } //----------------------------------------------------------------------------- From 7810ee4f513c6dee9ec444bec54ef8d3a42a2268 Mon Sep 17 00:00:00 2001 From: marauder2k7 Date: Thu, 5 Dec 2024 00:34:17 +0000 Subject: [PATCH 4/4] Update guiMaterialPreview.cpp light movement now makes sense --- Engine/source/T3D/guiMaterialPreview.cpp | 28 ++++++++++++------------ 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/Engine/source/T3D/guiMaterialPreview.cpp b/Engine/source/T3D/guiMaterialPreview.cpp index 096490629..a83569f6e 100644 --- a/Engine/source/T3D/guiMaterialPreview.cpp +++ b/Engine/source/T3D/guiMaterialPreview.cpp @@ -115,20 +115,20 @@ void GuiMaterialPreview::setLightTranslate(S32 modifier, F32 xstep, F32 ystep) F32 _lighttransstep = (modifier & SI_SHIFT ? mLightTransStep : (mLightTransStep*mLightTranMult)); Point3F relativeLightDirection = GuiMaterialPreview::mFakeSun->getDirection(); - // May be able to get rid of this. For now, it helps to fix the position of the light if i gets messed up. - if (modifier & SI_PRIMARY_CTRL) - { - relativeLightDirection.x += ( xstep * _lighttransstep * -1 );//need to invert this for some reason. Otherwise, it's backwards. - relativeLightDirection.y += ( ystep * _lighttransstep ); - GuiMaterialPreview::mFakeSun->setDirection(relativeLightDirection); - } - // Default action taken by mouse wheel clicking. - else - { - relativeLightDirection.x += ( xstep * _lighttransstep * -1 ); //need to invert this for some reason. Otherwise, it's backwards. - relativeLightDirection.z += ( ystep * _lighttransstep ); - GuiMaterialPreview::mFakeSun->setDirection(relativeLightDirection); - } + + F32 azimuth = mAtan2(relativeLightDirection.y, relativeLightDirection.x); + F32 elevation = mAsin(relativeLightDirection.z); + + // Modify azimuth and elevation based on input + azimuth += xstep * _lighttransstep; + elevation = mClampF(elevation + ystep * _lighttransstep, -M_2PI_F, M_2PI_F); + + // Convert back to Cartesian coordinates + relativeLightDirection.x = mCos(elevation) * mCos(azimuth); + relativeLightDirection.y = mCos(elevation) * mSin(azimuth); + relativeLightDirection.z = mSin(elevation); + + GuiMaterialPreview::mFakeSun->setDirection(relativeLightDirection); } // This is for panning the viewport camera.