Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Material Preview Renders a scene #1336

Open
wants to merge 15 commits into
base: development
Choose a base branch
from
Prev Previous commit
Next Next commit
Revert "Update guiMaterialPreview.cpp"
This reverts commit 75f634e.
  • Loading branch information
marauder2k7 committed Jan 24, 2025
commit 86410bae529889bba516734cae9e908deec8bc41
78 changes: 60 additions & 18 deletions Engine/source/T3D/guiMaterialPreview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
#include "gfx/gfxDrawUtil.h"

#include "environment/skySphere.h"
#include "T3D/tsStatic.h"

// GuiMaterialPreview
GuiMaterialPreview::GuiMaterialPreview()
Expand Down Expand Up @@ -371,6 +370,8 @@ void GuiMaterialPreview::renderWorld(const RectI &updateRect)
//S32 dt = time - lastRenderTime;
lastRenderTime = time;



F32 left, right, top, bottom, nearPlane, farPlane;
bool isOrtho;
GFX->getFrustum( &left, &right, &bottom, &top, &nearPlane, &farPlane, &isOrtho);
Expand All @@ -379,30 +380,71 @@ void GuiMaterialPreview::renderWorld(const RectI &updateRect)
mSaveProjection = GFX->getProjectionMatrix();
mSaveWorldToScreenScale = GFX->getWorldToScreenScale();

ScopedSceneManager scopeManager(mTempScene);

LIGHTMGR->unregisterAllLights();
LIGHTMGR->setSpecialLight(LightManager::slSunLightType, mFakeSun);
// BFW(Big fucking warning) DO NOT MERGE WITH THIS SETUP
// WE NEED PROPER SCENE MANAGEMENT NOT THIS TEST!
// use the ScopedSceneManager
{
ScopedSceneManager scopeManager(mTempScene);

SkySphere* bgSkybox = new SkySphere();
bgSkybox->_setMaterial("Prototyping:hdrMaterial");
bgSkybox->_initRender();
bgSkybox->_updateMaterial();
mTempScene->addObjectToScene(bgSkybox);

mTempScene->renderScene(SPT_Diffuse);

mTempScene->removeObjectFromScene(bgSkybox);
delete bgSkybox;
}

if (Skylight::smSkylightProbe.isValid())
PROBEMGR->submitProbe(Skylight::smSkylightProbe->getProbeInfo());

SkySphere* bgSkybox = new SkySphere();
bgSkybox->_setMaterial("Prototyping:hdrMaterial");
bgSkybox->_initRender();
bgSkybox->_updateMaterial();
mTempScene->addObjectToScene(bgSkybox);
RenderPassManager* renderPass = getActiveClientScene()->getDefaultRenderPass();
SceneRenderState state
(
getActiveClientScene(),
SPT_Diffuse,
SceneCameraState( GFX->getViewport(), mSaveFrustum, GFX->getWorldMatrix(), GFX->getProjectionMatrix() ),
renderPass,
true
);

// Set up our TS render state here.
TSRenderState rdata;
rdata.setSceneState( &state );

// We might have some forward lit materials
// so pass down a query to gather lights.
LightQuery query;
query.init( SphereF( Point3F::Zero, 1.0f ) );
rdata.setLightQuery( &query );

// Set up pass transforms
renderPass->assignSharedXform(RenderPassManager::View, MatrixF::Identity);
renderPass->assignSharedXform(RenderPassManager::Projection, GFX->getProjectionMatrix());

TSStatic* shape = new TSStatic();
shape->mShapeInstance = mModel;
mTempScene->addObjectToScene(shape);
LIGHTMGR->unregisterAllLights();
LIGHTMGR->setSpecialLight( LightManager::slSunLightType, mFakeSun );

mTempScene->renderScene(SPT_Diffuse);
if ( mModel )
mModel->render( rdata );

if ( mMountedModel )
{
// render a weapon
/*
MatrixF mat;

GFX->pushWorldMatrix();
GFX->multWorld( mat );

GFX->popWorldMatrix();
*/
}

mTempScene->removeObjectFromScene(bgSkybox);
mTempScene->removeObjectFromScene(shape);
delete bgSkybox;
delete shape;
renderPass->renderPass( &state );

if (mMouseState == MovingLight)
{
Expand Down