mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-01-19 20:24:49 +00:00
seperated offset from position (we pass the net to the shader for use in the reflection box), and added a scalar (also only used in the reflection box). maked both as probeRef to denote reflection parameters.
This commit is contained in:
parent
e4ddfcfb01
commit
5bce2d0904
|
|
@ -106,6 +106,7 @@ ReflectionProbe::ReflectionProbe()
|
|||
mDirty = false;
|
||||
|
||||
mRadius = 10;
|
||||
mProbeRefScale = Point3F::One*10;
|
||||
|
||||
mUseCubemap = false;
|
||||
mUseHDRCaptures = true;
|
||||
|
|
@ -130,7 +131,7 @@ ReflectionProbe::ReflectionProbe()
|
|||
mPrefilterMap = nullptr;
|
||||
mIrridianceMap = nullptr;
|
||||
|
||||
mProbePosOffset = Point3F::Zero;
|
||||
mProbeRefOffset = Point3F::Zero;
|
||||
mEditPosOffset = false;
|
||||
|
||||
mProbeInfoIdx = -1;
|
||||
|
|
@ -160,13 +161,14 @@ void ReflectionProbe::initPersistFields()
|
|||
&_setEnabled, &defaultProtectedGetFn, "Regenerate Voxel Grid");
|
||||
|
||||
addField("radius", TypeF32, Offset(mRadius, ReflectionProbe), "The name of the material used to render the mesh.");
|
||||
addField("posOffset", TypePoint3F, Offset(mProbePosOffset, ReflectionProbe), "");
|
||||
|
||||
//addProtectedField("EditPosOffset", TypeBool, Offset(mEditPosOffset, ReflectionProbe),
|
||||
// &_toggleEditPosOffset, &defaultProtectedGetFn, "Toggle Edit Pos Offset Mode", AbstractClassRep::FieldFlags::FIELD_ComponentInspectors);
|
||||
endGroup("Rendering");
|
||||
|
||||
addGroup("Reflection");
|
||||
addField("refOffset", TypePoint3F, Offset(mProbeRefOffset, ReflectionProbe), "");
|
||||
addField("refScale", TypePoint3F, Offset(mProbeRefScale, ReflectionProbe), "");
|
||||
addField("ReflectionMode", TypeReflectionModeEnum, Offset(mReflectionModeType, ReflectionProbe),
|
||||
"The type of mesh data to use for collision queries.");
|
||||
|
||||
|
|
@ -319,7 +321,7 @@ void ReflectionProbe::setTransform(const MatrixF & mat)
|
|||
if (!mEditPosOffset)
|
||||
Parent::setTransform(mat);
|
||||
else
|
||||
mProbePosOffset = mat.getPosition();
|
||||
mProbeRefOffset = mat.getPosition();
|
||||
|
||||
mDirty = true;
|
||||
|
||||
|
|
@ -338,7 +340,8 @@ U32 ReflectionProbe::packUpdate(NetConnection *conn, U32 mask, BitStream *stream
|
|||
{
|
||||
mathWrite(*stream, getTransform());
|
||||
mathWrite(*stream, getScale());
|
||||
mathWrite(*stream, mProbePosOffset);
|
||||
mathWrite(*stream, mProbeRefOffset);
|
||||
mathWrite(*stream, mProbeRefScale);
|
||||
}
|
||||
|
||||
if (stream->writeFlag(mask & ShapeTypeMask))
|
||||
|
|
@ -387,7 +390,8 @@ void ReflectionProbe::unpackUpdate(NetConnection *conn, BitStream *stream)
|
|||
|
||||
setTransform(mObjToWorld);
|
||||
|
||||
mathRead(*stream, &mProbePosOffset);
|
||||
mathRead(*stream, &mProbeRefOffset);
|
||||
mathRead(*stream, &mProbeRefScale);
|
||||
}
|
||||
|
||||
if (stream->readFlag()) // ShapeTypeMask
|
||||
|
|
@ -487,7 +491,6 @@ void ReflectionProbe::updateProbeParams()
|
|||
mProbeInfo->mTransform = getWorldTransform();
|
||||
|
||||
mProbeInfo->mPosition = getPosition();
|
||||
|
||||
mObjScale.set(mRadius, mRadius, mRadius);
|
||||
|
||||
// Skip our transform... it just dirties mask bits.
|
||||
|
|
@ -500,7 +503,8 @@ void ReflectionProbe::updateProbeParams()
|
|||
|
||||
mProbeInfo->mIsSkylight = false;
|
||||
|
||||
mProbeInfo->mProbePosOffset = mProbePosOffset;
|
||||
mProbeInfo->mProbeRefOffset = mProbeRefOffset;
|
||||
mProbeInfo->mProbeRefScale = mProbeRefScale;
|
||||
|
||||
mProbeInfo->mDirty = true;
|
||||
mProbeInfo->mScore = mMaxDrawDistance;
|
||||
|
|
@ -742,7 +746,7 @@ void ReflectionProbe::prepRenderImage(SceneRenderState *state)
|
|||
mat.scale(Point3F(1, 1, 1));
|
||||
|
||||
Point3F centerPos = mat.getPosition();
|
||||
centerPos += mProbePosOffset;
|
||||
centerPos += mProbeRefOffset;
|
||||
mat.setPosition(centerPos);
|
||||
|
||||
GFX->setWorldMatrix(mat);
|
||||
|
|
@ -786,21 +790,23 @@ void ReflectionProbe::_onRenderViz(ObjectRenderInst *ri,
|
|||
ColorI color = ColorI::WHITE;
|
||||
color.alpha = 25;
|
||||
|
||||
const MatrixF worldToObjectXfm = getTransform();
|
||||
if (mProbeShapeType == ProbeRenderInst::Sphere)
|
||||
{
|
||||
draw->drawSphere(desc, mRadius, getPosition(), color);
|
||||
}
|
||||
else
|
||||
{
|
||||
const MatrixF worldToObjectXfm = getTransform();
|
||||
|
||||
Box3F cube(-Point3F(mRadius, mRadius, mRadius),Point3F(mRadius, mRadius, mRadius));
|
||||
Box3F wb = getWorldBox();
|
||||
cube.setCenter(getPosition()+mProbePosOffset);
|
||||
wb.setCenter(getPosition() + mProbePosOffset);
|
||||
draw->drawCube(desc, cube, color, &worldToObjectXfm);
|
||||
draw->drawCube(desc, wb, color, &worldToObjectXfm);
|
||||
Box3F projCube(-Point3F(mRadius, mRadius, mRadius),Point3F(mRadius, mRadius, mRadius));
|
||||
projCube.setCenter(getPosition());
|
||||
draw->drawCube(desc, projCube, color, &worldToObjectXfm);
|
||||
}
|
||||
Box3F refCube = getWorldBox();
|
||||
refCube.set(mProbeRefScale);
|
||||
refCube.setCenter(getPosition() + mProbeRefOffset);
|
||||
color = ColorI::BLUE;
|
||||
color.alpha = 25;
|
||||
draw->drawCube(desc, refCube, color, &worldToObjectXfm);
|
||||
}
|
||||
|
||||
void ReflectionProbe::setPreviewMatParameters(SceneRenderState* renderState, BaseMatInstance* mat)
|
||||
|
|
|
|||
|
|
@ -111,7 +111,8 @@ protected:
|
|||
ReflectionModeType mReflectionModeType;
|
||||
|
||||
F32 mRadius;
|
||||
Point3F mProbePosOffset;
|
||||
Point3F mProbeRefOffset;
|
||||
Point3F mProbeRefScale;
|
||||
bool mEditPosOffset;
|
||||
|
||||
String mCubemapName;
|
||||
|
|
|
|||
|
|
@ -81,7 +81,8 @@ ProbeRenderInst::ProbeRenderInst() : SystemInterface(),
|
|||
mCubemap(NULL),
|
||||
mIrradianceCubemap(NULL),
|
||||
mRadius(1.0f),
|
||||
mProbePosOffset(0, 0, 0)
|
||||
mProbeRefOffset(0, 0, 0),
|
||||
mProbeRefScale(1,1,1)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
@ -282,6 +283,7 @@ void RenderProbeMgr::_setupStaticParameters()
|
|||
if (probePositionsData.size() != MAXPROBECOUNT)
|
||||
{
|
||||
probePositionsData.setSize(MAXPROBECOUNT);
|
||||
probeRefPositionsData.setSize(MAXPROBECOUNT);
|
||||
probeWorldToObjData.setSize(MAXPROBECOUNT);
|
||||
probeBBMinData.setSize(MAXPROBECOUNT);
|
||||
probeBBMaxData.setSize(MAXPROBECOUNT);
|
||||
|
|
@ -289,6 +291,7 @@ void RenderProbeMgr::_setupStaticParameters()
|
|||
}
|
||||
|
||||
probePositionsData.fill(Point4F::Zero);
|
||||
probeRefPositionsData.fill(Point4F::Zero);
|
||||
probeWorldToObjData.fill(MatrixF::Identity);
|
||||
probeBBMinData.fill(Point4F::Zero);
|
||||
probeBBMaxData.fill(Point4F::Zero);
|
||||
|
|
@ -324,13 +327,16 @@ void RenderProbeMgr::_setupStaticParameters()
|
|||
mMipCount = curEntry.mCubemap.getPointer()->getMipMapLevels();
|
||||
|
||||
//Setup
|
||||
Point3F probePos = curEntry.getPosition() + curEntry.mProbePosOffset;
|
||||
Point3F probePos = curEntry.getPosition();
|
||||
Point3F refPos = curEntry.getPosition() +curEntry.mProbeRefOffset;
|
||||
probePositionsData[mEffectiveProbeCount] = Point4F(probePos.x, probePos.y, probePos.z,0);
|
||||
probeRefPositionsData[mEffectiveProbeCount] = Point4F(refPos.x, refPos.y, refPos.z, 0);
|
||||
|
||||
probeWorldToObjData[mEffectiveProbeCount] = curEntry.getTransform();
|
||||
|
||||
probeBBMinData[mEffectiveProbeCount] = Point4F(curEntry.mBounds.minExtents.x, curEntry.mBounds.minExtents.y, curEntry.mBounds.minExtents.z, 0);
|
||||
probeBBMaxData[mEffectiveProbeCount] = Point4F(curEntry.mBounds.maxExtents.x, curEntry.mBounds.maxExtents.y, curEntry.mBounds.maxExtents.z, 0);
|
||||
Point3F bbMin = refPos - curEntry.mProbeRefScale;
|
||||
Point3F bbMax = refPos + curEntry.mProbeRefScale;
|
||||
probeBBMinData[mEffectiveProbeCount] = Point4F(bbMin.x, bbMin.y, bbMin.z, 0);
|
||||
probeBBMaxData[mEffectiveProbeCount] = Point4F(bbMax.x, bbMax.y, bbMax.z, 0);
|
||||
|
||||
probeConfigData[mEffectiveProbeCount] = Point4F(curEntry.mProbeShapeType == ProbeRenderInst::Sphere ? 1 : 0,
|
||||
curEntry.mRadius,
|
||||
|
|
@ -647,6 +653,7 @@ void RenderProbeMgr::render( SceneRenderState *state )
|
|||
|
||||
mProbeArrayEffect->setShaderConst("$numProbes", (float)mEffectiveProbeCount);
|
||||
mProbeArrayEffect->setShaderConst("$inProbePosArray", probePositionsData);
|
||||
mProbeArrayEffect->setShaderConst("$inRefPosArray", probeRefPositionsData);
|
||||
mProbeArrayEffect->setShaderConst("$worldToObjArray", probeWorldToObjData);
|
||||
mProbeArrayEffect->setShaderConst("$bbMinArray", probeBBMinData);
|
||||
mProbeArrayEffect->setShaderConst("$bbMaxArray", probeBBMaxData);
|
||||
|
|
|
|||
|
|
@ -67,7 +67,8 @@ struct ProbeRenderInst : public SystemInterface<ProbeRenderInst>
|
|||
|
||||
Box3F mBounds;
|
||||
Point3F mPosition;
|
||||
Point3F mProbePosOffset;
|
||||
Point3F mProbeRefOffset;
|
||||
Point3F mProbeRefScale;
|
||||
|
||||
GFXCubemapHandle mCubemap;
|
||||
GFXCubemapHandle mIrradianceCubemap;
|
||||
|
|
@ -161,6 +162,7 @@ class RenderProbeMgr : public RenderBinManager
|
|||
U32 mEffectiveProbeCount;
|
||||
S32 mMipCount;
|
||||
Vector<Point4F> probePositionsData;
|
||||
Vector<Point4F> probeRefPositionsData;
|
||||
Vector<MatrixF> probeWorldToObjData;
|
||||
Vector<Point4F> probeBBMinData;
|
||||
Vector<Point4F> probeBBMaxData;
|
||||
|
|
|
|||
|
|
@ -23,10 +23,11 @@ TORQUE_UNIFORM_SAMPLERCUBEARRAY(irradianceCubemapAR, 5);
|
|||
//TORQUE_UNIFORM_SAMPLERCUBE(cubeMapAR, 4);
|
||||
//TORQUE_UNIFORM_SAMPLERCUBE(irradianceCubemapAR, 5);
|
||||
uniform float4 inProbePosArray[MAX_PROBES];
|
||||
uniform float4 inRefPosArray[MAX_PROBES];
|
||||
uniform float4x4 worldToObjArray[MAX_PROBES];
|
||||
uniform float4 bbMinArray[MAX_PROBES];
|
||||
uniform float4 bbMaxArray[MAX_PROBES];
|
||||
uniform float4 probeConfigData[MAX_PROBES]; //r,g,b/mode,radius,atten
|
||||
uniform float4 probeConfigData[MAX_PROBES]; //r,g,b/mode,radius,atten
|
||||
|
||||
#if DEBUGVIZ_CONTRIB
|
||||
uniform float4 probeContribColors[MAX_PROBES];
|
||||
|
|
@ -54,7 +55,7 @@ float3 boxProject(float3 wsPosition, float3 wsEyeRay, float3 reflectDir, float3
|
|||
|
||||
float3 iblBoxDiffuse( Surface surface, int id)
|
||||
{
|
||||
float3 cubeN = boxProject(surface.P, surface.V, surface.R, inProbePosArray[id].xyz, bbMinArray[id].xyz, bbMaxArray[id].xyz);
|
||||
float3 cubeN = boxProject(surface.P, surface.V, surface.R, inRefPosArray[id].xyz, bbMinArray[id].xyz, bbMaxArray[id].xyz);
|
||||
cubeN.z *=-1;
|
||||
return TORQUE_TEXCUBEARRAYLOD(irradianceCubemapAR,cubeN,id,0).xyz;
|
||||
}
|
||||
|
|
@ -71,7 +72,7 @@ float3 iblBoxSpecular(Surface surface, TORQUE_SAMPLER2D(brdfTexture), int id)
|
|||
float lod = 0;
|
||||
#endif
|
||||
|
||||
float3 cubeR = boxProject(surface.P, surface.V, surface.R, inProbePosArray[id].xyz, bbMinArray[id].xyz, bbMaxArray[id].xyz);
|
||||
float3 cubeR = boxProject(surface.P, surface.V, surface.R, inRefPosArray[id].xyz, bbMinArray[id].xyz, bbMaxArray[id].xyz);
|
||||
|
||||
float3 radiance = TORQUE_TEXCUBEARRAYLOD(cubeMapAR,cubeR,id,lod).xyz * (brdf.x + brdf.y);
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue