diff --git a/Engine/source/core/util/swizzle.h b/Engine/source/core/util/swizzle.h index abbff288f..0f1d583f6 100644 --- a/Engine/source/core/util/swizzle.h +++ b/Engine/source/core/util/swizzle.h @@ -120,8 +120,7 @@ inline void Swizzle::ToBuffer( void *destination, const void *sour { // TODO: OpenMP? AssertFatal( size % ( sizeof( T ) * mapLength ) == 0, "Bad buffer size for swizzle, see docs." ); - AssertFatal( destination != NULL, "Swizzle::ToBuffer - got a NULL destination pointer!" ); - AssertFatal( source != NULL, "Swizzle::ToBuffer - got a NULL source pointer!" ); + if (!destination || !source) return; T *dest = reinterpret_cast( destination ); const T *src = reinterpret_cast( source ); diff --git a/Engine/source/environment/basicClouds.cpp b/Engine/source/environment/basicClouds.cpp index 185aa3a97..979579c2f 100644 --- a/Engine/source/environment/basicClouds.cpp +++ b/Engine/source/environment/basicClouds.cpp @@ -141,7 +141,7 @@ bool BasicClouds::onAdd() GFXStateBlockDesc desc; desc.setCullMode( GFXCullNone ); desc.setBlend( true ); - desc.setZReadWrite( false, false ); + desc.setZReadWrite( true, false ); desc.samplersDefined = true; desc.samplers[0].addressModeU = GFXAddressWrap; desc.samplers[0].addressModeV = GFXAddressWrap; diff --git a/Engine/source/environment/cloudLayer.cpp b/Engine/source/environment/cloudLayer.cpp index dca9faf00..3fe02368f 100644 --- a/Engine/source/environment/cloudLayer.cpp +++ b/Engine/source/environment/cloudLayer.cpp @@ -161,7 +161,7 @@ bool CloudLayer::onAdd() GFXStateBlockDesc desc; desc.setCullMode( GFXCullNone ); desc.setBlend( true ); - desc.setZReadWrite( false, false ); + desc.setZReadWrite( true, false ); desc.samplersDefined = true; desc.samplers[0].addressModeU = GFXAddressWrap; desc.samplers[0].addressModeV = GFXAddressWrap; diff --git a/Engine/source/environment/decalRoad.cpp b/Engine/source/environment/decalRoad.cpp index 3cde83149..1cea7ed4a 100644 --- a/Engine/source/environment/decalRoad.cpp +++ b/Engine/source/environment/decalRoad.cpp @@ -732,7 +732,7 @@ void DecalRoad::prepRenderImage( SceneRenderState* state ) MathUtils::getZBiasProjectionMatrix( gDecalBias, frustum, tempMat ); coreRI.projection = tempMat; - coreRI.type = RenderPassManager::RIT_Decal; + coreRI.type = RenderPassManager::RIT_DecalRoad; coreRI.vertBuff = &mVB; coreRI.primBuff = &mPB; coreRI.matInst = matInst; diff --git a/Engine/source/environment/scatterSky.cpp b/Engine/source/environment/scatterSky.cpp index 328a64187..dbdeef48b 100644 --- a/Engine/source/environment/scatterSky.cpp +++ b/Engine/source/environment/scatterSky.cpp @@ -955,12 +955,21 @@ void ScatterSky::_render( ObjectRenderInst *ri, SceneRenderState *state, BaseMat Point3F camPos2 = state->getCameraPosition(); MatrixF xfm(true); - xfm.setPosition(camPos2 - Point3F( 0, 0, mZOffset)); + GFX->multWorld(xfm); MatrixF xform(proj);//GFX->getProjectionMatrix()); xform *= GFX->getViewMatrix(); xform *= GFX->getWorldMatrix(); + if(state->isReflectPass()) + { + static MatrixF rotMat(EulerF(0.0, 0.0, M_PI_F)); + xform.mul(rotMat); + rotMat.set(EulerF(M_PI_F, 0.0, 0.0)); + xform.mul(rotMat); + } + xform.setPosition(xform.getPosition() - Point3F(0, 0, mZOffset)); + mShaderConsts->setSafe( mModelViewProjSC, xform ); mShaderConsts->setSafe( mMiscSC, miscParams ); mShaderConsts->setSafe( mSphereRadiiSC, sphereRadii ); diff --git a/Engine/source/environment/skyBox.cpp b/Engine/source/environment/skyBox.cpp index 6ed2174e5..83c9bb6e7 100644 --- a/Engine/source/environment/skyBox.cpp +++ b/Engine/source/environment/skyBox.cpp @@ -599,7 +599,8 @@ void SkyBox::_initMaterial() // We want to disable culling and z write. GFXStateBlockDesc desc; - desc.setCullMode( GFXCullCW ); + desc.setCullMode( GFXCullNone ); + desc.setBlend( true ); desc.setZReadWrite( true, false ); mMatInstance->addStateBlockDesc( desc ); diff --git a/Engine/source/gfx/D3D9/gfxD3D9CardProfiler.cpp b/Engine/source/gfx/D3D9/gfxD3D9CardProfiler.cpp index 988e3a4e2..c6b169614 100644 --- a/Engine/source/gfx/D3D9/gfxD3D9CardProfiler.cpp +++ b/Engine/source/gfx/D3D9/gfxD3D9CardProfiler.cpp @@ -87,9 +87,11 @@ void GFXD3D9CardProfiler::setupCardCapabilities() bool canDoFourStageDetailBlend = ( caps.TextureOpCaps & D3DTEXOPCAPS_SUBTRACT ) && ( caps.PrimitiveMiscCaps & D3DPMISCCAPS_TSSARGTEMP ) && ( caps.MaxTextureBlendStages > 3 ); + bool canDoIndependentMrtBitDepth = (caps.PrimitiveMiscCaps & D3DPMISCCAPS_MRTINDEPENDENTBITDEPTHS ? 1 : 0 ); setCapability( "lerpDetailBlend", canDoLERPDetailBlend ); setCapability( "fourStageDetailBlend", canDoFourStageDetailBlend ); + setCapability( "independentMrtBitDepth", canDoIndependentMrtBitDepth); } bool GFXD3D9CardProfiler::_queryCardCap(const String &query, U32 &foundResult) diff --git a/Engine/source/gfx/D3D9/pc/gfxPCD3D9Target.cpp b/Engine/source/gfx/D3D9/pc/gfxPCD3D9Target.cpp index d545b5ba2..415801263 100644 --- a/Engine/source/gfx/D3D9/pc/gfxPCD3D9Target.cpp +++ b/Engine/source/gfx/D3D9/pc/gfxPCD3D9Target.cpp @@ -31,6 +31,9 @@ #include "gfx/gfxDebugEvent.h" #include "windowManager/win32/win32Window.h" +#ifndef _GFXDEVICE_H_ +#include "gfx/gfxDevice.h" +#endif GFXPCD3D9TextureTarget::GFXPCD3D9TextureTarget() : mTargetSize( Point2I::Zero ), @@ -451,6 +454,7 @@ void GFXPCD3D9WindowTarget::createAdditionalSwapChain() void GFXPCD3D9WindowTarget::resetMode() { + GFX->beginReset(); mWindow->setSuppressReset(true); if (mSwapChain) @@ -509,6 +513,7 @@ void GFXPCD3D9WindowTarget::zombify() void GFXPCD3D9WindowTarget::resurrect() { + GFX->beginReset(); if(mImplicit) { setImplicitSwapChain(); diff --git a/Engine/source/gfx/gfxDevice.h b/Engine/source/gfx/gfxDevice.h index e8ca6739b..aa7ba0edf 100644 --- a/Engine/source/gfx/gfxDevice.h +++ b/Engine/source/gfx/gfxDevice.h @@ -302,6 +302,7 @@ protected: /// This will allow querying to see if a device is initialized and ready to /// have operations performed on it. bool mInitialized; + bool mReset; /// This is called before this, or any other device, is deleted in the global destroy() /// method. It allows the device to clean up anything while everything is still valid. @@ -326,6 +327,10 @@ public: /// @see endScene bool canCurrentlyRender() const { return mCanCurrentlyRender; } + bool recentlyReset(){ return mReset; } + void beginReset(){ mReset = true; } + void finalizeReset(){ mReset = false; } + void setAllowRender( bool render ) { mAllowRender = render; } inline bool allowRender() const { return mAllowRender; } diff --git a/Engine/source/gfx/gl/gfxGLStateBlock.cpp b/Engine/source/gfx/gl/gfxGLStateBlock.cpp index a1af2910c..34f816dc9 100644 --- a/Engine/source/gfx/gl/gfxGLStateBlock.cpp +++ b/Engine/source/gfx/gl/gfxGLStateBlock.cpp @@ -107,6 +107,14 @@ void GFXGLStateBlock::activate(const GFXGLStateBlock* oldState) if(STATE_CHANGE(blendOp)) glBlendEquation(GFXGLBlendOp[mDesc.blendOp]); + if (mDesc.separateAlphaBlendEnable == true) + { + if (STATE_CHANGE(separateAlphaBlendSrc) || STATE_CHANGE(separateAlphaBlendDest)) + glBlendFuncSeparate(GFXGLBlend[mDesc.blendSrc], GFXGLBlend[mDesc.blendDest], GFXGLBlend[mDesc.separateAlphaBlendSrc], GFXGLBlend[mDesc.separateAlphaBlendDest]); + if (STATE_CHANGE(separateAlphaBlendOp)) + glBlendEquationSeparate(GFXGLBlendOp[mDesc.blendOp], GFXGLBlendOp[mDesc.separateAlphaBlendOp]); + } + // Color write masks if(STATE_CHANGE(colorWriteRed) || STATE_CHANGE(colorWriteBlue) || STATE_CHANGE(colorWriteGreen) || STATE_CHANGE(colorWriteAlpha)) glColorMask(mDesc.colorWriteRed, mDesc.colorWriteBlue, mDesc.colorWriteGreen, mDesc.colorWriteAlpha); diff --git a/Engine/source/gfx/gl/gfxGLTextureTarget.cpp b/Engine/source/gfx/gl/gfxGLTextureTarget.cpp index ddb308adc..202265107 100644 --- a/Engine/source/gfx/gl/gfxGLTextureTarget.cpp +++ b/Engine/source/gfx/gl/gfxGLTextureTarget.cpp @@ -163,6 +163,10 @@ void _GFXGLTextureTargetFBOImpl::applyState() PRESERVE_FRAMEBUFFER(); glBindFramebuffer(GL_FRAMEBUFFER, mFramebuffer); + bool drawbufs[16]; + int bufsize = 0; + for (int i = 0; i < 16; i++) + drawbufs[i] = false; bool hasColor = false; for(int i = 0; i < GFXGL->getNumRenderTargets(); ++i) { @@ -200,6 +204,20 @@ void _GFXGLTextureTargetFBOImpl::applyState() glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, 0, 0); } + GLenum *buf = new GLenum[bufsize]; + int count = 0; + for (int i = 0; i < bufsize; i++) + { + if (drawbufs[i]) + { + buf[count] = GL_COLOR_ATTACHMENT0 + i; + count++; + } + } + + glDrawBuffers(bufsize, buf); + + delete[] buf; CHECK_FRAMEBUFFER_STATUS(); } diff --git a/Engine/source/gfx/gl/gfxGLWindowTarget.cpp b/Engine/source/gfx/gl/gfxGLWindowTarget.cpp index c00506835..5f8808cae 100644 --- a/Engine/source/gfx/gl/gfxGLWindowTarget.cpp +++ b/Engine/source/gfx/gl/gfxGLWindowTarget.cpp @@ -57,6 +57,7 @@ void GFXGLWindowTarget::resetMode() _teardownCurrentMode(); _setupNewMode(); } + GFX->beginReset(); } void GFXGLWindowTarget::_onAppSignal(WindowId wnd, S32 event) diff --git a/Engine/source/lighting/advanced/glsl/advancedLightingFeaturesGLSL.cpp b/Engine/source/lighting/advanced/glsl/advancedLightingFeaturesGLSL.cpp index ce90bcc39..c97fbbcf5 100644 --- a/Engine/source/lighting/advanced/glsl/advancedLightingFeaturesGLSL.cpp +++ b/Engine/source/lighting/advanced/glsl/advancedLightingFeaturesGLSL.cpp @@ -156,8 +156,8 @@ void DeferredRTLightingFeatGLSL::processPix( Vector &component oneOverTargetSize->constSortPos = cspPass; } - meta->addStatement( new GenOp( " float id_NL_Att, id_specular;\r\n float3 id_lightcolor;\r\n" ) ); - meta->addStatement( new GenOp( avar( " %s(tex2D(@, @ + float2(0.0, @.y)), id_lightcolor, id_NL_Att, id_specular);\r\n", + meta->addStatement( new GenOp( " float id_NL_Att, id_specular;\r\n vec3 id_lightcolor;\r\n" ) ); + meta->addStatement( new GenOp( avar( " %s(tex2D(@, @ + vec2(0.0, @.y)), id_lightcolor, id_NL_Att, id_specular);\r\n", unconditionLightInfo.c_str() ), lightInfoBuffer, uvScene, oneOverTargetSize ) ); meta->addStatement( new GenOp(" @ = lerp(@, id_lightcolor, 0.5);\r\n", d_lightcolor, d_lightcolor ) ); @@ -167,7 +167,7 @@ void DeferredRTLightingFeatGLSL::processPix( Vector &component // This is kind of weak sauce if( !fd.features[MFT_VertLit] && !fd.features[MFT_ToneMap] && !fd.features[MFT_LightMap] && !fd.features[MFT_SubSurface] ) - meta->addStatement( new GenOp( " @;\r\n", assignColor( new GenOp( "float4(@, 1.0)", d_lightcolor ), Material::Mul ) ) ); + meta->addStatement( new GenOp( " @;\r\n", assignColor( new GenOp( "vec4(@, 1.0)", d_lightcolor ), Material::Mul ) ) ); output = meta; } @@ -311,7 +311,7 @@ void DeferredBumpFeatGLSL::processPix( Vector &componentList, meta->addStatement( new GenOp( " @.xy += @.xy * @;\r\n", bumpNorm, detailBump, detailBumpScale ) ); } - // This var is read from GBufferConditionerHLSL and + // This var is read from GBufferConditionerGLSL and // used in the prepass output. // // By using the 'half' type here we get a bunch of partial @@ -533,11 +533,13 @@ void DeferredPixelSpecularGLSL::processPix( Vector &component specPow->constSortPos = cspPotentialPrimitive; } - Var *specStrength = new Var; - specStrength->setType( "float" ); - specStrength->setName( "specularStrength" ); - specStrength->uniform = true; - specStrength->constSortPos = cspPotentialPrimitive; + Var *specStrength = (Var*)LangElement::find( "specularStrength" ); + if (!specStrength) + { + specStrength = new Var( "specularStrength", "float" ); + specStrength->uniform = true; + specStrength->constSortPos = cspPotentialPrimitive; + } Var *lightInfoSamp = (Var *)LangElement::find( "lightInfoSample" ); Var *d_specular = (Var*)LangElement::find( "d_specular" ); @@ -555,10 +557,10 @@ void DeferredPixelSpecularGLSL::processPix( Vector &component meta->addStatement(new GenOp(" @ = clamp( lerp( @, @ * @, @.a), 0, 1);\r\n", d_specular, d_specular, accuSpecular, d_specular, accuPlc)); } // (a^m)^n = a^(m*n) - meta->addStatement( new GenOp( " @ = pow( abs(@), max((@ / AL_ConstantSpecularPower),1.0f)) * @;\r\n", + meta->addStatement( new GenOp( " @ = pow( abs(@), max((@ / AL_ConstantSpecularPower),1.0f)) * @;\r\n", specDecl, d_specular, specPow, specStrength ) ); - LangElement *specMul = new GenOp( "float4( @.rgb, 0 ) * @", specCol, specular ); + LangElement *specMul = new GenOp( "vec4( @.rgb, 0 ) * @", specCol, specular ); LangElement *final = specMul; // We we have a normal map then mask the specular @@ -682,10 +684,10 @@ void DeferredMinnaertGLSL::processPix( Vector &componentList, Var *d_NL_Att = (Var*)LangElement::find( "d_NL_Att" ); - meta->addStatement( new GenOp( avar( " float4 normalDepth = %s(@, @);\r\n", unconditionPrePassMethod.c_str() ), prepassBuffer, uvScene ) ); + meta->addStatement( new GenOp( avar( " vec4 normalDepth = %s(@, @);\r\n", unconditionPrePassMethod.c_str() ), prepassBuffer, uvScene ) ); meta->addStatement( new GenOp( " float vDotN = dot(normalDepth.xyz, @);\r\n", wsViewVec ) ); meta->addStatement( new GenOp( " float Minnaert = pow( @, @) * pow(vDotN, 1.0 - @);\r\n", d_NL_Att, minnaertConstant, minnaertConstant ) ); - meta->addStatement( new GenOp( " @;\r\n", assignColor( new GenOp( "float4(Minnaert, Minnaert, Minnaert, 1.0)" ), Material::Mul ) ) ); + meta->addStatement( new GenOp( " @;\r\n", assignColor( new GenOp( "vec4(Minnaert, Minnaert, Minnaert, 1.0)" ), Material::Mul ) ) ); output = meta; } @@ -713,7 +715,7 @@ void DeferredSubSurfaceGLSL::processPix( Vector &componentLis MultiLine *meta = new MultiLine; meta->addStatement( new GenOp( " float subLamb = smoothstep(-@.a, 1.0, @) - smoothstep(0.0, 1.0, @);\r\n", subSurfaceParams, d_NL_Att, d_NL_Att ) ); meta->addStatement( new GenOp( " subLamb = max(0.0, subLamb);\r\n" ) ); - meta->addStatement( new GenOp( " @;\r\n", assignColor( new GenOp( "float4(@ + (subLamb * @.rgb), 1.0)", d_lightcolor, subSurfaceParams ), Material::Mul ) ) ); + meta->addStatement( new GenOp( " @;\r\n", assignColor( new GenOp( "vec4(@ + (subLamb * @.rgb), 1.0)", d_lightcolor, subSurfaceParams ), Material::Mul ) ) ); output = meta; } diff --git a/Engine/source/lighting/advanced/glsl/deferredShadingFeaturesGLSL.cpp b/Engine/source/lighting/advanced/glsl/deferredShadingFeaturesGLSL.cpp new file mode 100644 index 000000000..e457b9eab --- /dev/null +++ b/Engine/source/lighting/advanced/glsl/deferredShadingFeaturesGLSL.cpp @@ -0,0 +1,190 @@ +//----------------------------------------------------------------------------- +// 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 "platform/platform.h" +#include "lighting/advanced/glsl/deferredShadingFeaturesGLSL.h" + +#include "lighting/advanced/advancedLightBinManager.h" +#include "shaderGen/langElement.h" +#include "shaderGen/shaderOp.h" +#include "shaderGen/conditionerFeature.h" +#include "renderInstance/renderPrePassMgr.h" +#include "materials/processedMaterial.h" +#include "materials/materialFeatureTypes.h" + + +//**************************************************************************** +// Deferred Shading Features +//**************************************************************************** + +// Specular Map -> Blue of Material Buffer ( greyscaled ) +// Gloss Map (Alpha Channel of Specular Map) -> Alpha ( Spec Power ) of Material Info Buffer. +void DeferredSpecMapGLSL::processPix( Vector &componentList, const MaterialFeatureData &fd ) +{ + // Get the texture coord. + Var *texCoord = getInTexCoord( "texCoord", "vec2", true, componentList ); + + // search for color var + Var *material = (Var*) LangElement::find( getOutputTargetVarName(ShaderFeature::RenderTarget2) ); + MultiLine * meta = new MultiLine; + if ( !material ) + { + // create color var + material = new Var; + material->setType( "vec4" ); + material->setName( getOutputTargetVarName(ShaderFeature::RenderTarget2) ); + material->setStructName("OUT"); + } + + // create texture var + Var *specularMap = new Var; + specularMap->setType( "sampler2D" ); + specularMap->setName( "specularMap" ); + specularMap->uniform = true; + specularMap->sampler = true; + specularMap->constNum = Var::getTexUnitNum(); + LangElement *texOp = new GenOp( "tex2D(@, @)", specularMap, texCoord ); + //matinfo.g slot reserved for AO later + meta->addStatement(new GenOp(" @.g = 1.0;\r\n", material)); + meta->addStatement(new GenOp(" @.b = dot(tex2D(@, @).rgb, vec3(0.3, 0.59, 0.11));\r\n", material, specularMap, texCoord)); + meta->addStatement(new GenOp(" @.a = tex2D(@, @).a;\r\n", material, specularMap, texCoord)); + output = meta; +} + +ShaderFeature::Resources DeferredSpecMapGLSL::getResources( const MaterialFeatureData &fd ) +{ + Resources res; + res.numTex = 1; + res.numTexReg = 1; + + return res; +} + +void DeferredSpecMapGLSL::setTexData( Material::StageData &stageDat, + const MaterialFeatureData &fd, + RenderPassData &passData, + U32 &texIndex ) +{ + GFXTextureObject *tex = stageDat.getTex( MFT_SpecularMap ); + if ( tex ) + { + passData.mTexType[ texIndex ] = Material::Standard; + passData.mSamplerNames[ texIndex ] = "specularMap"; + passData.mTexSlot[ texIndex++ ].texObject = tex; + } +} + +void DeferredSpecMapGLSL::processVert( Vector &componentList, + const MaterialFeatureData &fd ) +{ + MultiLine *meta = new MultiLine; + getOutTexCoord( "texCoord", + "vec2", + true, + fd.features[MFT_TexAnim], + meta, + componentList ); + output = meta; +} + +// Material Info Flags -> Red ( Flags ) of Material Info Buffer. +void DeferredMatInfoFlagsGLSL::processPix( Vector &componentList, const MaterialFeatureData &fd ) +{ + MultiLine *meta = new MultiLine; + + // search for material var + Var *material = (Var*) LangElement::find( getOutputTargetVarName(ShaderFeature::RenderTarget2) ); + if ( !material ) + { + // create material var + material = new Var; + material->setType( "vec4" ); + material->setName( getOutputTargetVarName(ShaderFeature::RenderTarget2) ); + material->setStructName("OUT"); + } + + Var *matInfoFlags = new Var; + matInfoFlags->setType( "float" ); + matInfoFlags->setName( "matInfoFlags" ); + matInfoFlags->uniform = true; + matInfoFlags->constSortPos = cspPotentialPrimitive; + + meta->addStatement(output = new GenOp(" @.r = @;\r\n", material, matInfoFlags)); + output = meta; +} + +// Spec Strength -> Blue Channel of Material Info Buffer. +// Spec Power -> Alpha Channel ( of Material Info Buffer. +void DeferredSpecVarsGLSL::processPix( Vector &componentList, const MaterialFeatureData &fd ) +{ + + // search for material var + Var *material = (Var*) LangElement::find( getOutputTargetVarName(ShaderFeature::RenderTarget2) ); + if ( !material ) + { + // create material var + material = new Var; + material->setType( "vec4" ); + material->setName( getOutputTargetVarName(ShaderFeature::RenderTarget2) ); + material->setStructName("OUT"); + } + + Var *specStrength = new Var; + specStrength->setType( "float" ); + specStrength->setName( "specularStrength" ); + specStrength->uniform = true; + specStrength->constSortPos = cspPotentialPrimitive; + + Var *specPower = new Var; + specPower->setType("float"); + specPower->setName("specularPower"); + specPower->uniform = true; + specPower->constSortPos = cspPotentialPrimitive; + + MultiLine *meta = new MultiLine; + //matinfo.g slot reserved for AO later + meta->addStatement(new GenOp(" @.g = 1.0;\r\n", material)); + meta->addStatement(new GenOp(" @.b = @/128;\r\n", material, specStrength)); + meta->addStatement(new GenOp(" @.a = @/5;\r\n", material, specPower)); + output = meta; +} + +// Black -> Blue and Alpha of Color Buffer (representing no specular) +void DeferredEmptySpecGLSL::processPix( Vector &componentList, const MaterialFeatureData &fd ) +{ + // search for material var + Var *material = (Var*) LangElement::find( getOutputTargetVarName(ShaderFeature::RenderTarget2) ); + if ( !material ) + { + // create material var + material = new Var; + material->setType( "vec4" ); + material->setName( getOutputTargetVarName(ShaderFeature::RenderTarget2) ); + material->setStructName("OUT"); + } + + MultiLine * meta = new MultiLine; + //matinfo.g slot reserved for AO later + meta->addStatement(new GenOp(" @.g = 1.0;\r\n", material)); + meta->addStatement(new GenOp(" @.ba = vec2(0.0);\r\n", material)); + output = meta; +} diff --git a/Engine/source/lighting/advanced/glsl/deferredShadingFeaturesGLSL.h b/Engine/source/lighting/advanced/glsl/deferredShadingFeaturesGLSL.h new file mode 100644 index 000000000..f687bd917 --- /dev/null +++ b/Engine/source/lighting/advanced/glsl/deferredShadingFeaturesGLSL.h @@ -0,0 +1,85 @@ +//----------------------------------------------------------------------------- +// 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. +//----------------------------------------------------------------------------- + +#ifndef _DEFERREDSHADINGGLSL_H_ +#define _DEFERREDSHADINGGLSL_H_ + +#include "shaderGen/GLSL/shaderFeatureGLSL.h" +#include "shaderGen/GLSL/bumpGLSL.h" +#include "shaderGen/GLSL/pixSpecularGLSL.h" + +// Specular Outputs +class DeferredSpecMapGLSL : public ShaderFeatureGLSL +{ +public: + virtual String getName() { return "Deferred Shading: Specular Map"; } + + virtual void processPix( Vector &componentList, + const MaterialFeatureData &fd ); + + virtual Resources getResources( const MaterialFeatureData &fd ); + + // Sets textures and texture flags for current pass + virtual void setTexData( Material::StageData &stageDat, + const MaterialFeatureData &fd, + RenderPassData &passData, + U32 &texIndex ); + + virtual void processVert( Vector &componentList, + const MaterialFeatureData &fd ); +}; + +class DeferredMatInfoFlagsGLSL : public ShaderFeatureGLSL +{ +public: + virtual String getName() { return "Deferred Shading: Mat Info Flags"; } + + virtual void processPix( Vector &componentList, + const MaterialFeatureData &fd ); + + virtual U32 getOutputTargets( const MaterialFeatureData &fd ) const { return ShaderFeature::RenderTarget2; } +}; + +class DeferredSpecVarsGLSL : public ShaderFeatureGLSL +{ +public: + virtual String getName() { return "Deferred Shading: Specular Explicit Numbers"; } + + virtual void processPix( Vector &componentList, + const MaterialFeatureData &fd ); + + virtual U32 getOutputTargets( const MaterialFeatureData &fd ) const { return ShaderFeature::RenderTarget2; } +}; + + +class DeferredEmptySpecGLSL : public ShaderFeatureGLSL +{ +public: + virtual String getName() { return "Deferred Shading: Empty Specular"; } + + virtual void processPix( Vector &componentList, + const MaterialFeatureData &fd ); + + virtual U32 getOutputTargets( const MaterialFeatureData &fd ) const { return ShaderFeature::RenderTarget2; } +}; + +#endif \ No newline at end of file diff --git a/Engine/source/lighting/advanced/glsl/gBufferConditionerGLSL.cpp b/Engine/source/lighting/advanced/glsl/gBufferConditionerGLSL.cpp index 6e5795e83..d2d383148 100644 --- a/Engine/source/lighting/advanced/glsl/gBufferConditionerGLSL.cpp +++ b/Engine/source/lighting/advanced/glsl/gBufferConditionerGLSL.cpp @@ -170,7 +170,7 @@ void GBufferConditionerGLSL::processPix( Vector &componentLis if ( fd.features[ MFT_IsTranslucentZWrite ] ) { alphaVal = new Var( "outAlpha", "float" ); - meta->addStatement( new GenOp( " @ = col.a; // MFT_IsTranslucentZWrite\r\n", new DecOp( alphaVal ) ) ); + meta->addStatement( new GenOp( " @ = OUT_col1.a; // MFT_IsTranslucentZWrite\r\n", new DecOp( alphaVal ) ) ); } // If using interlaced normals, invert the normal @@ -397,7 +397,7 @@ Var* GBufferConditionerGLSL::_unconditionInput( Var *conditionedInput, MultiLine // Recover depth from encoding if(mNormalStorageType != CartesianXYZ) { - const U64 maxValPerChannel = 1 << mBitsPerChannel; + const U64 maxValPerChannel = (U64)1 << mBitsPerChannel; meta->addStatement( new GenOp( " \r\n // Decode depth\r\n" ) ); meta->addStatement( new GenOp( avar( " @.w = dot( @.zw, float2(1.0, 1.0/%llu.0));\r\n", maxValPerChannel - 1 ), retVar, conditionedInput ) ); diff --git a/Engine/source/lighting/advanced/hlsl/advancedLightingFeaturesHLSL.cpp b/Engine/source/lighting/advanced/hlsl/advancedLightingFeaturesHLSL.cpp index deda7cbae..0bfbed42a 100644 --- a/Engine/source/lighting/advanced/hlsl/advancedLightingFeaturesHLSL.cpp +++ b/Engine/source/lighting/advanced/hlsl/advancedLightingFeaturesHLSL.cpp @@ -227,7 +227,7 @@ void DeferredBumpFeatHLSL::processVert( Vector &componentLis const bool useTexAnim = fd.features[MFT_TexAnim]; // Make sure there are texcoords - if( !fd.features[MFT_Parallax] && !fd.features[MFT_DiffuseMap] ) + if( !fd.features[MFT_Parallax] && !fd.features[MFT_DiffuseMap]) { getOutTexCoord( "texCoord", @@ -532,11 +532,13 @@ void DeferredPixelSpecularHLSL::processPix( Vector &component specPow->constSortPos = cspPotentialPrimitive; } - Var *specStrength = new Var; - specStrength->setType( "float" ); - specStrength->setName( "specularStrength" ); - specStrength->uniform = true; - specStrength->constSortPos = cspPotentialPrimitive; + Var *specStrength = (Var*)LangElement::find( "specularStrength" ); + if (!specStrength) + { + specStrength = new Var( "specularStrength", "float" ); + specStrength->uniform = true; + specStrength->constSortPos = cspPotentialPrimitive; + } Var *lightInfoSamp = (Var *)LangElement::find( "lightInfoSample" ); Var *d_specular = (Var*)LangElement::find( "d_specular" ); @@ -556,7 +558,7 @@ void DeferredPixelSpecularHLSL::processPix( Vector &component // (a^m)^n = a^(m*n) meta->addStatement( new GenOp( " @ = pow( abs(@), max((@ / AL_ConstantSpecularPower),1.0f)) * @;\r\n", - specDecl, d_specular, specPow, specStrength ) ); + specDecl, d_specular, specPow, specStrength)); LangElement *specMul = new GenOp( "float4( @.rgb, 0 ) * @", specCol, specular ); LangElement *final = specMul; diff --git a/Engine/source/lighting/advanced/hlsl/deferredShadingFeaturesHLSL.cpp b/Engine/source/lighting/advanced/hlsl/deferredShadingFeaturesHLSL.cpp new file mode 100644 index 000000000..6b8b990a0 --- /dev/null +++ b/Engine/source/lighting/advanced/hlsl/deferredShadingFeaturesHLSL.cpp @@ -0,0 +1,187 @@ +//----------------------------------------------------------------------------- +// 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 "platform/platform.h" +#include "lighting/advanced/hlsl/deferredShadingFeaturesHLSL.h" + +#include "lighting/advanced/advancedLightBinManager.h" +#include "shaderGen/langElement.h" +#include "shaderGen/shaderOp.h" +#include "shaderGen/conditionerFeature.h" +#include "renderInstance/renderPrePassMgr.h" +#include "materials/processedMaterial.h" +#include "materials/materialFeatureTypes.h" + + +//**************************************************************************** +// Deferred Shading Features +//**************************************************************************** + +// Specular Map -> Blue of Material Buffer ( greyscaled ) +// Gloss Map (Alpha Channel of Specular Map) -> Alpha ( Spec Power ) of Material Info Buffer. +void DeferredSpecMapHLSL::processPix( Vector &componentList, const MaterialFeatureData &fd ) +{ + // Get the texture coord. + Var *texCoord = getInTexCoord( "texCoord", "float2", true, componentList ); + + // search for color var + Var *material = (Var*) LangElement::find( getOutputTargetVarName(ShaderFeature::RenderTarget2) ); + MultiLine * meta = new MultiLine; + if ( !material ) + { + // create color var + material = new Var; + material->setType( "fragout" ); + material->setName( getOutputTargetVarName(ShaderFeature::RenderTarget2) ); + material->setStructName( "OUT" ); + } + + // create texture var + Var *specularMap = new Var; + specularMap->setType( "sampler2D" ); + specularMap->setName( "specularMap" ); + specularMap->uniform = true; + specularMap->sampler = true; + specularMap->constNum = Var::getTexUnitNum(); + LangElement *texOp = new GenOp( "tex2D(@, @)", specularMap, texCoord ); + + //matinfo.g slot reserved for AO later + meta->addStatement(new GenOp(" @.g = 1.0;\r\n", material)); + meta->addStatement(new GenOp(" @.b = dot(tex2D(@, @).rgb, float3(0.3, 0.59, 0.11));\r\n", material, specularMap, texCoord)); + meta->addStatement(new GenOp(" @.a = tex2D(@, @).a;\r\n", material, specularMap, texCoord)); + output = meta; +} + +ShaderFeature::Resources DeferredSpecMapHLSL::getResources( const MaterialFeatureData &fd ) +{ + Resources res; + res.numTex = 1; + res.numTexReg = 1; + + return res; +} + +void DeferredSpecMapHLSL::setTexData( Material::StageData &stageDat, + const MaterialFeatureData &fd, + RenderPassData &passData, + U32 &texIndex ) +{ + GFXTextureObject *tex = stageDat.getTex( MFT_SpecularMap ); + if ( tex ) + { + passData.mTexType[ texIndex ] = Material::Standard; + passData.mSamplerNames[ texIndex ] = "specularMap"; + passData.mTexSlot[ texIndex++ ].texObject = tex; + } +} + +void DeferredSpecMapHLSL::processVert( Vector &componentList, + const MaterialFeatureData &fd ) +{ + MultiLine *meta = new MultiLine; + getOutTexCoord( "texCoord", + "float2", + true, + fd.features[MFT_TexAnim], + meta, + componentList ); + output = meta; +} + +// Material Info Flags -> Red ( Flags ) of Material Info Buffer. +void DeferredMatInfoFlagsHLSL::processPix( Vector &componentList, const MaterialFeatureData &fd ) +{ + // search for material var + Var *material = (Var*) LangElement::find( getOutputTargetVarName(ShaderFeature::RenderTarget2) ); + if ( !material ) + { + // create material var + material = new Var; + material->setType( "fragout" ); + material->setName( getOutputTargetVarName(ShaderFeature::RenderTarget2) ); + material->setStructName( "OUT" ); + } + + Var *matInfoFlags = new Var; + matInfoFlags->setType( "float" ); + matInfoFlags->setName( "matInfoFlags" ); + matInfoFlags->uniform = true; + matInfoFlags->constSortPos = cspPotentialPrimitive; + + output = new GenOp( " @.r = @;\r\n", material, matInfoFlags ); +} + +// Spec Strength -> Blue Channel of Material Info Buffer. +// Spec Power -> Alpha Channel ( of Material Info Buffer. +void DeferredSpecVarsHLSL::processPix( Vector &componentList, const MaterialFeatureData &fd ) +{ + // search for material var + Var *material = (Var*) LangElement::find( getOutputTargetVarName(ShaderFeature::RenderTarget2) ); + if ( !material ) + { + // create material var + material = new Var; + material->setType( "fragout" ); + material->setName( getOutputTargetVarName(ShaderFeature::RenderTarget2) ); + material->setStructName( "OUT" ); + } + + Var *specStrength = new Var; + specStrength->setType( "float" ); + specStrength->setName( "specularStrength" ); + specStrength->uniform = true; + specStrength->constSortPos = cspPotentialPrimitive; + + Var *specPower = new Var; + specPower->setType( "float" ); + specPower->setName( "specularPower" ); + specPower->uniform = true; + specPower->constSortPos = cspPotentialPrimitive; + + MultiLine * meta = new MultiLine; + //matinfo.g slot reserved for AO later + meta->addStatement(new GenOp(" @.g = 1.0;\r\n", material)); + meta->addStatement(new GenOp(" @.b = @/128;\r\n", material, specStrength)); + meta->addStatement(new GenOp(" @.a = @/5;\r\n", material, specPower)); + output = meta; +} + +// Black -> Blue and Alpha of matinfo Buffer (representing no specular), White->G (representing No AO) +void DeferredEmptySpecHLSL::processPix( Vector &componentList, const MaterialFeatureData &fd ) +{ + // search for material var + Var *material = (Var*)LangElement::find(getOutputTargetVarName(ShaderFeature::RenderTarget2)); + if (!material) + { + // create color var + material = new Var; + material->setType("fragout"); + material->setName(getOutputTargetVarName(ShaderFeature::RenderTarget2)); + material->setStructName("OUT"); + } + + MultiLine * meta = new MultiLine; + //matinfo.g slot reserved for AO later + meta->addStatement(new GenOp(" @.g = 1.0;\r\n", material)); + meta->addStatement(new GenOp(" @.ba = 0.0;\r\n", material)); + output = meta; +} diff --git a/Engine/source/lighting/advanced/hlsl/deferredShadingFeaturesHLSL.h b/Engine/source/lighting/advanced/hlsl/deferredShadingFeaturesHLSL.h new file mode 100644 index 000000000..9f43321b7 --- /dev/null +++ b/Engine/source/lighting/advanced/hlsl/deferredShadingFeaturesHLSL.h @@ -0,0 +1,84 @@ +//----------------------------------------------------------------------------- +// 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. +//----------------------------------------------------------------------------- + +#ifndef _DEFERREDSHADINGHLSL_H_ +#define _DEFERREDSHADINGHLSL_H_ + +#include "shaderGen/HLSL/shaderFeatureHLSL.h" +#include "shaderGen/HLSL/bumpHLSL.h" +#include "shaderGen/HLSL/pixSpecularHLSL.h" + +// Specular Outputs +class DeferredSpecMapHLSL : public ShaderFeatureHLSL +{ +public: + virtual String getName() { return "Deferred Shading: Specular Map"; } + + virtual void processPix( Vector &componentList, + const MaterialFeatureData &fd ); + + virtual Resources getResources( const MaterialFeatureData &fd ); + + // Sets textures and texture flags for current pass + virtual void setTexData( Material::StageData &stageDat, + const MaterialFeatureData &fd, + RenderPassData &passData, + U32 &texIndex ); + + virtual void processVert( Vector &componentList, + const MaterialFeatureData &fd ); +}; + +class DeferredMatInfoFlagsHLSL : public ShaderFeatureHLSL +{ +public: + virtual String getName() { return "Deferred Shading: Mat Info Flags"; } + + virtual void processPix( Vector &componentList, + const MaterialFeatureData &fd ); + + virtual U32 getOutputTargets( const MaterialFeatureData &fd ) const { return ShaderFeature::RenderTarget2; } +}; + +class DeferredSpecVarsHLSL : public ShaderFeatureHLSL +{ +public: + virtual String getName() { return "Deferred Shading: Specular Explicit Numbers"; } + + virtual void processPix( Vector &componentList, + const MaterialFeatureData &fd ); + + virtual U32 getOutputTargets( const MaterialFeatureData &fd ) const { return ShaderFeature::RenderTarget2; } +}; + +class DeferredEmptySpecHLSL : public ShaderFeatureHLSL +{ +public: + virtual String getName() { return "Deferred Shading: Empty Specular"; } + + virtual void processPix( Vector &componentList, + const MaterialFeatureData &fd ); + + virtual U32 getOutputTargets( const MaterialFeatureData &fd ) const { return ShaderFeature::RenderTarget2; } +}; + +#endif \ No newline at end of file diff --git a/Engine/source/lighting/advanced/hlsl/gBufferConditionerHLSL.cpp b/Engine/source/lighting/advanced/hlsl/gBufferConditionerHLSL.cpp index 93f9477e9..6f99d035c 100644 --- a/Engine/source/lighting/advanced/hlsl/gBufferConditionerHLSL.cpp +++ b/Engine/source/lighting/advanced/hlsl/gBufferConditionerHLSL.cpp @@ -170,7 +170,7 @@ void GBufferConditionerHLSL::processPix( Vector &componentLis if ( fd.features[ MFT_IsTranslucentZWrite ] ) { alphaVal = new Var( "outAlpha", "float" ); - meta->addStatement( new GenOp( " @ = OUT.col.a; // MFT_IsTranslucentZWrite\r\n", new DecOp( alphaVal ) ) ); + meta->addStatement( new GenOp( " @ = OUT.col1.a; // MFT_IsTranslucentZWrite\r\n", new DecOp( alphaVal ) ) ); } // If using interlaced normals, invert the normal diff --git a/Engine/source/materials/matTextureTarget.cpp b/Engine/source/materials/matTextureTarget.cpp index ba84142f6..f6770c83b 100644 --- a/Engine/source/materials/matTextureTarget.cpp +++ b/Engine/source/materials/matTextureTarget.cpp @@ -47,9 +47,16 @@ bool NamedTexTarget::registerWithName( const String &name ) } // Make sure the target name isn't empty or already taken. - if ( name.isEmpty() || smTargets.contains( name ) ) + if ( name.isEmpty()) + { + Con::errorf("NamedTexTarget::registerWithName( const String &name ) No name given!"); + return false; + } + if (smTargets.contains( name ) ) + { + Con::errorf("NamedTexTarget::registerWithName( %s ) Already used!", name.c_str()); return false; - + } mName = name; mIsRegistered = true; smTargets.insert( mName, this ); diff --git a/Engine/source/materials/materialDefinition.cpp b/Engine/source/materials/materialDefinition.cpp index 408df976f..883d4b7ab 100644 --- a/Engine/source/materials/materialDefinition.cpp +++ b/Engine/source/materials/materialDefinition.cpp @@ -162,6 +162,9 @@ Material::Material() mSeqFramePerSec[i] = 0.0f; mSeqSegSize[i] = 0.0f; + + // Deferred Shading + mMatInfoFlags[i] = 0.0f; } dMemset(mCellIndex, 0, sizeof(mCellIndex)); @@ -170,6 +173,9 @@ Material::Material() dMemset(mNormalMapAtlas, 0, sizeof(mNormalMapAtlas)); dMemset(mUseAnisotropic, 0, sizeof(mUseAnisotropic)); + // Deferred Shading : Metalness + dMemset(mUseMetalness, 0, sizeof(mUseMetalness)); + mImposterLimits = Point4F::Zero; mDoubleSided = false; @@ -204,6 +210,9 @@ Material::Material() mDirectSoundOcclusion = 1.f; mReverbSoundOcclusion = 1.0; + + // Deferred Shading + mIsSky = false; } void Material::initPersistFields() @@ -289,10 +298,7 @@ void Material::initPersistFields() addField( "useAnisotropic", TypeBool, Offset(mUseAnisotropic, Material), MAX_STAGES, "Use anisotropic filtering for the textures of this stage." ); - - addField("envMap", TypeImageFilename, Offset(mEnvMapFilename, Material), MAX_STAGES, - "The name of an environment map cube map to apply to this material." ); - + addField("vertLit", TypeBool, Offset(mVertLit, Material), MAX_STAGES, "If true the vertex color is used for lighting." ); @@ -379,9 +385,6 @@ void Material::initPersistFields() addProtectedField("bumpTex", TypeImageFilename, Offset(mNormalMapFilename, Material), defaultProtectedSetNotEmptyFn, emptyStringProtectedGetFn, MAX_STAGES, "For backwards compatibility.\n@see normalMap\n"); - addProtectedField("envTex", TypeImageFilename, Offset(mEnvMapFilename, Material), - defaultProtectedSetNotEmptyFn, emptyStringProtectedGetFn, MAX_STAGES, - "For backwards compatibility.\n@see envMap\n"); addProtectedField("colorMultiply", TypeColorF, Offset(mDiffuse, Material), defaultProtectedSetNotEmptyFn, emptyStringProtectedGetFn, MAX_STAGES, "For backwards compatibility.\n@see diffuseColor\n"); @@ -417,6 +420,9 @@ void Material::initPersistFields() addField("dynamicCubemap", TypeBool, Offset(mDynamicCubemap, Material), "Enables the material to use the dynamic cubemap from the ShapeBase object its applied to." ); + addField("isSky", TypeBool, Offset(mIsSky, Material), + "Sky support. Alters draw dimensions." ); + addGroup( "Behavioral" ); addField( "showFootprints", TypeBool, Offset( mShowFootprints, Material ), diff --git a/Engine/source/materials/materialDefinition.h b/Engine/source/materials/materialDefinition.h index 491b56cf0..d676c8f02 100644 --- a/Engine/source/materials/materialDefinition.h +++ b/Engine/source/materials/materialDefinition.h @@ -221,8 +221,6 @@ public: /// The strength scalar for the detail normal map. F32 mDetailNormalMapStrength[MAX_STAGES]; - FileName mEnvMapFilename[MAX_STAGES]; - /// This color is the diffuse color of the material /// or if it has a texture it is multiplied against /// the diffuse texture color. @@ -287,12 +285,18 @@ public: /// If the stage should use anisotropic filtering. bool mUseAnisotropic[MAX_STAGES]; + // Deferred Shading: Metalness + bool mUseMetalness[MAX_STAGES]; + bool mDoubleSided; String mCubemapName; CubemapData* mCubemapData; bool mDynamicCubemap; + // Deferred Shading + bool mIsSky; + F32 mMatInfoFlags[MAX_STAGES]; bool mTranslucent; BlendOp mTranslucentBlendOp; bool mTranslucentZWrite; diff --git a/Engine/source/materials/materialFeatureTypes.cpp b/Engine/source/materials/materialFeatureTypes.cpp index 9cdc57415..8ea7fbe8c 100644 --- a/Engine/source/materials/materialFeatureTypes.cpp +++ b/Engine/source/materials/materialFeatureTypes.cpp @@ -56,10 +56,9 @@ ImplementFeatureType( MFT_LightMap, MFG_Lighting, 4.0f, true ); ImplementFeatureType( MFT_ToneMap, MFG_Lighting, 5.0f, true ); ImplementFeatureType( MFT_VertLitTone, MFG_Lighting, 6.0f, false ); ImplementFeatureType( MFT_VertLit, MFG_Lighting, 7.0f, true ); -ImplementFeatureType( MFT_EnvMap, MFG_Lighting, 8.0f, true ); -ImplementFeatureType( MFT_CubeMap, MFG_Lighting, 9.0f, true ); -ImplementFeatureType( MFT_PixSpecular, MFG_Lighting, 10.0f, true ); -ImplementFeatureType( MFT_MinnaertShading, MFG_Lighting, 12.0f, true ); +ImplementFeatureType( MFT_PixSpecular, MFG_Lighting, 9.0f, true ); +ImplementFeatureType( MFT_MinnaertShading, MFG_Lighting, 10.0f, true ); +ImplementFeatureType( MFT_CubeMap, MFG_Lighting, 11.0f, true ); ImplementFeatureType( MFT_GlowMask, MFG_PostLighting, 1.0f, true ); ImplementFeatureType( MFT_Visibility, MFG_PostLighting, 2.0f, true ); @@ -85,6 +84,8 @@ ImplementFeatureType( MFT_NormalsOut, MFG_PreLighting, 1.0f, false ); ImplementFeatureType( MFT_LightbufferMRT, MFG_PreLighting, 1.0f, false ); ImplementFeatureType( MFT_RenderTarget1_Zero, MFG_PreTexture, 1.0f, false ); +ImplementFeatureType( MFT_RenderTarget2_Zero, MFG_PreTexture, 1.0f, false ); +ImplementFeatureType( MFT_RenderTarget3_Zero, MFG_PreTexture, 1.0f, false ); ImplementFeatureType( MFT_Foliage, MFG_PreTransform, 1.0f, false ); @@ -92,4 +93,13 @@ ImplementFeatureType( MFT_ParticleNormal, MFG_PreTransform, 2.0f, false ); ImplementFeatureType( MFT_ForwardShading, U32(-1), -1, true ); -ImplementFeatureType( MFT_ImposterVert, MFG_PreTransform, 1.0, false ); \ No newline at end of file +ImplementFeatureType( MFT_ImposterVert, MFG_PreTransform, 1.0, false ); + +// Deferred Shading +ImplementFeatureType( MFT_isDeferred, U32(-1), -1, true ); +ImplementFeatureType( MFT_SkyBox, MFG_Transform, 1.0f, true ); +ImplementFeatureType( MFT_DeferredEmptySpec, MFG_Texture, 8.01f, 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 ); diff --git a/Engine/source/materials/materialFeatureTypes.h b/Engine/source/materials/materialFeatureTypes.h index c302045c2..a002cd190 100644 --- a/Engine/source/materials/materialFeatureTypes.h +++ b/Engine/source/materials/materialFeatureTypes.h @@ -121,7 +121,6 @@ DeclareFeatureType( MFT_ToneMap ); DeclareFeatureType( MFT_VertLit ); DeclareFeatureType( MFT_VertLitTone ); -DeclareFeatureType( MFT_EnvMap ); DeclareFeatureType( MFT_CubeMap ); DeclareFeatureType( MFT_PixSpecular ); DeclareFeatureType( MFT_SpecularMap ); @@ -158,8 +157,10 @@ DeclareFeatureType( MFT_InterlacedPrePass ); /// to the second render-target DeclareFeatureType( MFT_LightbufferMRT ); -/// This feature outputs black to RenderTarget1 +/// This feature outputs black to RenderTarget3 DeclareFeatureType( MFT_RenderTarget1_Zero ); +DeclareFeatureType( MFT_RenderTarget2_Zero ); +DeclareFeatureType( MFT_RenderTarget3_Zero ); DeclareFeatureType( MFT_Foliage ); @@ -179,4 +180,11 @@ DeclareFeatureType( MFT_ForwardShading ); DeclareFeatureType( MFT_ImposterVert ); +// Deferred Shading +DeclareFeatureType( MFT_isDeferred ); +DeclareFeatureType( MFT_SkyBox ); +DeclareFeatureType( MFT_DeferredSpecMap ); +DeclareFeatureType( MFT_DeferredSpecVars ); +DeclareFeatureType( MFT_DeferredMatInfoFlags ); +DeclareFeatureType( MFT_DeferredEmptySpec ); #endif // _MATERIALFEATURETYPES_H_ diff --git a/Engine/source/materials/processedMaterial.cpp b/Engine/source/materials/processedMaterial.cpp index 10181179e..00a3b8ec2 100644 --- a/Engine/source/materials/processedMaterial.cpp +++ b/Engine/source/materials/processedMaterial.cpp @@ -455,14 +455,6 @@ void ProcessedMaterial::_setStageData() if(!mStages[i].getTex( MFT_SpecularMap )) mMaterial->logError("Failed to load specular map %s for stage %i", _getTexturePath(mMaterial->mSpecularMapFilename[i]).c_str(), i); } - - // EnironmentMap - if( mMaterial->mEnvMapFilename[i].isNotEmpty() ) - { - mStages[i].setTex( MFT_EnvMap, _createTexture( mMaterial->mEnvMapFilename[i], &GFXDefaultStaticDiffuseProfile ) ); - if(!mStages[i].getTex( MFT_EnvMap )) - mMaterial->logError("Failed to load environment map %s for stage %i", _getTexturePath(mMaterial->mEnvMapFilename[i]).c_str(), i); - } } mMaterial->mCubemapData = dynamic_cast(Sim::findObject( mMaterial->mCubemapName )); diff --git a/Engine/source/materials/processedShaderMaterial.cpp b/Engine/source/materials/processedShaderMaterial.cpp index 431e3bce6..37f745253 100644 --- a/Engine/source/materials/processedShaderMaterial.cpp +++ b/Engine/source/materials/processedShaderMaterial.cpp @@ -106,6 +106,9 @@ void ShaderConstHandles::init( GFXShader *shader, CustomMaterial* mat /*=NULL*/ for (S32 i = 0; i < Material::MAX_TEX_PER_PASS; ++i) mTexHandlesSC[i] = shader->getShaderConstHandle(mat->mSamplerNames[i]); } + + // Deferred Shading + mMatInfoFlagsSC = shader->getShaderConstHandle(ShaderGenVars::matInfoFlags); } /// @@ -208,28 +211,6 @@ bool ProcessedShaderMaterial::init( const FeatureSet &features, mInstancingState = new InstancingState(); mInstancingState->setFormat( &_getRPD( 0 )->shader->mInstancingFormat, mVertexFormat ); } - - // Check for a RenderTexTargetBin assignment - // *IMPORTANT NOTE* - // This is a temporary solution for getting diffuse mapping working with tex targets for standard materials - // It should be removed once this is done properly, at that time the sAllowTextureTargetAssignment should also be removed - // from Material (it is necessary for catching shadow maps/post effect this shouldn't be applied to) - if (Material::sAllowTextureTargetAssignment) - if (mMaterial && mMaterial->mDiffuseMapFilename[0].isNotEmpty() && mMaterial->mDiffuseMapFilename[0].substr( 0, 1 ).equal("#")) - { - String texTargetBufferName = mMaterial->mDiffuseMapFilename[0].substr(1, mMaterial->mDiffuseMapFilename[0].length() - 1); - NamedTexTarget *texTarget = NamedTexTarget::find( texTargetBufferName ); - - RenderPassData* rpd = getPass(0); - - if (rpd) - { - rpd->mTexSlot[0].texTarget = texTarget; - rpd->mTexType[0] = Material::TexTarget; - rpd->mSamplerNames[0] = "diffuseMap"; - } - } - return true; } @@ -353,11 +334,18 @@ void ProcessedShaderMaterial::_determineFeatures( U32 stageNum, fd.features.addFeature( MFT_VertLit ); // cubemaps only available on stage 0 for now - bramage - if ( stageNum < 1 && + if ( stageNum < 1 && mMaterial->isTranslucent() && ( ( mMaterial->mCubemapData && mMaterial->mCubemapData->mCubemap ) || mMaterial->mDynamicCubemap ) ) - fd.features.addFeature( MFT_CubeMap ); + { + fd.features.addFeature( MFT_CubeMap ); + } + if (mMaterial->mIsSky) + { + fd.features.addFeature(MFT_CubeMap); + fd.features.addFeature(MFT_SkyBox); + } fd.features.addFeature( MFT_Visibility ); if ( lastStage && @@ -428,7 +416,6 @@ void ProcessedShaderMaterial::_determineFeatures( U32 stageNum, if ( mMaterial->mAccuEnabled[stageNum] ) { - fd.features.addFeature( MFT_AccuMap ); mHasAccumulation = true; } @@ -441,19 +428,7 @@ void ProcessedShaderMaterial::_determineFeatures( U32 stageNum, fd.features.removeFeature( MFT_AccuMap ); mHasAccumulation = false; } - - // if we still have the AccuMap feature, we add all accu constant features - if ( fd.features[ MFT_AccuMap ] ) { - // add the dependencies of the accu map - fd.features.addFeature( MFT_AccuScale ); - fd.features.addFeature( MFT_AccuDirection ); - fd.features.addFeature( MFT_AccuStrength ); - fd.features.addFeature( MFT_AccuCoverage ); - fd.features.addFeature( MFT_AccuSpecular ); - // now remove some features that are not compatible with this - fd.features.removeFeature( MFT_UseInstancing ); - } - + // Without a base texture use the diffuse color // feature to ensure some sort of output. if (!fd.features[MFT_DiffuseMap]) @@ -1175,7 +1150,12 @@ void ProcessedShaderMaterial::_setShaderConstants(SceneRenderState * state, cons 0.0f, 0.0f ); // TODO: Wrap mode flags? shaderConsts->setSafe(handles->mBumpAtlasTileSC, atlasTileParams); } - + + // Deferred Shading: Determine Material Info Flags + S32 matInfoFlags = + (mMaterial->mEmissive[stageNum] ? 1 : 0); + mMaterial->mMatInfoFlags[stageNum] = matInfoFlags / 255.0f; + shaderConsts->setSafe(handles->mMatInfoFlagsSC, mMaterial->mMatInfoFlags[stageNum]); if( handles->mAccuScaleSC->isValid() ) shaderConsts->set( handles->mAccuScaleSC, mMaterial->mAccuScale[stageNum] ); if( handles->mAccuDirectionSC->isValid() ) diff --git a/Engine/source/materials/processedShaderMaterial.h b/Engine/source/materials/processedShaderMaterial.h index dc5dbf872..9bcc0eec7 100644 --- a/Engine/source/materials/processedShaderMaterial.h +++ b/Engine/source/materials/processedShaderMaterial.h @@ -87,6 +87,9 @@ public: GFXShaderConstHandle *mImposterUVs; GFXShaderConstHandle *mImposterLimits; + // Deferred Shading : Material Info Flags + GFXShaderConstHandle* mMatInfoFlagsSC; + GFXShaderConstHandle* mTexHandlesSC[Material::MAX_TEX_PER_PASS]; GFXShaderConstHandle* mRTParamsSC[TEXTURE_STAGE_COUNT]; diff --git a/Engine/source/renderInstance/renderBinManager.cpp b/Engine/source/renderInstance/renderBinManager.cpp index 8ebe69334..c3b3f135d 100644 --- a/Engine/source/renderInstance/renderBinManager.cpp +++ b/Engine/source/renderInstance/renderBinManager.cpp @@ -36,7 +36,8 @@ RenderBinManager::RenderBinManager( const RenderInstType& ritype, F32 renderOrde mRenderInstType( ritype ), mRenderOrder( renderOrder ), mProcessAddOrder( processAddOrder ), - mRenderPass( NULL ) + mRenderPass( NULL ), + mBasicOnly ( false ) { VECTOR_SET_ASSOCIATION( mElementList ); mElementList.reserve( 2048 ); @@ -60,6 +61,9 @@ void RenderBinManager::initPersistFields() addField("processAddOrder", TypeF32, Offset(mProcessAddOrder, RenderBinManager), "Defines the order for adding instances in relation to other bins." ); + addField( "basicOnly", TypeBool, Offset(mBasicOnly, RenderBinManager), + "Limites the render bin to basic lighting only." ); + Parent::initPersistFields(); } diff --git a/Engine/source/renderInstance/renderBinManager.h b/Engine/source/renderInstance/renderBinManager.h index cc5bbe6c3..2a1a4cbb5 100644 --- a/Engine/source/renderInstance/renderBinManager.h +++ b/Engine/source/renderInstance/renderBinManager.h @@ -128,6 +128,8 @@ protected: /// RenderInst if available, otherwise, return NULL. inline BaseMatInstance* getMaterial( RenderInst *inst ) const; + // Limits bin to rendering in basic lighting only. + bool mBasicOnly; }; @@ -160,6 +162,7 @@ inline BaseMatInstance* RenderBinManager::getMaterial( RenderInst *inst ) const { if ( inst->type == RenderPassManager::RIT_Mesh || inst->type == RenderPassManager::RIT_Decal || + inst->type == RenderPassManager::RIT_DecalRoad || inst->type == RenderPassManager::RIT_Translucent ) return static_cast(inst)->matInst; diff --git a/Engine/source/renderInstance/renderGlowMgr.cpp b/Engine/source/renderInstance/renderGlowMgr.cpp index ed48c095f..14e6ce016 100644 --- a/Engine/source/renderInstance/renderGlowMgr.cpp +++ b/Engine/source/renderInstance/renderGlowMgr.cpp @@ -79,6 +79,7 @@ void RenderGlowMgr::GlowMaterialHook::_overrideFeatures( ProcessedMaterial *mat, // the glow materials. fd.features.removeFeature( MFT_Fog ); fd.features.removeFeature( MFT_HDROut ); + fd.features.addFeature( MFT_Imposter ); } RenderGlowMgr::RenderGlowMgr() @@ -89,6 +90,7 @@ RenderGlowMgr::RenderGlowMgr() Point2I( 512, 512 ) ) { notifyType( RenderPassManager::RIT_Decal ); + notifyType( RenderPassManager::RIT_DecalRoad ); notifyType( RenderPassManager::RIT_Translucent ); notifyType( RenderPassManager::RIT_Particle ); diff --git a/Engine/source/renderInstance/renderMeshMgr.cpp b/Engine/source/renderInstance/renderMeshMgr.cpp index 67114329d..b224e5469 100644 --- a/Engine/source/renderInstance/renderMeshMgr.cpp +++ b/Engine/source/renderInstance/renderMeshMgr.cpp @@ -144,6 +144,14 @@ void RenderMeshMgr::render(SceneRenderState * state) if( !mat ) mat = MATMGR->getWarningMatInstance(); + // Check if bin is disabled in advanced lighting. + // Allow forward rendering pass on custom materials. + + if ( ( MATMGR->getPrePassEnabled() && mBasicOnly && !mat->isCustomMaterial() ) ) + { + j++; + continue; + } U32 matListEnd = j; lastMiscTex = sgData.miscTex; diff --git a/Engine/source/renderInstance/renderObjectMgr.cpp b/Engine/source/renderInstance/renderObjectMgr.cpp index 6f79f9128..6cfab0aba 100644 --- a/Engine/source/renderInstance/renderObjectMgr.cpp +++ b/Engine/source/renderInstance/renderObjectMgr.cpp @@ -22,6 +22,8 @@ #include "renderObjectMgr.h" #include "console/consoleTypes.h" #include "scene/sceneObject.h" +#include "materials/materialManager.h" +#include "scene/sceneRenderState.h" IMPLEMENT_CONOBJECT(RenderObjectMgr); @@ -66,6 +68,10 @@ void RenderObjectMgr::render( SceneRenderState *state ) if(!mElementList.size()) return; + // Check if bin is disabled in advanced lighting. + if ( MATMGR->getPrePassEnabled() && mBasicOnly ) + return; + for( U32 i=0; i(mElementList[i].inst); diff --git a/Engine/source/renderInstance/renderPassManager.cpp b/Engine/source/renderInstance/renderPassManager.cpp index 68daed77e..f620a627b 100644 --- a/Engine/source/renderInstance/renderPassManager.cpp +++ b/Engine/source/renderInstance/renderPassManager.cpp @@ -51,6 +51,7 @@ const RenderInstType RenderPassManager::RIT_Terrain("Terrain"); const RenderInstType RenderPassManager::RIT_Object("Object"); const RenderInstType RenderPassManager::RIT_ObjectTranslucent("ObjectTranslucent"); const RenderInstType RenderPassManager::RIT_Decal("Decal"); +const RenderInstType RenderPassManager::RIT_DecalRoad("DecalRoad"); const RenderInstType RenderPassManager::RIT_Water("Water"); const RenderInstType RenderPassManager::RIT_Foliage("Foliage"); const RenderInstType RenderPassManager::RIT_VolumetricFog("ObjectVolumetricFog"); diff --git a/Engine/source/renderInstance/renderPassManager.h b/Engine/source/renderInstance/renderPassManager.h index b192fdb0e..2aa1e37ee 100644 --- a/Engine/source/renderInstance/renderPassManager.h +++ b/Engine/source/renderInstance/renderPassManager.h @@ -108,6 +108,7 @@ public: static const RenderInstType RIT_Object; // objects that do their own rendering static const RenderInstType RIT_ObjectTranslucent;// self rendering; but sorted with static const RenderInstType RIT_Translucent static const RenderInstType RIT_Decal; + static const RenderInstType RIT_DecalRoad; static const RenderInstType RIT_Water; static const RenderInstType RIT_Foliage; static const RenderInstType RIT_VolumetricFog; diff --git a/Engine/source/renderInstance/renderPrePassMgr.cpp b/Engine/source/renderInstance/renderPrePassMgr.cpp index 326f346a0..4f08dc6ea 100644 --- a/Engine/source/renderInstance/renderPrePassMgr.cpp +++ b/Engine/source/renderInstance/renderPrePassMgr.cpp @@ -36,6 +36,7 @@ #include "scene/sceneRenderState.h" #include "gfx/gfxStringEnumTranslate.h" #include "gfx/gfxDebugEvent.h" +#include "gfx/gfxCardProfile.h" #include "materials/customMaterialDefinition.h" #include "lighting/advanced/advancedLightManager.h" #include "lighting/advanced/advancedLightBinManager.h" @@ -44,10 +45,17 @@ #include "terrain/terrCellMaterial.h" #include "math/mathUtils.h" #include "math/util/matrixSet.h" +#include "gfx/gfxTextureManager.h" +#include "gfx/primBuilder.h" +#include "gfx/gfxDrawUtil.h" +#include "materials/shaderData.h" +#include "gfx/sim/cubemapData.h" const MatInstanceHookType PrePassMatInstanceHook::Type( "PrePass" ); const String RenderPrePassMgr::BufferName("prepass"); const RenderInstType RenderPrePassMgr::RIT_PrePass("PrePass"); +const String RenderPrePassMgr::ColorBufferName("color"); +const String RenderPrePassMgr::MatInfoBufferName("matinfo"); IMPLEMENT_CONOBJECT(RenderPrePassMgr); @@ -79,6 +87,7 @@ RenderPrePassMgr::RenderPrePassMgr( bool gatherDepth, mPrePassMatInstance( NULL ) { notifyType( RenderPassManager::RIT_Decal ); + notifyType( RenderPassManager::RIT_DecalRoad ); notifyType( RenderPassManager::RIT_Mesh ); notifyType( RenderPassManager::RIT_Terrain ); notifyType( RenderPassManager::RIT_Object ); @@ -90,6 +99,10 @@ RenderPrePassMgr::RenderPrePassMgr( bool gatherDepth, GFXShader::addGlobalMacro( "TORQUE_LINEAR_DEPTH" ); mNamedTarget.registerWithName( BufferName ); + mColorTarget.registerWithName( ColorBufferName ); + mMatInfoTarget.registerWithName( MatInfoBufferName ); + + mClearGBufferShader = NULL; _registerFeatures(); } @@ -98,6 +111,8 @@ RenderPrePassMgr::~RenderPrePassMgr() { GFXShader::removeGlobalMacro( "TORQUE_LINEAR_DEPTH" ); + mColorTarget.release(); + mMatInfoTarget.release(); _unregisterFeatures(); SAFE_DELETE( mPrePassMatInstance ); } @@ -119,6 +134,8 @@ bool RenderPrePassMgr::setTargetSize(const Point2I &newTargetSize) { bool ret = Parent::setTargetSize( newTargetSize ); mNamedTarget.setViewport( GFX->getViewport() ); + mColorTarget.setViewport( GFX->getViewport() ); + mMatInfoTarget.setViewport( GFX->getViewport() ); return ret; } @@ -135,6 +152,40 @@ bool RenderPrePassMgr::_updateTargets() // reload materials, the conditioner needs to alter the generated shaders } + GFXFormat colorFormat = mTargetFormat; + bool independentMrtBitDepth = GFX->getCardProfiler()->queryProfile("independentMrtBitDepth", false); + //If independent bit depth on a MRT is supported than just use 8bit channels for the albedo color. + if(independentMrtBitDepth) + colorFormat = GFXFormatR8G8B8A8; + + // andrewmac: Deferred Shading Color Buffer + if (mColorTex.getFormat() != colorFormat || mColorTex.getWidthHeight() != mTargetSize || GFX->recentlyReset()) + { + mColorTarget.release(); + mColorTex.set(mTargetSize.x, mTargetSize.y, colorFormat, + &GFXDefaultRenderTargetProfile, avar("%s() - (line %d)", __FUNCTION__, __LINE__), + 1, GFXTextureManager::AA_MATCH_BACKBUFFER); + mColorTarget.setTexture(mColorTex); + + for (U32 i = 0; i < mTargetChainLength; i++) + mTargetChain[i]->attachTexture(GFXTextureTarget::Color1, mColorTarget.getTexture()); + } + + // andrewmac: Deferred Shading Material Info Buffer + if (mMatInfoTex.getFormat() != colorFormat || mMatInfoTex.getWidthHeight() != mTargetSize || GFX->recentlyReset()) + { + mMatInfoTarget.release(); + mMatInfoTex.set(mTargetSize.x, mTargetSize.y, colorFormat, + &GFXDefaultRenderTargetProfile, avar("%s() - (line %d)", __FUNCTION__, __LINE__), + 1, GFXTextureManager::AA_MATCH_BACKBUFFER); + mMatInfoTarget.setTexture(mMatInfoTex); + + for (U32 i = 0; i < mTargetChainLength; i++) + mTargetChain[i]->attachTexture(GFXTextureTarget::Color2, mMatInfoTarget.getTexture()); + } + + GFX->finalizeReset(); + // Attach the light info buffer as a second render target, if there is // lightmapped geometry in the scene. AdvancedLightBinManager *lightBin; @@ -154,11 +205,13 @@ bool RenderPrePassMgr::_updateTargets() for ( U32 i = 0; i < mTargetChainLength; i++ ) { GFXTexHandle lightInfoTex = lightBin->getTargetTexture(0, i); - mTargetChain[i]->attachTexture(GFXTextureTarget::Color1, lightInfoTex); + mTargetChain[i]->attachTexture(GFXTextureTarget::Color3, lightInfoTex); } } } + _initShaders(); + return ret; } @@ -191,7 +244,7 @@ void RenderPrePassMgr::addElement( RenderInst *inst ) return; // First what type of render instance is it? - const bool isDecalMeshInst = inst->type == RenderPassManager::RIT_Decal; + const bool isDecalMeshInst = ((inst->type == RenderPassManager::RIT_Decal)||(inst->type == RenderPassManager::RIT_DecalRoad)); const bool isMeshInst = inst->type == RenderPassManager::RIT_Mesh; @@ -280,9 +333,8 @@ void RenderPrePassMgr::render( SceneRenderState *state ) // Tell the superclass we're about to render const bool isRenderingToTarget = _onPreRender(state); - // Clear all the buffers to white so that the - // default depth is to the far plane. - GFX->clear( GFXClearTarget | GFXClearZBuffer | GFXClearStencil, ColorI::WHITE, 1.0f, 0); + // Clear all z-buffer, and g-buffer. + clearBuffers(); // Restore transforms MatrixSet &matrixSet = getRenderPass()->getMatrixSet(); @@ -329,7 +381,13 @@ void RenderPrePassMgr::render( SceneRenderState *state ) GFX->drawPrimitive( ri->prim ); } - + // init loop data + GFXTextureObject *lastLM = NULL; + GFXCubemap *lastCubemap = NULL; + GFXTextureObject *lastReflectTex = NULL; + GFXTextureObject *lastMiscTex = NULL; + GFXTextureObject *lastAccuTex = NULL; + // Next render all the meshes. itr = mElementList.begin(); for ( ; itr != mElementList.end(); ) @@ -363,12 +421,11 @@ void RenderPrePassMgr::render( SceneRenderState *state ) // Set up SG data for this instance. setupSGData( passRI, sgData ); + mat->setSceneInfo(state, sgData); matrixSet.setWorld(*passRI->objectToWorld); matrixSet.setView(*passRI->worldToCamera); matrixSet.setProjection(*passRI->projection); - - mat->setSceneInfo(state, sgData); mat->setTransforms(matrixSet, state); // If we're instanced then don't render yet. @@ -385,6 +442,43 @@ void RenderPrePassMgr::render( SceneRenderState *state ) continue; } + bool dirty = false; + + // set the lightmaps if different + if( passRI->lightmap && passRI->lightmap != lastLM ) + { + sgData.lightmap = passRI->lightmap; + lastLM = passRI->lightmap; + dirty = true; + } + + // set the cubemap if different. + if ( passRI->cubemap != lastCubemap ) + { + sgData.cubemap = passRI->cubemap; + lastCubemap = passRI->cubemap; + dirty = true; + } + + if ( passRI->reflectTex != lastReflectTex ) + { + sgData.reflectTex = passRI->reflectTex; + lastReflectTex = passRI->reflectTex; + dirty = true; + } + + // Update accumulation texture if it changed. + // Note: accumulation texture can be NULL, and must be updated. + if (passRI->accuTex != lastAccuTex) + { + sgData.accuTex = passRI->accuTex; + lastAccuTex = lastAccuTex; + dirty = true; + } + + if ( dirty ) + mat->setTextureStages( state, sgData ); + // Setup the vertex and index buffers. mat->setBuffers( passRI->vertBuff, passRI->primBuff ); @@ -525,6 +619,31 @@ void ProcessedPrePassMaterial::_determineFeatures( U32 stageNum, #ifndef TORQUE_DEDICATED + //tag all materials running through prepass as deferred + newFeatures.addFeature(MFT_isDeferred); + + // Deferred Shading : Diffuse + if (mStages[stageNum].getTex( MFT_DiffuseMap )) + { + newFeatures.addFeature(MFT_DiffuseMap); + } + newFeatures.addFeature( MFT_DiffuseColor ); + + // Deferred Shading : Specular + if( mStages[stageNum].getTex( MFT_SpecularMap ) ) + { + newFeatures.addFeature( MFT_DeferredSpecMap ); + } + else if ( mMaterial->mPixelSpecular[stageNum] ) + { + newFeatures.addFeature( MFT_DeferredSpecVars ); + } + else + newFeatures.addFeature(MFT_DeferredEmptySpec); + + // Deferred Shading : Material Info Flags + newFeatures.addFeature( MFT_DeferredMatInfoFlags ); + for ( U32 i=0; i < fd.features.getCount(); i++ ) { const FeatureType &type = fd.features.getAt( i ); @@ -553,7 +672,10 @@ void ProcessedPrePassMaterial::_determineFeatures( U32 stageNum, type == MFT_InterlacedPrePass || type == MFT_Visibility || type == MFT_UseInstancing || - type == MFT_DiffuseVertColor ) + type == MFT_DiffuseVertColor || + type == MFT_DetailMap || + type == MFT_DetailNormalMap || + type == MFT_DiffuseMapAtlas) newFeatures.addFeature( type ); // Add any transform features. @@ -563,11 +685,39 @@ void ProcessedPrePassMaterial::_determineFeatures( U32 stageNum, newFeatures.addFeature( type ); } + if (mMaterial->mAccuEnabled[stageNum]) + { + newFeatures.addFeature(MFT_AccuMap); + mHasAccumulation = true; + } + + // we need both diffuse and normal maps + sm3 to have an accu map + if (newFeatures[MFT_AccuMap] && + (!newFeatures[MFT_DiffuseMap] || + !newFeatures[MFT_NormalMap] || + GFX->getPixelShaderVersion() < 3.0f)) { + AssertWarn(false, "SAHARA: Using an Accu Map requires SM 3.0 and a normal map."); + newFeatures.removeFeature(MFT_AccuMap); + mHasAccumulation = false; + } + + // if we still have the AccuMap feature, we add all accu constant features + if (newFeatures[MFT_AccuMap]) { + // add the dependencies of the accu map + newFeatures.addFeature(MFT_AccuScale); + newFeatures.addFeature(MFT_AccuDirection); + newFeatures.addFeature(MFT_AccuStrength); + newFeatures.addFeature(MFT_AccuCoverage); + newFeatures.addFeature(MFT_AccuSpecular); + // now remove some features that are not compatible with this + newFeatures.removeFeature(MFT_UseInstancing); + } + // If there is lightmapped geometry support, add the MRT light buffer features if(bEnableMRTLightmap) { // If this material has a lightmap, pass it through, and flag it to - // send it's output to RenderTarget1 + // send it's output to RenderTarget3 if( fd.features.hasFeature( MFT_ToneMap ) ) { newFeatures.addFeature( MFT_ToneMap ); @@ -590,10 +740,16 @@ void ProcessedPrePassMaterial::_determineFeatures( U32 stageNum, else { // If this object isn't lightmapped, add a zero-output feature to it - newFeatures.addFeature( MFT_RenderTarget1_Zero ); + newFeatures.addFeature( MFT_RenderTarget3_Zero ); } } + // cubemaps only available on stage 0 for now - bramage + if ( stageNum < 1 && + ( ( mMaterial->mCubemapData && mMaterial->mCubemapData->mCubemap ) || + mMaterial->mDynamicCubemap ) ) + newFeatures.addFeature( MFT_CubeMap ); + #endif // Set the new features. @@ -602,8 +758,54 @@ void ProcessedPrePassMaterial::_determineFeatures( U32 stageNum, U32 ProcessedPrePassMaterial::getNumStages() { - // Return 1 stage so this material gets processed for sure - return 1; + // Loops through all stages to determine how many + // stages we actually use. + // + // The first stage is always active else we shouldn't be + // creating the material to begin with. + U32 numStages = 1; + + U32 i; + for( i=1; imCubemapData || mMaterial->mDynamicCubemap ) + { + numStages++; + continue; + } + } + + // If we have a texture for the a feature the + // stage is active. + if ( mStages[i].hasValidTex() ) + stageActive = true; + + // If this stage has specular lighting, it's active + if ( mMaterial->mPixelSpecular[i] ) + stageActive = true; + + // If this stage has diffuse color, it's active + if ( mMaterial->mDiffuse[i].alpha > 0 && + mMaterial->mDiffuse[i] != ColorF::WHITE ) + stageActive = true; + + // If we have a Material that is vertex lit + // then it may not have a texture + if( mMaterial->mVertLit[i] ) + stageActive = true; + + // Increment the number of active stages + numStages += stageActive; + } + + return numStages; } void ProcessedPrePassMaterial::addStateBlockDesc(const GFXStateBlockDesc& desc) @@ -633,7 +835,7 @@ void ProcessedPrePassMaterial::addStateBlockDesc(const GFXStateBlockDesc& desc) if ( isTranslucent ) { prePassStateBlock.setBlend( true, GFXBlendSrcAlpha, GFXBlendInvSrcAlpha ); - prePassStateBlock.setColorWrites( true, true, false, false ); + prePassStateBlock.setColorWrites(false, false, false, true); } // Enable z reads, but only enable zwrites if we're not translucent. @@ -663,7 +865,22 @@ ProcessedMaterial* PrePassMatInstance::getShaderMaterial() bool PrePassMatInstance::init( const FeatureSet &features, const GFXVertexFormat *vertexFormat ) { - return Parent::init( features, vertexFormat ); + bool vaild = Parent::init(features, vertexFormat); + + if (mMaterial && mMaterial->mDiffuseMapFilename[0].isNotEmpty() && mMaterial->mDiffuseMapFilename[0].substr(0, 1).equal("#")) + { + String texTargetBufferName = mMaterial->mDiffuseMapFilename[0].substr(1, mMaterial->mDiffuseMapFilename[0].length() - 1); + NamedTexTarget *texTarget = NamedTexTarget::find(texTargetBufferName); + RenderPassData* rpd = getPass(0); + + if (rpd) + { + rpd->mTexSlot[0].texTarget = texTarget; + rpd->mTexType[0] = Material::TexTarget; + rpd->mSamplerNames[0] = "diffuseMap"; + } + } + return vaild; } PrePassMatInstanceHook::PrePassMatInstanceHook( MatInstance *baseMatInst, @@ -850,3 +1067,77 @@ Var* LinearEyeDepthConditioner::printMethodHeader( MethodType methodType, const return retVal; } + +void RenderPrePassMgr::_initShaders() +{ + if ( mClearGBufferShader ) return; + + // Find ShaderData + ShaderData *shaderData; + mClearGBufferShader = Sim::findObject( "ClearGBufferShader", shaderData ) ? shaderData->getShader() : NULL; + if ( !mClearGBufferShader ) + Con::errorf( "RenderPrePassMgr::_initShaders - could not find ClearGBufferShader" ); + + // Create StateBlocks + GFXStateBlockDesc desc; + desc.setCullMode( GFXCullNone ); + desc.setBlend( true ); + desc.setZReadWrite( false, false ); + desc.samplersDefined = true; + desc.samplers[0].addressModeU = GFXAddressWrap; + desc.samplers[0].addressModeV = GFXAddressWrap; + desc.samplers[0].addressModeW = GFXAddressWrap; + desc.samplers[0].magFilter = GFXTextureFilterLinear; + desc.samplers[0].minFilter = GFXTextureFilterLinear; + desc.samplers[0].mipFilter = GFXTextureFilterLinear; + desc.samplers[0].textureColorOp = GFXTOPModulate; + + mStateblock = GFX->createStateBlock( desc ); + + // Set up shader constants. + mShaderConsts = mClearGBufferShader->allocConstBuffer(); + mSpecularStrengthSC = mClearGBufferShader->getShaderConstHandle( "$specularStrength" ); + mSpecularPowerSC = mClearGBufferShader->getShaderConstHandle( "$specularPower" ); +} + +void RenderPrePassMgr::clearBuffers() +{ + // Clear z-buffer. + GFX->clear( GFXClearTarget | GFXClearZBuffer | GFXClearStencil, ColorI::ZERO, 1.0f, 0); + + if ( !mClearGBufferShader ) + return; + + GFXTransformSaver saver; + + // Clear the g-buffer. + RectI box(-1, -1, 3, 3); + GFX->setWorldMatrix( MatrixF::Identity ); + GFX->setViewMatrix( MatrixF::Identity ); + GFX->setProjectionMatrix( MatrixF::Identity ); + + GFX->setShader(mClearGBufferShader); + GFX->setStateBlock(mStateblock); + + Point2F nw(-0.5,-0.5); + Point2F ne(0.5,-0.5); + + GFXVertexBufferHandle verts(GFX, 4, GFXBufferTypeVolatile); + verts.lock(); + + F32 ulOffset = 0.5f - GFX->getFillConventionOffset(); + + Point2F upperLeft(-1.0, -1.0); + Point2F lowerRight(1.0, 1.0); + + verts[0].point.set( upperLeft.x+nw.x+ulOffset, upperLeft.y+nw.y+ulOffset, 0.0f ); + verts[1].point.set( lowerRight.x+ne.x, upperLeft.y+ne.y+ulOffset, 0.0f ); + verts[2].point.set( upperLeft.x-ne.x+ulOffset, lowerRight.y-ne.y, 0.0f ); + verts[3].point.set( lowerRight.x-nw.x, lowerRight.y-nw.y, 0.0f ); + + verts.unlock(); + + GFX->setVertexBuffer( verts ); + GFX->drawPrimitive( GFXTriangleStrip, 0, 2 ); + GFX->setShader(NULL); +} diff --git a/Engine/source/renderInstance/renderPrePassMgr.h b/Engine/source/renderInstance/renderPrePassMgr.h index 70a36eb84..bf36c6218 100644 --- a/Engine/source/renderInstance/renderPrePassMgr.h +++ b/Engine/source/renderInstance/renderPrePassMgr.h @@ -43,6 +43,10 @@ public: // registered buffer name static const String BufferName; + // andremwac: Deferred Rendering + static const String ColorBufferName; + static const String MatInfoBufferName; + // Generic PrePass Render Instance Type static const RenderInstType RIT_PrePass; @@ -93,6 +97,22 @@ protected: virtual void _createPrePassMaterial(); bool _lightManagerActivate(bool active); + + // Deferred Shading + GFXVertexBufferHandle mClearGBufferVerts; + GFXShaderRef mClearGBufferShader; + GFXStateBlockRef mStateblock; + NamedTexTarget mColorTarget; + NamedTexTarget mMatInfoTarget; + GFXTexHandle mColorTex; + GFXTexHandle mMatInfoTex; + GFXShaderConstBufferRef mShaderConsts; + GFXShaderConstHandle *mSpecularStrengthSC; + GFXShaderConstHandle *mSpecularPowerSC; + +public: + void clearBuffers(); + void _initShaders(); }; //------------------------------------------------------------------------------ diff --git a/Engine/source/renderInstance/renderTerrainMgr.cpp b/Engine/source/renderInstance/renderTerrainMgr.cpp index f298ff51c..4a67e686f 100644 --- a/Engine/source/renderInstance/renderTerrainMgr.cpp +++ b/Engine/source/renderInstance/renderTerrainMgr.cpp @@ -35,6 +35,7 @@ #include "terrain/terrCell.h" #include "terrain/terrCellMaterial.h" #include "math/util/matrixSet.h" +#include "materials/materialManager.h" bool RenderTerrainMgr::smRenderWireframe = false; @@ -117,6 +118,10 @@ void RenderTerrainMgr::render( SceneRenderState *state ) if ( mInstVector.empty() ) return; + // Check if bin is disabled in advanced lighting. + if ( MATMGR->getPrePassEnabled() && mBasicOnly ) + return; + PROFILE_SCOPE( RenderTerrainMgr_Render ); GFXTransformSaver saver; diff --git a/Engine/source/scene/reflectionManager.cpp b/Engine/source/scene/reflectionManager.cpp index 057c72c0a..323e11c8a 100644 --- a/Engine/source/scene/reflectionManager.cpp +++ b/Engine/source/scene/reflectionManager.cpp @@ -58,7 +58,7 @@ MODULE_END; GFX_ImplementTextureProfile( ReflectRenderTargetProfile, GFXTextureProfile::DiffuseMap, - GFXTextureProfile::PreserveSize | GFXTextureProfile::NoMipmap | GFXTextureProfile::RenderTarget | GFXTextureProfile::Pooled, + GFXTextureProfile::PreserveSize | GFXTextureProfile::RenderTarget | GFXTextureProfile::Pooled, GFXTextureProfile::NONE ); GFX_ImplementTextureProfile( RefractTextureProfile, diff --git a/Engine/source/scene/reflectionMatHook.cpp b/Engine/source/scene/reflectionMatHook.cpp index b869cabc9..646b0145c 100644 --- a/Engine/source/scene/reflectionMatHook.cpp +++ b/Engine/source/scene/reflectionMatHook.cpp @@ -89,8 +89,6 @@ void ReflectionMaterialHook::_overrideFeatures( ProcessedMaterial *mat, return; } - // Forward shading on materials in reflections - fd.features.addFeature( MFT_ForwardShading ); fd.features.addFeature( MFT_Fog ); } diff --git a/Engine/source/scene/reflector.cpp b/Engine/source/scene/reflector.cpp index 254839813..1addaf191 100644 --- a/Engine/source/scene/reflector.cpp +++ b/Engine/source/scene/reflector.cpp @@ -419,7 +419,6 @@ void CubeReflector::updateFace( const ReflectParams ¶ms, U32 faceidx ) reflectRenderState.getMaterialDelegate().bind( REFLECTMGR, &ReflectionManager::getReflectionMaterial ); reflectRenderState.setDiffuseCameraTransform( params.query->cameraMatrix ); - reflectRenderState.disableAdvancedLightingBins(true); // render scene LIGHTMGR->registerGlobalLights( &reflectRenderState.getCullingFrustum(), false ); @@ -633,7 +632,6 @@ void PlaneReflector::updateReflection( const ReflectParams ¶ms ) renderStateLeft.setSceneRenderField(0); renderStateLeft.getMaterialDelegate().bind( REFLECTMGR, &ReflectionManager::getReflectionMaterial ); renderStateLeft.setDiffuseCameraTransform( params.query->eyeTransforms[0] ); - renderStateLeft.disableAdvancedLightingBins(true); gClientSceneGraph->renderSceneNoLights( &renderStateLeft, objTypeFlag ); @@ -672,7 +670,6 @@ void PlaneReflector::updateReflection( const ReflectParams ¶ms ) reflectRenderState.getMaterialDelegate().bind( REFLECTMGR, &ReflectionManager::getReflectionMaterial ); reflectRenderState.setDiffuseCameraTransform( params.query->cameraMatrix ); - reflectRenderState.disableAdvancedLightingBins(true); gClientSceneGraph->renderSceneNoLights( &reflectRenderState, objTypeFlag ); } diff --git a/Engine/source/shaderGen/GLSL/accuFeatureGLSL.cpp b/Engine/source/shaderGen/GLSL/accuFeatureGLSL.cpp index 04a280e09..aa2eda41d 100644 --- a/Engine/source/shaderGen/GLSL/accuFeatureGLSL.cpp +++ b/Engine/source/shaderGen/GLSL/accuFeatureGLSL.cpp @@ -56,7 +56,7 @@ void AccuTexFeatGLSL::processPix(Vector &componentList, output = meta; // OUT.col - Var *color = (Var*) LangElement::find( "col" ); + Var *color = (Var*) LangElement::find( "col1" ); if (!color) { output = new GenOp(" //NULL COLOR!"); @@ -144,8 +144,6 @@ void AccuTexFeatGLSL::processPix(Vector &componentList, // get the accu pixel color meta->addStatement( new GenOp( " @ = tex2D(@, @ * @);\r\n", colorAccuDecl, accuMap, inTex, accuScale ) ); - if (!fd.features[MFT_Imposter]) - meta->addStatement(new GenOp(" @ = toLinear(@);\r\n", accuColor, accuColor)); // scale up normals meta->addStatement( new GenOp( " @.xyz = @.xyz * 2.0 - 0.5;\r\n", bumpNorm, bumpNorm ) ); diff --git a/Engine/source/shaderGen/GLSL/shaderFeatureGLSL.cpp b/Engine/source/shaderGen/GLSL/shaderFeatureGLSL.cpp index eed42dd68..cea0ca5db 100644 --- a/Engine/source/shaderGen/GLSL/shaderFeatureGLSL.cpp +++ b/Engine/source/shaderGen/GLSL/shaderFeatureGLSL.cpp @@ -156,10 +156,10 @@ LangElement *ShaderFeatureGLSL::expandNormalMap( LangElement *sampleNormalOp, } else { - // DXT Swizzle trick - meta->addStatement( new GenOp( " @ = float4( @.ag * 2.0 - 1.0, 0.0, 0.0 ); // DXTnm\r\n", normalDecl, sampleNormalOp ) ); - meta->addStatement( new GenOp( " @.z = sqrt( 1.0 - dot( @.xy, @.xy ) ); // DXTnm\r\n", normalVar, normalVar, normalVar ) ); - } + // DXT Swizzle trick + meta->addStatement( new GenOp( " @ = float4( @.ag * 2.0 - 1.0, 0.0, 0.0 ); // DXTnm\r\n", normalDecl, sampleNormalOp ) ); + meta->addStatement( new GenOp( " @.z = sqrt( 1.0 - dot( @.xy, @.xy ) ); // DXTnm\r\n", normalVar, normalVar, normalVar ) ); + } } else { @@ -365,7 +365,7 @@ Var* ShaderFeatureGLSL::getOutTexCoord( const char *name, // Statement allows for casting of different types which // eliminates vector truncation problems. - String statement = String::ToString( " @ = %s(tMul(@, @));\r\n", type ); + String statement = String::ToString( " @ = %s(tMul(@, @).xy);\r\n", type ); meta->addStatement( new GenOp( statement , texCoord, texMat, inTex ) ); } else @@ -708,7 +708,7 @@ void ShaderFeatureGLSL::getWsPosition( Vector &componentList, Var *objTrans = getObjTrans( componentList, useInstancing, meta ); - meta->addStatement( new GenOp( " @ = tMul( @, float4( @.xyz, 1 ) ).xyz;\r\n", + meta->addStatement( new GenOp( " @ = tMul( @, vec4( @.xyz, 1 ) ).xyz;\r\n", wsPosition, objTrans, inPosition ) ); } @@ -813,7 +813,7 @@ Var* ShaderFeatureGLSL::addOutDetailTexCoord( Vector &compon texMat->constSortPos = cspPass; } - meta->addStatement( new GenOp( " @ = tMul(@, @) * @;\r\n", outTex, texMat, inTex, detScale ) ); + meta->addStatement( new GenOp( " @ = tMul(@, @).xy * @;\r\n", outTex, texMat, inTex, detScale ) ); } else { @@ -847,12 +847,22 @@ void DiffuseMapFeatGLSL::processVert( Vector &componentList, output = meta; } +U32 DiffuseMapFeatGLSL::getOutputTargets(const MaterialFeatureData &fd) const +{ + return fd.features[MFT_isDeferred] ? ShaderFeature::RenderTarget1 : ShaderFeature::DefaultTarget; +} + void DiffuseMapFeatGLSL::processPix( Vector &componentList, const MaterialFeatureData &fd ) { // grab connector texcoord register Var *inTex = getInTexCoord( "texCoord", "vec2", true, componentList ); + //determine output target + ShaderFeature::OutputTarget targ = ShaderFeature::DefaultTarget; + if (fd.features[MFT_isDeferred]) + targ = ShaderFeature::RenderTarget1; + // create texture var Var *diffuseMap = new Var; diffuseMap->setType( "sampler2D" ); @@ -869,7 +879,6 @@ void DiffuseMapFeatGLSL::processPix( Vector &componentList, MultiLine * meta = new MultiLine; output = meta; - if ( fd.features[MFT_CubeMap] ) { meta->addStatement( new GenOp( " @ = tex2D(@, @);\r\n", @@ -878,9 +887,8 @@ void DiffuseMapFeatGLSL::processPix( Vector &componentList, inTex ) ); if (!fd.features[MFT_Imposter]) meta->addStatement( new GenOp(" @ = toLinear(@);\r\n", diffColor, diffColor) ); - - meta->addStatement( new GenOp( " @;\r\n", assignColor( diffColor, Material::Mul ) ) ); - output = meta; + + meta->addStatement( new GenOp( " @;\r\n", assignColor( diffColor, Material::Mul, NULL, targ) ) ); } else if(fd.features[MFT_DiffuseMapAtlas]) { @@ -946,8 +954,8 @@ void DiffuseMapFeatGLSL::processPix( Vector &componentList, #ifdef DEBUG_ATLASED_UV_COORDS if(!fd.features[MFT_PrePassConditioner]) { - meta->addStatement(new GenOp(" @ = float4(@.xy, mipLod / @.w, 1.0);\r\n", new DecOp(diffColor), inTex, atParams)); - meta->addStatement(new GenOp(" @; return OUT;\r\n", assignColor(diffColor, Material::Mul))); + meta->addStatement(new GenOp(" @ = vec4(@.xy, mipLod / @.w, 1.0);\r\n", new DecOp(diffColor), inTex, atParams)); + meta->addStatement(new GenOp(" @; return OUT;\r\n", assignColor(diffColor, Material::Mul, NULL, targ) ) ); return; } #endif @@ -961,20 +969,20 @@ void DiffuseMapFeatGLSL::processPix( Vector &componentList, } else { - meta->addStatement(new GenOp( " @ = tex2D(@, @);\r\n", - new DecOp(diffColor), diffuseMap, inTex)); + meta->addStatement(new GenOp( " @ = tex2D(@, @);\r\n", + new DecOp(diffColor), diffuseMap, inTex)); if (!fd.features[MFT_Imposter]) meta->addStatement(new GenOp(" @ = toLinear(@);\r\n", diffColor, diffColor)); } - meta->addStatement(new GenOp( " @;\r\n", assignColor(diffColor, Material::Mul))); + meta->addStatement(new GenOp( " @;\r\n", assignColor(diffColor, Material::Mul, NULL, targ) ) ); } else { meta->addStatement(new GenOp("@ = tex2D(@, @);\r\n", colorDecl, diffuseMap, inTex)); if (!fd.features[MFT_Imposter]) meta->addStatement(new GenOp(" @ = toLinear(@);\r\n", diffColor, diffColor)); - meta->addStatement(new GenOp(" @;\r\n", assignColor(diffColor, Material::Mul))); + meta->addStatement(new GenOp(" @;\r\n", assignColor(diffColor, Material::Mul, NULL, targ))); } } @@ -1089,6 +1097,11 @@ void OverlayTexFeatGLSL::setTexData( Material::StageData &stageDat, // Diffuse color //**************************************************************************** +U32 DiffuseFeatureGLSL::getOutputTargets(const MaterialFeatureData &fd) const +{ + return fd.features[MFT_isDeferred] ? ShaderFeature::RenderTarget1 : ShaderFeature::DefaultTarget; +} + void DiffuseFeatureGLSL::processPix( Vector &componentList, const MaterialFeatureData &fd ) { @@ -1099,7 +1112,33 @@ void DiffuseFeatureGLSL::processPix( Vector &componentList, diffuseMaterialColor->constSortPos = cspPotentialPrimitive; MultiLine* meta = new MultiLine; - meta->addStatement( new GenOp( " @;\r\n", assignColor( diffuseMaterialColor, Material::Mul ) ) ); + Var *col = (Var*)LangElement::find("col"); + ShaderFeature::OutputTarget targ = ShaderFeature::DefaultTarget; + if (fd.features[MFT_isDeferred]) + { + targ = ShaderFeature::RenderTarget1; + + col = (Var*)LangElement::find("col1"); + MultiLine * meta = new MultiLine; + if (!col) + { + // create color var + col = new Var; + col->setType("vec4"); + col->setName(getOutputTargetVarName(targ)); + col->setStructName("OUT"); + meta->addStatement(new GenOp(" @ = vec4(1.0);\r\n", col)); + } + } + + Material::BlendOp op; + + if (fd.features[MFT_DiffuseMap]) + op = Material::Mul; + else + op = Material::None; + + meta->addStatement(new GenOp(" @;\r\n", assignColor(diffuseMaterialColor, op, NULL, targ))); output = meta; } @@ -1231,9 +1270,9 @@ void LightmapFeatGLSL::processPix( Vector &componentList, // Lightmap has already been included in the advanced light bin, so // no need to do any sampling or anything if(bPreProcessedLighting) - statement = new GenOp( "float4(@, 1.0)", inColor ); + statement = new GenOp( "vec4(@, 1.0)", inColor ); else - statement = new GenOp( "tex2D(@, @) + float4(@.rgb, 0.0)", lightMap, inTex, inColor ); + statement = new GenOp( "tex2D(@, @) + vec4(@.rgb, 0.0)", lightMap, inTex, inColor ); } } @@ -1245,8 +1284,8 @@ void LightmapFeatGLSL::processPix( Vector &componentList, MultiLine *meta = new MultiLine; if( fd.features[MFT_LightbufferMRT] ) { - meta->addStatement( new GenOp( " @;\r\n", assignColor( statement, Material::None, NULL, ShaderFeature::RenderTarget1 ) ) ); - meta->addStatement( new GenOp( " @.a = 0.0001;\r\n", LangElement::find( getOutputTargetVarName(ShaderFeature::RenderTarget1) ) ) ); + meta->addStatement( new GenOp( " @;\r\n", assignColor( statement, Material::None, NULL, ShaderFeature::RenderTarget3 ) ) ); + meta->addStatement( new GenOp( " @.a = 0.0001;\r\n", LangElement::find( getOutputTargetVarName(ShaderFeature::RenderTarget3) ) ) ); } else meta->addStatement( new GenOp( " @;\r\n", assignColor( statement, Material::Mul ) ) ); @@ -1278,7 +1317,7 @@ void LightmapFeatGLSL::setTexData( Material::StageData &stageDat, U32 LightmapFeatGLSL::getOutputTargets( const MaterialFeatureData &fd ) const { - return fd.features[MFT_LightbufferMRT] ? ShaderFeature::RenderTarget1 : ShaderFeature::DefaultTarget; + return fd.features[MFT_LightbufferMRT] ? ShaderFeature::RenderTarget3 : ShaderFeature::DefaultTarget; } //**************************************************************************** @@ -1372,8 +1411,8 @@ void TonemapFeatGLSL::processPix( Vector &componentList, // Assign to proper render target if( fd.features[MFT_LightbufferMRT] ) { - meta->addStatement( new GenOp( " @;\r\n", assignColor( toneMapColor, Material::None, NULL, ShaderFeature::RenderTarget1 ) ) ); - meta->addStatement( new GenOp( " @.a = 0.0001;\r\n", LangElement::find( getOutputTargetVarName(ShaderFeature::RenderTarget1) ) ) ); + meta->addStatement( new GenOp( " @;\r\n", assignColor( toneMapColor, Material::None, NULL, ShaderFeature::RenderTarget3 ) ) ); + meta->addStatement( new GenOp( " @.a = 0.0001;\r\n", LangElement::find( getOutputTargetVarName(ShaderFeature::RenderTarget3) ) ) ); } else meta->addStatement( new GenOp( " @;\r\n", assignColor( toneMapColor, blendOp ) ) ); @@ -1406,7 +1445,7 @@ void TonemapFeatGLSL::setTexData( Material::StageData &stageDat, U32 TonemapFeatGLSL::getOutputTargets( const MaterialFeatureData &fd ) const { - return fd.features[MFT_LightbufferMRT] ? ShaderFeature::RenderTarget1 : ShaderFeature::DefaultTarget; + return fd.features[MFT_LightbufferMRT] ? ShaderFeature::RenderTarget3 : ShaderFeature::DefaultTarget; } //**************************************************************************** @@ -1512,17 +1551,17 @@ void VertLitGLSL::processPix( Vector &componentList, // the dynamic light buffer, and it already has the baked-vertex-color // included in it if(bPreProcessedLighting) - outColor = new GenOp( "float4(@.rgb, 1.0)", rtLightingColor ); + outColor = new GenOp( "vec4(@.rgb, 1.0)", rtLightingColor ); else - outColor = new GenOp( "float4(@.rgb + @.rgb, 1.0)", rtLightingColor, outColor ); + outColor = new GenOp( "vec4(@.rgb + @.rgb, 1.0)", rtLightingColor, outColor ); } } // Output the color if ( fd.features[MFT_LightbufferMRT] ) { - meta->addStatement( new GenOp( " @;\r\n", assignColor( outColor, Material::None, NULL, ShaderFeature::RenderTarget1 ) ) ); - meta->addStatement( new GenOp( " @.a = 0.0001;\r\n", LangElement::find( getOutputTargetVarName(ShaderFeature::RenderTarget1) ) ) ); + meta->addStatement( new GenOp( " @;\r\n", assignColor( outColor, Material::None, NULL, ShaderFeature::RenderTarget3 ) ) ); + meta->addStatement( new GenOp( " @.a = 0.0001;\r\n", LangElement::find( getOutputTargetVarName(ShaderFeature::RenderTarget3) ) ) ); } else meta->addStatement( new GenOp( " @;\r\n", assignColor( outColor, blendOp ) ) ); @@ -1532,7 +1571,7 @@ void VertLitGLSL::processPix( Vector &componentList, U32 VertLitGLSL::getOutputTargets( const MaterialFeatureData &fd ) const { - return fd.features[MFT_LightbufferMRT] ? ShaderFeature::RenderTarget1 : ShaderFeature::DefaultTarget; + return fd.features[MFT_LightbufferMRT] ? ShaderFeature::RenderTarget3 : ShaderFeature::DefaultTarget; } //**************************************************************************** @@ -1571,7 +1610,10 @@ void DetailFeatGLSL::processPix( Vector &componentList, // and a simple multiplication with the detail map. LangElement *statement = new GenOp( "( tex2D(@, @) * 2.0 ) - 1.0", detailMap, inTex ); - output = new GenOp( " @;\r\n", assignColor( statement, Material::Add ) ); + if ( fd.features[MFT_isDeferred]) + output = new GenOp( " @;\r\n", assignColor( statement, Material::Add, NULL, ShaderFeature::RenderTarget1 ) ); + else + output = new GenOp( " @;\r\n", assignColor( statement, Material::Add ) ); } ShaderFeature::Resources DetailFeatGLSL::getResources( const MaterialFeatureData &fd ) @@ -1630,7 +1672,7 @@ void VertPositionGLSL::processVert( Vector &componentList, Var *modelview = getModelView( componentList, fd.features[MFT_UseInstancing], meta ); - meta->addStatement( new GenOp( " @ = tMul(@, float4(@.xyz,1));\r\n", + meta->addStatement( new GenOp( " @ = tMul(@, vec4(@.xyz,1));\r\n", outPosition, modelview, inPosition ) ); output = meta; @@ -1694,8 +1736,8 @@ void ReflectCubeFeatGLSL::processVert( Vector &componentList, cubeNormal->setName( "cubeNormal" ); cubeNormal->setType( "vec3" ); LangElement *cubeNormDecl = new DecOp( cubeNormal ); - - meta->addStatement( new GenOp( " @ = ( tMul( (@), vec4(@, 0) ) ).xyz;\r\n", + + meta->addStatement( new GenOp( " @ = ( tMul( (@), vec4(@, 0) ) ).xyz;\r\n", cubeNormDecl, cubeTrans, inNormal ) ); meta->addStatement( new GenOp( " @ = bool(length(@)) ? normalize(@) : @;\r\n", @@ -1771,9 +1813,14 @@ void ReflectCubeFeatGLSL::processPix( Vector &componentList, } else { - glossColor = (Var*) LangElement::find( "diffuseColor" ); - if( !glossColor ) - glossColor = (Var*) LangElement::find( "bumpNormal" ); + if (fd.features[MFT_isDeferred]) + glossColor = (Var*)LangElement::find(getOutputTargetVarName(ShaderFeature::RenderTarget1)); + if (!glossColor) + glossColor = (Var*)LangElement::find("specularColor"); + if (!glossColor) + glossColor = (Var*)LangElement::find("diffuseColor"); + if (!glossColor) + glossColor = (Var*)LangElement::find("bumpNormal"); } // grab connector texcoord register @@ -1786,7 +1833,7 @@ void ReflectCubeFeatGLSL::processPix( Vector &componentList, // create cubemap var Var *cubeMap = new Var; - cubeMap->setType( "samplerCUBE" ); + cubeMap->setType( "samplerCube" ); cubeMap->setName( "cubeMap" ); cubeMap->uniform = true; cubeMap->sampler = true; @@ -1800,14 +1847,36 @@ void ReflectCubeFeatGLSL::processPix( Vector &componentList, if ( fd.materialFeatures[MFT_RTLighting] ) attn =(Var*)LangElement::find("d_NL_Att"); - LangElement *texCube = new GenOp( "texCUBE( @, @ )", cubeMap, reflectVec ); + LangElement *texCube = NULL; + Var* matinfo = (Var*) LangElement::find( getOutputTargetVarName(ShaderFeature::RenderTarget2) ); + //first try and grab the gbuffer + if (fd.features[MFT_isDeferred] && matinfo) + { + + if (fd.features[MFT_DeferredSpecMap]) + texCube = new GenOp("textureLod( @, @, (@.a*5) )", cubeMap, reflectVec, matinfo); + else + texCube = new GenOp("textureLod( @, @, (@.a/4) )", cubeMap, reflectVec, matinfo); + } + else if(glossColor) //failing that, rtry and find color data + texCube = new GenOp("textureLod( @, @, @.a*5)", cubeMap, reflectVec, glossColor); + else + texCube = new GenOp("texture( @, @)", cubeMap, reflectVec); + LangElement *lerpVal = NULL; Material::BlendOp blendOp = Material::LerpAlpha; // Note that the lerpVal needs to be a float4 so that // it will work with the LerpAlpha blend. - - if ( glossColor ) + + if (matinfo) + { + if (attn) + lerpVal = new GenOp("@ * saturate( @ )", matinfo, attn); + else + lerpVal = new GenOp("@", matinfo); + } + else if ( glossColor ) { if ( attn ) lerpVal = new GenOp( "@ * saturate( @ )", glossColor, attn ); @@ -1821,8 +1890,16 @@ void ReflectCubeFeatGLSL::processPix( Vector &componentList, else blendOp = Material::Mul; } - - meta->addStatement( new GenOp( " @;\r\n", assignColor( texCube, blendOp, lerpVal ) ) ); + if (fd.features[MFT_isDeferred]) + { + Var* targ = (Var*)LangElement::find(getOutputTargetVarName(ShaderFeature::RenderTarget1)); + if (fd.features[MFT_DeferredSpecMap]) + meta->addStatement(new GenOp(" @.rgb = lerp( @.rgb, (@).rgb, (@.b));\r\n", targ, targ, texCube, lerpVal)); + else + meta->addStatement(new GenOp(" @.rgb = lerp( @.rgb, (@).rgb, (@.b*128/5));\r\n", targ, targ, texCube, lerpVal)); + } + else + meta->addStatement( new GenOp( " @;\r\n", assignColor( texCube, blendOp, lerpVal ) ) ); output = meta; } @@ -1967,7 +2044,7 @@ void RTLightingFeatGLSL::processVert( Vector &componentList, Var *objTrans = getObjTrans( componentList, fd.features[MFT_UseInstancing], meta ); // Transform the normal to world space. - meta->addStatement( new GenOp( " @ = tMul( @, float4( normalize( @ ), 0.0 ) ).xyz;\r\n", outNormal, objTrans, inNormal ) ); + meta->addStatement( new GenOp( " @ = tMul( @, vec4( normalize( @ ), 0.0 ) ).xyz;\r\n", outNormal, objTrans, inNormal ) ); } addOutWsPosition( componentList, fd.features[MFT_UseInstancing], meta ); @@ -2025,7 +2102,7 @@ void RTLightingFeatGLSL::processPix( Vector &componentList, // feature (this is done for BL terrain lightmaps). LangElement *lightMask = LangElement::find( "lightMask" ); if ( !lightMask ) - lightMask = new GenOp( "float4( 1, 1, 1, 1 )" ); + lightMask = new GenOp( "vec4( 1, 1, 1, 1 )" ); // Get all the light constants. Var *inLightPos = new Var( "inLightPos", "vec4" ); @@ -2080,7 +2157,7 @@ void RTLightingFeatGLSL::processPix( Vector &componentList, rtShading, specular ) ); // Apply the lighting to the diffuse color. - LangElement *lighting = new GenOp( "float4( @.rgb + @.rgb, 1 )", rtShading, ambient ); + LangElement *lighting = new GenOp( "vec4( @.rgb + @.rgb, 1 )", rtShading, ambient ); meta->addStatement( new GenOp( " @;\r\n", assignColor( lighting, Material::Mul ) ) ); output = meta; } @@ -2351,7 +2428,9 @@ void AlphaTestGLSL::processPix( Vector &componentList, } // If we don't have a color var then we cannot do an alpha test. - Var *color = (Var*)LangElement::find( "col" ); + Var *color = (Var*)LangElement::find( "col1" ); + if ( !color ) + color = (Var*)LangElement::find("col"); if ( !color ) { output = NULL; @@ -2718,3 +2797,16 @@ void ImposterVertFeatureGLSL::determineFeature( Material *material, outFeatureData->features.addFeature( MFT_ImposterVert ); } +//**************************************************************************** +// Vertex position +//**************************************************************************** +void DeferredSkyGLSL::processVert( Vector &componentList, + const MaterialFeatureData &fd ) +{ + Var *outPosition = (Var*)LangElement::find( "gl_Position" ); + MultiLine *meta = new MultiLine; + meta->addStatement( new GenOp( " @.w = @.z;\r\n", outPosition, outPosition ) ); + + output = meta; +} + diff --git a/Engine/source/shaderGen/GLSL/shaderFeatureGLSL.h b/Engine/source/shaderGen/GLSL/shaderFeatureGLSL.h index 276183d99..c0d5ba832 100644 --- a/Engine/source/shaderGen/GLSL/shaderFeatureGLSL.h +++ b/Engine/source/shaderGen/GLSL/shaderFeatureGLSL.h @@ -248,6 +248,8 @@ public: virtual void processPix( Vector &componentList, const MaterialFeatureData &fd ); + virtual U32 getOutputTargets(const MaterialFeatureData &fd) const; + virtual Material::BlendOp getBlendOp(){ return Material::LerpAlpha; } virtual Resources getResources( const MaterialFeatureData &fd ); @@ -301,6 +303,8 @@ public: virtual Material::BlendOp getBlendOp(){ return Material::None; } + virtual U32 getOutputTargets(const MaterialFeatureData &fd) const; + virtual String getName() { return "Diffuse Color"; @@ -656,4 +660,11 @@ public: }; +class DeferredSkyGLSL : public ShaderFeatureGLSL +{ +public: + virtual String getName() { return "Deferred Shading: Sky"; } + virtual void processVert( Vector &componentList, + const MaterialFeatureData &fd ); +}; #endif // _SHADERGEN_GLSL_SHADERFEATUREGLSL_H_ diff --git a/Engine/source/shaderGen/GLSL/shaderGenGLSL.h b/Engine/source/shaderGen/GLSL/shaderGenGLSL.h index c14402875..77305b8e7 100644 --- a/Engine/source/shaderGen/GLSL/shaderGenGLSL.h +++ b/Engine/source/shaderGen/GLSL/shaderGenGLSL.h @@ -30,8 +30,11 @@ class ShaderGenPrinterGLSL : public ShaderGenPrinter { + bool extraRTs[3]; + public: - + ShaderGenPrinterGLSL() { for (int i = 0; i < 3; i++) extraRTs[i] = false; } + // ShaderGenPrinter virtual void printShaderHeader(Stream& stream); virtual void printMainComment(Stream& stream); diff --git a/Engine/source/shaderGen/GLSL/shaderGenGLSLInit.cpp b/Engine/source/shaderGen/GLSL/shaderGenGLSLInit.cpp index ef15793a5..020b68d43 100644 --- a/Engine/source/shaderGen/GLSL/shaderGenGLSLInit.cpp +++ b/Engine/source/shaderGen/GLSL/shaderGenGLSLInit.cpp @@ -34,6 +34,8 @@ #include "core/module.h" #include "shaderGen/GLSL/accuFeatureGLSL.h" +// Deferred Shading +#include "lighting/advanced/glsl/deferredShadingFeaturesGLSL.h" static ShaderGen::ShaderGenInitDelegate sInitDelegate; @@ -66,8 +68,13 @@ void _initShaderGenGLSL( ShaderGen *shaderGen ) FEATUREMGR->registerFeature( MFT_AccuMap, new AccuTexFeatGLSL ); FEATUREMGR->registerFeature( MFT_GlossMap, new NamedFeatureGLSL( "Gloss Map" ) ); FEATUREMGR->registerFeature( MFT_IsTranslucent, new NamedFeatureGLSL( "Translucent" ) ); + FEATUREMGR->registerFeature( MFT_IsTranslucentZWrite, new NamedFeatureGLSL( "Translucent ZWrite" ) ); FEATUREMGR->registerFeature( MFT_Visibility, new VisibilityFeatGLSL ); FEATUREMGR->registerFeature( MFT_Fog, new FogFeatGLSL ); + FEATUREMGR->registerFeature( MFT_LightbufferMRT, new NamedFeatureGLSL( "Lightbuffer MRT" ) ); + FEATUREMGR->registerFeature( MFT_RenderTarget1_Zero, new RenderTargetZeroGLSL( ShaderFeature::RenderTarget1 ) ); + FEATUREMGR->registerFeature( MFT_RenderTarget2_Zero, new RenderTargetZeroGLSL( ShaderFeature::RenderTarget2 ) ); + FEATUREMGR->registerFeature( MFT_RenderTarget3_Zero, new RenderTargetZeroGLSL( ShaderFeature::RenderTarget3 ) ); FEATUREMGR->registerFeature( MFT_Imposter, new NamedFeatureGLSL( "Imposter" ) ); FEATUREMGR->registerFeature( MFT_NormalsOut, new NormalsOutFeatGLSL ); @@ -80,9 +87,6 @@ void _initShaderGenGLSL( ShaderGen *shaderGen ) FEATUREMGR->registerFeature( MFT_ParaboloidVertTransform, new ParaboloidVertTransformGLSL ); FEATUREMGR->registerFeature( MFT_IsSinglePassParaboloid, new NamedFeatureGLSL( "Single Pass Paraboloid" ) ); FEATUREMGR->registerFeature( MFT_UseInstancing, new NamedFeatureGLSL( "Hardware Instancing" ) ); - - FEATUREMGR->registerFeature( MFT_RenderTarget1_Zero, new RenderTargetZeroGLSL - ( ShaderFeature::RenderTarget1 ) ); FEATUREMGR->registerFeature( MFT_DiffuseMapAtlas, new NamedFeatureGLSL( "Diffuse Map Atlas" ) ); FEATUREMGR->registerFeature( MFT_NormalMapAtlas, new NamedFeatureGLSL( "Normal Map Atlas" ) ); @@ -94,10 +98,13 @@ void _initShaderGenGLSL( ShaderGen *shaderGen ) FEATUREMGR->registerFeature( MFT_ImposterVert, new ImposterVertFeatureGLSL ); - FEATUREMGR->registerFeature( MFT_LightbufferMRT, new NamedFeatureGLSL( "Lightbuffer MRT" ) ); - //FEATUREMGR->registerFeature( MFT_IsTranslucentZWrite, new NamedFeatureGLSL( "Translucent ZWrite" ) ); - //FEATUREMGR->registerFeature( MFT_InterlacedPrePass, new NamedFeatureGLSL( "Interlaced Pre Pass" ) ); - + // Deferred Shading + FEATUREMGR->registerFeature( MFT_isDeferred, new NamedFeatureGLSL( "Deferred Material" ) ); + FEATUREMGR->registerFeature( MFT_DeferredSpecMap, new DeferredSpecMapGLSL ); + FEATUREMGR->registerFeature( MFT_DeferredSpecVars, new DeferredSpecVarsGLSL ); + FEATUREMGR->registerFeature( MFT_DeferredMatInfoFlags, new DeferredMatInfoFlagsGLSL ); + FEATUREMGR->registerFeature( MFT_DeferredEmptySpec, new DeferredEmptySpecGLSL ); + FEATUREMGR->registerFeature( MFT_SkyBox, new DeferredSkyGLSL ); } MODULE_BEGIN( ShaderGenGLSL ) diff --git a/Engine/source/shaderGen/HLSL/accuFeatureHLSL.cpp b/Engine/source/shaderGen/HLSL/accuFeatureHLSL.cpp index 1e90faa12..2bafc06f4 100644 --- a/Engine/source/shaderGen/HLSL/accuFeatureHLSL.cpp +++ b/Engine/source/shaderGen/HLSL/accuFeatureHLSL.cpp @@ -56,7 +56,7 @@ void AccuTexFeatHLSL::processPix( Vector &componentList, output = meta; // OUT.col - Var *color = (Var*) LangElement::find( "col" ); + Var *color = (Var*) LangElement::find( "col1" ); if (!color) { output = new GenOp(" //NULL COLOR!"); @@ -141,8 +141,6 @@ void AccuTexFeatHLSL::processPix( Vector &componentList, // get the accu pixel color meta->addStatement( new GenOp( " @ = tex2D(@, @ * @);\r\n", colorAccuDecl, accuMap, inTex, accuScale ) ); - if (!fd.features[MFT_Imposter]) - meta->addStatement(new GenOp(" @ = toLinear(@);\r\n", accuColor, accuColor)); // scale up normals meta->addStatement( new GenOp( " @.xyz = @.xyz * 2.0 - 0.5;\r\n", bumpNorm, bumpNorm ) ); diff --git a/Engine/source/shaderGen/HLSL/shaderFeatureHLSL.cpp b/Engine/source/shaderGen/HLSL/shaderFeatureHLSL.cpp index 17cf6333c..0b40cfac3 100644 --- a/Engine/source/shaderGen/HLSL/shaderFeatureHLSL.cpp +++ b/Engine/source/shaderGen/HLSL/shaderFeatureHLSL.cpp @@ -365,7 +365,7 @@ Var* ShaderFeatureHLSL::getOutTexCoord( const char *name, // Statement allows for casting of different types which // eliminates vector truncation problems. - String statement = String::ToString( " @ = (%s)mul(@, @);\r\n", type ); + String statement = String::ToString( " @ = (%s)mul(@, @).xy;\r\n", type ); meta->addStatement( new GenOp( statement, texCoord, texMat, inTex ) ); } else @@ -811,7 +811,7 @@ Var* ShaderFeatureHLSL::addOutDetailTexCoord( Vector &compon texMat->constSortPos = cspPass; } - meta->addStatement( new GenOp( " @ = mul(@, @) * @;\r\n", outTex, texMat, inTex, detScale ) ); + meta->addStatement( new GenOp( " @ = mul(@, @).xy * @;\r\n", outTex, texMat, inTex, detScale ) ); } else { @@ -845,12 +845,22 @@ void DiffuseMapFeatHLSL::processVert( Vector &componentList, output = meta; } +U32 DiffuseMapFeatHLSL::getOutputTargets(const MaterialFeatureData &fd) const +{ + return fd.features[MFT_isDeferred] ? ShaderFeature::RenderTarget1 : ShaderFeature::DefaultTarget; +} + void DiffuseMapFeatHLSL::processPix( Vector &componentList, const MaterialFeatureData &fd ) { // grab connector texcoord register Var *inTex = getInTexCoord( "texCoord", "float2", true, componentList ); + //determine output target + ShaderFeature::OutputTarget targ = ShaderFeature::DefaultTarget; + if (fd.features[MFT_isDeferred]) + targ = ShaderFeature::RenderTarget1; + // create texture var Var *diffuseMap = new Var; diffuseMap->setType( "sampler2D" ); @@ -877,7 +887,7 @@ void DiffuseMapFeatHLSL::processPix( Vector &componentList, if (!fd.features[MFT_Imposter]) meta->addStatement(new GenOp(" @ = toLinear(@);\r\n", diffColor, diffColor)); - meta->addStatement( new GenOp( " @;\r\n", assignColor( diffColor, Material::Mul ) ) ); + meta->addStatement(new GenOp(" @;\r\n", assignColor(diffColor, Material::Mul, NULL, targ))); } else if(fd.features[MFT_DiffuseMapAtlas]) { @@ -944,7 +954,7 @@ void DiffuseMapFeatHLSL::processPix( Vector &componentList, if(!fd.features[MFT_PrePassConditioner]) { meta->addStatement(new GenOp(" @ = float4(@.xy, mipLod / @.w, 1.0);\r\n", new DecOp(diffColor), inTex, atParams)); - meta->addStatement(new GenOp(" @; return OUT;\r\n", assignColor(diffColor, Material::Mul))); + meta->addStatement(new GenOp(" @; return OUT;\r\n", assignColor(diffColor, Material::Mul, NULL, targ) ) ); return; } #endif @@ -962,15 +972,15 @@ void DiffuseMapFeatHLSL::processPix( Vector &componentList, if (!fd.features[MFT_Imposter]) meta->addStatement(new GenOp(" @ = toLinear(@);\r\n", diffColor, diffColor)); - meta->addStatement(new GenOp( " @;\r\n", assignColor(diffColor, Material::Mul))); + meta->addStatement(new GenOp(" @;\r\n", assignColor(diffColor, Material::Mul, NULL, targ) ) ); } else { meta->addStatement(new GenOp("@ = tex2D(@, @);\r\n", colorDecl, diffuseMap, inTex)); if (!fd.features[MFT_Imposter]) meta->addStatement(new GenOp(" @ = toLinear(@);\r\n", diffColor, diffColor)); - meta->addStatement(new GenOp(" @;\r\n", assignColor(diffColor, Material::Mul))); - } + meta->addStatement(new GenOp(" @;\r\n", assignColor(diffColor, Material::Mul, NULL, targ))); + } } ShaderFeature::Resources DiffuseMapFeatHLSL::getResources( const MaterialFeatureData &fd ) @@ -1087,6 +1097,11 @@ void OverlayTexFeatHLSL::setTexData( Material::StageData &stageDat, // Diffuse color //**************************************************************************** +U32 DiffuseFeatureHLSL::getOutputTargets(const MaterialFeatureData &fd) const +{ + return fd.features[MFT_isDeferred] ? ShaderFeature::RenderTarget1 : ShaderFeature::DefaultTarget; +} + void DiffuseFeatureHLSL::processPix( Vector &componentList, const MaterialFeatureData &fd ) { @@ -1096,8 +1111,34 @@ void DiffuseFeatureHLSL::processPix( Vector &componentList, diffuseMaterialColor->uniform = true; diffuseMaterialColor->constSortPos = cspPotentialPrimitive; - MultiLine * meta = new MultiLine; - meta->addStatement( new GenOp( " @;\r\n", assignColor( diffuseMaterialColor, Material::Mul ) ) ); + MultiLine* meta = new MultiLine; + Var *col = (Var*)LangElement::find("col"); + ShaderFeature::OutputTarget targ = ShaderFeature::DefaultTarget; + if (fd.features[MFT_isDeferred]) + { + targ = ShaderFeature::RenderTarget1; + + col = (Var*)LangElement::find("col1"); + MultiLine * meta = new MultiLine; + if (!col) + { + // create color var + col = new Var; + col->setType("fragout"); + col->setName(getOutputTargetVarName(targ)); + col->setStructName("OUT"); + meta->addStatement(new GenOp(" @ = float4(1.0);\r\n", col)); + } + } + + Material::BlendOp op; + + if (fd.features[MFT_DiffuseMap]) + op = Material::Mul; + else + op = Material::None; + + meta->addStatement( new GenOp( " @;\r\n", assignColor( diffuseMaterialColor, op, NULL, targ ) ) ); output = meta; } @@ -1243,8 +1284,8 @@ void LightmapFeatHLSL::processPix( Vector &componentList, MultiLine *meta = new MultiLine; if( fd.features[MFT_LightbufferMRT] ) { - meta->addStatement( new GenOp( " @;\r\n", assignColor( statement, Material::None, NULL, ShaderFeature::RenderTarget1 ) ) ); - meta->addStatement( new GenOp( " @.a = 0.0001;\r\n", LangElement::find( getOutputTargetVarName(ShaderFeature::RenderTarget1) ) ) ); + meta->addStatement( new GenOp( " @;\r\n", assignColor( statement, Material::None, NULL, ShaderFeature::RenderTarget3 ) ) ); + meta->addStatement( new GenOp( " @.a = 0.0001;\r\n", LangElement::find( getOutputTargetVarName(ShaderFeature::RenderTarget3) ) ) ); } else meta->addStatement( new GenOp( " @;\r\n", assignColor( statement, Material::Mul ) ) ); @@ -1276,7 +1317,7 @@ void LightmapFeatHLSL::setTexData( Material::StageData &stageDat, U32 LightmapFeatHLSL::getOutputTargets( const MaterialFeatureData &fd ) const { - return fd.features[MFT_LightbufferMRT] ? ShaderFeature::RenderTarget1 : ShaderFeature::DefaultTarget; + return fd.features[MFT_LightbufferMRT] ? ShaderFeature::RenderTarget3 : ShaderFeature::DefaultTarget; } //**************************************************************************** @@ -1370,8 +1411,8 @@ void TonemapFeatHLSL::processPix( Vector &componentList, // Assign to proper render target if( fd.features[MFT_LightbufferMRT] ) { - meta->addStatement( new GenOp( " @;\r\n", assignColor( toneMapColor, Material::None, NULL, ShaderFeature::RenderTarget1 ) ) ); - meta->addStatement( new GenOp( " @.a = 0.0001;\r\n", LangElement::find( getOutputTargetVarName(ShaderFeature::RenderTarget1) ) ) ); + meta->addStatement( new GenOp( " @;\r\n", assignColor( toneMapColor, Material::None, NULL, ShaderFeature::RenderTarget3 ) ) ); + meta->addStatement( new GenOp( " @.a = 0.0001;\r\n", LangElement::find( getOutputTargetVarName(ShaderFeature::RenderTarget3) ) ) ); } else meta->addStatement( new GenOp( " @;\r\n", assignColor( toneMapColor, blendOp ) ) ); @@ -1404,7 +1445,7 @@ void TonemapFeatHLSL::setTexData( Material::StageData &stageDat, U32 TonemapFeatHLSL::getOutputTargets( const MaterialFeatureData &fd ) const { - return fd.features[MFT_LightbufferMRT] ? ShaderFeature::RenderTarget1 : ShaderFeature::DefaultTarget; + return fd.features[MFT_LightbufferMRT] ? ShaderFeature::RenderTarget3 : ShaderFeature::DefaultTarget; } //**************************************************************************** @@ -1519,8 +1560,8 @@ void VertLitHLSL::processPix( Vector &componentList, // Output the color if ( fd.features[MFT_LightbufferMRT] ) { - meta->addStatement( new GenOp( " @;\r\n", assignColor( outColor, Material::None, NULL, ShaderFeature::RenderTarget1 ) ) ); - meta->addStatement( new GenOp( " @.a = 0.0001;\r\n", LangElement::find( getOutputTargetVarName(ShaderFeature::RenderTarget1) ) ) ); + meta->addStatement( new GenOp( " @;\r\n", assignColor( outColor, Material::None, NULL, ShaderFeature::RenderTarget3 ) ) ); + meta->addStatement( new GenOp( " @.a = 0.0001;\r\n", LangElement::find( getOutputTargetVarName(ShaderFeature::RenderTarget3) ) ) ); } else meta->addStatement( new GenOp( " @;\r\n", assignColor( outColor, blendOp ) ) ); @@ -1530,7 +1571,7 @@ void VertLitHLSL::processPix( Vector &componentList, U32 VertLitHLSL::getOutputTargets( const MaterialFeatureData &fd ) const { - return fd.features[MFT_LightbufferMRT] ? ShaderFeature::RenderTarget1 : ShaderFeature::DefaultTarget; + return fd.features[MFT_LightbufferMRT] ? ShaderFeature::RenderTarget3 : ShaderFeature::DefaultTarget; } //**************************************************************************** @@ -1569,7 +1610,10 @@ void DetailFeatHLSL::processPix( Vector &componentList, // and a simple multiplication with the detail map. LangElement *statement = new GenOp( "( tex2D(@, @) * 2.0 ) - 1.0", detailMap, inTex ); - output = new GenOp( " @;\r\n", assignColor( statement, Material::Add ) ); + if ( fd.features[MFT_isDeferred]) + output = new GenOp( " @;\r\n", assignColor( statement, Material::Add, NULL, ShaderFeature::RenderTarget1 ) ); + else + output = new GenOp( " @;\r\n", assignColor( statement, Material::Add ) ); } ShaderFeature::Resources DetailFeatHLSL::getResources( const MaterialFeatureData &fd ) @@ -1694,7 +1738,7 @@ void ReflectCubeFeatHLSL::processVert( Vector &componentList, cubeNormal->setType( "float3" ); LangElement *cubeNormDecl = new DecOp( cubeNormal ); - meta->addStatement( new GenOp( " @ = normalize( mul(@, float4(normalize(@),0.0)).xyz );\r\n", + meta->addStatement( new GenOp( " @ = normalize( mul(@, float4(normalize(@),0.0)).xyz );\r\n", cubeNormDecl, cubeTrans, inNormal ) ); // grab the eye position @@ -1767,9 +1811,14 @@ void ReflectCubeFeatHLSL::processPix( Vector &componentList, } else { - glossColor = (Var*) LangElement::find( "diffuseColor" ); - if( !glossColor ) - glossColor = (Var*) LangElement::find( "bumpNormal" ); + if (fd.features[MFT_isDeferred]) + glossColor = (Var*)LangElement::find(getOutputTargetVarName(ShaderFeature::RenderTarget1)); + if (!glossColor) + glossColor = (Var*)LangElement::find("specularColor"); + if (!glossColor) + glossColor = (Var*)LangElement::find("diffuseColor"); + if (!glossColor) + glossColor = (Var*)LangElement::find("bumpNormal"); } // grab connector texcoord register @@ -1795,15 +1844,41 @@ void ReflectCubeFeatHLSL::processPix( Vector &componentList, //else if ( fd.materialFeatures[MFT_RTLighting] ) attn =(Var*)LangElement::find("d_NL_Att"); + + LangElement *texCube = NULL; + Var* matinfo = (Var*) LangElement::find( getOutputTargetVarName(ShaderFeature::RenderTarget2) ); + //first try and grab the gbuffer + if (fd.features[MFT_isDeferred] && matinfo) + { + // Cube LOD level = (1.0 - Roughness) * 8 + // mip_levle = min((1.0 - u_glossiness)*11.0 + 1.0, 8.0) + //LangElement *texCube = new GenOp( "texCUBElod( @, float4(@, min((1.0 - (@ / 128.0)) * 11.0 + 1.0, 8.0)) )", cubeMap, reflectVec, specPower ); + + if (fd.features[MFT_DeferredSpecMap]) + texCube = new GenOp("texCUBElod( @, float4(@, (@.a*5)) )", cubeMap, reflectVec, matinfo); + else + texCube = new GenOp("texCUBElod( @, float4(@, (@.a/4)) )", cubeMap, reflectVec, matinfo); + } + else + if (glossColor) //failing that, rtry and find color data + texCube = new GenOp("texCUBElod( @, float4(@, @.a*5))", cubeMap, reflectVec, glossColor); + else //failing *that*, just draw the cubemap + texCube = new GenOp("texCUBE( @, @)", cubeMap, reflectVec); - LangElement *texCube = new GenOp( "texCUBE( @, @ )", cubeMap, reflectVec ); LangElement *lerpVal = NULL; Material::BlendOp blendOp = Material::LerpAlpha; // Note that the lerpVal needs to be a float4 so that // it will work with the LerpAlpha blend. - if ( glossColor ) + if (matinfo) + { + if (attn) + lerpVal = new GenOp("@ * saturate( @ )", matinfo, attn); + else + lerpVal = new GenOp("@", matinfo); + } + else if ( glossColor ) { if ( attn ) lerpVal = new GenOp( "@ * saturate( @ )", glossColor, attn ); @@ -1817,8 +1892,16 @@ void ReflectCubeFeatHLSL::processPix( Vector &componentList, else blendOp = Material::Mul; } - - meta->addStatement( new GenOp( " @;\r\n", assignColor( texCube, blendOp, lerpVal ) ) ); + if (fd.features[MFT_isDeferred]) + { + Var* targ = (Var*)LangElement::find(getOutputTargetVarName(ShaderFeature::RenderTarget1)); + if (fd.features[MFT_DeferredSpecMap]) + meta->addStatement(new GenOp(" @.rgb = lerp( @.rgb, (@).rgb, (@.b));\r\n", targ, targ, texCube, lerpVal)); + else + meta->addStatement(new GenOp(" @.rgb = lerp( @.rgb, (@).rgb, (@.b*128/5));\r\n", targ, targ, texCube, lerpVal)); + } + else + meta->addStatement( new GenOp( " @;\r\n", assignColor( texCube, blendOp, lerpVal ) ) ); output = meta; } @@ -1865,9 +1948,9 @@ void ReflectCubeFeatHLSL::setTexData( Material::StageData &stageDat, { passData.mSamplerNames[ texIndex ] = "bumpMap"; passData.mTexSlot[ texIndex++ ].texObject = tex; + } } } - } if( stageDat.getCubemap() ) { @@ -2347,7 +2430,9 @@ void AlphaTestHLSL::processPix( Vector &componentList, } // If we don't have a color var then we cannot do an alpha test. - Var *color = (Var*)LangElement::find( "col" ); + Var *color = (Var*)LangElement::find( "col1" ); + if (!color) + color = (Var*)LangElement::find("col"); if ( !color ) { output = NULL; @@ -2714,3 +2799,16 @@ void ImposterVertFeatureHLSL::determineFeature( Material *material, outFeatureData->features.addFeature( MFT_ImposterVert ); } + +//**************************************************************************** +// Vertex position +//**************************************************************************** +void DeferredSkyHLSL::processVert( Vector &componentList, + const MaterialFeatureData &fd ) +{ + Var *outPosition = (Var*)LangElement::find( "hpos" ); + MultiLine *meta = new MultiLine; + meta->addStatement( new GenOp( " @.w = @.z;\r\n", outPosition, outPosition ) ); + + output = meta; +} diff --git a/Engine/source/shaderGen/HLSL/shaderFeatureHLSL.h b/Engine/source/shaderGen/HLSL/shaderFeatureHLSL.h index 4f77c175a..b09d4d561 100644 --- a/Engine/source/shaderGen/HLSL/shaderFeatureHLSL.h +++ b/Engine/source/shaderGen/HLSL/shaderFeatureHLSL.h @@ -248,6 +248,8 @@ public: virtual void processPix( Vector &componentList, const MaterialFeatureData &fd ); + virtual U32 getOutputTargets(const MaterialFeatureData &fd) const; + virtual Material::BlendOp getBlendOp(){ return Material::LerpAlpha; } virtual Resources getResources( const MaterialFeatureData &fd ); @@ -301,6 +303,7 @@ public: virtual Material::BlendOp getBlendOp(){ return Material::None; } + virtual U32 getOutputTargets(const MaterialFeatureData &fd) const; virtual String getName() { return "Diffuse Color"; @@ -656,4 +659,12 @@ public: }; +class DeferredSkyHLSL : public ShaderFeatureHLSL +{ +public: + virtual String getName() { return "Deferred Shading: Sky"; } + virtual void processVert( Vector &componentList, + const MaterialFeatureData &fd ); +}; + #endif // _SHADERGEN_HLSL_SHADERFEATUREHLSL_H_ diff --git a/Engine/source/shaderGen/HLSL/shaderGenHLSLInit.cpp b/Engine/source/shaderGen/HLSL/shaderGenHLSLInit.cpp index a5c6165e0..fd30656bd 100644 --- a/Engine/source/shaderGen/HLSL/shaderGenHLSLInit.cpp +++ b/Engine/source/shaderGen/HLSL/shaderGenHLSLInit.cpp @@ -32,6 +32,8 @@ #include "shaderGen/HLSL/paraboloidHLSL.h" #include "materials/materialFeatureTypes.h" #include "core/module.h" +// Deferred Shading +#include "lighting/advanced/hlsl/deferredShadingFeaturesHLSL.h" #include "shaderGen/HLSL/accuFeatureHLSL.h" static ShaderGen::ShaderGenInitDelegate sInitDelegate; @@ -70,6 +72,8 @@ void _initShaderGenHLSL( ShaderGen *shaderGen ) FEATUREMGR->registerFeature( MFT_GlossMap, new NamedFeatureHLSL( "Gloss Map" ) ); FEATUREMGR->registerFeature( MFT_LightbufferMRT, new NamedFeatureHLSL( "Lightbuffer MRT" ) ); FEATUREMGR->registerFeature( MFT_RenderTarget1_Zero, new RenderTargetZeroHLSL( ShaderFeature::RenderTarget1 ) ); + FEATUREMGR->registerFeature( MFT_RenderTarget2_Zero, new RenderTargetZeroHLSL( ShaderFeature::RenderTarget2 ) ); + FEATUREMGR->registerFeature( MFT_RenderTarget3_Zero, new RenderTargetZeroHLSL( ShaderFeature::RenderTarget3 ) ); FEATUREMGR->registerFeature( MFT_Imposter, new NamedFeatureHLSL( "Imposter" ) ); FEATUREMGR->registerFeature( MFT_DiffuseMapAtlas, new NamedFeatureHLSL( "Diffuse Map Atlas" ) ); @@ -95,6 +99,14 @@ void _initShaderGenHLSL( ShaderGen *shaderGen ) FEATUREMGR->registerFeature( MFT_ForwardShading, new NamedFeatureHLSL( "Forward Shaded Material" ) ); FEATUREMGR->registerFeature( MFT_ImposterVert, new ImposterVertFeatureHLSL ); + + // Deferred Shading + FEATUREMGR->registerFeature( MFT_isDeferred, new NamedFeatureHLSL( "Deferred Material" ) ); + FEATUREMGR->registerFeature( MFT_DeferredSpecMap, new DeferredSpecMapHLSL ); + FEATUREMGR->registerFeature( MFT_DeferredSpecVars, new DeferredSpecVarsHLSL ); + FEATUREMGR->registerFeature( MFT_DeferredMatInfoFlags, new DeferredMatInfoFlagsHLSL ); + FEATUREMGR->registerFeature( MFT_DeferredEmptySpec, new DeferredEmptySpecHLSL ); + FEATUREMGR->registerFeature( MFT_SkyBox, new DeferredSkyHLSL ); } MODULE_BEGIN( ShaderGenHLSL ) diff --git a/Engine/source/shaderGen/shaderFeature.cpp b/Engine/source/shaderGen/shaderFeature.cpp index 9c1d8d955..7e22f72ad 100644 --- a/Engine/source/shaderGen/shaderFeature.cpp +++ b/Engine/source/shaderGen/shaderFeature.cpp @@ -47,10 +47,24 @@ ShaderFeature::Resources ShaderFeature::getResources( const MaterialFeatureData const char* ShaderFeature::getOutputTargetVarName( OutputTarget target ) const { const char* targName = "col"; - if ( target != DefaultTarget ) + + switch(target) { + case DefaultTarget: + targName = "col"; + break; + + case RenderTarget1: targName = "col1"; - AssertFatal(target == RenderTarget1, "yeah Pat is lame and didn't want to do bit math stuff, TODO"); + break; + + case RenderTarget2: + targName = "col2"; + break; + + case RenderTarget3: + targName = "col3"; + break; } return targName; diff --git a/Engine/source/shaderGen/shaderGenVars.cpp b/Engine/source/shaderGen/shaderGenVars.cpp index 3e5a577ee..f4aca6cf5 100644 --- a/Engine/source/shaderGen/shaderGenVars.cpp +++ b/Engine/source/shaderGen/shaderGenVars.cpp @@ -80,4 +80,7 @@ const String ShaderGenVars::cubeMap("$cubeMap"); const String ShaderGenVars::dLightMap("$dlightMap"); const String ShaderGenVars::dLightMapSec("$dlightMapSec"); const String ShaderGenVars::dLightMask("$dlightMask"); -const String ShaderGenVars::toneMap("$toneMap"); \ No newline at end of file +const String ShaderGenVars::toneMap("$toneMap"); + +// Deferred shading +const String ShaderGenVars::matInfoFlags("$matInfoFlags"); \ No newline at end of file diff --git a/Engine/source/shaderGen/shaderGenVars.h b/Engine/source/shaderGen/shaderGenVars.h index a98940101..52ff016d0 100644 --- a/Engine/source/shaderGen/shaderGenVars.h +++ b/Engine/source/shaderGen/shaderGenVars.h @@ -94,6 +94,9 @@ struct ShaderGenVars const static String dLightMapSec; const static String dLightMask; const static String toneMap; + + // Deferred Shading + const static String matInfoFlags; }; #endif diff --git a/Engine/source/terrain/glsl/terrFeatureGLSL.cpp b/Engine/source/terrain/glsl/terrFeatureGLSL.cpp index dd67124c6..b9105cdd2 100644 --- a/Engine/source/terrain/glsl/terrFeatureGLSL.cpp +++ b/Engine/source/terrain/glsl/terrFeatureGLSL.cpp @@ -26,6 +26,7 @@ #include "terrain/terrFeatureTypes.h" #include "materials/materialFeatureTypes.h" #include "materials/materialFeatureData.h" +#include "materials/processedMaterial.h" #include "gfx/gfxDevice.h" #include "shaderGen/langElement.h" #include "shaderGen/shaderOp.h" @@ -48,6 +49,10 @@ namespace FEATUREMGR->registerFeature( MFT_TerrainLightMap, new TerrainLightMapFeatGLSL ); FEATUREMGR->registerFeature( MFT_TerrainSideProject, new NamedFeatureGLSL( "Terrain Side Projection" ) ); FEATUREMGR->registerFeature( MFT_TerrainAdditive, new TerrainAdditiveFeatGLSL ); + FEATUREMGR->registerFeature( MFT_DeferredTerrainBaseMap, new TerrainBaseMapFeatGLSL ); + FEATUREMGR->registerFeature( MFT_DeferredTerrainMacroMap, new TerrainMacroMapFeatGLSL ); + FEATUREMGR->registerFeature( MFT_DeferredTerrainDetailMap, new TerrainDetailMapFeatGLSL ); + FEATUREMGR->registerFeature( MFT_DeferredTerrainBlankInfoMap, new TerrainBlankInfoMapFeatGLSL ); } }; @@ -250,10 +255,6 @@ void TerrainBaseMapFeatGLSL::processPix( Vector &componentLis // grab connector texcoord register Var *texCoord = getInTexCoord( "texCoord", "vec3", true, componentList ); - // We do nothing more if this is a prepass. - if ( fd.features.hasFeature( MFT_PrePassConditioner ) ) - return; - // create texture var Var *diffuseMap = new Var; diffuseMap->setType( "sampler2D" ); @@ -269,7 +270,14 @@ void TerrainBaseMapFeatGLSL::processPix( Vector &componentLis baseColor->setName( "baseColor" ); meta->addStatement( new GenOp( " @ = tex2D( @, @.xy );\r\n", new DecOp( baseColor ), diffuseMap, texCoord ) ); meta->addStatement(new GenOp(" @ = toLinear(@);\r\n", baseColor, baseColor)); - meta->addStatement( new GenOp( " @;\r\n", assignColor( baseColor, Material::Mul ) ) ); + + ShaderFeature::OutputTarget target = ShaderFeature::DefaultTarget; + + if(fd.features.hasFeature(MFT_isDeferred)) + { + target= ShaderFeature::RenderTarget1; + } + meta->addStatement( new GenOp( " @;\r\n", assignColor( baseColor, Material::Mul,NULL,target ) ) ); output = meta; } @@ -278,14 +286,16 @@ ShaderFeature::Resources TerrainBaseMapFeatGLSL::getResources( const MaterialFea { Resources res; res.numTexReg = 1; - - // We only sample from the base map during a diffuse pass. - if ( !fd.features.hasFeature( MFT_PrePassConditioner ) ) res.numTex = 1; return res; } +U32 TerrainBaseMapFeatGLSL::getOutputTargets( const MaterialFeatureData &fd ) const +{ + return fd.features[MFT_isDeferred] ? ShaderFeature::RenderTarget1 : ShaderFeature::DefaultTarget; +} + TerrainDetailMapFeatGLSL::TerrainDetailMapFeatGLSL() : mTorqueDep( "shaders/common/gl/torque.glsl" ), mTerrainDep( "shaders/common/terrain/terrain.glsl" ) @@ -386,6 +396,9 @@ void TerrainDetailMapFeatGLSL::processPix( Vector &component const S32 detailIndex = getProcessIndex(); Var *inTex = getVertTexCoord( "texCoord" ); + // new terrain + bool hasNormal = fd.features.hasFeature(MFT_TerrainNormalMap, detailIndex); + MultiLine *meta = new MultiLine; // We need the negative tangent space view vector @@ -454,6 +467,100 @@ void TerrainDetailMapFeatGLSL::processPix( Vector &component meta->addStatement( new GenOp( " @ = calcBlend( @.x, @.xy, @, @ );\r\n", new DecOp( detailBlend ), detailInfo, inTex, layerSize, layerSample ) ); + // New terrain + + Var *lerpBlend = (Var*)LangElement::find("lerpBlend"); + if (!lerpBlend) + { + lerpBlend = new Var; + lerpBlend->setType("float"); + lerpBlend->setName("lerpBlend"); + lerpBlend->uniform = true; + lerpBlend->constSortPos = cspPrimitive; + } + + + Var *blendDepth = (Var*)LangElement::find(String::ToString("blendDepth%d", detailIndex)); + if (!blendDepth) + { + blendDepth = new Var; + blendDepth->setType("float"); + blendDepth->setName(String::ToString("blendDepth%d", detailIndex)); + blendDepth->uniform = true; + blendDepth->constSortPos = cspPrimitive; + } + + Var *baseColor = (Var*)LangElement::find("baseColor"); + ShaderFeature::OutputTarget target = ShaderFeature::DefaultTarget; + + if(fd.features.hasFeature( MFT_DeferredTerrainDetailMap )) + target= ShaderFeature::RenderTarget1; + + Var *outColor = (Var*)LangElement::find( getOutputTargetVarName(target) ); + + if (!outColor) + { + // create color var + outColor = new Var; + outColor->setType("float4"); + outColor->setName("col"); + outColor->setStructName("OUT"); + meta->addStatement(new GenOp(" @;\r\n", outColor)); + } + + Var *detailColor = (Var*)LangElement::find("detailColor"); + if (!detailColor) + { + detailColor = new Var; + detailColor->setType("float4"); + detailColor->setName("detailColor"); + meta->addStatement(new GenOp(" @;\r\n", new DecOp(detailColor))); + } + + // Get the detail texture. + Var *detailMap = new Var; + detailMap->setType("sampler2D"); + detailMap->setName(String::ToString("detailMap%d", detailIndex)); + detailMap->uniform = true; + detailMap->sampler = true; + detailMap->constNum = Var::getTexUnitNum(); // used as texture unit num here + + // Get the normal map texture. + Var *normalMap = _getNormalMapTex(); + + // Issue happens somewhere here ----- + + // Sample the normal map. + // + // We take two normal samples and lerp between them for + // side projection layers... else a single sample. + LangElement *texOp; + + // Note that we're doing the standard greyscale detail + // map technique here which can darken and lighten the + // diffuse texture. + // + // We take two color samples and lerp between them for + // side projection layers... else a single sample. + // + if (fd.features.hasFeature(MFT_TerrainSideProject, detailIndex)) + { + meta->addStatement(new GenOp(" @ = ( lerp( tex2D( @, @.yz ), tex2D( @, @.xz ), @.z ) * 2.0 ) - 1.0;\r\n", + detailColor, detailMap, inDet, detailMap, inDet, inTex)); + + texOp = new GenOp("lerp( tex2D( @, @.yz ), tex2D( @, @.xz ), @.z )", + normalMap, inDet, normalMap, inDet, inTex); + } + else + { + meta->addStatement(new GenOp(" @ = ( tex2D( @, @.xy ) * 2.0 ) - 1.0;\r\n", + detailColor, detailMap, inDet)); + + texOp = new GenOp("tex2D(@, @.xy)", normalMap, inDet); + } + + // New terrain + // Get a var and accumulate the blend amount. Var *blendTotal = (Var*)LangElement::find( "blendTotal" ); if ( !blendTotal ) @@ -487,46 +594,6 @@ void TerrainDetailMapFeatGLSL::processPix( Vector &component } } - // If this is a prepass then we skip color. - if ( fd.features.hasFeature( MFT_PrePassConditioner ) ) - { - // Check to see if we have a gbuffer normal. - Var *gbNormal = (Var*)LangElement::find( "gbNormal" ); - - // If we have a gbuffer normal and we don't have a - // normal map feature then we need to lerp in a - // default normal else the normals below this layer - // will show thru. - if ( gbNormal && - !fd.features.hasFeature( MFT_TerrainNormalMap, detailIndex ) ) - { - Var *viewToTangent = getInViewToTangent( componentList ); - - meta->addStatement( new GenOp( " @ = lerp( @, tGetMatrix3Row(@, 2), min( @, @.w ) );\r\n", - gbNormal, gbNormal, viewToTangent, detailBlend, inDet ) ); - } - - output = meta; - return; - } - - Var *detailColor = (Var*)LangElement::find( "detailColor" ); - if ( !detailColor ) - { - detailColor = new Var; - detailColor->setType( "vec4" ); - detailColor->setName( "detailColor" ); - meta->addStatement( new GenOp( " @;\r\n", new DecOp( detailColor ) ) ); - } - - // Get the detail texture. - Var *detailMap = new Var; - detailMap->setType( "sampler2D" ); - detailMap->setName( String::ToString( "detailMap%d", detailIndex ) ); - detailMap->uniform = true; - detailMap->sampler = true; - detailMap->constNum = Var::getTexUnitNum(); // used as texture unit num here - // If we're using SM 3.0 then take advantage of // dynamic branching to skip layers per-pixel. @@ -557,9 +624,6 @@ void TerrainDetailMapFeatGLSL::processPix( Vector &component meta->addStatement( new GenOp( " @ *= @.y * @.w;\r\n", detailColor, detailInfo, inDet ) ); - Var *baseColor = (Var*)LangElement::find( "baseColor" ); - Var *outColor = (Var*)LangElement::find( "col" ); - meta->addStatement( new GenOp( " @ = lerp( @, @ + @, @ );\r\n", outColor, outColor, baseColor, detailColor, detailBlend ) ); @@ -585,9 +649,7 @@ ShaderFeature::Resources TerrainDetailMapFeatGLSL::getResources( const MaterialF res.numTexReg += 4; } - // If this isn't the prepass then we sample - // from the detail texture for diffuse coloring. - if ( !fd.features.hasFeature( MFT_PrePassConditioner ) ) + // sample from the detail texture for diffuse coloring. res.numTex += 1; // If we have parallax for this layer then we'll also @@ -602,6 +664,11 @@ ShaderFeature::Resources TerrainDetailMapFeatGLSL::getResources( const MaterialF return res; } +U32 TerrainDetailMapFeatGLSL::getOutputTargets( const MaterialFeatureData &fd ) const +{ + return fd.features[MFT_DeferredTerrainDetailMap] ? ShaderFeature::RenderTarget1 : ShaderFeature::DefaultTarget; +} + TerrainMacroMapFeatGLSL::TerrainMacroMapFeatGLSL() : mTorqueDep( "shaders/common/gl/torque.glsl" ), @@ -759,29 +826,6 @@ void TerrainMacroMapFeatGLSL::processPix( Vector &componentL // Add to the blend total. meta->addStatement( new GenOp( " @ = max( @, @ );\r\n", blendTotal, blendTotal, detailBlend ) ); - // If this is a prepass then we skip color. - if ( fd.features.hasFeature( MFT_PrePassConditioner ) ) - { - // Check to see if we have a gbuffer normal. - Var *gbNormal = (Var*)LangElement::find( "gbNormal" ); - - // If we have a gbuffer normal and we don't have a - // normal map feature then we need to lerp in a - // default normal else the normals below this layer - // will show thru. - if ( gbNormal && - !fd.features.hasFeature( MFT_TerrainNormalMap, detailIndex ) ) - { - Var *viewToTangent = getInViewToTangent( componentList ); - - meta->addStatement( new GenOp( " @ = lerp( @, tGetMatrix3Row(@, 2), min( @, @.w ) );\r\n", - gbNormal, gbNormal, viewToTangent, detailBlend, inDet ) ); - } - - output = meta; - return; - } - Var *detailColor = (Var*)LangElement::find( "macroColor" ); if ( !detailColor ) { @@ -826,8 +870,12 @@ void TerrainMacroMapFeatGLSL::processPix( Vector &componentL meta->addStatement( new GenOp( " @ *= @.y * @.w;\r\n", detailColor, detailInfo, inDet ) ); + ShaderFeature::OutputTarget target = ShaderFeature::DefaultTarget; - Var *outColor = (Var*)LangElement::find( "col" ); + if(fd.features.hasFeature(MFT_DeferredTerrainMacroMap)) + target= ShaderFeature::RenderTarget1; + + Var *outColor = (Var*)LangElement::find( getOutputTargetVarName(target) ); meta->addStatement( new GenOp( " @ = lerp( @, @ + @, @ );\r\n", outColor, outColor, outColor, detailColor, detailBlend ) ); @@ -850,9 +898,6 @@ ShaderFeature::Resources TerrainMacroMapFeatGLSL::getResources( const MaterialFe res.numTex += 1; } - // If this isn't the prepass then we sample - // from the detail texture for diffuse coloring. - if ( !fd.features.hasFeature( MFT_PrePassConditioner ) ) res.numTex += 1; // Finally we always send the detail texture @@ -862,6 +907,11 @@ ShaderFeature::Resources TerrainMacroMapFeatGLSL::getResources( const MaterialFe return res; } +U32 TerrainMacroMapFeatGLSL::getOutputTargets( const MaterialFeatureData &fd ) const +{ + return fd.features[MFT_DeferredTerrainMacroMap] ? ShaderFeature::RenderTarget1 : ShaderFeature::DefaultTarget; +} + void TerrainNormalMapFeatGLSL::processVert( Vector &componentList, const MaterialFeatureData &fd ) { @@ -881,9 +931,6 @@ void TerrainNormalMapFeatGLSL::processVert( Vector &component void TerrainNormalMapFeatGLSL::processPix( Vector &componentList, const MaterialFeatureData &fd ) { - // We only need to process normals during the prepass. - if ( !fd.features.hasFeature( MFT_PrePassConditioner ) ) - return; MultiLine *meta = new MultiLine; @@ -1023,7 +1070,12 @@ ShaderFeature::Resources TerrainLightMapFeatGLSL::getResources( const MaterialFe void TerrainAdditiveFeatGLSL::processPix( Vector &componentList, const MaterialFeatureData &fd ) { - Var *color = (Var*) LangElement::find( "col" ); + Var *color = NULL; + if (fd.features[MFT_DeferredTerrainDetailMap]) + color = (Var*) LangElement::find( getOutputTargetVarName(ShaderFeature::RenderTarget1) ); + else + color = (Var*) LangElement::find( getOutputTargetVarName(ShaderFeature::DefaultTarget) ); + Var *blendTotal = (Var*)LangElement::find( "blendTotal" ); if ( !color || !blendTotal ) return; @@ -1035,3 +1087,40 @@ void TerrainAdditiveFeatGLSL::processPix( Vector &componentLis output = meta; } + +//standard matInfo map contains data of the form .r = bitflags, .g = (will contain AO), +//.b = specular strength, a= spec power. +//here, it's merely a cutout for now, so that lightmapping (target3) doesn't get mangled. +//we'll most likely revisit that later. possibly several ways... + +U32 TerrainBlankInfoMapFeatGLSL::getOutputTargets(const MaterialFeatureData &fd) const +{ + return fd.features[MFT_isDeferred] ? ShaderFeature::RenderTarget2 : ShaderFeature::RenderTarget1; +} + +void TerrainBlankInfoMapFeatGLSL::processPix(Vector &componentList, + const MaterialFeatureData &fd) +{ + // search for material var + Var *material; + OutputTarget targ = RenderTarget1; + if (fd.features[MFT_isDeferred]) + { + targ = RenderTarget2; + } + material = (Var*)LangElement::find(getOutputTargetVarName(targ)); + + MultiLine * meta = new MultiLine; + if (!material) + { + // create color var + material = new Var; + material->setType("vec4"); + material->setName(getOutputTargetVarName(targ)); + material->setStructName("OUT"); + } + + meta->addStatement(new GenOp(" @ = float4(0.0,0.0,0.0,0.0001);\r\n", material)); + + output = meta; +} diff --git a/Engine/source/terrain/glsl/terrFeatureGLSL.h b/Engine/source/terrain/glsl/terrFeatureGLSL.h index 6cb3a3c0c..7839558b1 100644 --- a/Engine/source/terrain/glsl/terrFeatureGLSL.h +++ b/Engine/source/terrain/glsl/terrFeatureGLSL.h @@ -67,6 +67,8 @@ public: virtual Resources getResources( const MaterialFeatureData &fd ); virtual String getName() { return "Terrain Base Texture"; } + + virtual U32 getOutputTargets( const MaterialFeatureData &fd ) const; }; @@ -90,6 +92,8 @@ public: virtual Resources getResources( const MaterialFeatureData &fd ); virtual String getName() { return "Terrain Detail Texture"; } + + virtual U32 getOutputTargets( const MaterialFeatureData &fd ) const; }; @@ -113,6 +117,8 @@ public: virtual Resources getResources( const MaterialFeatureData &fd ); virtual String getName() { return "Terrain Macro Texture"; } + + virtual U32 getOutputTargets( const MaterialFeatureData &fd ) const; }; @@ -154,4 +160,15 @@ public: virtual String getName() { return "Terrain Additive"; } }; +class TerrainBlankInfoMapFeatGLSL : public ShaderFeatureGLSL +{ +public: + + virtual void processPix(Vector &componentList, + const MaterialFeatureData &fd); + + virtual U32 getOutputTargets(const MaterialFeatureData &fd) const; + virtual String getName() { return "Blank Matinfo map"; } +}; + #endif // _TERRFEATUREGLSL_H_ diff --git a/Engine/source/terrain/hlsl/terrFeatureHLSL.cpp b/Engine/source/terrain/hlsl/terrFeatureHLSL.cpp index d993f4bd8..b0e16bb64 100644 --- a/Engine/source/terrain/hlsl/terrFeatureHLSL.cpp +++ b/Engine/source/terrain/hlsl/terrFeatureHLSL.cpp @@ -26,6 +26,7 @@ #include "terrain/terrFeatureTypes.h" #include "materials/materialFeatureTypes.h" #include "materials/materialFeatureData.h" +#include "materials/processedMaterial.h" #include "gfx/gfxDevice.h" #include "shaderGen/langElement.h" #include "shaderGen/shaderOp.h" @@ -47,9 +48,12 @@ namespace FEATUREMGR->registerFeature( MFT_TerrainMacroMap, new TerrainMacroMapFeatHLSL ); FEATUREMGR->registerFeature( MFT_TerrainLightMap, new TerrainLightMapFeatHLSL ); FEATUREMGR->registerFeature( MFT_TerrainSideProject, new NamedFeatureHLSL( "Terrain Side Projection" ) ); - FEATUREMGR->registerFeature( MFT_TerrainAdditive, new TerrainAdditiveFeatHLSL ); + FEATUREMGR->registerFeature( MFT_TerrainAdditive, new TerrainAdditiveFeatHLSL ); + FEATUREMGR->registerFeature( MFT_DeferredTerrainBaseMap, new TerrainBaseMapFeatHLSL ); + FEATUREMGR->registerFeature( MFT_DeferredTerrainMacroMap, new TerrainMacroMapFeatHLSL ); + FEATUREMGR->registerFeature( MFT_DeferredTerrainDetailMap, new TerrainDetailMapFeatHLSL ); + FEATUREMGR->registerFeature( MFT_DeferredTerrainBlankInfoMap, new TerrainBlankInfoMapFeatHLSL ); } - }; MODULE_BEGIN( TerrainFeatHLSL ) @@ -250,10 +254,6 @@ void TerrainBaseMapFeatHLSL::processPix( Vector &componentLis // grab connector texcoord register Var *texCoord = getInTexCoord( "texCoord", "float3", true, componentList ); - // We do nothing more if this is a prepass. - if ( fd.features.hasFeature( MFT_PrePassConditioner ) ) - return; - // create texture var Var *diffuseMap = new Var; diffuseMap->setType( "sampler2D" ); @@ -269,8 +269,15 @@ void TerrainBaseMapFeatHLSL::processPix( Vector &componentLis baseColor->setName( "baseColor" ); meta->addStatement( new GenOp( " @ = tex2D( @, @.xy );\r\n", new DecOp( baseColor ), diffuseMap, texCoord ) ); meta->addStatement(new GenOp(" @ = toLinear(@);\r\n", baseColor, baseColor)); - meta->addStatement( new GenOp( " @;\r\n", assignColor( baseColor, Material::Mul ) ) ); + ShaderFeature::OutputTarget target = ShaderFeature::DefaultTarget; + + if (fd.features.hasFeature(MFT_isDeferred)) + { + target= ShaderFeature::RenderTarget1; + } + + meta->addStatement( new GenOp( " @;\r\n", assignColor( baseColor, Material::Mul,NULL,target ) ) ); output = meta; } @@ -278,14 +285,16 @@ ShaderFeature::Resources TerrainBaseMapFeatHLSL::getResources( const MaterialFea { Resources res; res.numTexReg = 1; - - // We only sample from the base map during a diffuse pass. - if ( !fd.features.hasFeature( MFT_PrePassConditioner ) ) res.numTex = 1; return res; } +U32 TerrainBaseMapFeatHLSL::getOutputTargets( const MaterialFeatureData &fd ) const +{ + return fd.features[MFT_DeferredTerrainBaseMap] ? ShaderFeature::RenderTarget1 : ShaderFeature::DefaultTarget; +} + TerrainDetailMapFeatHLSL::TerrainDetailMapFeatHLSL() : mTorqueDep( "shaders/common/torque.hlsl" ), mTerrainDep( "shaders/common/terrain/terrain.hlsl" ) @@ -477,7 +486,7 @@ void TerrainDetailMapFeatHLSL::processPix( Vector &component // Call the library function to do the rest. if(fd.features.hasFeature( MFT_IsDXTnm, detailIndex ) ) { - meta->addStatement( new GenOp( " @.xy += parallaxOffsetDxtnm( @, @.xy, @, @.z * @ );\r\n", + meta->addStatement( new GenOp( " @.xy += parallaxOffsetDxtnm( @, @.xy, @, @.z * @ );\r\n", inDet, normalMap, inDet, negViewTS, detailInfo, detailBlend ) ); } else @@ -487,29 +496,6 @@ void TerrainDetailMapFeatHLSL::processPix( Vector &component } } - // If this is a prepass then we skip color. - if ( fd.features.hasFeature( MFT_PrePassConditioner ) ) - { - // Check to see if we have a gbuffer normal. - Var *gbNormal = (Var*)LangElement::find( "gbNormal" ); - - // If we have a gbuffer normal and we don't have a - // normal map feature then we need to lerp in a - // default normal else the normals below this layer - // will show thru. - if ( gbNormal && - !fd.features.hasFeature( MFT_TerrainNormalMap, detailIndex ) ) - { - Var *viewToTangent = getInViewToTangent( componentList ); - - meta->addStatement( new GenOp( " @ = lerp( @, @[2], min( @, @.w ) );\r\n", - gbNormal, gbNormal, viewToTangent, detailBlend, inDet ) ); - } - - output = meta; - return; - } - Var *detailColor = (Var*)LangElement::find( "detailColor" ); if ( !detailColor ) { @@ -543,21 +529,35 @@ void TerrainDetailMapFeatHLSL::processPix( Vector &component // We take two color samples and lerp between them for // side projection layers... else a single sample. // + + //Sampled detail texture that is not expanded + Var *detailTex = new Var; + detailTex->setType("float4"); + detailTex->setName("detailTex"); + meta->addStatement( new GenOp( " @;\r\n", new DecOp( detailTex ) ) ); + if ( fd.features.hasFeature( MFT_TerrainSideProject, detailIndex ) ) { - meta->addStatement( new GenOp( " @ = ( lerp( tex2D( @, @.yz ), tex2D( @, @.xz ), @.z ) * 2.0 ) - 1.0;\r\n", - detailColor, detailMap, inDet, detailMap, inDet, inTex ) ); + meta->addStatement( new GenOp(" @ = lerp( tex2D( @, @.yz ), tex2D( @, @.xz ), @.z);\r\n",detailTex,detailMap,inDet,detailMap,inDet,inTex)); + meta->addStatement( new GenOp( " @ = ( @ * 2.0 ) - 1.0;\r\n", detailColor, detailTex) ); } else { - meta->addStatement( new GenOp( " @ = ( tex2D( @, @.xy ) * 2.0 ) - 1.0;\r\n", - detailColor, detailMap, inDet ) ); + meta->addStatement( new GenOp(" @ = tex2D(@,@.xy);\r\n",detailTex,detailMap,inDet)); + meta->addStatement( new GenOp( " @ = ( @ * 2.0 ) - 1.0;\r\n", + detailColor, detailTex) ); } meta->addStatement( new GenOp( " @ *= @.y * @.w;\r\n", detailColor, detailInfo, inDet ) ); - Var *outColor = (Var*)LangElement::find( "col" ); + Var *baseColor = (Var*)LangElement::find( "baseColor" ); + ShaderFeature::OutputTarget target = ShaderFeature::DefaultTarget; + + if(fd.features.hasFeature( MFT_DeferredTerrainDetailMap )) + target= ShaderFeature::RenderTarget1; + + Var *outColor = (Var*)LangElement::find( getOutputTargetVarName(target) ); meta->addStatement( new GenOp( " @ += @ * @;\r\n", outColor, detailColor, detailBlend)); @@ -584,9 +584,7 @@ ShaderFeature::Resources TerrainDetailMapFeatHLSL::getResources( const MaterialF res.numTexReg += 4; } - // If this isn't the prepass then we sample - // from the detail texture for diffuse coloring. - if ( !fd.features.hasFeature( MFT_PrePassConditioner ) ) + // sample from the detail texture for diffuse coloring. res.numTex += 1; // If we have parallax for this layer then we'll also @@ -601,6 +599,11 @@ ShaderFeature::Resources TerrainDetailMapFeatHLSL::getResources( const MaterialF return res; } +U32 TerrainDetailMapFeatHLSL::getOutputTargets( const MaterialFeatureData &fd ) const +{ + return fd.features[MFT_DeferredTerrainDetailMap] ? ShaderFeature::RenderTarget1 : ShaderFeature::DefaultTarget; +} + TerrainMacroMapFeatHLSL::TerrainMacroMapFeatHLSL() : mTorqueDep( "shaders/common/torque.hlsl" ), @@ -758,29 +761,6 @@ void TerrainMacroMapFeatHLSL::processPix( Vector &componentL // Add to the blend total. meta->addStatement( new GenOp( " @ += @;\r\n", blendTotal, detailBlend ) ); - // If this is a prepass then we skip color. - if ( fd.features.hasFeature( MFT_PrePassConditioner ) ) - { - // Check to see if we have a gbuffer normal. - Var *gbNormal = (Var*)LangElement::find( "gbNormal" ); - - // If we have a gbuffer normal and we don't have a - // normal map feature then we need to lerp in a - // default normal else the normals below this layer - // will show thru. - if ( gbNormal && - !fd.features.hasFeature( MFT_TerrainNormalMap, detailIndex ) ) - { - Var *viewToTangent = getInViewToTangent( componentList ); - - meta->addStatement( new GenOp( " @ = lerp( @, @[2], min( @, @.w ) );\r\n", - gbNormal, gbNormal, viewToTangent, detailBlend, inDet ) ); - } - - output = meta; - return; - } - Var *detailColor = (Var*)LangElement::find( "macroColor" ); if ( !detailColor ) { @@ -826,8 +806,14 @@ void TerrainMacroMapFeatHLSL::processPix( Vector &componentL meta->addStatement( new GenOp( " @ *= @.y * @.w;\r\n", detailColor, detailInfo, inDet ) ); - //Var *baseColor = (Var*)LangElement::find( "baseColor" ); - Var *outColor = (Var*)LangElement::find( "col" ); + Var *baseColor = (Var*)LangElement::find( "baseColor" ); + + ShaderFeature::OutputTarget target = ShaderFeature::DefaultTarget; + + if(fd.features.hasFeature(MFT_DeferredTerrainMacroMap)) + target= ShaderFeature::RenderTarget1; + + Var *outColor = (Var*)LangElement::find( getOutputTargetVarName(target) ); meta->addStatement(new GenOp(" @ += @ * @;\r\n", outColor, detailColor, detailBlend)); @@ -837,8 +823,6 @@ void TerrainMacroMapFeatHLSL::processPix( Vector &componentL output = meta; } - - ShaderFeature::Resources TerrainMacroMapFeatHLSL::getResources( const MaterialFeatureData &fd ) { Resources res; @@ -850,9 +834,6 @@ ShaderFeature::Resources TerrainMacroMapFeatHLSL::getResources( const MaterialFe res.numTex += 1; } - // If this isn't the prepass then we sample - // from the detail texture for diffuse coloring. - if ( !fd.features.hasFeature( MFT_PrePassConditioner ) ) res.numTex += 1; // Finally we always send the detail texture @@ -862,6 +843,11 @@ ShaderFeature::Resources TerrainMacroMapFeatHLSL::getResources( const MaterialFe return res; } +U32 TerrainMacroMapFeatHLSL::getOutputTargets( const MaterialFeatureData &fd ) const +{ + return fd.features[MFT_DeferredTerrainMacroMap] ? ShaderFeature::RenderTarget1 : ShaderFeature::DefaultTarget; +} + void TerrainNormalMapFeatHLSL::processVert( Vector &componentList, const MaterialFeatureData &fd ) { @@ -881,9 +867,6 @@ void TerrainNormalMapFeatHLSL::processVert( Vector &component void TerrainNormalMapFeatHLSL::processPix( Vector &componentList, const MaterialFeatureData &fd ) { - // We only need to process normals during the prepass. - if ( !fd.features.hasFeature( MFT_PrePassConditioner ) ) - return; MultiLine *meta = new MultiLine; @@ -1019,11 +1002,15 @@ ShaderFeature::Resources TerrainLightMapFeatHLSL::getResources( const MaterialFe return res; } - void TerrainAdditiveFeatHLSL::processPix( Vector &componentList, const MaterialFeatureData &fd ) { - Var *color = (Var*) LangElement::find( "col" ); + Var *color = NULL; + if (fd.features[MFT_DeferredTerrainDetailMap]) + color = (Var*) LangElement::find( getOutputTargetVarName(ShaderFeature::RenderTarget1) ); + else + color = (Var*) LangElement::find( getOutputTargetVarName(ShaderFeature::DefaultTarget) ); + Var *blendTotal = (Var*)LangElement::find( "blendTotal" ); if ( !color || !blendTotal ) return; @@ -1033,5 +1020,43 @@ void TerrainAdditiveFeatHLSL::processPix( Vector &componentLis meta->addStatement( new GenOp( " clip( @ - 0.0001 );\r\n", blendTotal ) ); meta->addStatement( new GenOp( " @.a = @;\r\n", color, blendTotal ) ); + + output = meta; +} + +//standard matInfo map contains data of the form .r = bitflags, .g = (will contain AO), +//.b = specular strength, a= spec power. +//here, it's merely a cutout for now, so that lightmapping (target3) doesn't get mangled. +//we'll most likely revisit that later. possibly several ways... + +U32 TerrainBlankInfoMapFeatHLSL::getOutputTargets(const MaterialFeatureData &fd) const +{ + return fd.features[MFT_DeferredTerrainBaseMap] ? ShaderFeature::RenderTarget2 : ShaderFeature::RenderTarget1; +} + +void TerrainBlankInfoMapFeatHLSL::processPix(Vector &componentList, + const MaterialFeatureData &fd) +{ + // search for material var + Var *material; + OutputTarget targ = RenderTarget1; + if (fd.features[MFT_isDeferred]) + { + targ = RenderTarget2; + } + material = (Var*)LangElement::find(getOutputTargetVarName(targ)); + + MultiLine * meta = new MultiLine; + if (!material) + { + // create color var + material = new Var; + material->setType("fragout"); + material->setName(getOutputTargetVarName(targ)); + material->setStructName("OUT"); + } + + meta->addStatement(new GenOp(" @ = float4(0.0,0.0,0.0,0.0001);\r\n", material)); + output = meta; } diff --git a/Engine/source/terrain/hlsl/terrFeatureHLSL.h b/Engine/source/terrain/hlsl/terrFeatureHLSL.h index e6297f3b4..2effbdc36 100644 --- a/Engine/source/terrain/hlsl/terrFeatureHLSL.h +++ b/Engine/source/terrain/hlsl/terrFeatureHLSL.h @@ -68,6 +68,8 @@ public: virtual Resources getResources( const MaterialFeatureData &fd ); virtual String getName() { return "Terrain Base Texture"; } + + virtual U32 getOutputTargets( const MaterialFeatureData &fd ) const; }; @@ -91,6 +93,8 @@ public: virtual Resources getResources( const MaterialFeatureData &fd ); virtual String getName() { return "Terrain Detail Texture"; } + + virtual U32 getOutputTargets( const MaterialFeatureData &fd ) const; }; @@ -114,6 +118,8 @@ public: virtual Resources getResources( const MaterialFeatureData &fd ); virtual String getName() { return "Terrain Macro Texture"; } + + virtual U32 getOutputTargets( const MaterialFeatureData &fd ) const; }; @@ -155,4 +161,15 @@ public: virtual String getName() { return "Terrain Additive"; } }; +class TerrainBlankInfoMapFeatHLSL : public TerrainFeatHLSL +{ +public: + + virtual void processPix(Vector &componentList, + const MaterialFeatureData &fd); + + virtual U32 getOutputTargets(const MaterialFeatureData &fd) const; + virtual String getName() { return "Blank Matinfo map"; } +}; + #endif // _TERRFEATUREHLSL_H_ diff --git a/Engine/source/terrain/terrCellMaterial.cpp b/Engine/source/terrain/terrCellMaterial.cpp index 101c21f0c..3b96a1318 100644 --- a/Engine/source/terrain/terrCellMaterial.cpp +++ b/Engine/source/terrain/terrCellMaterial.cpp @@ -37,6 +37,7 @@ #include "gfx/util/screenspace.h" #include "lighting/advanced/advancedLightBinManager.h" +S32 sgMaxTerrainMaterialsPerPass = 3; AFTER_MODULE_INIT( MaterialManager ) { @@ -310,12 +311,12 @@ bool TerrainCellMaterial::_createPass( Vector *materials, if ( GFX->getPixelShaderVersion() < 3.0f ) baseOnly = true; - // NOTE: At maximum we only try to combine 3 materials + // NOTE: At maximum we only try to combine sgMaxTerrainMaterialsPerPass materials // into a single pass. This is sub-optimal for the simplest // cases, but the most common case results in much fewer // shader generation failures and permutations leading to // faster load time and less hiccups during gameplay. - U32 matCount = getMin( 3, materials->size() ); + U32 matCount = getMin( sgMaxTerrainMaterialsPerPass, materials->size() ); Vector normalMaps; @@ -349,24 +350,27 @@ bool TerrainCellMaterial::_createPass( Vector *materials, { FeatureSet features; features.addFeature( MFT_VertTransform ); - features.addFeature( MFT_TerrainBaseMap ); if ( prePassMat ) { features.addFeature( MFT_EyeSpaceDepthOut ); features.addFeature( MFT_PrePassConditioner ); + features.addFeature( MFT_DeferredTerrainBaseMap ); + features.addFeature(MFT_isDeferred); if ( advancedLightmapSupport ) - features.addFeature( MFT_RenderTarget1_Zero ); + features.addFeature( MFT_RenderTarget3_Zero ); } else { + features.addFeature( MFT_TerrainBaseMap ); features.addFeature( MFT_RTLighting ); // The HDR feature is always added... it will compile out // if HDR is not enabled in the engine. features.addFeature( MFT_HDROut ); } + features.addFeature(MFT_DeferredTerrainBlankInfoMap); // Enable lightmaps and fogging if we're in BL. if ( reflectMat || useBLM ) @@ -405,8 +409,16 @@ bool TerrainCellMaterial::_createPass( Vector *materials, // check for macro detail texture if ( !(mat->getMacroSize() <= 0 || mat->getMacroDistance() <= 0 || mat->getMacroMap().isEmpty() ) ) + { + if(prePassMat) + features.addFeature( MFT_DeferredTerrainMacroMap, featureIndex ); + else features.addFeature( MFT_TerrainMacroMap, featureIndex ); + } + if(prePassMat) + features.addFeature( MFT_DeferredTerrainDetailMap, featureIndex ); + else features.addFeature( MFT_TerrainDetailMap, featureIndex ); pass->materials.push_back( (*materials)[i] ); @@ -536,8 +548,8 @@ bool TerrainCellMaterial::_createPass( Vector *materials, // MFT_TerrainAdditive feature to lerp the // output normal with the previous pass. // - if ( prePassMat ) - desc.setColorWrites( true, true, false, false ); + //if ( prePassMat ) + //desc.setColorWrites( true, true, false, false ); } // We write to the zbuffer if this is a prepass @@ -656,9 +668,9 @@ bool TerrainCellMaterial::_createPass( Vector *materials, if ( prePassMat ) desc.addDesc( RenderPrePassMgr::getOpaqueStenciWriteDesc( false ) ); - // Flip the cull for reflection materials. - if ( reflectMat ) - desc.setCullMode( GFXCullCW ); + // Shut off culling for prepass materials (reflection support). + if ( prePassMat ) + desc.setCullMode( GFXCullNone ); pass->stateBlock = GFX->createStateBlock( desc ); diff --git a/Engine/source/terrain/terrFeatureTypes.cpp b/Engine/source/terrain/terrFeatureTypes.cpp index b65085916..5eb8ff0e0 100644 --- a/Engine/source/terrain/terrFeatureTypes.cpp +++ b/Engine/source/terrain/terrFeatureTypes.cpp @@ -34,4 +34,8 @@ ImplementFeatureType( MFT_TerrainMacroMap, MFG_Texture, 104.0f, false ); ImplementFeatureType( MFT_TerrainLightMap, MFG_Texture, 105.0f, false ); ImplementFeatureType( MFT_TerrainSideProject, MFG_Texture, 106.0f, false ); ImplementFeatureType( MFT_TerrainAdditive, MFG_PostProcess, 999.0f, false ); - +//Deferred Shading +ImplementFeatureType( MFT_DeferredTerrainBaseMap, MFG_Texture, 100.1f, false ); +ImplementFeatureType( MFT_DeferredTerrainDetailMap, MFG_Texture, 102.1f, false ); +ImplementFeatureType( MFT_DeferredTerrainMacroMap, MFG_Texture, 104.1f, false ); +ImplementFeatureType( MFT_DeferredTerrainBlankInfoMap, MFG_Texture, 104.1f, false); diff --git a/Engine/source/terrain/terrFeatureTypes.h b/Engine/source/terrain/terrFeatureTypes.h index 0d2826da9..6246c5fa6 100644 --- a/Engine/source/terrain/terrFeatureTypes.h +++ b/Engine/source/terrain/terrFeatureTypes.h @@ -35,6 +35,12 @@ DeclareFeatureType( MFT_TerrainParallaxMap ); DeclareFeatureType( MFT_TerrainLightMap ); DeclareFeatureType( MFT_TerrainSideProject ); DeclareFeatureType( MFT_TerrainAdditive ); +//Deferred Shading +DeclareFeatureType( MFT_DeferredTerrainBaseMap ); +DeclareFeatureType( MFT_DeferredTerrainDetailMap ); +DeclareFeatureType( MFT_DeferredTerrainMacroMap ); +DeclareFeatureType( MFT_DeferredTerrainBlankInfoMap ); + #endif // _TERRFEATURETYPES_H_ diff --git a/Templates/Empty/game/shaders/common/postFx/hdr/gl/finalPassCombineP.glsl b/Templates/Empty/game/shaders/common/postFx/hdr/gl/finalPassCombineP.glsl index 38762baa5..f34cff1ef 100644 --- a/Templates/Empty/game/shaders/common/postFx/hdr/gl/finalPassCombineP.glsl +++ b/Templates/Empty/game/shaders/common/postFx/hdr/gl/finalPassCombineP.glsl @@ -42,10 +42,11 @@ uniform vec3 g_fBlueShiftColor; uniform float g_fBloomScale; uniform float g_fOneOverGamma; +uniform float Brightness; +uniform float Contrast; out vec4 OUT_col; - void main() { vec4 _sample = hdrDecode( texture( sceneTex, IN_uv0 ) ); @@ -94,5 +95,11 @@ void main() // Apply gamma correction _sample.rgb = pow( abs(_sample.rgb), vec3(g_fOneOverGamma) ); + // Apply contrast + _sample.rgb = ((_sample.rgb - 0.5f) * Contrast) + 0.5f; + + // Apply brightness + _sample.rgb += Brightness; + OUT_col = _sample; } diff --git a/Templates/Full/game/art/prefabs/fire.prefab b/Templates/Full/game/art/prefabs/fire.prefab new file mode 100644 index 000000000..6213e33a8 --- /dev/null +++ b/Templates/Full/game/art/prefabs/fire.prefab @@ -0,0 +1,49 @@ +//--- OBJECT WRITE BEGIN --- +$ThisPrefab = new SimGroup() { + canSave = "1"; + canSaveDynamicFields = "1"; + + new ParticleEmitterNode() { + active = "1"; + emitter = "FireEmitter"; + velocity = "1"; + dataBlock = "EmberNode"; + position = "0 0 0"; + rotation = "1 0 0 0"; + scale = "1 1 1"; + canSave = "1"; + canSaveDynamicFields = "1"; + }; + new PointLight() { + radius = "10"; + isEnabled = "1"; + color = "1 0.603922 0 1"; + brightness = "1"; + castShadows = "1"; + staticRefreshFreq = "250"; + dynamicRefreshFreq = "8"; + priority = "1"; + animate = "1"; + animationPeriod = "1"; + animationPhase = "1"; + flareScale = "1"; + attenuationRatio = "0 1 1"; + shadowType = "DualParaboloidSinglePass"; + texSize = "512"; + overDarkFactor = "2000 1000 500 100"; + shadowDistance = "400"; + shadowSoftness = "0.15"; + numSplits = "1"; + logWeight = "0.91"; + fadeStartDistance = "0"; + lastSplitTerrainOnly = "0"; + representedInLightmap = "0"; + shadowDarkenColor = "0 0 0 -1"; + includeLightmappedGeometryInShadow = "0"; + position = "0 0 0"; + rotation = "1 0 0 0"; + canSave = "1"; + canSaveDynamicFields = "1"; + }; +}; +//--- OBJECT WRITE END --- diff --git a/Templates/Full/game/art/shapes/trees/defaulttree/materials.cs b/Templates/Full/game/art/shapes/trees/defaulttree/materials.cs index f82946ccb..c17ea71eb 100644 --- a/Templates/Full/game/art/shapes/trees/defaulttree/materials.cs +++ b/Templates/Full/game/art/shapes/trees/defaulttree/materials.cs @@ -27,7 +27,6 @@ singleton Material(defaultTree_bark_material) diffuseMap[0] = "art/shapes/trees/defaulttree/defaulttree_bark_diffuse.dds"; normalMap[0] = "art/shapes/trees/defaulttree/defaulttree_bark_normal_specular.dds"; - specularMap[0] = ""; diffuseColor[0] = "1 1 1 1"; specular[0] = "0.9 0.9 0.9 1"; @@ -37,6 +36,7 @@ singleton Material(defaultTree_bark_material) translucent = false; translucentBlendOp = "None"; pixelSpecular[0] = "1"; + castDynamicShadows = "0"; }; singleton Material(defaulttree_material) @@ -45,7 +45,6 @@ singleton Material(defaulttree_material) diffuseMap[0] = "art/shapes/trees/defaulttree/defaulttree_diffuse_transparency.dds"; normalMap[0] = "art/shapes/trees/defaulttree/defaulttree_normal_specular.dds"; - specularMap[0] = ""; diffuseColor[0] = "1 1 1 1"; specular[0] = "0.9 0.9 0.9 1"; @@ -57,6 +56,7 @@ singleton Material(defaulttree_material) pixelSpecular[0] = "1"; alphaTest = "1"; alphaRef = "127"; + castDynamicShadows = "0"; }; singleton Material(defaultTree_fronds_material) @@ -71,6 +71,7 @@ singleton Material(defaultTree_fronds_material) alphaTest = "1"; alphaRef = "114"; translucent = "1"; + castDynamicShadows = "0"; }; singleton Material(defaulttree_ColorEffectR27G177B88_material) @@ -79,4 +80,6 @@ singleton Material(defaulttree_ColorEffectR27G177B88_material) diffuseColor[0] = "0.105882 0.694118 0.345098 1"; specularPower[0] = "10"; translucentBlendOp = "None"; + castDynamicShadows = "0"; + castShadows = "0"; }; diff --git a/Templates/Full/game/art/skies/Desert_Sky/materials.cs b/Templates/Full/game/art/skies/Desert_Sky/materials.cs index af6a979c8..0ee4080d8 100644 --- a/Templates/Full/game/art/skies/Desert_Sky/materials.cs +++ b/Templates/Full/game/art/skies/Desert_Sky/materials.cs @@ -34,4 +34,5 @@ singleton Material( DesertSkyMat ) { cubemap = DesertSkyCubemap; materialTag0 = "Skies"; + isSky = true; }; diff --git a/Templates/Full/game/art/skies/night/materials.cs b/Templates/Full/game/art/skies/night/materials.cs index 79cc050fc..11f9f6348 100644 --- a/Templates/Full/game/art/skies/night/materials.cs +++ b/Templates/Full/game/art/skies/night/materials.cs @@ -34,6 +34,7 @@ singleton Material( NightSkyMat ) { cubemap = NightCubemap; materialTag0 = "Skies"; + isSky = true; }; singleton Material( Moon_Glow_Mat ) @@ -50,4 +51,5 @@ singleton Material( Moon_Mat ) emissive = true; translucent = true; vertColor[ 0 ] = true; + isSky = true; }; diff --git a/Templates/Full/game/core/art/skies/blank/materials.cs b/Templates/Full/game/core/art/skies/blank/materials.cs index 179eafcf2..39f268866 100644 --- a/Templates/Full/game/core/art/skies/blank/materials.cs +++ b/Templates/Full/game/core/art/skies/blank/materials.cs @@ -34,6 +34,7 @@ singleton Material( BlackSkyMat ) { cubemap = BlackSkyCubemap; materialTag0 = "Skies"; + isSky = true; }; singleton CubemapData( BlueSkyCubemap ) @@ -50,6 +51,7 @@ singleton Material( BlueSkyMat ) { cubemap = BlueSkyCubemap; materialTag0 = "Skies"; + isSky = true; }; singleton CubemapData( GreySkyCubemap ) @@ -66,4 +68,5 @@ singleton Material( GreySkyMat ) { cubemap = GreySkyCubemap; materialTag0 = "Skies"; + isSky = true; }; diff --git a/Templates/Full/game/core/scripts/client/lighting/advanced/deferredShading.cs b/Templates/Full/game/core/scripts/client/lighting/advanced/deferredShading.cs new file mode 100644 index 000000000..8a1df2c67 --- /dev/null +++ b/Templates/Full/game/core/scripts/client/lighting/advanced/deferredShading.cs @@ -0,0 +1,147 @@ +singleton ShaderData( ClearGBufferShader ) +{ + DXVertexShaderFile = "shaders/common/postFx/postFxV.hlsl"; + DXPixelShaderFile = "shaders/common/lighting/advanced/deferredClearGBufferP.hlsl"; + + OGLVertexShaderFile = "shaders/common/postFx/gl/postFxV.glsl"; + OGLPixelShaderFile = "shaders/common/lighting/advanced/gl/deferredClearGBufferP.glsl"; + + pixVersion = 2.0; +}; + +singleton ShaderData( DeferredColorShader ) +{ + DXVertexShaderFile = "shaders/common/postFx/postFxV.hlsl"; + DXPixelShaderFile = "shaders/common/lighting/advanced/deferredColorShaderP.hlsl"; + + OGLVertexShaderFile = "shaders/common/postFx/gl/postFxV.glsl"; + OGLPixelShaderFile = "shaders/common/lighting/advanced/gl/deferredColorShaderP.glsl"; + + 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; +}; + +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] = "lightPrePassTex"; + samplerNames[2] = "matInfoTex"; + samplerNames[3] = "prepassTex"; + + pixVersion = 2.0; +}; + +singleton PostEffect( AL_DeferredShading ) +{ + renderTime = "PFXBeforeBin"; + renderBin = "SkyBin"; + shader = AL_DeferredShader; + stateBlock = AL_DeferredShadingState; + texture[0] = "#color"; + texture[1] = "#lightinfo"; + texture[2] = "#matinfo"; + texture[3] = "#prepass"; + + target = "$backBuffer"; + renderPriority = 10000; + allowReflectPass = true; +}; + +// Debug Shaders. +new ShaderData( AL_ColorBufferShader ) +{ + DXVertexShaderFile = "shaders/common/postFx/postFxV.hlsl"; + DXPixelShaderFile = "shaders/common/lighting/advanced/dbgColorBufferP.hlsl"; + + OGLVertexShaderFile = "shaders/common/postFx/gl/postFxV.glsl"; + OGLPixelShaderFile = "shaders/common/lighting/advanced/gl/dbgColorBufferP.glsl"; + + samplerNames[0] = "colorBufferTex"; + pixVersion = 2.0; +}; + +singleton PostEffect( AL_ColorBufferVisualize ) +{ + shader = AL_ColorBufferShader; + stateBlock = AL_DefaultVisualizeState; + texture[0] = "#color"; + target = "$backBuffer"; + renderPriority = 9999; +}; + +/// Toggles the visualization of the AL lighting specular power buffer. +function toggleColorBufferViz( %enable ) +{ + if ( %enable $= "" ) + { + $AL_ColorBufferShaderVar = AL_ColorBufferVisualize.isEnabled() ? false : true; + AL_ColorBufferVisualize.toggle(); + } + else if ( %enable ) + { + AL_DeferredShading.disable(); + AL_ColorBufferVisualize.enable(); + } + else if ( !%enable ) + { + AL_ColorBufferVisualize.disable(); + AL_DeferredShading.enable(); + } +} + +new ShaderData( AL_SpecMapShader ) +{ + DXVertexShaderFile = "shaders/common/postFx/postFxV.hlsl"; + DXPixelShaderFile = "shaders/common/lighting/advanced/dbgSpecMapVisualizeP.hlsl"; + + OGLVertexShaderFile = "shaders/common/postFx/gl/postFxV.glsl"; + OGLPixelShaderFile = "shaders/common/lighting/advanced/gl/dbgSpecMapVisualizeP.glsl"; + + samplerNames[0] = "matinfoTex"; + pixVersion = 2.0; +}; + +singleton PostEffect( AL_SpecMapVisualize ) +{ + shader = AL_SpecMapShader; + stateBlock = AL_DefaultVisualizeState; + texture[0] = "#matinfo"; + target = "$backBuffer"; + renderPriority = 9999; +}; + +/// Toggles the visualization of the AL lighting specular power buffer. +function toggleSpecMapViz( %enable ) +{ + if ( %enable $= "" ) + { + $AL_SpecMapShaderVar = AL_SpecMapVisualize.isEnabled() ? false : true; + AL_SpecMapVisualize.toggle(); + } + else if ( %enable ) + AL_SpecMapVisualize.enable(); + else if ( !%enable ) + AL_SpecMapVisualize.disable(); +} \ No newline at end of file diff --git a/Templates/Full/game/core/scripts/client/lighting/advanced/init.cs b/Templates/Full/game/core/scripts/client/lighting/advanced/init.cs index 2c78e9ca4..d74aff69a 100644 --- a/Templates/Full/game/core/scripts/client/lighting/advanced/init.cs +++ b/Templates/Full/game/core/scripts/client/lighting/advanced/init.cs @@ -43,6 +43,7 @@ exec( "./shaders.cs" ); exec( "./lightViz.cs" ); exec( "./shadowViz.cs" ); exec( "./shadowViz.gui" ); +exec( "./deferredShading.cs" ); function onActivateAdvancedLM() { @@ -58,12 +59,18 @@ function onActivateAdvancedLM() // Enable the offscreen target so that AL will work // with MSAA back buffers and for HDR rendering. AL_FormatToken.enable(); + + // Activate Deferred Shading + AL_DeferredShading.enable(); } function onDeactivateAdvancedLM() { // Disable the offscreen render target. AL_FormatToken.disable(); + + // Deactivate Deferred Shading + AL_DeferredShading.disable(); } function setAdvancedLighting() diff --git a/Templates/Full/game/core/scripts/client/lighting/advanced/lightViz.cs b/Templates/Full/game/core/scripts/client/lighting/advanced/lightViz.cs index 22665120d..fcaf72942 100644 --- a/Templates/Full/game/core/scripts/client/lighting/advanced/lightViz.cs +++ b/Templates/Full/game/core/scripts/client/lighting/advanced/lightViz.cs @@ -56,7 +56,7 @@ new ShaderData( AL_DepthVisualizeShader ) OGLVertexShaderFile = "shaders/common/postFx/gl/postFxV.glsl"; OGLPixelShaderFile = "shaders/common/lighting/advanced/gl/dbgDepthVisualizeP.glsl"; - samplerNames[0] = "prepassBuffer"; + samplerNames[0] = "prepassTex"; samplerNames[1] = "depthViz"; pixVersion = 2.0; @@ -113,7 +113,7 @@ new ShaderData( AL_NormalsVisualizeShader ) OGLVertexShaderFile = "shaders/common/postFx/gl/postFxV.glsl"; OGLPixelShaderFile = "shaders/common/lighting/advanced/gl/dbgNormalVisualizeP.glsl"; - samplerNames[0] = "prepassBuffer"; + samplerNames[0] = "prepassTex"; pixVersion = 2.0; }; @@ -149,7 +149,7 @@ new ShaderData( AL_LightColorVisualizeShader ) OGLVertexShaderFile = "shaders/common/postFx/gl/postFxV.glsl"; OGLPixelShaderFile = "shaders/common/lighting/advanced/gl/dbgLightColorVisualizeP.glsl"; - samplerNames[0] = "lightInfoBuffer"; + samplerNames[0] = "lightPrePassTex"; pixVersion = 2.0; }; @@ -184,7 +184,7 @@ new ShaderData( AL_LightSpecularVisualizeShader ) OGLVertexShaderFile = "shaders/common/postFx/gl/postFxV.glsl"; OGLPixelShaderFile = "shaders/common/lighting/advanced/gl/dbgLightSpecularVisualizeP.glsl"; - samplerNames[0] = "lightInfoBuffer"; + samplerNames[0] = "lightPrePassTex"; pixVersion = 2.0; }; @@ -280,3 +280,16 @@ function toggleLightSpecularViz( %enable ) AL_LightSpecularVisualize.disable(); } +function toggleBackbufferViz( %enable ) +{ + if ( %enable $= "" ) + { + $AL_BackbufferVisualizeVar = AL_DeferredShading.isEnabled() ? true : false; + AL_DeferredShading.toggle(); + } + else if ( %enable ) + AL_DeferredShading.disable(); + else if ( !%enable ) + AL_DeferredShading.enable(); +} + diff --git a/Templates/Full/game/core/scripts/client/lighting/advanced/shaders.cs b/Templates/Full/game/core/scripts/client/lighting/advanced/shaders.cs index 2e73b6569..eaf7f70b8 100644 --- a/Templates/Full/game/core/scripts/client/lighting/advanced/shaders.cs +++ b/Templates/Full/game/core/scripts/client/lighting/advanced/shaders.cs @@ -36,8 +36,11 @@ new GFXStateBlockData( AL_VectorLightState ) samplersDefined = true; samplerStates[0] = SamplerClampPoint; // G-buffer + mSamplerNames[0] = "prePassBuffer"; samplerStates[1] = SamplerClampPoint; // Shadow Map (Do not change this to linear, as all cards can not filter equally.) + mSamplerNames[1] = "shadowMap"; samplerStates[2] = SamplerClampLinear; // SSAO Mask + mSamplerNames[2] = "ssaoMask"; samplerStates[3] = SamplerWrapPoint; // Random Direction Map cullDefined = true; @@ -66,7 +69,9 @@ new ShaderData( AL_VectorLightShader ) samplerNames[2] = "$dynamicShadowMap"; samplerNames[3] = "$ssaoMask"; samplerNames[4] = "$gTapRotationTex"; - + samplerNames[5] = "$lightBuffer"; + samplerNames[6] = "$colorBuffer"; + samplerNames[7] = "$matInfoBuffer"; pixVersion = 3.0; }; @@ -78,7 +83,10 @@ new CustomMaterial( AL_VectorLightMaterial ) sampler["prePassBuffer"] = "#prepass"; sampler["shadowMap"] = "$dynamiclight"; sampler["dynamicShadowMap"] = "$dynamicShadowMap"; - sampler["ssaoMask"] = "#ssaoMask"; + sampler["ssaoMask"] = "#ssaoMask"; + sampler["lightBuffer"] = "#lightinfo"; + sampler["colorBuffer"] = "#color"; + sampler["matInfoBuffer"] = "#matinfo"; target = "lightinfo"; @@ -103,7 +111,9 @@ new GFXStateBlockData( AL_ConvexLightState ) samplersDefined = true; samplerStates[0] = SamplerClampPoint; // G-buffer + mSamplerNames[0] = "prePassBuffer"; samplerStates[1] = SamplerClampPoint; // Shadow Map (Do not use linear, these are perspective projections) + mSamplerNames[1] = "shadowMap"; samplerStates[2] = SamplerClampLinear; // Cookie Map samplerStates[3] = SamplerWrapPoint; // Random Direction Map @@ -133,6 +143,9 @@ new ShaderData( AL_PointLightShader ) samplerNames[2] = "$dynamicShadowMap"; samplerNames[3] = "$cookieMap"; samplerNames[4] = "$gTapRotationTex"; + samplerNames[5] = "$lightBuffer"; + samplerNames[6] = "$colorBuffer"; + samplerNames[7] = "$matInfoBuffer"; pixVersion = 3.0; }; @@ -146,6 +159,9 @@ new CustomMaterial( AL_PointLightMaterial ) sampler["shadowMap"] = "$dynamiclight"; sampler["dynamicShadowMap"] = "$dynamicShadowMap"; sampler["cookieMap"] = "$dynamiclightmask"; + sampler["lightBuffer"] = "#lightinfo"; + sampler["colorBuffer"] = "#color"; + sampler["matInfoBuffer"] = "#matinfo"; target = "lightinfo"; @@ -166,6 +182,9 @@ new ShaderData( AL_SpotLightShader ) samplerNames[2] = "$dynamicShadowMap"; samplerNames[3] = "$cookieMap"; samplerNames[4] = "$gTapRotationTex"; + samplerNames[5] = "$lightBuffer"; + samplerNames[6] = "$colorBuffer"; + samplerNames[7] = "$matInfoBuffer"; pixVersion = 3.0; }; @@ -179,6 +198,9 @@ new CustomMaterial( AL_SpotLightMaterial ) sampler["shadowMap"] = "$dynamiclight"; sampler["dynamicShadowMap"] = "$dynamicShadowMap"; sampler["cookieMap"] = "$dynamiclightmask"; + sampler["lightBuffer"] = "#lightinfo"; + sampler["colorBuffer"] = "#color"; + sampler["matInfoBuffer"] = "#matinfo"; target = "lightinfo"; diff --git a/Templates/Full/game/core/scripts/client/postFx/caustics.cs b/Templates/Full/game/core/scripts/client/postFx/caustics.cs index 3e8b14de0..11fda8083 100644 --- a/Templates/Full/game/core/scripts/client/postFx/caustics.cs +++ b/Templates/Full/game/core/scripts/client/postFx/caustics.cs @@ -51,7 +51,7 @@ singleton ShaderData( PFX_CausticsShader ) singleton PostEffect( CausticsPFX ) { isEnabled = false; - renderTime = "PFXBeforeBin"; + renderTime = "PFXAfterDiffuse"; renderBin = "ObjTranslucentBin"; //renderPriority = 0.1; diff --git a/Templates/Full/game/core/scripts/client/postFx/hdr.cs b/Templates/Full/game/core/scripts/client/postFx/hdr.cs index 136a5ca95..6c8e870d0 100644 --- a/Templates/Full/game/core/scripts/client/postFx/hdr.cs +++ b/Templates/Full/game/core/scripts/client/postFx/hdr.cs @@ -172,6 +172,8 @@ singleton ShaderData( HDR_CombineShader ) samplerNames[2] = "$bloomTex"; samplerNames[3] = "$colorCorrectionTex"; + samplerNames[4] = "prepassTex"; + pixVersion = 3.0; }; @@ -469,6 +471,7 @@ singleton PostEffect( HDRPostFX ) texture[1] = "#adaptedLum"; texture[2] = "#bloomFinal"; texture[3] = $HDRPostFX::colorCorrectionRamp; + texture[4] = "#prepass"; target = "$backBuffer"; }; }; diff --git a/Templates/Full/game/core/scripts/client/postFx/turbulence.cs b/Templates/Full/game/core/scripts/client/postFx/turbulence.cs index c2309f808..dd8c0e2dc 100644 --- a/Templates/Full/game/core/scripts/client/postFx/turbulence.cs +++ b/Templates/Full/game/core/scripts/client/postFx/turbulence.cs @@ -47,7 +47,7 @@ singleton PostEffect( TurbulenceFx ) isEnabled = false; allowReflectPass = true; - renderTime = "PFXAfterBin"; + renderTime = "PFXAfterDiffuse"; renderBin = "GlowBin"; renderPriority = 0.5; // Render after the glows themselves diff --git a/Templates/Full/game/core/scripts/client/renderManager.cs b/Templates/Full/game/core/scripts/client/renderManager.cs index 71200ad49..a14287db1 100644 --- a/Templates/Full/game/core/scripts/client/renderManager.cs +++ b/Templates/Full/game/core/scripts/client/renderManager.cs @@ -55,8 +55,8 @@ function initRenderManager() DiffuseRenderPassManager.addManager( new RenderObjectMgr(BeginBin) { bintype = "Begin"; renderOrder = 0.2; processAddOrder = 0.2; } ); // Normal mesh rendering. - DiffuseRenderPassManager.addManager( new RenderTerrainMgr(TerrainBin) { renderOrder = 0.4; processAddOrder = 0.4; } ); - DiffuseRenderPassManager.addManager( new RenderMeshMgr(MeshBin) { bintype = "Mesh"; renderOrder = 0.5; processAddOrder = 0.5; } ); + DiffuseRenderPassManager.addManager( new RenderTerrainMgr(TerrainBin) { renderOrder = 0.4; processAddOrder = 0.4; basicOnly = true; } ); + DiffuseRenderPassManager.addManager( new RenderMeshMgr(MeshBin) { bintype = "Mesh"; renderOrder = 0.5; processAddOrder = 0.5; basicOnly = true; } ); DiffuseRenderPassManager.addManager( new RenderImposterMgr(ImposterBin) { renderOrder = 0.56; processAddOrder = 0.56; } ); DiffuseRenderPassManager.addManager( new RenderObjectMgr(ObjectBin) { bintype = "Object"; renderOrder = 0.6; processAddOrder = 0.6; } ); diff --git a/Templates/Full/game/core/scripts/client/scatterSky.cs b/Templates/Full/game/core/scripts/client/scatterSky.cs index 7701b0adf..a2b19ab23 100644 --- a/Templates/Full/game/core/scripts/client/scatterSky.cs +++ b/Templates/Full/game/core/scripts/client/scatterSky.cs @@ -22,13 +22,13 @@ new GFXStateBlockData( ScatterSkySBData ) { - cullDefined = true; + //cullDefined = true; cullMode = "GFXCullNone"; zDefined = true; zEnable = true; zWriteEnable = false; - zFunc = "GFXCmpLessEqual"; + //zFunc = "GFXCmpLessEqual"; samplersDefined = true; samplerStates[0] = SamplerClampLinear; diff --git a/Templates/Full/game/shaders/common/basicCloudsV.hlsl b/Templates/Full/game/shaders/common/basicCloudsV.hlsl index 49842fd37..a3d4bb5fe 100644 --- a/Templates/Full/game/shaders/common/basicCloudsV.hlsl +++ b/Templates/Full/game/shaders/common/basicCloudsV.hlsl @@ -46,6 +46,7 @@ ConnectData main( CloudVert IN ) ConnectData OUT; OUT.hpos = mul(modelview, IN.pos); + OUT.hpos.w = OUT.hpos.z; float2 uv = IN.uv0; uv += texOffset; diff --git a/Templates/Full/game/shaders/common/cloudLayerV.hlsl b/Templates/Full/game/shaders/common/cloudLayerV.hlsl index 8c1cc555f..c34a57c05 100644 --- a/Templates/Full/game/shaders/common/cloudLayerV.hlsl +++ b/Templates/Full/game/shaders/common/cloudLayerV.hlsl @@ -60,8 +60,8 @@ uniform float3 texScale; ConnectData main( CloudVert IN ) { ConnectData OUT; - OUT.hpos = mul(modelview, IN.pos); + OUT.hpos.w = OUT.hpos.z; // Offset the uv so we don't have a seam directly over our head. float2 uv = IN.uv0 + float2( 0.5, 0.5 ); diff --git a/Templates/Full/game/shaders/common/gl/basicCloudsV.glsl b/Templates/Full/game/shaders/common/gl/basicCloudsV.glsl index cccbafa8c..40c597120 100644 --- a/Templates/Full/game/shaders/common/gl/basicCloudsV.glsl +++ b/Templates/Full/game/shaders/common/gl/basicCloudsV.glsl @@ -41,6 +41,7 @@ out vec2 texCoord; void main() { gl_Position = tMul(modelview, IN_pos); + gl_Position.w = gl_Position.z; vec2 uv = IN_uv0; uv += texOffset; diff --git a/Templates/Full/game/shaders/common/gl/cloudLayerV.glsl b/Templates/Full/game/shaders/common/gl/cloudLayerV.glsl index 395c6f286..cba5c009a 100644 --- a/Templates/Full/game/shaders/common/gl/cloudLayerV.glsl +++ b/Templates/Full/game/shaders/common/gl/cloudLayerV.glsl @@ -62,6 +62,7 @@ void main() vec2 IN_uv0 = vTexCoord0.st; gl_Position = modelview * IN_pos; + gl_Position.w = gl_Position.z; // Offset the uv so we don't have a seam directly over our head. vec2 uv = IN_uv0 + vec2( 0.5, 0.5 ); diff --git a/Templates/Full/game/shaders/common/gl/lighting.glsl b/Templates/Full/game/shaders/common/gl/lighting.glsl index eb1c9b355..804ab1e3b 100644 --- a/Templates/Full/game/shaders/common/gl/lighting.glsl +++ b/Templates/Full/game/shaders/common/gl/lighting.glsl @@ -20,6 +20,7 @@ // IN THE SOFTWARE. //----------------------------------------------------------------------------- +#include "./torque.glsl" #ifndef TORQUE_SHADERGEN @@ -207,14 +208,42 @@ void compute4Lights( vec3 wsView, /// float AL_CalcSpecular( vec3 toLight, vec3 normal, vec3 toEye ) { - #ifdef PHONG_SPECULAR - // (R.V)^c - float specVal = dot( normalize( -reflect( toLight, normal ) ), toEye ); - #else - // (N.H)^c [Blinn-Phong, TGEA style, default] - float specVal = dot( normal, normalize( toLight + toEye ) ); - #endif + // (R.V)^c + float specVal = dot( normalize( -reflect( toLight, normal ) ), toEye ); // Return the specular factor. return pow( max( specVal, 0.00001f ), AL_ConstantSpecularPower ); } + +/// The output for Deferred Lighting +/// +/// @param toLight Normalized vector representing direction from the pixel +/// being lit, to the light source, in world space. +/// +/// @param normal Normalized surface normal. +/// +/// @param toEye The normalized vector representing direction from the pixel +/// being lit to the camera. +/// +vec4 AL_DeferredOutput( + vec3 lightColor, + vec3 diffuseColor, + vec4 matInfo, + vec4 ambient, + float specular, + float shadowAttenuation) +{ + vec3 specularColor = vec3(specular); + bool metalness = getFlag(matInfo.r, 3); + if ( metalness ) + { + specularColor = 0.04 * (1 - specular) + diffuseColor * specular; + } + + //specular = color * map * spec^gloss + float specularOut = (specularColor * matInfo.b * min(pow(max(specular,1.0f), max((matInfo.a / AL_ConstantSpecularPower),1.0f)),matInfo.a)).r; + + lightColor *= vec3(shadowAttenuation); + lightColor += ambient.rgb; + return vec4(lightColor.rgb, specularOut); +} diff --git a/Templates/Full/game/shaders/common/gl/scatterSkyP.glsl b/Templates/Full/game/shaders/common/gl/scatterSkyP.glsl index d9fa80bcf..b4e70f902 100644 --- a/Templates/Full/game/shaders/common/gl/scatterSkyP.glsl +++ b/Templates/Full/game/shaders/common/gl/scatterSkyP.glsl @@ -73,5 +73,8 @@ void main() discard; OUT_col.a = 1; + + OUT_col = clamp(OUT_col, 0.0, 1.0); + OUT_col = hdrEncode( OUT_col ); } diff --git a/Templates/Full/game/shaders/common/lighting.hlsl b/Templates/Full/game/shaders/common/lighting.hlsl index ec8129e94..a2c753618 100644 --- a/Templates/Full/game/shaders/common/lighting.hlsl +++ b/Templates/Full/game/shaders/common/lighting.hlsl @@ -20,6 +20,7 @@ // IN THE SOFTWARE. //----------------------------------------------------------------------------- +#include "./torque.hlsl" #ifndef TORQUE_SHADERGEN @@ -207,14 +208,42 @@ void compute4Lights( float3 wsView, /// float AL_CalcSpecular( float3 toLight, float3 normal, float3 toEye ) { - #ifdef PHONG_SPECULAR - // (R.V)^c - float specVal = dot( normalize( -reflect( toLight, normal ) ), toEye ); - #else - // (N.H)^c [Blinn-Phong, TGEA style, default] - float specVal = dot( normal, normalize( toLight + toEye ) ); - #endif + // (R.V)^c + float specVal = dot( normalize( -reflect( toLight, normal ) ), toEye ); // Return the specular factor. return pow( max( specVal, 0.00001f ), AL_ConstantSpecularPower ); } + +/// The output for Deferred Lighting +/// +/// @param toLight Normalized vector representing direction from the pixel +/// being lit, to the light source, in world space. +/// +/// @param normal Normalized surface normal. +/// +/// @param toEye The normalized vector representing direction from the pixel +/// being lit to the camera. +/// +float4 AL_DeferredOutput( + float3 lightColor, + float3 diffuseColor, + float4 matInfo, + float4 ambient, + float specular, + float shadowAttenuation) +{ + float3 specularColor = float3(specular, specular, specular); + bool metalness = getFlag(matInfo.r, 3); + if ( metalness ) + { + specularColor = 0.04 * (1 - specular) + diffuseColor * specular; + } + + //specular = color * map * spec^gloss + float specularOut = (specularColor * matInfo.b * min(pow(specular, max(( matInfo.a/ AL_ConstantSpecularPower),1.0f)),matInfo.a)).r; + + lightColor *= shadowAttenuation; + lightColor += ambient.rgb; + return float4(lightColor.rgb, specularOut); +} diff --git a/Templates/Full/game/shaders/common/lighting/advanced/dbgColorBufferP.hlsl b/Templates/Full/game/shaders/common/lighting/advanced/dbgColorBufferP.hlsl new file mode 100644 index 000000000..349c943f9 --- /dev/null +++ b/Templates/Full/game/shaders/common/lighting/advanced/dbgColorBufferP.hlsl @@ -0,0 +1,31 @@ +//----------------------------------------------------------------------------- +// 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 "shadergen:/autogenConditioners.h" +#include "../../postfx/postFx.hlsl" + + +float4 main( PFXVertToPix IN, + uniform sampler2D colorBufferTex : register(S0) ) : COLOR0 +{ + return float4(tex2D( colorBufferTex, IN.uv0 ).rgb, 1.0); +} diff --git a/Templates/Full/game/shaders/common/lighting/advanced/dbgLightColorVisualizeP.hlsl b/Templates/Full/game/shaders/common/lighting/advanced/dbgLightColorVisualizeP.hlsl index 487b4c740..e037ad8b9 100644 --- a/Templates/Full/game/shaders/common/lighting/advanced/dbgLightColorVisualizeP.hlsl +++ b/Templates/Full/game/shaders/common/lighting/advanced/dbgLightColorVisualizeP.hlsl @@ -27,8 +27,6 @@ float4 main( PFXVertToPix IN, uniform sampler2D lightPrePassTex : register(S0) ) : COLOR0 { - float3 lightcolor; - float nl_Att, specular; - lightinfoUncondition( tex2D( lightPrePassTex, IN.uv0 ), lightcolor, nl_Att, specular ); - return float4( lightcolor, 1.0 ); + float4 lightColor = tex2D( lightPrePassTex, IN.uv0 ); + return float4( lightColor.rgb, 1.0 ); } diff --git a/Templates/Full/game/shaders/common/lighting/advanced/dbgLightSpecularVisualizeP.hlsl b/Templates/Full/game/shaders/common/lighting/advanced/dbgLightSpecularVisualizeP.hlsl index edc25ed03..8e1074add 100644 --- a/Templates/Full/game/shaders/common/lighting/advanced/dbgLightSpecularVisualizeP.hlsl +++ b/Templates/Full/game/shaders/common/lighting/advanced/dbgLightSpecularVisualizeP.hlsl @@ -27,8 +27,6 @@ float4 main( PFXVertToPix IN, uniform sampler2D lightPrePassTex : register(S0) ) : COLOR0 { - float3 lightcolor; - float nl_Att, specular; - lightinfoUncondition( tex2D( lightPrePassTex, IN.uv0 ), lightcolor, nl_Att, specular ); + float specular = tex2D( lightPrePassTex, IN.uv0 ).a; return float4( specular, specular, specular, 1.0 ); } diff --git a/Templates/Full/game/shaders/common/lighting/advanced/dbgSpecMapVisualizeP.hlsl b/Templates/Full/game/shaders/common/lighting/advanced/dbgSpecMapVisualizeP.hlsl new file mode 100644 index 000000000..ba5f2c0e1 --- /dev/null +++ b/Templates/Full/game/shaders/common/lighting/advanced/dbgSpecMapVisualizeP.hlsl @@ -0,0 +1,32 @@ +//----------------------------------------------------------------------------- +// 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 "shadergen:/autogenConditioners.h" +#include "../../postfx/postFx.hlsl" + + +float4 main( PFXVertToPix IN, + uniform sampler2D matinfoTex : register(S0) ) : COLOR0 +{ + float specular = tex2D( matinfoTex, IN.uv0 ).b; + return float4( specular, specular, specular, 1.0 ); +} diff --git a/Templates/Full/game/shaders/common/lighting/advanced/deferredClearGBufferP.hlsl b/Templates/Full/game/shaders/common/lighting/advanced/deferredClearGBufferP.hlsl new file mode 100644 index 000000000..df9870248 --- /dev/null +++ b/Templates/Full/game/shaders/common/lighting/advanced/deferredClearGBufferP.hlsl @@ -0,0 +1,47 @@ +//----------------------------------------------------------------------------- +// 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. +//----------------------------------------------------------------------------- + +struct Fragout +{ + float4 col : COLOR0; + float4 col1 : COLOR1; + float4 col2 : COLOR2; +}; + +//----------------------------------------------------------------------------- +// Main +//----------------------------------------------------------------------------- +Fragout main( ) +{ + Fragout OUT; + + // Clear Prepass Buffer ( Normals/Depth ); + OUT.col = float4(1.0, 1.0, 1.0, 1.0); + + // Clear Color Buffer. + OUT.col1 = float4(0.0, 0.0, 0.0, 1.0); + + // Clear Material Info Buffer. + OUT.col2 = float4(0.0, 0.0, 0.0, 1.0); + + return OUT; +} diff --git a/Templates/Full/game/shaders/common/lighting/advanced/deferredColorShaderP.hlsl b/Templates/Full/game/shaders/common/lighting/advanced/deferredColorShaderP.hlsl new file mode 100644 index 000000000..5e6d0a984 --- /dev/null +++ b/Templates/Full/game/shaders/common/lighting/advanced/deferredColorShaderP.hlsl @@ -0,0 +1,44 @@ +//----------------------------------------------------------------------------- +// 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. +//----------------------------------------------------------------------------- + +struct Fragout +{ + float4 col : COLOR0; + float4 col1 : COLOR1; + float4 col2 : COLOR2; +}; + +//----------------------------------------------------------------------------- +// Main +//----------------------------------------------------------------------------- +Fragout main( ) +{ + Fragout OUT; + + OUT.col = float4(0.0, 0.0, 0.0, 0.0); + OUT.col1 = float4(1.0, 1.0, 1.0, 1.0); + + // Draw on color buffer. + OUT.col2 = float4(1.0, 0.0, 0.0, 1.0); + + return OUT; +} diff --git a/Templates/Full/game/shaders/common/lighting/advanced/deferredShadingP.hlsl b/Templates/Full/game/shaders/common/lighting/advanced/deferredShadingP.hlsl new file mode 100644 index 000000000..80e6acde0 --- /dev/null +++ b/Templates/Full/game/shaders/common/lighting/advanced/deferredShadingP.hlsl @@ -0,0 +1,54 @@ +//----------------------------------------------------------------------------- +// 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 "shadergen:/autogenConditioners.h" +#include "../../postfx/postFx.hlsl" +#include "shaders/common/torque.hlsl" + + +float4 main( PFXVertToPix IN, + uniform sampler2D colorBufferTex : register(S0), + uniform sampler2D lightPrePassTex : register(S1), + uniform sampler2D matInfoTex : register(S2), + uniform sampler2D prepassTex : register(S3)) : COLOR0 +{ + float4 lightBuffer = tex2D( lightPrePassTex, IN.uv0 ); + float4 colorBuffer = tex2D( colorBufferTex, IN.uv0 ); + float4 matInfo = tex2D( matInfoTex, IN.uv0 ); + float specular = saturate(lightBuffer.a); + float depth = prepassUncondition( prepassTex, IN.uv0 ).w; + + if (depth>0.9999) + return float4(0,0,0,0); + + // Diffuse Color Altered by Metalness + bool metalness = getFlag(matInfo.r, 3); + if ( metalness ) + { + colorBuffer *= (1.0 - colorBuffer.a); + } + + colorBuffer *= float4(lightBuffer.rgb, 1.0); + colorBuffer += float4(specular, specular, specular, 1.0); + + return hdrEncode( float4(colorBuffer.rgb, 1.0) ); +} diff --git a/Templates/Full/game/shaders/common/lighting/advanced/gl/dbgColorBufferP.glsl b/Templates/Full/game/shaders/common/lighting/advanced/gl/dbgColorBufferP.glsl new file mode 100644 index 000000000..48a96d47d --- /dev/null +++ b/Templates/Full/game/shaders/common/lighting/advanced/gl/dbgColorBufferP.glsl @@ -0,0 +1,34 @@ +//----------------------------------------------------------------------------- +// 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 "../../../gl/hlslCompat.glsl" +#include "shadergen:/autogenConditioners.h" +#include "../../../postfx/gl/postFx.glsl" + +uniform sampler2D colorBufferTex; + +out vec4 OUT_FragColor0; + +void main() +{ + OUT_FragColor0 = vec4(texture( colorBufferTex, uv0 ).rgb, 1.0); +} diff --git a/Templates/Full/game/shaders/common/lighting/advanced/gl/dbgDepthVisualizeP.glsl b/Templates/Full/game/shaders/common/lighting/advanced/gl/dbgDepthVisualizeP.glsl index 7c1754097..eb3d6f761 100644 --- a/Templates/Full/game/shaders/common/lighting/advanced/gl/dbgDepthVisualizeP.glsl +++ b/Templates/Full/game/shaders/common/lighting/advanced/gl/dbgDepthVisualizeP.glsl @@ -24,13 +24,13 @@ #include "shadergen:/autogenConditioners.h" in vec2 uv0; -uniform sampler2D prepassBuffer; +uniform sampler2D prepassTex; uniform sampler1D depthViz; out vec4 OUT_col; void main() { - float depth = prepassUncondition( prepassBuffer, uv0 ).w; + float depth = prepassUncondition( prepassTex, uv0 ).w; OUT_col = vec4( texture( depthViz, depth ).rgb, 1.0 ); } \ No newline at end of file diff --git a/Templates/Full/game/shaders/common/lighting/advanced/gl/dbgLightColorVisualizeP.glsl b/Templates/Full/game/shaders/common/lighting/advanced/gl/dbgLightColorVisualizeP.glsl index 05645e193..501e261ca 100644 --- a/Templates/Full/game/shaders/common/lighting/advanced/gl/dbgLightColorVisualizeP.glsl +++ b/Templates/Full/game/shaders/common/lighting/advanced/gl/dbgLightColorVisualizeP.glsl @@ -24,14 +24,12 @@ #include "shadergen:/autogenConditioners.h" in vec2 uv0; -uniform sampler2D lightInfoBuffer; +uniform sampler2D lightPrePassTex; out vec4 OUT_col; void main() { - vec3 lightcolor; - float nl_Att, specular; - lightinfoUncondition( texture( lightInfoBuffer, uv0 ), lightcolor, nl_Att, specular ); - OUT_col = vec4( lightcolor, 1.0 ); + vec4 lightColor = texture( lightPrePassTex, uv0 ); + OUT_col = vec4( lightColor.rgb, 1.0 ); } \ No newline at end of file diff --git a/Templates/Full/game/shaders/common/lighting/advanced/gl/dbgLightSpecularVisualizeP.glsl b/Templates/Full/game/shaders/common/lighting/advanced/gl/dbgLightSpecularVisualizeP.glsl index 7e3e41ee9..c21c9b60f 100644 --- a/Templates/Full/game/shaders/common/lighting/advanced/gl/dbgLightSpecularVisualizeP.glsl +++ b/Templates/Full/game/shaders/common/lighting/advanced/gl/dbgLightSpecularVisualizeP.glsl @@ -24,14 +24,12 @@ #include "shadergen:/autogenConditioners.h" in vec2 uv0; -uniform sampler2D lightInfoBuffer; +uniform sampler2D lightPrePassTex; out vec4 OUT_col; void main() { - vec3 lightcolor; - float nl_Att, specular; - lightinfoUncondition( texture( lightInfoBuffer, uv0 ), lightcolor, nl_Att, specular ); + float specular = texture( lightPrePassTex, uv0 ).a; OUT_col = vec4( specular, specular, specular, 1.0 ); } \ No newline at end of file diff --git a/Templates/Full/game/shaders/common/lighting/advanced/gl/dbgNormalVisualizeP.glsl b/Templates/Full/game/shaders/common/lighting/advanced/gl/dbgNormalVisualizeP.glsl index dfc611e88..84ea4d3fb 100644 --- a/Templates/Full/game/shaders/common/lighting/advanced/gl/dbgNormalVisualizeP.glsl +++ b/Templates/Full/game/shaders/common/lighting/advanced/gl/dbgNormalVisualizeP.glsl @@ -24,12 +24,12 @@ #include "shadergen:/autogenConditioners.h" in vec2 uv0; -uniform sampler2D prepassBuffer; +uniform sampler2D prepassTex; out vec4 OUT_col; void main() { - vec3 normal = prepassUncondition( prepassBuffer, uv0 ).xyz; + vec3 normal = prepassUncondition( prepassTex, uv0 ).xyz; OUT_col = vec4( ( normal + 1.0 ) * 0.5, 1.0 ); } \ No newline at end of file diff --git a/Templates/Full/game/shaders/common/lighting/advanced/gl/dbgSpecMapVisualizeP.glsl b/Templates/Full/game/shaders/common/lighting/advanced/gl/dbgSpecMapVisualizeP.glsl new file mode 100644 index 000000000..4ba9f6734 --- /dev/null +++ b/Templates/Full/game/shaders/common/lighting/advanced/gl/dbgSpecMapVisualizeP.glsl @@ -0,0 +1,34 @@ +//----------------------------------------------------------------------------- +// 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 "../../../gl/hlslCompat.glsl" +#include "shadergen:/autogenConditioners.h" +#include "../../../postfx/gl/postFx.glsl" + +uniform sampler2D matinfoTex; + +out vec4 OUT_FragColor0; + +void main() +{ + float specular = texture( matinfoTex, uv0 ).a; + OUT_FragColor0 = vec4( specular, specular, specular, 1.0 ); +} diff --git a/Templates/Full/game/shaders/common/lighting/advanced/gl/deferredClearGBufferP.glsl b/Templates/Full/game/shaders/common/lighting/advanced/gl/deferredClearGBufferP.glsl new file mode 100644 index 000000000..39dc0dc9f --- /dev/null +++ b/Templates/Full/game/shaders/common/lighting/advanced/gl/deferredClearGBufferP.glsl @@ -0,0 +1,40 @@ +//----------------------------------------------------------------------------- +// 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. +//----------------------------------------------------------------------------- + +out vec4 OUT_col; +out vec4 OUT_col1; +out vec4 OUT_col2; + +//----------------------------------------------------------------------------- +// Main +//----------------------------------------------------------------------------- +void main() +{ + // Clear Prepass Buffer ( Normals/Depth ); + OUT_col = vec4(1.0, 1.0, 1.0, 1.0); + + // Clear Color Buffer. + OUT_col1 = vec4(0.0, 0.0, 0.0, 1.0); + + // Clear Material Info Buffer. + OUT_col2 = vec4(0.0, 0.0, 0.0, 1.0); +} diff --git a/Templates/Full/game/shaders/common/lighting/advanced/gl/deferredColorShaderP.glsl b/Templates/Full/game/shaders/common/lighting/advanced/gl/deferredColorShaderP.glsl new file mode 100644 index 000000000..85c553089 --- /dev/null +++ b/Templates/Full/game/shaders/common/lighting/advanced/gl/deferredColorShaderP.glsl @@ -0,0 +1,37 @@ +//----------------------------------------------------------------------------- +// 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. +//----------------------------------------------------------------------------- + +layout (location = 0) out vec4 col; +layout (location = 1) out vec4 col1; +layout (location = 2) out vec4 col2; + +//----------------------------------------------------------------------------- +// Main +//----------------------------------------------------------------------------- +void main() +{ + col = vec4(0.0, 0.0, 0.0, 0.0); + col1 = vec4(1.0, 1.0, 1.0, 1.0); + + // Draw on color buffer. + col2 = vec4(1.0, 0.0, 0.0, 1.0); +} diff --git a/Templates/Full/game/shaders/common/lighting/advanced/gl/deferredShadingP.glsl b/Templates/Full/game/shaders/common/lighting/advanced/gl/deferredShadingP.glsl new file mode 100644 index 000000000..4ee4b1d81 --- /dev/null +++ b/Templates/Full/game/shaders/common/lighting/advanced/gl/deferredShadingP.glsl @@ -0,0 +1,59 @@ +//----------------------------------------------------------------------------- +// 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 "../../../gl/hlslCompat.glsl" +#include "shadergen:/autogenConditioners.h" +#include "../../../postfx/gl/postFx.glsl" +#include "../../../gl/torque.glsl" + +uniform sampler2D colorBufferTex; +uniform sampler2D lightPrePassTex; +uniform sampler2D matInfoTex; +uniform sampler2D prepassTex; + +out vec4 OUT_col; + +void main() +{ + float depth = prepassUncondition( prepassTex, uv0 ).w; + if (depth>0.9999) + { + OUT_col = vec4(0.0); + return; + } + vec4 lightBuffer = texture( lightPrePassTex, uv0 ); + vec4 colorBuffer = texture( colorBufferTex, uv0 ); + vec4 matInfo = texture( matInfoTex, uv0 ); + float specular = clamp(lightBuffer.a,0.0,1.0); + + // Diffuse Color Altered by Metalness + bool metalness = getFlag(matInfo.r, 3); + if ( metalness ) + { + colorBuffer *= (1.0 - colorBuffer.a); + } + + colorBuffer *= vec4(lightBuffer.rgb, 1.0); + colorBuffer += vec4(specular, specular, specular, 1.0); + + OUT_col = hdrEncode( vec4(colorBuffer.rgb, 1.0) ); +} diff --git a/Templates/Full/game/shaders/common/lighting/advanced/gl/pointLightP.glsl b/Templates/Full/game/shaders/common/lighting/advanced/gl/pointLightP.glsl index 92c9369a7..8a1aae3ca 100644 --- a/Templates/Full/game/shaders/common/lighting/advanced/gl/pointLightP.glsl +++ b/Templates/Full/game/shaders/common/lighting/advanced/gl/pointLightP.glsl @@ -33,6 +33,7 @@ in vec4 wsEyeDir; in vec4 ssPos; in vec4 vsEyeDir; +in vec4 color; #ifdef USE_COOKIE_TEX @@ -111,6 +112,10 @@ uniform sampler2D prePassBuffer; uniform sampler2D dynamicShadowMap; #endif +uniform sampler2D lightBuffer; +uniform sampler2D colorBuffer; +uniform sampler2D matInfoBuffer; + uniform vec4 rtParams0; uniform vec3 lightPosition; @@ -133,6 +138,15 @@ void main() vec3 ssPos = ssPos.xyz / ssPos.w; vec2 uvScene = getUVFromSSPos( ssPos, rtParams0 ); + // Emissive. + vec4 matInfo = texture( matInfoBuffer, uvScene ); + bool emissive = getFlag( matInfo.r, 0 ); + if ( emissive ) + { + OUT_col = vec4(0.0, 0.0, 0.0, 0.0); + return; + } + // Sample/unpack the normal/z data vec4 prepassSample = prepassUncondition( prePassBuffer, uvScene ); vec3 normal = prepassSample.rgb; @@ -244,5 +258,6 @@ void main() addToResult = ( 1.0 - shadowed ) * abs(lightMapParams); } - OUT_col = lightinfoCondition( lightColorOut, Sat_NL_Att, specular, addToResult ); + vec4 colorSample = texture( colorBuffer, uvScene ); + OUT_col = AL_DeferredOutput(lightColorOut, colorSample.rgb, matInfo, addToResult, specular, Sat_NL_Att); } diff --git a/Templates/Full/game/shaders/common/lighting/advanced/gl/spotLightP.glsl b/Templates/Full/game/shaders/common/lighting/advanced/gl/spotLightP.glsl index 29c278508..e7f3e88a7 100644 --- a/Templates/Full/game/shaders/common/lighting/advanced/gl/spotLightP.glsl +++ b/Templates/Full/game/shaders/common/lighting/advanced/gl/spotLightP.glsl @@ -32,10 +32,12 @@ in vec4 wsEyeDir; in vec4 ssPos; in vec4 vsEyeDir; +in vec4 color; #define IN_wsEyeDir wsEyeDir #define IN_ssPos ssPos #define IN_vsEyeDir vsEyeDir +#define IN_color color #ifdef USE_COOKIE_TEX @@ -48,6 +50,10 @@ uniform sampler2D prePassBuffer; uniform sampler2D shadowMap; uniform sampler2D dynamicShadowMap; +uniform sampler2D lightBuffer; +uniform sampler2D colorBuffer; +uniform sampler2D matInfoBuffer; + uniform vec4 rtParams0; uniform vec3 lightPosition; @@ -74,6 +80,15 @@ void main() vec3 ssPos = IN_ssPos.xyz / IN_ssPos.w; vec2 uvScene = getUVFromSSPos( ssPos, rtParams0 ); + // Emissive. + vec4 matInfo = texture( matInfoBuffer, uvScene ); + bool emissive = getFlag( matInfo.r, 0 ); + if ( emissive ) + { + OUT_col = vec4(0.0, 0.0, 0.0, 0.0); + return; + } + // Sample/unpack the normal/z data vec4 prepassSample = prepassUncondition( prePassBuffer, uvScene ); vec3 normal = prepassSample.rgb; @@ -180,5 +195,6 @@ void main() addToResult = ( 1.0 - shadowed ) * abs(lightMapParams); } - OUT_col = lightinfoCondition( lightColorOut, Sat_NL_Att, specular, addToResult ); + vec4 colorSample = texture( colorBuffer, uvScene ); + OUT_col = AL_DeferredOutput(lightColorOut, colorSample.rgb, matInfo, addToResult, specular, Sat_NL_Att); } diff --git a/Templates/Full/game/shaders/common/lighting/advanced/gl/vectorLightP.glsl b/Templates/Full/game/shaders/common/lighting/advanced/gl/vectorLightP.glsl index 4eb4973a3..608524a5a 100644 --- a/Templates/Full/game/shaders/common/lighting/advanced/gl/vectorLightP.glsl +++ b/Templates/Full/game/shaders/common/lighting/advanced/gl/vectorLightP.glsl @@ -39,10 +39,13 @@ uniform sampler2D dynamicShadowMap; #ifdef USE_SSAO_MASK uniform sampler2D ssaoMask ; -uniform vec4 rtParams2; +uniform vec4 rtParams3; #endif -uniform sampler2D prePassBuffer; +uniform sampler2D prePassBuffer; +uniform sampler2D lightBuffer; +uniform sampler2D colorBuffer; +uniform sampler2D matInfoBuffer; uniform vec3 lightDirection; uniform vec4 lightColor; uniform float lightBrightness; @@ -189,7 +192,16 @@ vec4 AL_VectorLightShadowCast( sampler2D _sourceshadowMap, out vec4 OUT_col; void main() -{ +{ + // Emissive. + float4 matInfo = texture( matInfoBuffer, uv0 ); + bool emissive = getFlag( matInfo.r, 0 ); + if ( emissive ) + { + OUT_col = vec4(1.0, 1.0, 1.0, 0.0); + return; + } + // Sample/unpack the normal/z data vec4 prepassSample = prepassUncondition( prePassBuffer, uv0 ); vec3 normal = prepassSample.rgb; @@ -228,8 +240,6 @@ void main() shadowSoftness, dotNL, overDarkPSSM); - - vec4 dynamic_shadowed_colors = AL_VectorLightShadowCast( dynamicShadowMap, uv0.xy, dynamicWorldToLightProj, @@ -242,14 +252,13 @@ void main() shadowSoftness, dotNL, overDarkPSSM); - float static_shadowed = static_shadowed_colors.a; float dynamic_shadowed = dynamic_shadowed_colors.a; #ifdef PSSM_DEBUG_RENDER debugColor = static_shadowed_colors.rgb*0.5+dynamic_shadowed_colors.rgb*0.5; #endif - + // Fade out the shadow at the end of the range. vec4 zDist = vec4(zNearFarInvNearFar.x + zNearFarInvNearFar.y * depth); float fadeOutAmt = ( zDist.x - fadeStartLength.x ) * fadeStartLength.y; @@ -295,7 +304,7 @@ void main() // Sample the AO texture. #ifdef USE_SSAO_MASK - float ao = 1.0 - texture( ssaoMask, viewportCoordToRenderTarget( uv0.xy, rtParams2 ) ).r; + float ao = 1.0 - texture( ssaoMask, viewportCoordToRenderTarget( uv0.xy, rtParams3 ) ).r; addToResult *= ao; #endif @@ -303,6 +312,6 @@ void main() lightColorOut = debugColor; #endif - OUT_col = lightinfoCondition( lightColorOut, Sat_NL_Att, specular, addToResult ); - + vec4 colorSample = texture( colorBuffer, uv0 ); + OUT_col = AL_DeferredOutput(lightColorOut, colorSample.rgb, matInfo, addToResult, specular, Sat_NL_Att); } diff --git a/Templates/Full/game/shaders/common/lighting/advanced/pointLightP.hlsl b/Templates/Full/game/shaders/common/lighting/advanced/pointLightP.hlsl index 48c0d76e3..9051ff09d 100644 --- a/Templates/Full/game/shaders/common/lighting/advanced/pointLightP.hlsl +++ b/Templates/Full/game/shaders/common/lighting/advanced/pointLightP.hlsl @@ -34,6 +34,7 @@ struct ConvexConnectP float4 wsEyeDir : TEXCOORD0; float4 ssPos : TEXCOORD1; float4 vsEyeDir : TEXCOORD2; + float4 color : COLOR0; }; @@ -117,6 +118,10 @@ float4 main( ConvexConnectP IN, uniform sampler2D dynamicShadowMap : register(S2), #endif + uniform sampler2D lightBuffer : register(S5), + uniform sampler2D colorBuffer : register(S6), + uniform sampler2D matInfoBuffer : register(S7), + uniform float4 rtParams0, uniform float3 lightPosition, @@ -136,7 +141,15 @@ float4 main( ConvexConnectP IN, // Compute scene UV float3 ssPos = IN.ssPos.xyz / IN.ssPos.w; float2 uvScene = getUVFromSSPos( ssPos, rtParams0 ); - + + // Emissive. + float4 matInfo = tex2D( matInfoBuffer, uvScene ); + bool emissive = getFlag( matInfo.r, 0 ); + if ( emissive ) + { + return float4(0.0, 0.0, 0.0, 0.0); + } + // Sample/unpack the normal/z data float4 prepassSample = prepassUncondition( prePassBuffer, uvScene ); float3 normal = prepassSample.rgb; @@ -250,5 +263,6 @@ float4 main( ConvexConnectP IN, addToResult = ( 1.0 - shadowed ) * abs(lightMapParams); } - return lightinfoCondition( lightColorOut, Sat_NL_Att, specular, addToResult ); + float4 colorSample = tex2D( colorBuffer, uvScene ); + return AL_DeferredOutput(lightColorOut, colorSample.rgb, matInfo, addToResult, specular, Sat_NL_Att); } diff --git a/Templates/Full/game/shaders/common/lighting/advanced/spotLightP.hlsl b/Templates/Full/game/shaders/common/lighting/advanced/spotLightP.hlsl index 33c7f333e..226b9cfea 100644 --- a/Templates/Full/game/shaders/common/lighting/advanced/spotLightP.hlsl +++ b/Templates/Full/game/shaders/common/lighting/advanced/spotLightP.hlsl @@ -34,6 +34,7 @@ struct ConvexConnectP float4 wsEyeDir : TEXCOORD0; float4 ssPos : TEXCOORD1; float4 vsEyeDir : TEXCOORD2; + float4 color : COLOR0; }; #ifdef USE_COOKIE_TEX @@ -50,6 +51,10 @@ float4 main( ConvexConnectP IN, uniform sampler2D shadowMap : register(S1), uniform sampler2D dynamicShadowMap : register(S2), + uniform sampler2D lightBuffer : register(S5), + uniform sampler2D colorBuffer : register(S6), + uniform sampler2D matInfoBuffer : register(S7), + uniform float4 rtParams0, uniform float3 lightPosition, @@ -72,6 +77,14 @@ float4 main( ConvexConnectP IN, float3 ssPos = IN.ssPos.xyz / IN.ssPos.w; float2 uvScene = getUVFromSSPos( ssPos, rtParams0 ); + // Emissive. + float4 matInfo = tex2D( matInfoBuffer, uvScene ); + bool emissive = getFlag( matInfo.r, 0 ); + if ( emissive ) + { + return float4(0.0, 0.0, 0.0, 0.0); + } + // Sample/unpack the normal/z data float4 prepassSample = prepassUncondition( prePassBuffer, uvScene ); float3 normal = prepassSample.rgb; @@ -179,5 +192,6 @@ float4 main( ConvexConnectP IN, addToResult = ( 1.0 - shadowed ) * abs(lightMapParams); } - return lightinfoCondition( lightColorOut, Sat_NL_Att, specular, addToResult ); + float4 colorSample = tex2D( colorBuffer, uvScene ); + return AL_DeferredOutput(lightColorOut, colorSample.rgb, matInfo, addToResult, specular, Sat_NL_Att); } diff --git a/Templates/Full/game/shaders/common/lighting/advanced/vectorLightP.hlsl b/Templates/Full/game/shaders/common/lighting/advanced/vectorLightP.hlsl index 2d719587e..896576564 100644 --- a/Templates/Full/game/shaders/common/lighting/advanced/vectorLightP.hlsl +++ b/Templates/Full/game/shaders/common/lighting/advanced/vectorLightP.hlsl @@ -157,6 +157,10 @@ float4 main( FarFrustumQuadConnectP IN, uniform sampler2D prePassBuffer : register(S0), + uniform sampler2D lightBuffer : register(S5), + uniform sampler2D colorBuffer : register(S6), + uniform sampler2D matInfoBuffer : register(S7), + uniform float3 lightDirection, uniform float4 lightColor, uniform float lightBrightness, @@ -190,7 +194,15 @@ float4 main( FarFrustumQuadConnectP IN, uniform float4 dynamicFarPlaneScalePSSM ) : COLOR0 -{ +{ + // Emissive. + float4 matInfo = tex2D( matInfoBuffer, IN.uv0 ); + bool emissive = getFlag( matInfo.r, 0 ); + if ( emissive ) + { + return float4(1.0, 1.0, 1.0, 0.0); + } + // Sample/unpack the normal/z data float4 prepassSample = prepassUncondition( prePassBuffer, IN.uv0 ); float3 normal = prepassSample.rgb; @@ -229,7 +241,6 @@ float4 main( FarFrustumQuadConnectP IN, shadowSoftness, dotNL, overDarkPSSM); - float4 dynamic_shadowed_colors = AL_VectorLightShadowCast( dynamicShadowMap, IN.uv0.xy, dynamicWorldToLightProj, @@ -276,6 +287,7 @@ float4 main( FarFrustumQuadConnectP IN, float Sat_NL_Att = saturate( dotNL * shadowed ) * lightBrightness; float3 lightColorOut = lightMapParams.rgb * lightColor.rgb; + float4 addToResult = (lightAmbient * (1 - ambientCameraFactor)) + ( lightAmbient * ambientCameraFactor * saturate(dot(normalize(-IN.vsEyeRay), normal)) ); // TODO: This needs to be removed when lightmapping is disabled @@ -303,5 +315,6 @@ float4 main( FarFrustumQuadConnectP IN, lightColorOut = debugColor; #endif - return lightinfoCondition( lightColorOut, Sat_NL_Att, specular, addToResult ); + float4 colorSample = tex2D( colorBuffer, IN.uv0 ); + return AL_DeferredOutput(lightColorOut, colorSample.rgb, matInfo, addToResult, specular, Sat_NL_Att); } diff --git a/Templates/Full/game/shaders/common/postFx/hdr/finalPassCombineP.hlsl b/Templates/Full/game/shaders/common/postFx/hdr/finalPassCombineP.hlsl index 9541f39cb..cb71f01c2 100644 --- a/Templates/Full/game/shaders/common/postFx/hdr/finalPassCombineP.hlsl +++ b/Templates/Full/game/shaders/common/postFx/hdr/finalPassCombineP.hlsl @@ -20,6 +20,7 @@ // IN THE SOFTWARE. //----------------------------------------------------------------------------- +#include "shadergen:/autogenConditioners.h" #include "../../torque.hlsl" #include "../postFx.hlsl" @@ -27,6 +28,7 @@ uniform sampler2D sceneTex : register( s0 ); uniform sampler2D luminanceTex : register( s1 ); uniform sampler2D bloomTex : register( s2 ); uniform sampler1D colorCorrectionTex : register( s3 ); +uniform sampler2D prepassTex : register(S4); uniform float2 texSize0; uniform float2 texSize2; @@ -83,13 +85,16 @@ float4 main( PFXVertToPix IN ) : COLOR0 } // Add the bloom effect. - sample += g_fBloomScale * bloom; + float depth = prepassUncondition( prepassTex, IN.uv0 ).w; + if (depth>0.9999) + sample += g_fBloomScale * bloom; // Apply the color correction. sample.r = tex1D( colorCorrectionTex, sample.r ).r; sample.g = tex1D( colorCorrectionTex, sample.g ).g; sample.b = tex1D( colorCorrectionTex, sample.b ).b; + // Apply gamma correction sample.rgb = pow( abs(sample.rgb), g_fOneOverGamma ); diff --git a/Templates/Full/game/shaders/common/postFx/hdr/gl/finalPassCombineP.glsl b/Templates/Full/game/shaders/common/postFx/hdr/gl/finalPassCombineP.glsl index 123c831f3..24a516e79 100644 --- a/Templates/Full/game/shaders/common/postFx/hdr/gl/finalPassCombineP.glsl +++ b/Templates/Full/game/shaders/common/postFx/hdr/gl/finalPassCombineP.glsl @@ -23,11 +23,13 @@ #include "../../../gl/torque.glsl" #include "../../../gl/hlslCompat.glsl" #include "../../gl/postFX.glsl" +#include "shadergen:/autogenConditioners.h" uniform sampler2D sceneTex; uniform sampler2D luminanceTex; uniform sampler2D bloomTex; uniform sampler1D colorCorrectionTex; +uniform sampler2D prepassTex; uniform vec2 texSize0; uniform vec2 texSize2; @@ -86,7 +88,9 @@ void main() } // Add the bloom effect. - _sample += g_fBloomScale * bloom; + float depth = prepassUncondition( prepassTex, IN_uv0 ).w; + if (depth>0.9999) + _sample += g_fBloomScale * bloom; // Apply the color correction. _sample.r = texture( colorCorrectionTex, _sample.r ).r; diff --git a/Templates/Full/game/shaders/common/scatterSkyP.hlsl b/Templates/Full/game/shaders/common/scatterSkyP.hlsl index 572abdd74..1a9433c73 100644 --- a/Templates/Full/game/shaders/common/scatterSkyP.hlsl +++ b/Templates/Full/game/shaders/common/scatterSkyP.hlsl @@ -62,6 +62,6 @@ float4 main( Conn In ) : COLOR0 Out = lerp( color, nightSkyColor, nightInterpAndExposure.y ); Out.a = 1; - + Out = saturate(Out); return hdrEncode( Out ); } diff --git a/Templates/Full/game/shaders/common/terrain/terrain.glsl b/Templates/Full/game/shaders/common/terrain/terrain.glsl index 79f80888c..756edd553 100644 --- a/Templates/Full/game/shaders/common/terrain/terrain.glsl +++ b/Templates/Full/game/shaders/common/terrain/terrain.glsl @@ -32,6 +32,7 @@ float calcBlend( float texId, vec2 layerCoord, float layerSize, vec4 layerSample vec4 diff = clamp( abs( layerSample - texId ), 0.0, 1.0 ); float noBlend = float(any( bvec4(1 - diff) )); + // Check if any of the layer samples // match the current texture id. vec4 factors = vec4(0); for(int i = 0; i < 4; i++) diff --git a/Templates/Full/game/shaders/common/water/gl/waterP.glsl b/Templates/Full/game/shaders/common/water/gl/waterP.glsl index 15002849f..a68ede84e 100644 --- a/Templates/Full/game/shaders/common/water/gl/waterP.glsl +++ b/Templates/Full/game/shaders/common/water/gl/waterP.glsl @@ -295,7 +295,7 @@ void main() foamColor.rgb *= FOAM_OPACITY * foamAmt * foamColor.a; // Get reflection map color. - vec4 refMapColor = hdrDecode( texture( reflectMap, reflectCoord ) ); + vec4 refMapColor = texture( reflectMap, reflectCoord ); // If we do not have a reflection texture then we use the cubemap. refMapColor = mix( refMapColor, texture( skyMap, reflectionVec ), NO_REFLECT ); diff --git a/Templates/Full/game/shaders/common/water/waterP.hlsl b/Templates/Full/game/shaders/common/water/waterP.hlsl index 2b4035755..c4edff0d7 100644 --- a/Templates/Full/game/shaders/common/water/waterP.hlsl +++ b/Templates/Full/game/shaders/common/water/waterP.hlsl @@ -282,7 +282,7 @@ float4 main( ConnectData IN ) : COLOR foamColor.rgb *= FOAM_OPACITY * foamAmt * foamColor.a; // Get reflection map color. - float4 refMapColor = hdrDecode( tex2D( reflectMap, reflectCoord ) ); + float4 refMapColor = tex2D( reflectMap, reflectCoord ); // If we do not have a reflection texture then we use the cubemap. refMapColor = lerp( refMapColor, texCUBE( skyMap, reflectionVec ), NO_REFLECT ); diff --git a/Templates/Full/game/tools/materialEditor/gui/guiMaterialPropertiesWindow.ed.gui b/Templates/Full/game/tools/materialEditor/gui/guiMaterialPropertiesWindow.ed.gui index 2062f43f3..63ce28e2a 100644 --- a/Templates/Full/game/tools/materialEditor/gui/guiMaterialPropertiesWindow.ed.gui +++ b/Templates/Full/game/tools/materialEditor/gui/guiMaterialPropertiesWindow.ed.gui @@ -1354,132 +1354,6 @@ bitmap = "tools/gui/images/delete"; }; }; - new GuiBitmapCtrl(){ - position="6 357"; - extent ="175 2"; - HorizSizing = "width"; - bitmap ="tools/gui/images/separator-v"; - }; - new GuiContainer(){ // Environment Map - profile="ToolsGuiDefaultProfile"; - isContainer = "1"; - position = "6 359"; - Extent = "185 52"; - HorizSizing = "width"; - - new GuiBitmapCtrl() { - canSaveDynamicFields = "0"; - internalName = "envMapDisplayBitmap"; - Enabled = "1"; - isContainer = "0"; - Profile = "ToolsGuiDefaultProfile"; - HorizSizing = "right"; - VertSizing = "bottom"; - position = "1 1"; - Extent = "48 48"; - MinExtent = "8 2"; - canSave = "1"; - Visible = "1"; - hovertime = "1000"; - bitmap = "tools/materialeditor/gui/unknownImage"; - wrap = "0"; - }; - new GuiTextCtrl() { - canSaveDynamicFields = "0"; - Enabled = "1"; - isContainer = "0"; - Profile = "EditorTextProfile"; - HorizSizing = "right"; - VertSizing = "bottom"; - position = "56 -3"; - Extent = "72 18"; - MinExtent = "8 2"; - canSave = "1"; - Visible = "1"; - hovertime = "1000"; - Margin = "0 0 0 0"; - Padding = "0 0 0 0"; - AnchorTop = "1"; - AnchorBottom = "0"; - AnchorLeft = "1"; - AnchorRight = "0"; - text = "Env Map"; - maxLength = "1024"; - }; - new GuiBitmapButtonCtrl() { - canSaveDynamicFields = "0"; - Enabled = "1"; - isContainer = "0"; - Profile = "ToolsGuiDefaultProfile"; - HorizSizing = "right"; - VertSizing = "bottom"; - position = "1 1"; - Extent = "48 48"; - MinExtent = "8 2"; - canSave = "1"; - Visible = "1"; - Command = "MaterialEditorGui.updateTextureMap(\"env\", 1);"; - tooltipprofile = "ToolsGuiDefaultProfile"; - ToolTip = "Change the active Environment Map for this layer."; - hovertime = "1000"; - groupNum = "-1"; - buttonType = "PushButton"; - useMouseEvents = "0"; - bitmap = "tools/materialEditor/gui/cubemapBtnBorder"; - }; - new GuiTextCtrl() { - canSaveDynamicFields = "0"; - internalName = "envMapNameText"; - Enabled = "1"; - isContainer = "0"; - Profile = "ToolsGuiTextProfile"; - HorizSizing = "width"; - VertSizing = "bottom"; - position = "56 16"; - Extent = "143 17"; - MinExtent = "8 2"; - canSave = "1"; - Visible = "1"; - hovertime = "1000"; - Margin = "0 0 0 0"; - Padding = "0 0 0 0"; - AnchorTop = "1"; - AnchorBottom = "0"; - AnchorLeft = "1"; - AnchorRight = "0"; - text = "None"; - maxLength = "1024"; - }; - new GuiButtonCtrl(){ - profile="ToolsGuiButtonProfile"; - text ="Edit"; - HorizSizing = "left"; - VertSizing = "bottom"; - position = "134 34"; - Extent = "40 16"; - buttonType = "PushButton"; - command="MaterialEditorGui.updateTextureMap(\"env\", 1);"; - }; - new GuiBitmapButtonCtrl() { - canSaveDynamicFields = "0"; - Enabled = "1"; - isContainer = "0"; - Profile = "ToolsGuiDefaultProfile"; - HorizSizing = "left"; - VertSizing = "bottom"; - position = "177 34"; - Extent = "16 16"; - MinExtent = "8 2"; - canSave = "1"; - Visible = "1"; - Command = "MaterialEditorGui.updateTextureMap(\"env\", 0);"; - hovertime = "1000"; - groupNum = "-1"; - buttonType = "PushButton"; - useMouseEvents = "0"; - bitmap = "tools/gui/images/delete"; - }; - }; }; }; new GuiRolloutCtrl() { @@ -1491,6 +1365,7 @@ Position = "0 0"; Extent = "195 0"; Caption = "Accumulation Properties"; + Expanded = false; Margin = "-1 0 0 0"; DragSizable = false; container = true; @@ -1967,6 +1842,7 @@ Position = "0 0"; Extent = "185 0"; Caption = "Lighting Properties"; + Expanded = false; Margin = "-1 0 0 0"; DragSizable = false; container = true; @@ -2364,101 +2240,6 @@ useMouseEvents = "0"; useInactiveState = "0"; }; - new GuiCheckBoxCtrl() { - canSaveDynamicFields = "0"; - internalName = "subSurfaceCheckbox"; - Enabled = "1"; - isContainer = "0"; - Profile = "ToolsGuiCheckBoxProfile"; - HorizSizing = "right"; - VertSizing = "bottom"; - position = "8 46"; - Extent = "79 16"; - MinExtent = "8 2"; - canSave = "1"; - Visible = "1"; - Command = "MaterialEditorGui.updateActiveMaterial(\"subSurface[\" @ MaterialEditorGui.currentLayer @ \"]\", $ThisControl.getValue());"; - tooltipprofile = "ToolsGuiDefaultProfile"; - ToolTip = "Enables the use of subsurface scattering for this layer."; - hovertime = "1000"; - text = "Sub Surface"; - groupNum = "-1"; - buttonType = "ToggleButton"; - useMouseEvents = "0"; - useInactiveState = "0"; - }; - new GuiSwatchButtonCtrl() { - canSaveDynamicFields = "0"; - internalName = "subSurfaceColorSwatch"; - Enabled = "1"; - isContainer = "0"; - Profile = "GuiInspectorSwatchButtonProfile"; - HorizSizing = "right"; - VertSizing = "bottom"; - position = "90 46"; - Extent = "16 16"; - MinExtent = "8 2"; - canSave = "1"; - Visible = "1"; - Command = "getColorF(materialEd_PreviewMaterial.subSurfaceColor[MaterialEditorGui.currentLayer], \"MaterialEditorGui.updateSubSurfaceColor\");"; - tooltip = "Set the subsurface scattering color"; - hovertime = "1000"; - groupNum = "-1"; - buttonType = "PushButton"; - useMouseEvents = "0"; - }; - new GuiTextEditCtrl() { - canSaveDynamicFields = "0"; - internalName = "subSurfaceRolloffTextEdit"; - Enabled = "1"; - isContainer = "0"; - Profile = "ToolsGuiTextEditProfile"; - HorizSizing = "right"; - VertSizing = "bottom"; - position = "114 45"; - Extent = "29 18"; - MinExtent = "8 2"; - canSave = "1"; - Visible = "1"; - tooltip = "Set the subsurface rolloff factor"; - Command = "MaterialEditorGui.updateActiveMaterial(\"subSurfaceRolloff[\" @ MaterialEditorGui.currentLayer @ \"]\", $ThisControl.getText());"; - hovertime = "1000"; - AnchorTop = "1"; - AnchorBottom = "0"; - AnchorLeft = "1"; - AnchorRight = "0"; - text = "32"; - maxLength = "5"; - }; - new GuiTextCtrl() { - HorizSizing = "right"; - VertSizing = "bottom"; - position = "9 65"; - Extent = "89 16"; - text = "Minnaert constant"; - }; - new GuiTextEditCtrl() { - canSaveDynamicFields = "0"; - internalName = "minnaertTextEdit"; - Enabled = "1"; - isContainer = "0"; - Profile = "ToolsGuiTextEditProfile"; - HorizSizing = "right"; - VertSizing = "bottom"; - position = "114 65"; - Extent = "29 18"; - MinExtent = "8 2"; - canSave = "1"; - Visible = "1"; - Command = "MaterialEditorGui.updateActiveMaterial(\"minnaertConstant[\" @ MaterialEditorGui.currentLayer @ \"]\", $ThisControl.getText());"; - hovertime = "1000"; - AnchorTop = "1"; - AnchorBottom = "0"; - AnchorLeft = "1"; - AnchorRight = "0"; - text = "32"; - maxLength = "3"; - }; }; }; }; @@ -2471,9 +2252,9 @@ Position = "0 0"; Extent = "185 0"; Caption = "Animation Properties"; + Expanded = false; Margin = "-1 0 0 0"; DragSizable = false; - Expanded = false; container = true; parentRollout = %this.rollout; object = %behavior; @@ -3283,6 +3064,7 @@ Position = "0 0"; Extent = "202 0"; Caption = "Advanced (all layers)"; + Expanded = false; Margin = "4 4 4 0"; DragSizable = false; container = true; @@ -3519,7 +3301,7 @@ Profile = "ToolsGuiCheckBoxProfile"; HorizSizing = "right"; VertSizing = "bottom"; - position = "100 56"; + position = "105 55"; Extent = "85 16"; MinExtent = "8 2"; canSave = "1"; diff --git a/Templates/Full/game/tools/worldEditor/main.cs b/Templates/Full/game/tools/worldEditor/main.cs index a6ecb2872..59301ea53 100644 --- a/Templates/Full/game/tools/worldEditor/main.cs +++ b/Templates/Full/game/tools/worldEditor/main.cs @@ -120,6 +120,9 @@ function initializeWorldEditor() EVisibility.addOption( "AL: Light Specular Viz", "$AL_LightSpecularVisualizeVar", "toggleLightSpecularViz" ); EVisibility.addOption( "AL: Normals Viz", "$AL_NormalsVisualizeVar", "toggleNormalsViz" ); EVisibility.addOption( "AL: Depth Viz", "$AL_DepthVisualizeVar", "toggleDepthViz" ); + EVisibility.addOption( "AL: Color Buffer", "$AL_ColorBufferShaderVar", "toggleColorBufferViz" ); + EVisibility.addOption( "AL: Spec Map", "$AL_SpecMapShaderVar", "toggleSpecMapViz"); + EVisibility.addOption( "AL: Backbuffer", "$AL_BackbufferVisualizeVar", "toggleBackbufferViz" ); EVisibility.addOption( "AL: Glow Buffer", "$AL_GlowVisualizeVar", "toggleGlowViz" ); EVisibility.addOption( "AL: PSSM Cascade Viz", "$AL::PSSMDebugRender", "" ); EVisibility.addOption( "Frustum Lock", "$Scene::lockCull", "" );