mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-02-14 04:03:46 +00:00
lighting single buffer
This commit is contained in:
parent
ecef09525a
commit
b0fff30d33
37 changed files with 309 additions and 813 deletions
|
|
@ -144,6 +144,8 @@ ReflectionProbe::ReflectionProbe()
|
|||
mEditPosOffset = false;
|
||||
|
||||
mProbeInfoIdx = -1;
|
||||
|
||||
mCaptureMask = REFLECTION_PROBE_CAPTURE_TYPEMASK;
|
||||
}
|
||||
|
||||
ReflectionProbe::~ReflectionProbe()
|
||||
|
|
@ -620,9 +622,9 @@ bool ReflectionProbe::createClientResources()
|
|||
//brdf lookup resources
|
||||
//make the brdf lookup texture the same size as the prefilter texture
|
||||
|
||||
String brdfPath = Con::getVariable("$Core::BRDFTexture", "core/art/brdfTexture.dds");
|
||||
String brdfPath = Con::getVariable("$Core::BRDFTexture", "core/art/pbr/brdfTexture.dds");
|
||||
|
||||
mBrdfTexture = TEXMGR->createTexture(brdfPath, &GFXTexturePersistentProfile);// TEXMGR->createTexture(mPrefilterSize, mPrefilterSize, GFXFormatR16G16B16A16F, &GFXRenderTargetProfile, 1, 0);
|
||||
mBrdfTexture = TEXMGR->createTexture(brdfPath, &GFXTexturePersistentProfile);
|
||||
|
||||
if (!mBrdfTexture)
|
||||
{
|
||||
|
|
@ -978,7 +980,7 @@ void ReflectionProbe::bake(String outputPath, S32 resolution, bool renderWithPro
|
|||
MathUtils::makeFrustum(&left, &right, &top, &bottom, M_HALFPI_F, 1.0f, nearPlane);
|
||||
Frustum frustum(false, left, right, top, bottom, nearPlane, farDist);
|
||||
|
||||
renderFrame(&baseTarget, matView, frustum, StaticObjectType | StaticShapeObjectType & EDITOR_RENDER_TYPEMASK, gCanvasClearColor);
|
||||
renderFrame(&baseTarget, matView, frustum, mCaptureMask & EDITOR_RENDER_TYPEMASK, gCanvasClearColor);
|
||||
|
||||
baseTarget->resolve();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -169,6 +169,7 @@ protected:
|
|||
F32 mMaxDrawDistance;
|
||||
|
||||
bool mResourcesCreated;
|
||||
U32 mCaptureMask;
|
||||
|
||||
public:
|
||||
ReflectionProbe();
|
||||
|
|
@ -242,6 +243,8 @@ public:
|
|||
String getPrefilterMapPath();
|
||||
String getIrradianceMapPath();
|
||||
void bake(String outputPath, S32 resolution, bool renderWithProbes = false);
|
||||
|
||||
const U32 getProbeInfoIndex() { return mProbeInfoIdx; }
|
||||
};
|
||||
|
||||
typedef ProbeRenderInst::ProbeShapeType ReflectProbeType;
|
||||
|
|
|
|||
|
|
@ -78,7 +78,7 @@ ConsoleDocClass(Skylight,
|
|||
//-----------------------------------------------------------------------------
|
||||
Skylight::Skylight() : ReflectionProbe()
|
||||
{
|
||||
|
||||
mCaptureMask = SKYLIGHT_CAPTURE_TYPEMASK;
|
||||
}
|
||||
|
||||
Skylight::~Skylight()
|
||||
|
|
|
|||
|
|
@ -216,7 +216,10 @@ enum SceneObjectTypeMasks : U32
|
|||
///
|
||||
/// @note Terrains have their own means for rendering inside interior zones.
|
||||
OUTDOOR_OBJECT_TYPEMASK = ( TerrainObjectType |
|
||||
EnvironmentObjectType )
|
||||
EnvironmentObjectType ),
|
||||
|
||||
SKYLIGHT_CAPTURE_TYPEMASK = (EnvironmentObjectType),
|
||||
REFLECTION_PROBE_CAPTURE_TYPEMASK = (StaticObjectType | StaticShapeObjectType)
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -38,12 +38,14 @@
|
|||
#include "gfx/D3D11/screenshotD3D11.h"
|
||||
#include "materials/shaderData.h"
|
||||
#include "shaderGen/shaderGen.h"
|
||||
#include <d3d9.h> //d3dperf
|
||||
|
||||
#ifdef TORQUE_DEBUG
|
||||
#include "d3d11sdklayers.h"
|
||||
#endif
|
||||
|
||||
#pragma comment(lib, "dxgi.lib")
|
||||
#pragma comment(lib, "d3d9.lib") //d3dperf
|
||||
#pragma comment(lib, "d3d11.lib")
|
||||
|
||||
class GFXPCD3D11RegisterDevice
|
||||
|
|
@ -90,9 +92,6 @@ GFXD3D11Device::GFXD3D11Device(U32 index)
|
|||
mAdapterIndex = index;
|
||||
mD3DDevice = NULL;
|
||||
mD3DDeviceContext = NULL;
|
||||
mD3DDevice1 = NULL;
|
||||
mD3DDeviceContext1 = NULL;
|
||||
mUserAnnotation = NULL;
|
||||
mVolatileVB = NULL;
|
||||
|
||||
mCurrentPB = NULL;
|
||||
|
|
@ -126,7 +125,6 @@ GFXD3D11Device::GFXD3D11Device(U32 index)
|
|||
mCurrentConstBuffer = NULL;
|
||||
|
||||
mOcclusionQuerySupported = false;
|
||||
mCbufferPartialSupported = false;
|
||||
|
||||
mDebugLayers = false;
|
||||
|
||||
|
|
@ -166,8 +164,6 @@ GFXD3D11Device::~GFXD3D11Device()
|
|||
SAFE_RELEASE(mDeviceBackBufferView);
|
||||
SAFE_RELEASE(mDeviceDepthStencil);
|
||||
SAFE_RELEASE(mDeviceBackbuffer);
|
||||
SAFE_RELEASE(mUserAnnotation);
|
||||
SAFE_RELEASE(mD3DDeviceContext1);
|
||||
SAFE_RELEASE(mD3DDeviceContext);
|
||||
|
||||
SAFE_DELETE(mCardProfiler);
|
||||
|
|
@ -185,7 +181,6 @@ GFXD3D11Device::~GFXD3D11Device()
|
|||
#endif
|
||||
|
||||
SAFE_RELEASE(mSwapChain);
|
||||
SAFE_RELEASE(mD3DDevice1);
|
||||
SAFE_RELEASE(mD3DDevice);
|
||||
}
|
||||
|
||||
|
|
@ -439,6 +434,7 @@ void GFXD3D11Device::init(const GFXVideoMode &mode, PlatformWindow *window)
|
|||
AssertFatal(window, "GFXD3D11Device::init - must specify a window!");
|
||||
|
||||
HWND winHwnd = (HWND)window->getSystemWindow( PlatformWindow::WindowSystem_Windows );
|
||||
SetFocus(winHwnd);
|
||||
|
||||
UINT createDeviceFlags = D3D11_CREATE_DEVICE_SINGLETHREADED | D3D11_CREATE_DEVICE_BGRA_SUPPORT;
|
||||
#ifdef TORQUE_DEBUG
|
||||
|
|
@ -489,26 +485,6 @@ void GFXD3D11Device::init(const GFXVideoMode &mode, PlatformWindow *window)
|
|||
#endif
|
||||
}
|
||||
|
||||
// Grab DX 11.1 device and context if available and also ID3DUserDefinedAnnotation
|
||||
hres = mD3DDevice->QueryInterface(__uuidof(ID3D11Device1), reinterpret_cast<void**>(&mD3DDevice1));
|
||||
if (SUCCEEDED(hres))
|
||||
{
|
||||
//11.1 context
|
||||
mD3DDeviceContext->QueryInterface(__uuidof(ID3D11DeviceContext1), reinterpret_cast<void**>(&mD3DDeviceContext1));
|
||||
// ID3DUserDefinedAnnotation
|
||||
mD3DDeviceContext->QueryInterface(IID_PPV_ARGS(&mUserAnnotation));
|
||||
//Check what is supported, windows 7 supports very little from 11.1
|
||||
D3D11_FEATURE_DATA_D3D11_OPTIONS options;
|
||||
mD3DDevice1->CheckFeatureSupport(D3D11_FEATURE_D3D11_OPTIONS, &options,
|
||||
sizeof(D3D11_FEATURE_DATA_D3D11_OPTIONS));
|
||||
|
||||
//Cbuffer partial updates
|
||||
if (options.ConstantBufferOffsetting && options.ConstantBufferPartialUpdate)
|
||||
mCbufferPartialSupported = true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
//set the fullscreen state here if we need to
|
||||
if(mode.fullScreen)
|
||||
{
|
||||
|
|
@ -1875,28 +1851,27 @@ GFXCubemapArray * GFXD3D11Device::createCubemapArray()
|
|||
//------------------------------------------------------------------------------
|
||||
void GFXD3D11Device::enterDebugEvent(ColorI color, const char *name)
|
||||
{
|
||||
if (mUserAnnotation)
|
||||
{
|
||||
WCHAR eventName[260];
|
||||
MultiByteToWideChar(CP_ACP, 0, name, -1, eventName, 260);
|
||||
mUserAnnotation->BeginEvent(eventName);
|
||||
}
|
||||
// BJGFIX
|
||||
WCHAR eventName[260];
|
||||
MultiByteToWideChar(CP_ACP, 0, name, -1, eventName, 260);
|
||||
|
||||
D3DPERF_BeginEvent(D3DCOLOR_ARGB(color.alpha, color.red, color.green, color.blue),
|
||||
(LPCWSTR)&eventName);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
void GFXD3D11Device::leaveDebugEvent()
|
||||
{
|
||||
if (mUserAnnotation)
|
||||
mUserAnnotation->EndEvent();
|
||||
D3DPERF_EndEvent();
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
void GFXD3D11Device::setDebugMarker(ColorI color, const char *name)
|
||||
{
|
||||
if (mUserAnnotation)
|
||||
{
|
||||
WCHAR eventName[260];
|
||||
MultiByteToWideChar(CP_ACP, 0, name, -1, eventName, 260);
|
||||
mUserAnnotation->SetMarker(eventName);
|
||||
}
|
||||
// BJGFIX
|
||||
WCHAR eventName[260];
|
||||
MultiByteToWideChar(CP_ACP, 0, name, -1, eventName, 260);
|
||||
|
||||
D3DPERF_SetMarker(D3DCOLOR_ARGB(color.alpha, color.red, color.green, color.blue),
|
||||
(LPCWSTR)&eventName);
|
||||
}
|
||||
|
|
@ -23,7 +23,7 @@
|
|||
#ifndef _GFXD3D11DEVICE_H_
|
||||
#define _GFXD3D11DEVICE_H_
|
||||
|
||||
#include <d3d11_1.h>
|
||||
#include <d3d11.h>
|
||||
|
||||
#include "platform/tmm_off.h"
|
||||
#include "platformWin32/platformWin32.h"
|
||||
|
|
@ -39,9 +39,6 @@
|
|||
#define D3D11 static_cast<GFXD3D11Device*>(GFX)
|
||||
#define D3D11DEVICE D3D11->getDevice()
|
||||
#define D3D11DEVICECONTEXT D3D11->getDeviceContext()
|
||||
// DX 11.1 - always check these are not NULL, dodgy support with win 7
|
||||
#define D3D11DEVICE1 D3D11->getDevice1()
|
||||
#define D3D11DEVICECONTEXT1 D3D11->getDeviceContext1()
|
||||
|
||||
class PlatformWindow;
|
||||
class GFXD3D11ShaderConstBuffer;
|
||||
|
|
@ -129,10 +126,6 @@ protected:
|
|||
IDXGISwapChain *mSwapChain;
|
||||
ID3D11Device* mD3DDevice;
|
||||
ID3D11DeviceContext* mD3DDeviceContext;
|
||||
// DX 11.1
|
||||
ID3D11Device1* mD3DDevice1;
|
||||
ID3D11DeviceContext1* mD3DDeviceContext1;
|
||||
ID3DUserDefinedAnnotation* mUserAnnotation;
|
||||
|
||||
GFXShaderRef mGenericShader[GS_COUNT];
|
||||
GFXShaderConstBufferRef mGenericShaderBuffer[GS_COUNT];
|
||||
|
|
@ -153,7 +146,6 @@ protected:
|
|||
DXGI_SAMPLE_DESC mMultisampleDesc;
|
||||
|
||||
bool mOcclusionQuerySupported;
|
||||
bool mCbufferPartialSupported;
|
||||
|
||||
U32 mDrawInstancesCount;
|
||||
|
||||
|
|
@ -300,9 +292,6 @@ public:
|
|||
ID3D11DeviceContext* getDeviceContext(){ return mD3DDeviceContext; }
|
||||
ID3D11Device* getDevice(){ return mD3DDevice; }
|
||||
IDXGISwapChain* getSwapChain() { return mSwapChain; }
|
||||
//DX 11.1
|
||||
ID3D11DeviceContext1* getDeviceContext1() { return mD3DDeviceContext1; }
|
||||
ID3D11Device1* getDevice1() { return mD3DDevice1; }
|
||||
|
||||
/// Reset
|
||||
void reset( DXGI_SWAP_CHAIN_DESC &d3dpp );
|
||||
|
|
|
|||
|
|
@ -561,7 +561,7 @@ const String GFXD3D11ShaderConstBuffer::describeSelf() const
|
|||
GenericConstBufferLayout::ParamDesc pd;
|
||||
mVertexConstBufferLayout->getDesc(i, pd);
|
||||
|
||||
ret += String::ToString(" Constant name: %s", pd.name);
|
||||
ret += String::ToString(" Constant name: %s", pd.name.c_str());
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
|
|
|||
|
|
@ -119,17 +119,8 @@ AdvancedLightBinManager::AdvancedLightBinManager( AdvancedLightManager *lm /* =
|
|||
: RenderBinManager( RIT_LightInfo, 1.0f, 1.0f ),
|
||||
mNumLightsCulled(0),
|
||||
mLightManager(lm),
|
||||
mShadowManager(sm),
|
||||
mConditioner(NULL)
|
||||
mShadowManager(sm)
|
||||
{
|
||||
// Create an RGB conditioner
|
||||
NamedTexTarget* specLightTarg = NamedTexTarget::find(RenderDeferredMgr::SpecularLightBufferName);
|
||||
|
||||
mConditioner = new AdvancedLightBufferConditioner(lightBufferFormat,
|
||||
AdvancedLightBufferConditioner::RGB );
|
||||
|
||||
specLightTarg->setConditioner( mConditioner );
|
||||
|
||||
mMRTLightmapsDuringDeferred = true;
|
||||
|
||||
Con::NotifyDelegate callback( this, &AdvancedLightBinManager::_deleteLightMaterials );
|
||||
|
|
@ -143,8 +134,6 @@ AdvancedLightBinManager::~AdvancedLightBinManager()
|
|||
{
|
||||
_deleteLightMaterials();
|
||||
|
||||
SAFE_DELETE(mConditioner);
|
||||
|
||||
Con::NotifyDelegate callback( this, &AdvancedLightBinManager::_deleteLightMaterials );
|
||||
Con::removeVariableNotify( "$pref::shadows::filterMode", callback );
|
||||
Con::removeVariableNotify( "$AL::PSSMDebugRender", callback );
|
||||
|
|
@ -274,16 +263,8 @@ void AdvancedLightBinManager::render( SceneRenderState *state )
|
|||
//if ( !_onPreRender( state ) )
|
||||
// return;
|
||||
|
||||
//GFX->clear(GFXClearTarget, ColorI(0, 0, 0, 0), 1.0f, 0);
|
||||
|
||||
NamedTexTargetRef diffuseLightingTarget = NamedTexTarget::find("diffuseLighting");
|
||||
|
||||
if (diffuseLightingTarget.isNull())
|
||||
return;
|
||||
|
||||
NamedTexTargetRef specularLightingTarget = NamedTexTarget::find("specularLighting");
|
||||
|
||||
if (specularLightingTarget.isNull())
|
||||
NamedTexTargetRef sceneColorTargetRef = NamedTexTarget::find("AL_FormatToken");
|
||||
if (sceneColorTargetRef.isNull())
|
||||
return;
|
||||
|
||||
GFXTextureTargetRef lightingTargetRef = GFX->allocRenderToTextureTarget();
|
||||
|
|
@ -294,13 +275,12 @@ void AdvancedLightBinManager::render( SceneRenderState *state )
|
|||
//Do a quick pass to update our probes if they're dirty
|
||||
PROBEMGR->updateDirtyProbes();
|
||||
|
||||
lightingTargetRef->attachTexture(GFXTextureTarget::Color0, specularLightingTarget->getTexture());
|
||||
lightingTargetRef->attachTexture(GFXTextureTarget::Color1, diffuseLightingTarget->getTexture());
|
||||
lightingTargetRef->attachTexture(GFXTextureTarget::Color0, sceneColorTargetRef->getTexture());
|
||||
|
||||
GFX->pushActiveRenderTarget();
|
||||
GFX->setActiveRenderTarget(lightingTargetRef);
|
||||
|
||||
GFX->setViewport(specularLightingTarget->getViewport());
|
||||
GFX->setViewport(sceneColorTargetRef->getViewport());
|
||||
|
||||
// Restore transforms
|
||||
MatrixSet &matrixSet = getRenderPass()->getMatrixSet();
|
||||
|
|
@ -415,7 +395,6 @@ void AdvancedLightBinManager::render( SceneRenderState *state )
|
|||
|
||||
// Finish up the rendering
|
||||
//_onPostRender();
|
||||
lightingTargetRef->resolve();
|
||||
GFX->popActiveRenderTarget();
|
||||
}
|
||||
|
||||
|
|
@ -765,9 +744,8 @@ void AdvancedLightBinManager::LightMaterialInfo::setLightParameters( const Light
|
|||
0.0f );
|
||||
|
||||
matParams->setSafe( lightSpotParams, spotParams );
|
||||
|
||||
VectorF lightDir = lightInfo->getDirection();
|
||||
matParams->setSafe( lightDirection, lightDir );
|
||||
matParams->setSafe( lightDirection, lightInfo->getDirection());
|
||||
matParams->setSafe( lightPosition, lightInfo->getPosition());
|
||||
}
|
||||
// Fall through
|
||||
|
||||
|
|
|
|||
|
|
@ -230,8 +230,6 @@ protected:
|
|||
///
|
||||
void _onShadowFilterChanged();
|
||||
|
||||
AdvancedLightBufferConditioner *mConditioner;
|
||||
|
||||
typedef GFXVertexPNTT FarFrustumQuadVert;
|
||||
GFXVertexBufferHandle<FarFrustumQuadVert> mFarFrustumQuadVerts;
|
||||
|
||||
|
|
|
|||
|
|
@ -179,3 +179,25 @@ void DeferredSpecVarsHLSL::processPix( Vector<ShaderComponent*> &componentList,
|
|||
meta->addStatement(new GenOp(" @.a = @;\r\n", material, metalness));
|
||||
output = meta;
|
||||
}
|
||||
|
||||
//deferred emissive
|
||||
void DeferredEmissiveHLSL::processPix(Vector<ShaderComponent*> &componentList, const MaterialFeatureData &fd)
|
||||
{
|
||||
//for now emission just uses the diffuse color, we could plug in a separate texture for emission at some stage
|
||||
Var *diffuseTargetVar = (Var*)LangElement::find(getOutputTargetVarName(ShaderFeature::RenderTarget1));
|
||||
if (!diffuseTargetVar)
|
||||
return; //oh dear something is not right, maybe we should just write 0's instead
|
||||
|
||||
// search for scene color target var
|
||||
Var *sceneColorVar = (Var*)LangElement::find(getOutputTargetVarName(ShaderFeature::RenderTarget3));
|
||||
if (!sceneColorVar)
|
||||
{
|
||||
// create scene color target var
|
||||
sceneColorVar = new Var;
|
||||
sceneColorVar->setType("fragout");
|
||||
sceneColorVar->setName(getOutputTargetVarName(ShaderFeature::RenderTarget3));
|
||||
sceneColorVar->setStructName("OUT");
|
||||
}
|
||||
|
||||
output = new GenOp("@ = float4(@.rgb,0);", sceneColorVar, diffuseTargetVar);
|
||||
}
|
||||
|
|
@ -69,4 +69,16 @@ public:
|
|||
|
||||
virtual U32 getOutputTargets( const MaterialFeatureData &fd ) const { return ShaderFeature::RenderTarget2; }
|
||||
};
|
||||
|
||||
class DeferredEmissiveHLSL : public ShaderFeatureHLSL
|
||||
{
|
||||
public:
|
||||
virtual String getName() { return "Deferred Shading: Emissive"; }
|
||||
|
||||
virtual void processPix(Vector<ShaderComponent*> &componentList,
|
||||
const MaterialFeatureData &fd);
|
||||
|
||||
virtual U32 getOutputTargets(const MaterialFeatureData &fd) const { return ShaderFeature::RenderTarget3; }
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
@ -106,6 +106,7 @@ ImplementFeatureType( MFT_SkyBox, MFG_Transform, 1.0f, false );
|
|||
ImplementFeatureType( MFT_DeferredSpecMap, MFG_Texture, 8.2f, false );
|
||||
ImplementFeatureType( MFT_DeferredSpecVars, MFG_Texture, 8.5f, false );
|
||||
ImplementFeatureType( MFT_DeferredMatInfoFlags, MFG_Texture, 8.7f, false );
|
||||
ImplementFeatureType( MFT_DeferredEmissive, MFG_Texture, 8.9f, false);
|
||||
|
||||
ImplementFeatureType( MFT_HardwareSkinning, MFG_Transform,-2.0, false );
|
||||
|
||||
|
|
|
|||
|
|
@ -193,4 +193,5 @@ DeclareFeatureType( MFT_SkyBox );
|
|||
DeclareFeatureType( MFT_DeferredSpecMap );
|
||||
DeclareFeatureType( MFT_DeferredSpecVars );
|
||||
DeclareFeatureType( MFT_DeferredMatInfoFlags );
|
||||
DeclareFeatureType( MFT_DeferredEmissive );
|
||||
#endif // _MATERIALFEATURETYPES_H_
|
||||
|
|
|
|||
|
|
@ -56,8 +56,6 @@ const String RenderDeferredMgr::BufferName("deferred");
|
|||
const RenderInstType RenderDeferredMgr::RIT_Deferred("Deferred");
|
||||
const String RenderDeferredMgr::ColorBufferName("color");
|
||||
const String RenderDeferredMgr::MatInfoBufferName("matinfo");
|
||||
const String RenderDeferredMgr::DiffuseLightBufferName("diffuseLighting");
|
||||
const String RenderDeferredMgr::SpecularLightBufferName("specularLighting");
|
||||
|
||||
IMPLEMENT_CONOBJECT(RenderDeferredMgr);
|
||||
|
||||
|
|
@ -104,8 +102,6 @@ RenderDeferredMgr::RenderDeferredMgr( bool gatherDepth,
|
|||
mNamedTarget.registerWithName( BufferName );
|
||||
mColorTarget.registerWithName( ColorBufferName );
|
||||
mMatInfoTarget.registerWithName( MatInfoBufferName );
|
||||
mDiffuseLightTarget.registerWithName( DiffuseLightBufferName );
|
||||
mSpecularLightTarget.registerWithName(SpecularLightBufferName);
|
||||
|
||||
_registerFeatures();
|
||||
}
|
||||
|
|
@ -116,8 +112,6 @@ RenderDeferredMgr::~RenderDeferredMgr()
|
|||
|
||||
mColorTarget.release();
|
||||
mMatInfoTarget.release();
|
||||
mDiffuseLightTarget.release();
|
||||
mSpecularLightTarget.release();
|
||||
_unregisterFeatures();
|
||||
SAFE_DELETE( mDeferredMatInstance );
|
||||
}
|
||||
|
|
@ -141,8 +135,6 @@ bool RenderDeferredMgr::setTargetSize(const Point2I &newTargetSize)
|
|||
mNamedTarget.setViewport( GFX->getViewport() );
|
||||
mColorTarget.setViewport( GFX->getViewport() );
|
||||
mMatInfoTarget.setViewport( GFX->getViewport() );
|
||||
mDiffuseLightTarget.setViewport( GFX->getViewport() );
|
||||
mSpecularLightTarget.setViewport(GFX->getViewport());
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
|
@ -183,35 +175,25 @@ bool RenderDeferredMgr::_updateTargets()
|
|||
mMatInfoTex.set(mTargetSize.x, mTargetSize.y, matInfoFormat,
|
||||
&GFXRenderTargetProfile, avar("%s() - (line %d)", __FUNCTION__, __LINE__),
|
||||
1, GFXTextureManager::AA_MATCH_BACKBUFFER);
|
||||
mMatInfoTarget.setTexture(mMatInfoTex);
|
||||
mMatInfoTarget.setTexture(mMatInfoTex);
|
||||
|
||||
for (U32 i = 0; i < mTargetChainLength; i++)
|
||||
mTargetChain[i]->attachTexture(GFXTextureTarget::Color2, mMatInfoTarget.getTexture());
|
||||
}
|
||||
|
||||
if (mDiffuseLightTex.getFormat() != GFXFormatR16G16B16A16F || mDiffuseLightTex.getWidthHeight() != mTargetSize || GFX->recentlyReset())
|
||||
//scene color target
|
||||
NamedTexTargetRef sceneColorTargetRef = NamedTexTarget::find("AL_FormatToken");
|
||||
if (sceneColorTargetRef.isValid())
|
||||
{
|
||||
mDiffuseLightTarget.release();
|
||||
mDiffuseLightTex.set(mTargetSize.x, mTargetSize.y, GFXFormatR16G16B16A16F,
|
||||
&GFXRenderTargetProfile, avar("%s() - (line %d)", __FUNCTION__, __LINE__),
|
||||
1, GFXTextureManager::AA_MATCH_BACKBUFFER);
|
||||
mDiffuseLightTarget.setTexture(mDiffuseLightTex);
|
||||
|
||||
for (U32 i = 0; i < mTargetChainLength; i++)
|
||||
mTargetChain[i]->attachTexture(GFXTextureTarget::Color3, mDiffuseLightTarget.getTexture());
|
||||
mTargetChain[i]->attachTexture(GFXTextureTarget::Color3, sceneColorTargetRef->getTexture(0));
|
||||
}
|
||||
else
|
||||
{
|
||||
Con::errorf("RenderDeferredMgr: Could not find AL_FormatToken");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (mSpecularLightTex.getFormat() != GFXFormatR16G16B16A16F || mSpecularLightTex.getWidthHeight() != mTargetSize || GFX->recentlyReset())
|
||||
{
|
||||
mSpecularLightTarget.release();
|
||||
mSpecularLightTex.set(mTargetSize.x, mTargetSize.y, GFXFormatR16G16B16A16F,
|
||||
&GFXRenderTargetProfile, avar("%s() - (line %d)", __FUNCTION__, __LINE__),
|
||||
1, GFXTextureManager::AA_MATCH_BACKBUFFER);
|
||||
mSpecularLightTarget.setTexture(mSpecularLightTex);
|
||||
|
||||
for (U32 i = 0; i < mTargetChainLength; i++)
|
||||
mTargetChain[i]->attachTexture(GFXTextureTarget::Color4, mSpecularLightTarget.getTexture());
|
||||
}
|
||||
GFX->finalizeReset();
|
||||
|
||||
return ret;
|
||||
|
|
@ -337,12 +319,11 @@ void RenderDeferredMgr::render( SceneRenderState *state )
|
|||
const bool isRenderingToTarget = _onPreRender(state);
|
||||
|
||||
// Clear z-buffer and g-buffer.
|
||||
GFX->clear(GFXClearZBuffer | GFXClearStencil, ColorI::ZERO, 1.0f, 0);
|
||||
GFX->clear(GFXClearZBuffer | GFXClearStencil, LinearColorF::ZERO, 1.0f, 0);
|
||||
GFX->clearColorAttachment(0, LinearColorF::ONE);//normdepth
|
||||
GFX->clearColorAttachment(1, LinearColorF::ZERO);//albedo
|
||||
GFX->clearColorAttachment(2, LinearColorF::ZERO);//matinfo
|
||||
GFX->clearColorAttachment(3, LinearColorF::ZERO);//diffuse
|
||||
GFX->clearColorAttachment(4, LinearColorF::ZERO);//specular
|
||||
//AL_FormatToken is cleared by it's own class
|
||||
|
||||
// Restore transforms
|
||||
MatrixSet &matrixSet = getRenderPass()->getMatrixSet();
|
||||
|
|
@ -358,7 +339,7 @@ void RenderDeferredMgr::render( SceneRenderState *state )
|
|||
mDeferredMatInstance->setTransforms(matrixSet, state);
|
||||
}
|
||||
|
||||
// Signal start of pre-pass
|
||||
// Signal start of deferred
|
||||
getRenderSignal().trigger( state, this, true );
|
||||
|
||||
// First do a loop and render all the terrain... these are
|
||||
|
|
@ -751,8 +732,11 @@ void ProcessedDeferredMaterial::_determineFeatures( U32 stageNum,
|
|||
}
|
||||
else
|
||||
{
|
||||
// If this object isn't lightmapped, add a zero-output feature to it
|
||||
newFeatures.addFeature( MFT_RenderTarget3_Zero );
|
||||
// If this object isn't lightmapped or emissive, add a zero-output feature for render target 3
|
||||
if (fd.features.hasFeature(MFT_IsEmissive))
|
||||
newFeatures.addFeature(MFT_DeferredEmissive);
|
||||
else
|
||||
newFeatures.addFeature( MFT_RenderTarget3_Zero );
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -46,8 +46,6 @@ public:
|
|||
// andremwac: Deferred Rendering
|
||||
static const String ColorBufferName;
|
||||
static const String MatInfoBufferName;
|
||||
static const String DiffuseLightBufferName;
|
||||
static const String SpecularLightBufferName;
|
||||
|
||||
// Generic Deferred Render Instance Type
|
||||
static const RenderInstType RIT_Deferred;
|
||||
|
|
@ -106,8 +104,6 @@ protected:
|
|||
// Deferred Shading
|
||||
NamedTexTarget mColorTarget;
|
||||
NamedTexTarget mMatInfoTarget;
|
||||
NamedTexTarget mDiffuseLightTarget;
|
||||
NamedTexTarget mSpecularLightTarget;
|
||||
GFXTexHandle mColorTex;
|
||||
GFXTexHandle mMatInfoTex;
|
||||
GFXTexHandle mDiffuseLightTex;
|
||||
|
|
|
|||
|
|
@ -222,15 +222,12 @@ void RenderFormatToken::_updateTargets()
|
|||
if( !mTargetColorTexture[i] || mTargetColorTexture[i].getFormat() != mColorFormat
|
||||
|| mTargetColorTexture[i].getWidthHeight() != rtSize)
|
||||
{
|
||||
mTargetColorTexture[i].set( rtSize.x, rtSize.y, mColorFormat,
|
||||
&GFXRenderTargetSRGBProfile, avar( "%s() - (line %d)", __FUNCTION__, __LINE__ ),
|
||||
1, mTargetAALevel );
|
||||
mTargetChain[i]->attachTexture( GFXTextureTarget::Color0, mTargetColorTexture[i] );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
mTargetColorTexture[i].set( rtSize.x, rtSize.y, mColorFormat,
|
||||
&GFXRenderTargetSRGBProfile, avar( "%s() - (line %d)", __FUNCTION__, __LINE__ ),
|
||||
1, mTargetAALevel );
|
||||
mTargetChain[i]->attachTexture( GFXTextureTarget::Color0, mTargetColorTexture[i] );
|
||||
}
|
||||
}
|
||||
|
||||
// Update depth target
|
||||
if(mDepthFormat != GFXFormat_COUNT)
|
||||
|
|
@ -239,15 +236,16 @@ void RenderFormatToken::_updateTargets()
|
|||
if( !mTargetDepthStencilTexture[i] || mTargetDepthStencilTexture[i].getFormat() != mColorFormat
|
||||
|| mTargetDepthStencilTexture[i].getWidthHeight() != rtSize)
|
||||
{
|
||||
mTargetDepthStencilTexture[i].set( rtSize.x, rtSize.y, mDepthFormat,
|
||||
&GFXZTargetProfile, avar( "%s() - (line %d)", __FUNCTION__, __LINE__ ),
|
||||
1, mTargetAALevel );
|
||||
mTargetDepthStencilTexture[i].set( rtSize.x, rtSize.y, mDepthFormat,
|
||||
&GFXZTargetProfile, avar( "%s() - (line %d)", __FUNCTION__, __LINE__ ),
|
||||
1, mTargetAALevel );
|
||||
mTargetChain[i]->attachTexture( GFXTextureTarget::DepthStencil, mTargetDepthStencilTexture[i] );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
//set the texture for now as the first color target texture
|
||||
mTarget.setTexture(mTargetColorTexture[0]);
|
||||
}
|
||||
|
||||
void RenderFormatToken::_teardownTargets()
|
||||
|
|
|
|||
|
|
@ -156,12 +156,6 @@ void RenderProbeMgr::_setupPerFrameParameters(const SceneRenderState *state)
|
|||
PlaneF farPlane(wsFrustumPoints[Frustum::FarBottomLeft], wsFrustumPoints[Frustum::FarTopLeft], wsFrustumPoints[Frustum::FarTopRight]);
|
||||
PlaneF vsFarPlane(verts[0].normal, verts[1].normal, verts[2].normal);
|
||||
|
||||
MatrixSet &matrixSet = getRenderPass()->getMatrixSet();
|
||||
matrixSet.restoreSceneViewProjection();
|
||||
|
||||
const MatrixF &worldToCameraXfm = matrixSet.getCameraToWorld();
|
||||
|
||||
MatrixF inverseViewMatrix = worldToCameraXfm;
|
||||
|
||||
// Parameters calculated, assign them to the materials
|
||||
ProbeManager::SkylightMaterialInfo* skylightMat = PROBEMGR->getSkylightMaterial();
|
||||
|
|
@ -198,9 +192,6 @@ void RenderProbeMgr::render( SceneRenderState *state )
|
|||
if (!ProbeRenderInst::all.size())
|
||||
return;
|
||||
|
||||
if (PROBEMGR->mRegisteredProbes.empty())
|
||||
return;
|
||||
|
||||
if (!ProbeManager::smRenderReflectionProbes)
|
||||
return;
|
||||
|
||||
|
|
@ -208,14 +199,8 @@ void RenderProbeMgr::render( SceneRenderState *state )
|
|||
|
||||
GFXDEBUGEVENT_SCOPE(RenderProbeMgr_render, ColorI::WHITE);
|
||||
|
||||
NamedTexTargetRef diffuseLightingTarget = NamedTexTarget::find("diffuseLighting");
|
||||
|
||||
if (diffuseLightingTarget.isNull())
|
||||
return;
|
||||
|
||||
NamedTexTargetRef specularLightingTarget = NamedTexTarget::find("specularLighting");
|
||||
|
||||
if (specularLightingTarget.isNull())
|
||||
NamedTexTargetRef sceneColorTargetRef = NamedTexTarget::find("AL_FormatToken");
|
||||
if (sceneColorTargetRef.isNull())
|
||||
return;
|
||||
|
||||
GFXTextureTargetRef probeLightingTargetRef = GFX->allocRenderToTextureTarget();
|
||||
|
|
@ -226,14 +211,12 @@ void RenderProbeMgr::render( SceneRenderState *state )
|
|||
//Do a quick pass to update our probes if they're dirty
|
||||
PROBEMGR->updateDirtyProbes();
|
||||
|
||||
probeLightingTargetRef->attachTexture(GFXTextureTarget::Color0, specularLightingTarget->getTexture());
|
||||
probeLightingTargetRef->attachTexture(GFXTextureTarget::Color1, diffuseLightingTarget->getTexture());
|
||||
probeLightingTargetRef->attachTexture(GFXTextureTarget::Color0, sceneColorTargetRef->getTexture(0));
|
||||
|
||||
GFX->pushActiveRenderTarget();
|
||||
GFX->setActiveRenderTarget(probeLightingTargetRef);
|
||||
|
||||
GFX->setViewport(specularLightingTarget->getViewport());
|
||||
//GFX->setViewport(specularLightingTarget->getViewport());
|
||||
GFX->setViewport(sceneColorTargetRef->getViewport());
|
||||
|
||||
// Restore transforms
|
||||
MatrixSet &matrixSet = getRenderPass()->getMatrixSet();
|
||||
|
|
@ -258,9 +241,9 @@ void RenderProbeMgr::render( SceneRenderState *state )
|
|||
ProbeManager::SkylightMaterialInfo* skylightMat = PROBEMGR->getSkylightMaterial();
|
||||
ProbeManager::ReflectProbeMaterialInfo* reflProbeMat = PROBEMGR->getReflectProbeMaterial();
|
||||
|
||||
for (U32 i = 0; i < PROBEMGR->mRegisteredProbes.size(); i++)
|
||||
for (U32 i = 0; i < ProbeRenderInst::all.size(); i++)
|
||||
{
|
||||
ProbeRenderInst* curEntry = ProbeRenderInst::all[PROBEMGR->mRegisteredProbes[i]];
|
||||
ProbeRenderInst* curEntry = ProbeRenderInst::all[i];
|
||||
|
||||
if (!curEntry->mIsEnabled)
|
||||
continue;
|
||||
|
|
@ -324,10 +307,6 @@ void RenderProbeMgr::render( SceneRenderState *state )
|
|||
}
|
||||
}
|
||||
|
||||
//And clean us up
|
||||
PROBEMGR->mRegisteredProbes.clear();
|
||||
|
||||
probeLightingTargetRef->resolve();
|
||||
GFX->popActiveRenderTarget();
|
||||
|
||||
//PROBEMGR->unregisterAllProbes();
|
||||
|
|
|
|||
|
|
@ -108,6 +108,7 @@ void _initShaderGenHLSL( ShaderGen *shaderGen )
|
|||
FEATUREMGR->registerFeature( MFT_DeferredSpecMap, new DeferredSpecMapHLSL );
|
||||
FEATUREMGR->registerFeature( MFT_DeferredSpecVars, new DeferredSpecVarsHLSL );
|
||||
FEATUREMGR->registerFeature( MFT_DeferredMatInfoFlags, new DeferredMatInfoFlagsHLSL );
|
||||
FEATUREMGR->registerFeature( MFT_DeferredEmissive, new DeferredEmissiveHLSL);
|
||||
FEATUREMGR->registerFeature( MFT_SkyBox, new NamedFeatureHLSL( "skybox" ) );
|
||||
FEATUREMGR->registerFeature( MFT_HardwareSkinning, new HardwareSkinningFeatureHLSL );
|
||||
}
|
||||
|
|
|
|||
BIN
Templates/Full/game/core/art/pbr/default_irradiance.dds
Normal file
BIN
Templates/Full/game/core/art/pbr/default_irradiance.dds
Normal file
Binary file not shown.
BIN
Templates/Full/game/core/art/pbr/default_prefilter.dds
Normal file
BIN
Templates/Full/game/core/art/pbr/default_prefilter.dds
Normal file
Binary file not shown.
|
|
@ -9,40 +9,6 @@ singleton ShaderData( DeferredColorShader )
|
|||
pixVersion = 2.0;
|
||||
};
|
||||
|
||||
// Primary Deferred Shader
|
||||
new GFXStateBlockData( AL_DeferredShadingState : PFX_DefaultStateBlock )
|
||||
{
|
||||
cullMode = GFXCullNone;
|
||||
|
||||
blendDefined = true;
|
||||
blendEnable = true;
|
||||
blendSrc = GFXBlendSrcAlpha;
|
||||
blendDest = GFXBlendInvSrcAlpha;
|
||||
|
||||
samplersDefined = true;
|
||||
samplerStates[0] = SamplerWrapLinear;
|
||||
samplerStates[1] = SamplerWrapLinear;
|
||||
samplerStates[2] = SamplerWrapLinear;
|
||||
samplerStates[3] = SamplerWrapLinear;
|
||||
samplerStates[4] = SamplerWrapLinear;
|
||||
};
|
||||
|
||||
new ShaderData( AL_DeferredShader )
|
||||
{
|
||||
DXVertexShaderFile = "shaders/common/postFx/postFxV.hlsl";
|
||||
DXPixelShaderFile = "shaders/common/lighting/advanced/deferredShadingP.hlsl";
|
||||
|
||||
OGLVertexShaderFile = "shaders/common/postFx/gl/postFxV.glsl";
|
||||
OGLPixelShaderFile = "shaders/common/lighting/advanced/gl/deferredShadingP.glsl";
|
||||
|
||||
samplerNames[0] = "colorBufferTex";
|
||||
samplerNames[1] = "diffuseLightingBuffer";
|
||||
samplerNames[2] = "matInfoTex";
|
||||
samplerNames[3] = "specularLightingBuffer";
|
||||
samplerNames[4] = "deferredTex";
|
||||
pixVersion = 2.0;
|
||||
};
|
||||
|
||||
new GFXStateBlockData( AL_DeferredCaptureState : PFX_DefaultStateBlock )
|
||||
{
|
||||
blendEnable = false;
|
||||
|
|
@ -94,23 +60,6 @@ singleton PostEffect( AL_PreCapture )
|
|||
allowReflectPass = true;
|
||||
};
|
||||
|
||||
singleton PostEffect( AL_DeferredShading )
|
||||
{
|
||||
renderTime = "PFXAfterBin";
|
||||
renderBin = "BeginBin";
|
||||
shader = AL_DeferredShader;
|
||||
stateBlock = AL_DeferredShadingState;
|
||||
texture[0] = "#color";
|
||||
texture[1] = "#diffuseLighting";
|
||||
texture[2] = "#matinfo";
|
||||
texture[3] = "#specularLighting";
|
||||
texture[4] = "#deferred";
|
||||
|
||||
target = "$backBuffer";
|
||||
renderPriority = 10000;
|
||||
allowReflectPass = true;
|
||||
};
|
||||
|
||||
// Debug Shaders.
|
||||
new ShaderData( AL_ColorBufferShader )
|
||||
{
|
||||
|
|
|
|||
|
|
@ -67,7 +67,7 @@ singleton PostEffect( AL_DepthVisualize )
|
|||
shader = AL_DepthVisualizeShader;
|
||||
stateBlock = AL_DefaultVisualizeState;
|
||||
texture[0] = "#deferred";
|
||||
texture[1] = "depthviz";
|
||||
texture[1] = "core/scripts/client/lighting/advanced/depthviz";
|
||||
target = "$backBuffer";
|
||||
renderPriority = 9999;
|
||||
};
|
||||
|
|
@ -75,11 +75,7 @@ singleton PostEffect( AL_DepthVisualize )
|
|||
function AL_DepthVisualize::onEnabled( %this )
|
||||
{
|
||||
AL_NormalsVisualize.disable();
|
||||
AL_LightColorVisualize.disable();
|
||||
AL_LightSpecularVisualize.disable();
|
||||
$AL_NormalsVisualizeVar = false;
|
||||
$AL_LightColorVisualizeVar = false;
|
||||
$AL_LightSpecularVisualizeVar = false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
@ -130,83 +126,7 @@ singleton PostEffect( AL_NormalsVisualize )
|
|||
function AL_NormalsVisualize::onEnabled( %this )
|
||||
{
|
||||
AL_DepthVisualize.disable();
|
||||
AL_LightColorVisualize.disable();
|
||||
AL_LightSpecularVisualize.disable();
|
||||
$AL_DepthVisualizeVar = false;
|
||||
$AL_LightColorVisualizeVar = false;
|
||||
$AL_LightSpecularVisualizeVar = false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
new ShaderData( AL_LightColorVisualizeShader )
|
||||
{
|
||||
DXVertexShaderFile = "shaders/common/postFx/postFxV.hlsl";
|
||||
DXPixelShaderFile = "shaders/common/lighting/advanced/dbgLightColorVisualizeP.hlsl";
|
||||
|
||||
OGLVertexShaderFile = "shaders/common/postFx/gl/postFxV.glsl";
|
||||
OGLPixelShaderFile = "shaders/common/lighting/advanced/gl/dbgLightColorVisualizeP.glsl";
|
||||
|
||||
samplerNames[0] = "diffuseLightingBuffer";
|
||||
|
||||
pixVersion = 2.0;
|
||||
};
|
||||
|
||||
singleton PostEffect( AL_LightColorVisualize )
|
||||
{
|
||||
shader = AL_LightColorVisualizeShader;
|
||||
stateBlock = AL_DefaultVisualizeState;
|
||||
texture[0] = "#diffuseLighting";
|
||||
target = "$backBuffer";
|
||||
renderPriority = 9999;
|
||||
};
|
||||
|
||||
function AL_LightColorVisualize::onEnabled( %this )
|
||||
{
|
||||
AL_NormalsVisualize.disable();
|
||||
AL_DepthVisualize.disable();
|
||||
AL_LightSpecularVisualize.disable();
|
||||
$AL_NormalsVisualizeVar = false;
|
||||
$AL_DepthVisualizeVar = false;
|
||||
$AL_LightSpecularVisualizeVar = false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
new ShaderData( AL_LightSpecularVisualizeShader )
|
||||
{
|
||||
DXVertexShaderFile = "shaders/common/postFx/postFxV.hlsl";
|
||||
DXPixelShaderFile = "shaders/common/lighting/advanced/dbgLightSpecularVisualizeP.hlsl";
|
||||
|
||||
OGLVertexShaderFile = "shaders/common/postFx/gl/postFxV.glsl";
|
||||
OGLPixelShaderFile = "shaders/common/lighting/advanced/gl/dbgLightSpecularVisualizeP.glsl";
|
||||
|
||||
samplerNames[0] = "diffuseLightingBuffer";
|
||||
|
||||
pixVersion = 2.0;
|
||||
};
|
||||
|
||||
singleton PostEffect( AL_LightSpecularVisualize )
|
||||
{
|
||||
shader = AL_LightColorVisualizeShader;
|
||||
stateBlock = AL_DefaultVisualizeState;
|
||||
texture[0] = "#specularLighting";
|
||||
target = "$backBuffer";
|
||||
renderPriority = 9999;
|
||||
};
|
||||
|
||||
function AL_LightSpecularVisualize::onEnabled( %this )
|
||||
{
|
||||
AL_NormalsVisualize.disable();
|
||||
AL_DepthVisualize.disable();
|
||||
AL_LightColorVisualize.disable();
|
||||
$AL_NormalsVisualizeVar = false;
|
||||
$AL_DepthVisualizeVar = false;
|
||||
$AL_LightColorVisualizeVar = false;
|
||||
|
||||
$AL_DepthVisualizeVar = false;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -238,48 +158,6 @@ function toggleGlowViz( %enable )
|
|||
AL_GlowVisualize.disable();
|
||||
}
|
||||
|
||||
/// Toggles the visualization of the AL normals buffer.
|
||||
function toggleNormalsViz( %enable )
|
||||
{
|
||||
if ( %enable $= "" )
|
||||
{
|
||||
$AL_NormalsVisualizeVar = AL_NormalsVisualize.isEnabled() ? false : true;
|
||||
AL_NormalsVisualize.toggle();
|
||||
}
|
||||
else if ( %enable )
|
||||
AL_NormalsVisualize.enable();
|
||||
else if ( !%enable )
|
||||
AL_NormalsVisualize.disable();
|
||||
}
|
||||
|
||||
/// Toggles the visualization of the AL lighting color buffer.
|
||||
function toggleLightColorViz( %enable )
|
||||
{
|
||||
if ( %enable $= "" )
|
||||
{
|
||||
$AL_LightColorVisualizeVar = AL_LightColorVisualize.isEnabled() ? false : true;
|
||||
AL_LightColorVisualize.toggle();
|
||||
}
|
||||
else if ( %enable )
|
||||
AL_LightColorVisualize.enable();
|
||||
else if ( !%enable )
|
||||
AL_LightColorVisualize.disable();
|
||||
}
|
||||
|
||||
/// Toggles the visualization of the AL lighting specular power buffer.
|
||||
function toggleLightSpecularViz( %enable )
|
||||
{
|
||||
if ( %enable $= "" )
|
||||
{
|
||||
$AL_LightSpecularVisualizeVar = AL_LightSpecularVisualize.isEnabled() ? false : true;
|
||||
AL_LightSpecularVisualize.toggle();
|
||||
}
|
||||
else if ( %enable )
|
||||
AL_LightSpecularVisualize.enable();
|
||||
else if ( !%enable )
|
||||
AL_LightSpecularVisualize.disable();
|
||||
}
|
||||
|
||||
function toggleBackbufferViz( %enable )
|
||||
{
|
||||
if ( %enable $= "" )
|
||||
|
|
|
|||
|
|
@ -73,8 +73,9 @@ new ShaderData( AL_VectorLightShader )
|
|||
samplerNames[2] = "$dynamicShadowMap";
|
||||
samplerNames[3] = "$ssaoMask";
|
||||
samplerNames[4] = "$gTapRotationTex";
|
||||
samplerNames[5] = "$colorBuffer";
|
||||
samplerNames[6] = "$matInfoBuffer";
|
||||
samplerNames[5] = "$lightBuffer";
|
||||
samplerNames[6] = "$colorBuffer";
|
||||
samplerNames[7] = "$matInfoBuffer";
|
||||
pixVersion = 3.0;
|
||||
};
|
||||
|
||||
|
|
@ -86,7 +87,8 @@ new CustomMaterial( AL_VectorLightMaterial )
|
|||
sampler["deferredBuffer"] = "#deferred";
|
||||
sampler["shadowMap"] = "$dynamiclight";
|
||||
sampler["dynamicShadowMap"] = "$dynamicShadowMap";
|
||||
sampler["ssaoMask"] = "#ssaoMask";
|
||||
sampler["ssaoMask"] = "#ssaoMask";
|
||||
sampler["lightBuffer"] = "#specularLighting";
|
||||
sampler["colorBuffer"] = "#color";
|
||||
sampler["matInfoBuffer"] = "#matinfo";
|
||||
|
||||
|
|
@ -148,8 +150,9 @@ new ShaderData( AL_PointLightShader )
|
|||
samplerNames[2] = "$dynamicShadowMap";
|
||||
samplerNames[3] = "$cookieMap";
|
||||
samplerNames[4] = "$gTapRotationTex";
|
||||
samplerNames[5] = "$colorBuffer";
|
||||
samplerNames[6] = "$matInfoBuffer";
|
||||
samplerNames[5] = "$lightBuffer";
|
||||
samplerNames[6] = "$colorBuffer";
|
||||
samplerNames[7] = "$matInfoBuffer";
|
||||
|
||||
pixVersion = 3.0;
|
||||
};
|
||||
|
|
@ -163,6 +166,7 @@ new CustomMaterial( AL_PointLightMaterial )
|
|||
sampler["shadowMap"] = "$dynamiclight";
|
||||
sampler["dynamicShadowMap"] = "$dynamicShadowMap";
|
||||
sampler["cookieMap"] = "$dynamiclightmask";
|
||||
sampler["lightBuffer"] = "#specularLighting";
|
||||
sampler["colorBuffer"] = "#color";
|
||||
sampler["matInfoBuffer"] = "#matinfo";
|
||||
|
||||
|
|
@ -185,8 +189,9 @@ new ShaderData( AL_SpotLightShader )
|
|||
samplerNames[2] = "$dynamicShadowMap";
|
||||
samplerNames[3] = "$cookieMap";
|
||||
samplerNames[4] = "$gTapRotationTex";
|
||||
samplerNames[5] = "$colorBuffer";
|
||||
samplerNames[6] = "$matInfoBuffer";
|
||||
samplerNames[5] = "$lightBuffer";
|
||||
samplerNames[6] = "$colorBuffer";
|
||||
samplerNames[7] = "$matInfoBuffer";
|
||||
|
||||
pixVersion = 3.0;
|
||||
};
|
||||
|
|
@ -200,6 +205,7 @@ new CustomMaterial( AL_SpotLightMaterial )
|
|||
sampler["shadowMap"] = "$dynamiclight";
|
||||
sampler["dynamicShadowMap"] = "$dynamicShadowMap";
|
||||
sampler["cookieMap"] = "$dynamiclightmask";
|
||||
sampler["lightBuffer"] = "#specularLighting";
|
||||
sampler["colorBuffer"] = "#color";
|
||||
sampler["matInfoBuffer"] = "#matinfo";
|
||||
|
||||
|
|
|
|||
|
|
@ -62,7 +62,7 @@ function initRenderManager()
|
|||
DiffuseRenderPassManager.addManager( new RenderMeshMgr(DecalBin) { bintype = "Decal"; renderOrder = 0.81; processAddOrder = 0.81; } );
|
||||
DiffuseRenderPassManager.addManager( new RenderOcclusionMgr(OccluderBin){ bintype = "Occluder"; renderOrder = 0.9; processAddOrder = 0.9; } );
|
||||
// Render the sky last
|
||||
DiffuseRenderPassManager.addManager( new RenderObjectMgr(SkyBin) { bintype = "Sky"; renderOrder = 1.95; processAddOrder = 1.95; } );
|
||||
DiffuseRenderPassManager.addManager( new RenderObjectMgr(SkyBin) { bintype = "Sky"; renderOrder = 0.95; processAddOrder = 0.95; } );
|
||||
|
||||
// We now render translucent objects that should handle
|
||||
// their own fogging and lighting.
|
||||
|
|
|
|||
|
|
@ -25,7 +25,8 @@
|
|||
#include "./torque.hlsl"
|
||||
|
||||
// BRDF from Frostbite presentation:
|
||||
// Moving Frostbite to Physically Based Rendering// S´ebastien Lagarde - Electronic Arts Frostbite
|
||||
// Moving Frostbite to Physically Based Rendering
|
||||
// S´ebastien Lagarde - Electronic Arts Frostbite
|
||||
// Charles de Rousiers - Electronic Arts Frostbite
|
||||
// SIGGRAPH 2014
|
||||
|
||||
|
|
|
|||
|
|
@ -45,12 +45,22 @@ uniform float4 albedo;
|
|||
|
||||
#endif // !TORQUE_SHADERGEN
|
||||
|
||||
//deferred lighting output
|
||||
struct LightTargetOutput
|
||||
inline float3 getDistanceVectorToPlane( float3 origin, float3 direction, float4 plane )
|
||||
{
|
||||
float4 spec: TORQUE_TARGET0;
|
||||
float4 diffuse: TORQUE_TARGET1;
|
||||
};
|
||||
float denum = dot( plane.xyz, direction.xyz );
|
||||
float num = dot( plane, float4( origin, 1.0 ) );
|
||||
float t = -num / denum;
|
||||
|
||||
return direction.xyz * t;
|
||||
}
|
||||
|
||||
inline float3 getDistanceVectorToPlane( float negFarPlaneDotEye, float3 direction, float4 plane )
|
||||
{
|
||||
float denum = dot( plane.xyz, direction.xyz );
|
||||
float t = negFarPlaneDotEye / denum;
|
||||
|
||||
return direction.xyz * t;
|
||||
}
|
||||
|
||||
//TODO fix compute 4 lights
|
||||
void compute4Lights( float3 wsView,
|
||||
|
|
@ -121,7 +131,7 @@ inline Surface CreateSurface(float4 gbuffer0, TORQUE_SAMPLER2D(gbufferTex1), TOR
|
|||
|
||||
surface.depth = gbuffer0.a;
|
||||
surface.P = wsEyePos + wsEyeRay * surface.depth;
|
||||
surface.N = mul(invView, float4(gbuffer0.xyz,0)).xyz;
|
||||
surface.N = mul(invView, float4(gbuffer0.xyz,0)).xyz; //TODO move t3d to use WS normals
|
||||
surface.V = normalize(wsEyePos - surface.P);
|
||||
surface.baseColor = gbuffer1;
|
||||
const float minRoughness=1e-4;
|
||||
|
|
@ -166,48 +176,56 @@ float3 BRDF_GetSpecular(in Surface surface, in SurfaceToLight surfaceToLight)
|
|||
return Fr;
|
||||
}
|
||||
|
||||
float BRDF_GetDiffuse(in Surface surface, in SurfaceToLight surfaceToLight)
|
||||
float3 BRDF_GetDiffuse(in Surface surface, in SurfaceToLight surfaceToLight)
|
||||
{
|
||||
//getting some banding with disney method, using lambert instead - todo futher testing
|
||||
float Fd = 1.0 / M_PI_F;//Fr_DisneyDiffuse(surface.NdotV, surfaceToLight.NdotL, surfaceToLight.HdotV, surface.roughness) / M_PI_F;
|
||||
return Fd;
|
||||
float Fd = 1.0 / M_PI_F;
|
||||
//energy conservation - remove this if reverting back to disney method
|
||||
float3 kD = 1.0.xxx - surface.F;
|
||||
kD *= 1.0 - surface.metalness;
|
||||
float3 diffuse = kD * surface.baseColor.rgb * Fd;
|
||||
return diffuse;
|
||||
}
|
||||
|
||||
struct LightResult
|
||||
// inverse square falloff from Epic Games' paper
|
||||
float Attenuate(float distToLight, float radius)
|
||||
{
|
||||
float3 diffuse;
|
||||
float3 spec;
|
||||
};
|
||||
|
||||
inline LightResult GetDirectionalLight(in Surface surface, in SurfaceToLight surfaceToLight, float3 lightColor, float lightIntensity, float shadow)
|
||||
{
|
||||
LightResult result = (LightResult)0;
|
||||
float3 factor = lightColor * max(surfaceToLight.NdotL, 0) * shadow * lightIntensity;
|
||||
result.diffuse = BRDF_GetDiffuse(surface,surfaceToLight) * factor;
|
||||
result.spec = BRDF_GetSpecular(surface,surfaceToLight) * factor;
|
||||
|
||||
result.diffuse = max(0.0f, result.diffuse);
|
||||
result.spec = max(0.0f, result.spec);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
inline LightResult GetPointLight(in Surface surface, in SurfaceToLight surfaceToLight, float3 lightColor, float lightIntensity,float distToLight, float radius, float shadow)
|
||||
{
|
||||
LightResult result = (LightResult)0;
|
||||
|
||||
// Distance attenuation from Epic Games' paper
|
||||
float distanceByRadius = 1.0f - pow((distToLight / radius), 4);
|
||||
float clamped = pow(clamp(distanceByRadius, 0.0f, 1.0f), 2.0f);
|
||||
float attenuation = clamped / (sqr(distToLight) + 1.0f);
|
||||
return clamped / (sqr(distToLight) + 1.0f);
|
||||
}
|
||||
|
||||
inline float3 GetDirectionalLight(in Surface surface, in SurfaceToLight surfaceToLight, float3 lightColor, float lightIntensity, float shadow)
|
||||
{
|
||||
float3 factor = lightColor * max(surfaceToLight.NdotL, 0) * shadow * lightIntensity;
|
||||
float3 diffuse = BRDF_GetDiffuse(surface,surfaceToLight) * factor;
|
||||
float3 spec = BRDF_GetSpecular(surface,surfaceToLight) * factor;
|
||||
|
||||
float3 final = max(0.0f, diffuse + spec * surface.ao);
|
||||
return final;
|
||||
}
|
||||
|
||||
inline float3 GetPointLight(in Surface surface, in SurfaceToLight surfaceToLight, float3 lightColor, float lightIntensity,float distToLight, float radius, float shadow)
|
||||
{
|
||||
float attenuation = Attenuate(distToLight,radius);
|
||||
|
||||
float3 factor = lightColor * max(surfaceToLight.NdotL, 0) * shadow * lightIntensity * attenuation;
|
||||
|
||||
result.diffuse = BRDF_GetDiffuse(surface,surfaceToLight) * factor;
|
||||
result.spec = BRDF_GetSpecular(surface,surfaceToLight) * factor;
|
||||
float3 diffuse = BRDF_GetDiffuse(surface,surfaceToLight) * factor;
|
||||
float3 spec = BRDF_GetSpecular(surface,surfaceToLight) * factor;
|
||||
|
||||
result.diffuse = max(0.0f, result.diffuse);
|
||||
result.spec = max(0.0f, result.spec);
|
||||
|
||||
return result;
|
||||
float3 final = max(0.0f, diffuse + spec * surface.ao * surface.F);
|
||||
return final;
|
||||
}
|
||||
|
||||
inline float3 GetSpotLight(in Surface surface, in SurfaceToLight surfaceToLight, float3 lightColor, float lightIntensity,float distToLight, float radius, float shadow)
|
||||
{
|
||||
float attenuation = Attenuate(distToLight,radius);
|
||||
//attenuation *= ( cosAlpha - lightSpotParams.x ) / lightSpotParams.y;
|
||||
float3 factor = lightColor * max(surfaceToLight.NdotL, 0) * shadow * lightIntensity * attenuation;
|
||||
float3 diffuse = BRDF_GetDiffuse(surface,surfaceToLight) * factor;
|
||||
float3 spec = BRDF_GetSpecular(surface,surfaceToLight) * factor;
|
||||
|
||||
float3 final = max(0.0f, diffuse + spec * surface.ao * surface.F);
|
||||
return final;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,32 +0,0 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) 2012 GarageGames, LLC
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to
|
||||
// deal in the Software without restriction, including without limitation the
|
||||
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
// sell copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
// IN THE SOFTWARE.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#include "../../shaderModelAutoGen.hlsl"
|
||||
#include "../../postfx/postFx.hlsl"
|
||||
|
||||
TORQUE_UNIFORM_SAMPLER2D(lightDeferredTex,0);
|
||||
|
||||
float4 main( PFXVertToPix IN ) : TORQUE_TARGET0
|
||||
{
|
||||
float4 lightColor = TORQUE_TEX2D( lightDeferredTex, IN.uv0 );
|
||||
return float4( lightColor.rgb, 1.0 );
|
||||
}
|
||||
|
|
@ -1,31 +0,0 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) 2012 GarageGames, LLC
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to
|
||||
// deal in the Software without restriction, including without limitation the
|
||||
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
// sell copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
// IN THE SOFTWARE.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#include "../../postfx/postFx.hlsl"
|
||||
|
||||
TORQUE_UNIFORM_SAMPLER2D(lightDeferredTex,0);
|
||||
|
||||
float4 main( PFXVertToPix IN ) : TORQUE_TARGET0
|
||||
{
|
||||
float specular = TORQUE_TEX2D( lightDeferredTex, IN.uv0 ).a;
|
||||
return float4( specular, specular, specular, 1.0 );
|
||||
}
|
||||
|
|
@ -1,54 +0,0 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) 2012 GarageGames, LLC
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to
|
||||
// deal in the Software without restriction, including without limitation the
|
||||
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
// sell copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
// IN THE SOFTWARE.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#include "../../postfx/postFx.hlsl"
|
||||
#include "shaders/common/torque.hlsl"
|
||||
#include "shaders/common/lighting.hlsl"
|
||||
|
||||
TORQUE_UNIFORM_SAMPLER2D(colorBufferTex,0);
|
||||
TORQUE_UNIFORM_SAMPLER2D(diffuseLightingBuffer,1);
|
||||
TORQUE_UNIFORM_SAMPLER2D(matInfoTex,2);
|
||||
TORQUE_UNIFORM_SAMPLER2D(specularLightingBuffer,3);
|
||||
TORQUE_UNIFORM_SAMPLER2D(deferredTex,4);
|
||||
|
||||
uniform float4x4 cameraToWorld;
|
||||
uniform float3 eyePosWorld;
|
||||
|
||||
//TODO add in emission
|
||||
float4 main( PFXVertToPix IN ) : TORQUE_TARGET0
|
||||
{
|
||||
//sky and editor background check
|
||||
float4 normDepth = UnpackDepthNormal(TORQUE_SAMPLER2D_MAKEARG(deferredTex), IN.uv0);
|
||||
if (normDepth.a>0.9999)
|
||||
return float4(0,0,0,0);
|
||||
|
||||
//create surface
|
||||
Surface surface = CreateSurface( normDepth, TORQUE_SAMPLER2D_MAKEARG(colorBufferTex),TORQUE_SAMPLER2D_MAKEARG(matInfoTex),
|
||||
IN.uv0, eyePosWorld, IN.wsEyeRay, cameraToWorld);
|
||||
|
||||
float4 diffuse = TORQUE_TEX2DLOD( diffuseLightingBuffer, float4(IN.uv0,0,0));
|
||||
float4 specular = TORQUE_TEX2DLOD( specularLightingBuffer, float4(IN.uv0,0,0));
|
||||
|
||||
float3 sceneColor = (surface.albedo * diffuse.rgb) + (surface.F * specular.rgb) * surface.ao;
|
||||
|
||||
return float4(sceneColor.rgb, 1.0);
|
||||
}
|
||||
|
|
@ -1,51 +0,0 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) 2012 GarageGames, LLC
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to
|
||||
// deal in the Software without restriction, including without limitation the
|
||||
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
// sell copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
// IN THE SOFTWARE.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
|
||||
float attenuate( float4 lightColor, float2 attParams, float dist )
|
||||
{
|
||||
// We're summing the results of a scaled constant,
|
||||
// linear, and quadratic attenuation.
|
||||
|
||||
#ifdef ACCUMULATE_LUV
|
||||
return lightColor.w * ( 1.0 - dot( attParams, float2( dist, dist * dist ) ) );
|
||||
#else
|
||||
return 1.0 - dot( attParams, float2( dist, dist * dist ) );
|
||||
#endif
|
||||
}
|
||||
|
||||
float3 getDistanceVectorToPlane( float3 origin, float3 direction, float4 plane )
|
||||
{
|
||||
float denum = dot( plane.xyz, direction.xyz );
|
||||
float num = dot( plane, float4( origin, 1.0 ) );
|
||||
float t = -num / denum;
|
||||
|
||||
return direction.xyz * t;
|
||||
}
|
||||
|
||||
float3 getDistanceVectorToPlane( float negFarPlaneDotEye, float3 direction, float4 plane )
|
||||
{
|
||||
float denum = dot( plane.xyz, direction.xyz );
|
||||
float t = negFarPlaneDotEye / denum;
|
||||
|
||||
return direction.xyz * t;
|
||||
}
|
||||
|
|
@ -23,7 +23,6 @@
|
|||
#include "../../shaderModelAutoGen.hlsl"
|
||||
|
||||
#include "farFrustumQuad.hlsl"
|
||||
#include "lightingUtils.hlsl"
|
||||
#include "../../lighting.hlsl"
|
||||
#include "../shadowMap/shadowMapIO_HLSL.h"
|
||||
#include "softShadow.hlsl"
|
||||
|
|
@ -88,7 +87,9 @@ TORQUE_UNIFORM_SAMPLERCUBE(cookieMap, 3);
|
|||
// this value was found via experementation
|
||||
// NOTE: this is wrong, it only biases in one direction, not towards the uv
|
||||
// center ( 0.5 0.5 ).
|
||||
//shadowCoord.xy *= 0.997;
|
||||
float offsetVal = 0.95;
|
||||
shadowCoord.xy *= offsetVal;
|
||||
shadowCoord.xy += (1.0-offsetVal).xx / 2.0;
|
||||
|
||||
#ifndef SHADOW_PARABOLOID
|
||||
|
||||
|
|
@ -139,18 +140,14 @@ uniform float3x3 dynamicViewToLightProj;
|
|||
uniform float3 eyePosWorld;
|
||||
uniform float4x4 cameraToWorld;
|
||||
|
||||
LightTargetOutput main( ConvexConnectP IN )
|
||||
float4 main( ConvexConnectP IN ) : SV_TARGET
|
||||
{
|
||||
LightTargetOutput Output = (LightTargetOutput)0;
|
||||
|
||||
// Compute scene UV
|
||||
float3 ssPos = IN.ssPos.xyz / IN.ssPos.w;
|
||||
float2 uvScene = getUVFromSSPos(ssPos, rtParams0);
|
||||
|
||||
//sky and editor background check
|
||||
float4 normDepth = UnpackDepthNormal(TORQUE_SAMPLER2D_MAKEARG(deferredBuffer), uvScene);
|
||||
if (normDepth.w>0.9999)
|
||||
return Output;
|
||||
//unpack normal and linear depth
|
||||
float4 normDepth = TORQUE_DEFERRED_UNCONDITION(deferredBuffer, uvScene);
|
||||
|
||||
//eye ray WS/VS
|
||||
float3 vsEyeRay = getDistanceVectorToPlane( -vsFarPlane.w, IN.vsEyeDir.xyz, vsFarPlane );
|
||||
|
|
@ -163,15 +160,12 @@ LightTargetOutput main( ConvexConnectP IN )
|
|||
//early out if emissive
|
||||
if (getFlag(surface.matFlag, 0))
|
||||
{
|
||||
Output.diffuse = surface.baseColor;
|
||||
Output.spec = surface.baseColor;
|
||||
return Output;
|
||||
return 0.0.xxxx;
|
||||
}
|
||||
|
||||
//create surface to light
|
||||
float3 L = lightPosition - surface.P;
|
||||
float dist = length(L);
|
||||
LightResult result = (LightResult)0;
|
||||
float3 result = 0.0.xxx;
|
||||
[branch]
|
||||
if (dist < lightRange)
|
||||
{
|
||||
|
|
@ -215,10 +209,10 @@ LightTargetOutput main( ConvexConnectP IN )
|
|||
#endif // !NO_SHADOW
|
||||
|
||||
float3 lightcol = lightColor.rgb;
|
||||
/*#ifdef USE_COOKIE_TEX
|
||||
#ifdef USE_COOKIE_TEX
|
||||
|
||||
// Lookup the cookie sample.
|
||||
float4 cookie = TORQUE_TEXCUBE(cookieMap, mul(viewToLightProj, -surfaceToLight.L));
|
||||
float4 cookie = TORQUE_TEXCUBE(cookieMap, mul(worldToLightProj, -surfaceToLight.L));
|
||||
|
||||
// Multiply the light with the cookie tex.
|
||||
lightcol *= cookie.rgb;
|
||||
|
|
@ -228,15 +222,11 @@ LightTargetOutput main( ConvexConnectP IN )
|
|||
// regions of the cookie texture.
|
||||
atten *= max(cookie.r, max(cookie.g, cookie.b));
|
||||
|
||||
#endif*/
|
||||
#endif
|
||||
|
||||
//get point light contribution
|
||||
result = GetPointLight(surface, surfaceToLight, lightcol, lightBrightness, dist, lightRange, shadowed);
|
||||
}
|
||||
|
||||
//output
|
||||
Output.diffuse = float4(result.diffuse, 0);
|
||||
Output.spec = float4(result.spec, 0);
|
||||
|
||||
return Output;
|
||||
return float4(result, 0);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
#include "../../shaderModelAutoGen.hlsl"
|
||||
|
||||
#include "farFrustumQuad.hlsl"
|
||||
#include "lightingUtils.hlsl"
|
||||
#include "../../lighting.hlsl"
|
||||
#include "../../torque.hlsl"
|
||||
|
||||
|
|
@ -44,16 +43,16 @@ uniform float useSphereMode;
|
|||
// and https://seblagarde.wordpress.com/2012/09/29/image-based-lighting-approaches-and-parallax-corrected-cubemap/
|
||||
float3 boxProject(float3 wsPosition, float3 reflectDir, float3 boxWSPos, float3 boxMin, float3 boxMax)
|
||||
{
|
||||
float3 nrdir = reflectDir;
|
||||
float3 nrdir = reflectDir;
|
||||
float3 offset = wsPosition;
|
||||
float3 plane1vec = (boxMax - offset) / nrdir;
|
||||
float3 plane2vec = (boxMin - offset) / nrdir;
|
||||
float3 plane1vec = (boxMax - offset) / nrdir;
|
||||
float3 plane2vec = (boxMin - offset) / nrdir;
|
||||
|
||||
float3 furthestPlane = max(plane1vec, plane2vec);
|
||||
float dist = min(min(furthestPlane.x, furthestPlane.y), furthestPlane.z);
|
||||
float3 posonbox = offset + nrdir * dist;
|
||||
float3 posonbox = offset + nrdir * dist;
|
||||
|
||||
return posonbox - boxWSPos;
|
||||
return posonbox - boxWSPos;
|
||||
}
|
||||
|
||||
float3 iblBoxDiffuse(float3 normal,
|
||||
|
|
@ -64,45 +63,37 @@ float3 iblBoxDiffuse(float3 normal,
|
|||
float3 boxMax)
|
||||
{
|
||||
// Irradiance (Diffuse)
|
||||
float3 cubeN = normalize(normal);
|
||||
float3 irradiance = TORQUE_TEXCUBE(irradianceCube, cubeN).xyz;
|
||||
float3 cubeN = normalize(normal);
|
||||
float3 irradiance = TORQUE_TEXCUBE(irradianceCube, cubeN).xyz;
|
||||
|
||||
return irradiance;
|
||||
return irradiance;
|
||||
}
|
||||
|
||||
float3 iblBoxSpecular(float3 normal,
|
||||
float3 wsPos,
|
||||
float roughness,
|
||||
float3 surfToEye,
|
||||
TORQUE_SAMPLER2D(brdfTexture),
|
||||
float3 iblBoxSpecular(float3 normal, float3 wsPos, float roughness, float3 surfToEye,
|
||||
TORQUE_SAMPLER2D(brdfTexture),
|
||||
TORQUE_SAMPLERCUBE(radianceCube),
|
||||
float3 boxPos,
|
||||
float3 boxMin,
|
||||
float3 boxMax)
|
||||
{
|
||||
float ndotv = clamp(dot(normal, surfToEye), 0.0, 1.0);
|
||||
float ndotv = clamp(dot(normal, surfToEye), 0.0, 1.0);
|
||||
|
||||
// BRDF
|
||||
float2 brdf = TORQUE_TEX2D(brdfTexture, float2(roughness, ndotv)).xy;
|
||||
float2 brdf = TORQUE_TEX2D(brdfTexture, float2(roughness, ndotv)).xy;
|
||||
|
||||
// Radiance (Specular)
|
||||
float maxmip = pow(cubeMips+1,2);
|
||||
float lod = roughness*maxmip;
|
||||
float3 r = reflect(surfToEye, normal);
|
||||
float3 cubeR = normalize(r);
|
||||
cubeR = boxProject(wsPos, cubeR, boxPos, boxMin, boxMax);
|
||||
float lod = roughness*maxmip;
|
||||
float3 r = reflect(surfToEye, normal);
|
||||
float3 cubeR = normalize(r);
|
||||
cubeR = boxProject(wsPos, cubeR, boxPos, boxMin, boxMax);
|
||||
|
||||
float3 radiance = TORQUE_TEXCUBELOD(radianceCube, float4(cubeR, lod)).xyz * (brdf.x + brdf.y);
|
||||
float3 radiance = TORQUE_TEXCUBELOD(radianceCube, float4(cubeR, lod)).xyz * (brdf.x + brdf.y);
|
||||
|
||||
return radiance;
|
||||
return radiance;
|
||||
}
|
||||
|
||||
struct PS_OUTPUT
|
||||
{
|
||||
float4 diffuse: TORQUE_TARGET1;
|
||||
float4 spec: TORQUE_TARGET0;
|
||||
};
|
||||
|
||||
/*
|
||||
float defineSphereSpaceInfluence(float3 centroidPosVS, float rad, float2 atten, float3 surfPosVS, float3 norm)
|
||||
{
|
||||
// Build light vec, get length, clip pixel if needed
|
||||
|
|
@ -125,6 +116,7 @@ float defineSphereSpaceInfluence(float3 centroidPosVS, float rad, float2 atten,
|
|||
|
||||
return saturate( nDotL * attn );
|
||||
}
|
||||
*/
|
||||
|
||||
float defineBoxSpaceInfluence(float3 surfPosWS, float3 probePos, float radius, float atten)
|
||||
{
|
||||
|
|
@ -139,9 +131,7 @@ float defineBoxSpaceInfluence(float3 surfPosWS, float3 probePos, float radius, f
|
|||
float3 localDir = float3(abs(surfPosLS.x), abs(surfPosLS.y), abs(surfPosLS.z));
|
||||
localDir = (localDir - boxInnerRange) / (boxOuterRange - boxInnerRange);
|
||||
|
||||
float influenceVal = max(localDir.x, max(localDir.y, localDir.z)) * -1;
|
||||
|
||||
return influenceVal;
|
||||
return max(localDir.x, max(localDir.y, localDir.z)) * -1;
|
||||
}
|
||||
|
||||
float defineDepthInfluence(float3 probePosWS, float3 surfPosWS, TORQUE_SAMPLERCUBE(radianceCube))
|
||||
|
|
@ -156,55 +146,41 @@ float defineDepthInfluence(float3 probePosWS, float3 surfPosWS, TORQUE_SAMPLERCU
|
|||
return depthRef-dist;
|
||||
}
|
||||
|
||||
PS_OUTPUT main( ConvexConnectP IN )
|
||||
float4 main( ConvexConnectP IN ) : SV_TARGET
|
||||
{
|
||||
PS_OUTPUT Output = (PS_OUTPUT)0;
|
||||
// Compute scene UV
|
||||
float3 ssPos = IN.ssPos.xyz / IN.ssPos.w;
|
||||
float2 uvScene = getUVFromSSPos( ssPos, rtParams0 );
|
||||
|
||||
// Compute scene UV
|
||||
float3 ssPos = IN.ssPos.xyz / IN.ssPos.w;
|
||||
//eye ray WS/LS
|
||||
float3 vsEyeRay = getDistanceVectorToPlane( -vsFarPlane.w, IN.vsEyeDir.xyz, vsFarPlane );
|
||||
float3 wsEyeRay = mul(cameraToWorld, float4(vsEyeRay, 0)).xyz;
|
||||
|
||||
//unpack normal and linear depth
|
||||
float4 normDepth = TORQUE_DEFERRED_UNCONDITION(deferredBuffer, uvScene);
|
||||
|
||||
//create surface
|
||||
Surface surface = CreateSurface( normDepth, TORQUE_SAMPLER2D_MAKEARG(colorBuffer),TORQUE_SAMPLER2D_MAKEARG(matInfoBuffer),
|
||||
uvScene, eyePosWorld, wsEyeRay, cameraToWorld);
|
||||
|
||||
float2 uvScene = getUVFromSSPos( ssPos, rtParams0 );
|
||||
// Sample/unpack the normal/z data
|
||||
float4 deferredSample = TORQUE_DEFERRED_UNCONDITION( deferredBuffer, uvScene );
|
||||
float3 normal = deferredSample.rgb;
|
||||
float depth = deferredSample.a;
|
||||
if (depth>0.9999)
|
||||
clip(-1);
|
||||
|
||||
// Matinfo flags
|
||||
float4 matInfo = TORQUE_TEX2D( matInfoBuffer, uvScene );
|
||||
|
||||
// Need world-space normal.
|
||||
float3 wsNormal = mul(cameraToWorld, float4(normal, 0)).xyz;
|
||||
|
||||
float3 vsEyeRay = getDistanceVectorToPlane( -vsFarPlane.w, IN.vsEyeDir.xyz, vsFarPlane );
|
||||
float3 vsPos = vsEyeRay * depth;
|
||||
|
||||
float3 wsEyeRay = mul(cameraToWorld, float4(vsEyeRay, 0)).xyz;
|
||||
// calculate world space position
|
||||
float3 wsPos = float3(eyePosWorld + wsEyeRay * depth);
|
||||
|
||||
float blendVal = 1.0;
|
||||
|
||||
//clip bounds and (TODO properly: set falloff)
|
||||
if(useSphereMode)
|
||||
{
|
||||
blendVal = defineSphereSpaceInfluence(probeLSPos, radius, attenuation, vsPos, normal);
|
||||
}
|
||||
else
|
||||
{
|
||||
float tempAttenVal = 3.5;
|
||||
blendVal = defineBoxSpaceInfluence(wsPos, probeWSPos, radius, tempAttenVal);
|
||||
}
|
||||
float tempAttenVal = 3.5;
|
||||
float blendVal = defineBoxSpaceInfluence(surface.P, probeWSPos, radius, tempAttenVal);
|
||||
clip(blendVal);
|
||||
|
||||
//flip me on to have probes filter by depth
|
||||
//clip(defineDepthInfluence(probeWSPos, worldPos, TORQUE_SAMPLERCUBE_MAKEARG(cubeMap)));
|
||||
|
||||
//clip(defineDepthInfluence(probeWSPos, worldPos, TORQUE_SAMPLERCUBE_MAKEARG(cubeMap)));
|
||||
|
||||
//render into the bound space defined above
|
||||
float3 surfToEye = normalize(wsPos - eyePosWorld);
|
||||
Output.diffuse = float4(iblBoxDiffuse(wsNormal, wsPos, TORQUE_SAMPLERCUBE_MAKEARG(irradianceCubemap), probeWSPos, bbMin, bbMax), blendVal);
|
||||
Output.spec = float4(iblBoxSpecular(wsNormal, wsPos, 1.0 - matInfo.b, surfToEye, TORQUE_SAMPLER2D_MAKEARG(BRDFTexture), TORQUE_SAMPLERCUBE_MAKEARG(cubeMap), probeWSPos, bbMin, bbMax), blendVal);
|
||||
return Output;
|
||||
float3 surfToEye = normalize(surface.P - eyePosWorld);
|
||||
float3 irradiance = iblBoxDiffuse(surface.N, surface.P, TORQUE_SAMPLERCUBE_MAKEARG(irradianceCubemap), probeWSPos, bbMin, bbMax);
|
||||
float3 specular = iblBoxSpecular(surface.N, surface.P, surface.roughness, surfToEye, TORQUE_SAMPLER2D_MAKEARG(BRDFTexture), TORQUE_SAMPLERCUBE_MAKEARG(cubeMap), probeWSPos, bbMin, bbMax);
|
||||
|
||||
//energy conservation
|
||||
float3 F = FresnelSchlickRoughness(surface.NdotV, surface.f0, surface.roughness);
|
||||
float3 kD = 1.0.xxx - F;
|
||||
kD *= 1.0 - surface.metalness;
|
||||
//final diffuse color
|
||||
float3 diffuse = kD * irradiance * surface.baseColor.rgb;
|
||||
|
||||
return float4((diffuse+specular) * surface.ao, blendVal);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
#include "../../shaderModelAutoGen.hlsl"
|
||||
|
||||
#include "farFrustumQuad.hlsl"
|
||||
#include "lightingUtils.hlsl"
|
||||
#include "../../lighting.hlsl"
|
||||
#include "../../torque.hlsl"
|
||||
|
||||
|
|
@ -25,19 +24,16 @@ uniform float4 vsFarPlane;
|
|||
uniform float4x4 cameraToWorld;
|
||||
uniform float3 eyePosWorld;
|
||||
|
||||
float3 iblSpecular(float3 v, float3 n, float roughness)
|
||||
float3 iblSpecular(in Surface surface, float3 F)
|
||||
{
|
||||
float3 R = reflect(v, n);
|
||||
const float MAX_REFLECTION_LOD = 4.0;
|
||||
float3 prefilteredColor = TORQUE_TEXCUBELOD(cubeMap, float4(R, roughness * MAX_REFLECTION_LOD)).rgb;
|
||||
float2 envBRDF = TORQUE_TEX2D(BRDFTexture, float2(max(dot(n, v), 0.0), roughness)).rg;
|
||||
return prefilteredColor * (envBRDF.x + envBRDF.y);
|
||||
float3 prefilteredColor = TORQUE_TEXCUBELOD(cubeMap, float4(surface.R, surface.roughness * MAX_REFLECTION_LOD)).rgb;
|
||||
float2 envBRDF = TORQUE_TEX2D(BRDFTexture, float2(surface.NdotV, surface.roughness)).rg;
|
||||
return prefilteredColor * (F * envBRDF.x + envBRDF.y);
|
||||
}
|
||||
|
||||
LightTargetOutput main( ConvexConnectP IN )
|
||||
float4 main( ConvexConnectP IN ) : SV_TARGET
|
||||
{
|
||||
LightTargetOutput Output = (LightTargetOutput)0;
|
||||
|
||||
// Compute scene UV
|
||||
float3 ssPos = IN.ssPos.xyz / IN.ssPos.w;
|
||||
float2 uvScene = getUVFromSSPos( ssPos, rtParams0 );
|
||||
|
|
@ -46,22 +42,23 @@ LightTargetOutput main( ConvexConnectP IN )
|
|||
float3 vsEyeRay = getDistanceVectorToPlane( -vsFarPlane.w, IN.vsEyeDir.xyz, vsFarPlane );
|
||||
float3 wsEyeRay = mul(cameraToWorld, float4(vsEyeRay, 0)).xyz;
|
||||
|
||||
//sky and editor background check
|
||||
float4 normDepth = UnpackDepthNormal(TORQUE_SAMPLER2D_MAKEARG(deferredBuffer), uvScene);
|
||||
if (normDepth.a>0.9999)
|
||||
return Output;
|
||||
//unpack normal and linear depth
|
||||
float4 normDepth = TORQUE_DEFERRED_UNCONDITION(deferredBuffer, uvScene);
|
||||
|
||||
//create surface
|
||||
Surface surface = CreateSurface( normDepth, TORQUE_SAMPLER2D_MAKEARG(colorBuffer),TORQUE_SAMPLER2D_MAKEARG(matInfoBuffer),
|
||||
uvScene, eyePosWorld, wsEyeRay, cameraToWorld);
|
||||
|
||||
float3 diffuse = TORQUE_TEXCUBELOD(irradianceCubemap, float4(surface.N,0)).rgb;
|
||||
float3 specular = iblSpecular(wsEyeRay, surface.N, surface.roughness);
|
||||
float3 F = FresnelSchlickRoughness(surface.NdotV, surface.f0, surface.roughness);
|
||||
float3 irradiance = TORQUE_TEXCUBELOD(irradianceCubemap, float4(surface.N,0)).rgb;
|
||||
float3 specular = iblSpecular(surface, F);
|
||||
//energy conservation
|
||||
float3 kD = 1.0.xxx - F;
|
||||
kD *= 1.0 - surface.metalness;
|
||||
//final diffuse color
|
||||
float3 diffuse = kD * irradiance * surface.baseColor.rgb;
|
||||
|
||||
float blendVal = 0.0001;// ?????
|
||||
|
||||
Output.diffuse = float4(diffuse, blendVal);
|
||||
Output.spec = float4(specular, blendVal);
|
||||
return Output;
|
||||
float blendVal = 0.0001;
|
||||
|
||||
return float4(diffuse + specular * surface.ao, blendVal);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,7 +24,6 @@
|
|||
#include "../../shaderModelAutoGen.hlsl"
|
||||
|
||||
#include "farFrustumQuad.hlsl"
|
||||
#include "lightingUtils.hlsl"
|
||||
#include "../../lighting.hlsl"
|
||||
#include "../shadowMap/shadowMapIO_HLSL.h"
|
||||
#include "softShadow.hlsl"
|
||||
|
|
@ -64,123 +63,57 @@ uniform float3 lightDirection;
|
|||
uniform float4 lightSpotParams;
|
||||
uniform float4 lightMapParams;
|
||||
uniform float4 vsFarPlane;
|
||||
uniform float4x4 viewToLightProj;
|
||||
uniform float4x4 worldToLightProj;
|
||||
uniform float4 lightParams;
|
||||
uniform float4x4 dynamicViewToLightProj;
|
||||
|
||||
uniform float2 lightAttenuation;
|
||||
uniform float shadowSoftness;
|
||||
|
||||
uniform float3 eyePosWorld;
|
||||
|
||||
uniform float4x4 cameraToWorld;
|
||||
|
||||
LightTargetOutput main( ConvexConnectP IN )
|
||||
float4 main( ConvexConnectP IN ) : SV_TARGET
|
||||
{
|
||||
LightTargetOutput Output = (LightTargetOutput)0;
|
||||
// Compute scene UV
|
||||
float3 ssPos = IN.ssPos.xyz / IN.ssPos.w;
|
||||
float2 uvScene = getUVFromSSPos( ssPos, rtParams0 );
|
||||
|
||||
//sky and editor background check
|
||||
float4 normDepth = UnpackDepthNormal(TORQUE_SAMPLER2D_MAKEARG(deferredBuffer), uvScene);
|
||||
if (normDepth.a>0.9999)
|
||||
return Output;
|
||||
|
||||
// Eye ray - Eye -> Pixel
|
||||
float3 eyeRay = getDistanceVectorToPlane( -vsFarPlane.w, IN.vsEyeDir.xyz, vsFarPlane );
|
||||
float3 viewSpacePos = eyeRay * normDepth.w;
|
||||
|
||||
// Build light vec, get length, clip pixel if needed
|
||||
float3 lightToPxlVec = viewSpacePos - lightPosition;
|
||||
float lenLightV = length( lightToPxlVec );
|
||||
lightToPxlVec /= lenLightV;
|
||||
float2 uvScene = getUVFromSSPos(ssPos, rtParams0);
|
||||
|
||||
//lightDirection = float3( -lightDirection.xy, lightDirection.z ); //float3( 0, 0, -1 );
|
||||
float cosAlpha = dot( lightDirection, lightToPxlVec );
|
||||
clip( cosAlpha - lightSpotParams.x );
|
||||
clip( lightRange - lenLightV );
|
||||
//unpack normal and linear depth
|
||||
float4 normDepth = TORQUE_DEFERRED_UNCONDITION(deferredBuffer, uvScene);
|
||||
|
||||
//eye ray WS/VS
|
||||
float3 vsEyeRay = getDistanceVectorToPlane( -vsFarPlane.w, IN.vsEyeDir.xyz, vsFarPlane );
|
||||
float3 wsEyeRay = mul(cameraToWorld, float4(vsEyeRay, 0)).xyz;
|
||||
|
||||
float atten = attenuate( lightColor, lightAttenuation, lenLightV );
|
||||
atten *= ( cosAlpha - lightSpotParams.x ) / lightSpotParams.y;
|
||||
clip( atten - 1e-6 );
|
||||
atten = saturate( atten );
|
||||
|
||||
//create surface
|
||||
Surface surface = CreateSurface( normDepth, TORQUE_SAMPLER2D_MAKEARG(colorBuffer),TORQUE_SAMPLER2D_MAKEARG(matInfoBuffer),
|
||||
uvScene, eyePosWorld, eyeRay, cameraToWorld);
|
||||
uvScene, eyePosWorld, wsEyeRay, cameraToWorld);
|
||||
|
||||
//early out if emissive
|
||||
if (getFlag(surface.matFlag, 0))
|
||||
{
|
||||
Output.diffuse = surface.baseColor;
|
||||
Output.spec = surface.baseColor;
|
||||
return Output;
|
||||
return 0.0.xxxx;
|
||||
}
|
||||
|
||||
float3 L = lightPosition - surface.P;
|
||||
float dist = length(L);
|
||||
float3 result = 0.0.xxx;
|
||||
[branch]
|
||||
if (dist < lightRange)
|
||||
{
|
||||
float distToLight = dist / lightRange;
|
||||
float spotFactor = dot(L, lightDirection);
|
||||
float spotCutOff = lightSpotParams.x;
|
||||
[branch]
|
||||
//if (spotFactor > spotCutOff)
|
||||
{
|
||||
SurfaceToLight surfaceToLight = CreateSurfaceToLight(surface, L);
|
||||
float shadowed = 1.0;
|
||||
float3 lightcol = lightColor.rgb;
|
||||
//get spot light contribution
|
||||
result = GetSpotLight(surface, surfaceToLight, lightcol, lightBrightness, dist, lightRange, shadowed);
|
||||
//result = float3(1.0,0,0);
|
||||
}
|
||||
}
|
||||
|
||||
//create surface to light
|
||||
float3 wsLightDir = mul(cameraToWorld, float4(lightDirection,0)).xyz;
|
||||
SurfaceToLight surfaceToLight = CreateSurfaceToLight(surface, -wsLightDir);
|
||||
|
||||
float nDotL = dot( normDepth.xyz, -lightToPxlVec );
|
||||
|
||||
// Get the shadow texture coordinate
|
||||
float4 pxlPosLightProj = mul( viewToLightProj, float4( viewSpacePos, 1 ) );
|
||||
float2 shadowCoord = ( ( pxlPosLightProj.xy / pxlPosLightProj.w ) * 0.5 ) + float2( 0.5, 0.5 );
|
||||
shadowCoord.y = 1.0f - shadowCoord.y;
|
||||
|
||||
// Get the dynamic shadow texture coordinate
|
||||
float4 dynpxlPosLightProj = mul( dynamicViewToLightProj, float4( viewSpacePos, 1 ) );
|
||||
float2 dynshadowCoord = ( ( dynpxlPosLightProj.xy / dynpxlPosLightProj.w ) * 0.5 ) + float2( 0.5, 0.5 );
|
||||
dynshadowCoord.y = 1.0f - dynshadowCoord.y;
|
||||
|
||||
#ifdef NO_SHADOW
|
||||
|
||||
float shadowed = 1.0;
|
||||
|
||||
#else
|
||||
|
||||
// Get a linear depth from the light source.
|
||||
float distToLight = pxlPosLightProj.z / lightRange;
|
||||
|
||||
float static_shadowed = softShadow_filter( TORQUE_SAMPLER2D_MAKEARG(shadowMap),
|
||||
ssPos.xy,
|
||||
shadowCoord,
|
||||
shadowSoftness,
|
||||
distToLight,
|
||||
nDotL,
|
||||
lightParams.y );
|
||||
|
||||
float dynamic_shadowed = softShadow_filter( TORQUE_SAMPLER2D_MAKEARG(dynamicShadowMap),
|
||||
ssPos.xy,
|
||||
dynshadowCoord,
|
||||
shadowSoftness,
|
||||
distToLight,
|
||||
nDotL,
|
||||
lightParams.y );
|
||||
float shadowed = min(static_shadowed, dynamic_shadowed);
|
||||
#endif // !NO_SHADOW
|
||||
|
||||
float3 lightcol = lightColor.rgb;
|
||||
#ifdef USE_COOKIE_TEX
|
||||
|
||||
// Lookup the cookie sample.
|
||||
float4 cookie = TORQUE_TEX2D( cookieMap, shadowCoord );
|
||||
|
||||
// Multiply the light with the cookie tex.
|
||||
lightcol *= cookie.rgb;
|
||||
|
||||
// Use a maximum channel luminance to attenuate
|
||||
// the lighting else we get specular in the dark
|
||||
// regions of the cookie texture.
|
||||
atten *= max( cookie.r, max( cookie.g, cookie.b ) );
|
||||
|
||||
#endif
|
||||
|
||||
//get directional light contribution
|
||||
LightResult result = GetDirectionalLight(surface, surfaceToLight, lightColor.rgb, lightBrightness, shadowed);
|
||||
|
||||
//output
|
||||
Output.diffuse = float4(result.diffuse*atten, 0);
|
||||
Output.spec = float4(result.spec*atten, 0);
|
||||
|
||||
return Output;
|
||||
return float4(result, 0);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,7 +26,6 @@
|
|||
#include "farFrustumQuad.hlsl"
|
||||
#include "../../torque.hlsl"
|
||||
#include "../../lighting.hlsl"
|
||||
#include "lightingUtils.hlsl"
|
||||
#include "../shadowMap/shadowMapIO_HLSL.h"
|
||||
#include "softShadow.hlsl"
|
||||
|
||||
|
|
@ -182,15 +181,11 @@ float4 AL_VectorLightShadowCast( TORQUE_SAMPLER2D(sourceShadowMap),
|
|||
};
|
||||
|
||||
|
||||
LightTargetOutput main(FarFrustumQuadConnectP IN)
|
||||
float4 main(FarFrustumQuadConnectP IN) : SV_TARGET
|
||||
{
|
||||
LightTargetOutput Output = (LightTargetOutput)0;
|
||||
|
||||
//sky and editor background check
|
||||
float4 normDepth = UnpackDepthNormal(TORQUE_SAMPLER2D_MAKEARG(deferredBuffer), IN.uv0);
|
||||
if (normDepth.w>0.9999)
|
||||
return Output;
|
||||
|
||||
//unpack normal and linear depth
|
||||
float4 normDepth = TORQUE_DEFERRED_UNCONDITION(deferredBuffer, IN.uv0);
|
||||
|
||||
//create surface
|
||||
Surface surface = CreateSurface( normDepth, TORQUE_SAMPLER2D_MAKEARG(colorBuffer),TORQUE_SAMPLER2D_MAKEARG(matInfoBuffer),
|
||||
IN.uv0, eyePosWorld, IN.wsEyeRay, cameraToWorld);
|
||||
|
|
@ -198,9 +193,7 @@ LightTargetOutput main(FarFrustumQuadConnectP IN)
|
|||
//early out if emissive
|
||||
if (getFlag(surface.matFlag, 0))
|
||||
{
|
||||
Output.diffuse = surface.baseColor;
|
||||
Output.spec = surface.baseColor;
|
||||
return Output;
|
||||
return 0.0.xxxx;
|
||||
}
|
||||
|
||||
//create surface to light
|
||||
|
|
@ -217,7 +210,7 @@ LightTargetOutput main(FarFrustumQuadConnectP IN)
|
|||
float4 zDist = (zNearFarInvNearFar.x + zNearFarInvNearFar.y * surface.depth);
|
||||
float fadeOutAmt = ( zDist.x - fadeStartLength.x ) * fadeStartLength.y;
|
||||
|
||||
//there must be a better way of doing this, two shadowcast lookups = very yucky!
|
||||
//there must be a more effecient way of doing this, two shadowcast lookups = very yucky!
|
||||
float4 static_shadowed_colors = AL_VectorLightShadowCast( TORQUE_SAMPLER2D_MAKEARG(shadowMap), IN.uv0.xy, worldToLightProj, surface.P, scaleX, scaleY, offsetX, offsetY,
|
||||
farPlaneScalePSSM, surfaceToLight.NdotL);
|
||||
|
||||
|
|
@ -244,10 +237,7 @@ LightTargetOutput main(FarFrustumQuadConnectP IN)
|
|||
#endif //NO_SHADOW
|
||||
|
||||
//get directional light contribution
|
||||
LightResult result = GetDirectionalLight(surface, surfaceToLight, lightingColor.rgb, lightBrightness, shadow);
|
||||
//output
|
||||
Output.diffuse = float4(result.diffuse, 0);
|
||||
Output.spec = float4(result.spec, 0);
|
||||
float3 result = GetDirectionalLight(surface, surfaceToLight, lightingColor.rgb, lightBrightness, shadow);
|
||||
|
||||
return Output;
|
||||
return float4(result, 0);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,22 +28,6 @@
|
|||
|
||||
// Portability helpers for autogenConditioners
|
||||
|
||||
//todo deprecate this function
|
||||
#define TORQUE_DEFERRED_UNCONDITION(tex, coords) deferredUncondition(tex, texture_##tex, coords)
|
||||
|
||||
inline float4 UnpackDepthNormal(TORQUE_SAMPLER2D(tex), float2 screenUVVar)
|
||||
{
|
||||
// Sampler g-buffer
|
||||
float4 bufferSample = TORQUE_TEX2DLOD(tex,float4(screenUVVar,0,0));
|
||||
// g-buffer unconditioner: float4(normal.X, normal.Y, depth Hi, depth Lo)
|
||||
float2 _inpXY = bufferSample.xy;
|
||||
float _xySQ = dot(_inpXY, _inpXY);
|
||||
float4 _gbUnconditionedInput = float4( sqrt(half(1.0 - (_xySQ / 4.0))) * _inpXY, -1.0 + (_xySQ / 2.0), bufferSample.a).xzyw;
|
||||
|
||||
// Decode depth
|
||||
_gbUnconditionedInput.w = dot( bufferSample.zw, float2(1.0, 1.0/65535.0));
|
||||
|
||||
return _gbUnconditionedInput;
|
||||
}
|
||||
|
||||
#endif //_TORQUE_SHADERMODEL_AUTOGEN_
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue