From 645f88d4af43c37a2261f40ed43edee719ffb2b6 Mon Sep 17 00:00:00 2001 From: AzaezelX Date: Thu, 29 Dec 2022 13:38:30 -0600 Subject: [PATCH] emissive to recivesShadows now we've got a glow mask and multiplier, ditch the emissive flag in favor of a proper recivesShadows --- Engine/source/environment/skyBox.cpp | 2 +- Engine/source/environment/skySphere.cpp | 2 +- Engine/source/materials/matInstance.cpp | 3 +-- .../source/materials/materialDefinition.cpp | 4 +-- Engine/source/materials/materialDefinition.h | 2 +- .../source/materials/materialFeatureTypes.cpp | 1 - .../source/materials/materialFeatureTypes.h | 1 - Engine/source/materials/materialManager.cpp | 2 +- .../materials/processedShaderMaterial.cpp | 13 +++------ .../renderInstance/renderOcclusionMgr.cpp | 4 +-- .../lighting/advanced/gl/pointLightP.glsl | 27 +++++++------------ .../advanced/gl/reflectionProbeArrayP.glsl | 7 ----- .../lighting/advanced/gl/spotLightP.glsl | 19 +++++-------- .../lighting/advanced/gl/vectorLightP.glsl | 21 +++++---------- .../lighting/advanced/pointLightP.hlsl | 16 +++++------ .../advanced/reflectionProbeArrayP.hlsl | 6 ----- .../shaders/lighting/advanced/spotLightP.hlsl | 24 +++++++++-------- .../lighting/advanced/vectorLightP.hlsl | 20 +++++--------- .../gui/guiMaterialPropertiesWindow.ed.gui | 8 +++--- .../scripts/materialEditor.ed.tscript | 2 +- 20 files changed, 70 insertions(+), 114 deletions(-) diff --git a/Engine/source/environment/skyBox.cpp b/Engine/source/environment/skyBox.cpp index 8bd378272..c7911533f 100644 --- a/Engine/source/environment/skyBox.cpp +++ b/Engine/source/environment/skyBox.cpp @@ -572,7 +572,7 @@ void SkyBox::_initRender() mFogBandMat->mTranslucent = true; mFogBandMat->mVertColor[0] = true; mFogBandMat->mDoubleSided = true; - mFogBandMat->mEmissive[0] = true; + mFogBandMat->mReceiveShadows[0] = false; FeatureSet features = MATMGR->getDefaultFeatures(); features.addFeature(MFT_isBackground); diff --git a/Engine/source/environment/skySphere.cpp b/Engine/source/environment/skySphere.cpp index a367b8854..433058dcd 100644 --- a/Engine/source/environment/skySphere.cpp +++ b/Engine/source/environment/skySphere.cpp @@ -570,7 +570,7 @@ void SkySphere::_initRender() mFogBandMat->mTranslucent = true; mFogBandMat->mVertColor[0] = true; mFogBandMat->mDoubleSided = true; - mFogBandMat->mEmissive[0] = true; + mFogBandMat->mReceiveShadows[0] = false; FeatureSet features = MATMGR->getDefaultFeatures(); features.addFeature(MFT_isBackground); diff --git a/Engine/source/materials/matInstance.cpp b/Engine/source/materials/matInstance.cpp index eeb049129..ab41a3892 100644 --- a/Engine/source/materials/matInstance.cpp +++ b/Engine/source/materials/matInstance.cpp @@ -384,8 +384,7 @@ bool MatInstance::processMaterial() mUsesHardwareSkinning = finalFeatures.hasFeature( MFT_HardwareSkinning ); mIsForwardLit = ( custMat && custMat->mForwardLit ) || - ( !finalFeatures.hasFeature( MFT_IsEmissive ) && - finalFeatures.hasFeature( MFT_ForwardShading ) ); + ( finalFeatures.hasFeature( MFT_ForwardShading ) ); mIsHardwareSkinned = finalFeatures.hasFeature( MFT_HardwareSkinning ); diff --git a/Engine/source/materials/materialDefinition.cpp b/Engine/source/materials/materialDefinition.cpp index 22a4bd7cf..29cc0420d 100644 --- a/Engine/source/materials/materialDefinition.cpp +++ b/Engine/source/materials/materialDefinition.cpp @@ -161,7 +161,7 @@ Material::Material() mVertColor[i] = false; mGlow[i] = false; - mEmissive[i] = false; + mReceiveShadows[i] = true; mDetailScale[i].set(2.0f, 2.0f); @@ -345,7 +345,7 @@ void Material::initPersistFields() addField("subSurfaceRolloff", TypeF32, Offset(mSubSurfaceRolloff, Material), MAX_STAGES, "The 0 to 1 rolloff factor used in the subsurface scattering approximation."); - addField("emissive", TypeBool, Offset(mEmissive, Material), MAX_STAGES, + addField("receiveShadows", TypeBool, Offset(mReceiveShadows, Material), MAX_STAGES, "Enables emissive lighting for the material."); addField("doubleSided", TypeBool, Offset(mDoubleSided, Material), diff --git a/Engine/source/materials/materialDefinition.h b/Engine/source/materials/materialDefinition.h index 369ea4b3d..076063872 100644 --- a/Engine/source/materials/materialDefinition.h +++ b/Engine/source/materials/materialDefinition.h @@ -305,7 +305,7 @@ public: F32 mSeqSegSize[MAX_STAGES]; bool mGlow[MAX_STAGES]; // entire stage glows - bool mEmissive[MAX_STAGES]; + bool mReceiveShadows[MAX_STAGES]; Point2I mCellIndex[MAX_STAGES]; Point2I mCellLayout[MAX_STAGES]; diff --git a/Engine/source/materials/materialFeatureTypes.cpp b/Engine/source/materials/materialFeatureTypes.cpp index 408f5111c..44220a9b1 100644 --- a/Engine/source/materials/materialFeatureTypes.cpp +++ b/Engine/source/materials/materialFeatureTypes.cpp @@ -78,7 +78,6 @@ ImplementFeatureType( MFT_IsBC3nm, U32(-1), -1, true ); ImplementFeatureType( MFT_IsBC5nm, U32(-1), -1, true); ImplementFeatureType( MFT_IsTranslucent, U32(-1), -1, true ); ImplementFeatureType( MFT_IsTranslucentZWrite, U32(-1), -1, true ); -ImplementFeatureType( MFT_IsEmissive, U32(-1), -1, true ); ImplementFeatureType( MFT_DiffuseMapAtlas, U32(-1), -1, true ); ImplementFeatureType( MFT_NormalMapAtlas, U32(-1), -1, true ); ImplementFeatureType( MFT_InterlacedDeferred, U32(-1), -1, true ); diff --git a/Engine/source/materials/materialFeatureTypes.h b/Engine/source/materials/materialFeatureTypes.h index 7a2eff089..5c6d5653f 100644 --- a/Engine/source/materials/materialFeatureTypes.h +++ b/Engine/source/materials/materialFeatureTypes.h @@ -115,7 +115,6 @@ DeclareFeatureType( MFT_AlphaTest ); DeclareFeatureType( MFT_NormalMap ); DeclareFeatureType( MFT_RTLighting ); -DeclareFeatureType( MFT_IsEmissive ); DeclareFeatureType( MFT_SubSurface ); DeclareFeatureType( MFT_LightMap ); DeclareFeatureType( MFT_ToneMap ); diff --git a/Engine/source/materials/materialManager.cpp b/Engine/source/materials/materialManager.cpp index 6922e946d..0a9d470c2 100644 --- a/Engine/source/materials/materialManager.cpp +++ b/Engine/source/materials/materialManager.cpp @@ -254,7 +254,7 @@ BaseMatInstance * MaterialManager::createMeshDebugMatInstance(const LinearColorF debugMat = allocateAndRegister( meshDebugStr ); debugMat->mDiffuse[0] = meshColor; - debugMat->mEmissive[0] = true; + debugMat->mReceiveShadows[0] = false; } BaseMatInstance *debugMatInstance = NULL; diff --git a/Engine/source/materials/processedShaderMaterial.cpp b/Engine/source/materials/processedShaderMaterial.cpp index 397028594..96c172517 100644 --- a/Engine/source/materials/processedShaderMaterial.cpp +++ b/Engine/source/materials/processedShaderMaterial.cpp @@ -353,15 +353,10 @@ void ProcessedShaderMaterial::_determineFeatures( U32 stageNum, if ( mMaterial->mAlphaTest ) fd.features.addFeature( MFT_AlphaTest ); - if (mMaterial->mEmissive[stageNum]) - { - fd.features.addFeature(MFT_IsEmissive); - } - else + if (mMaterial->isTranslucent()) { fd.features.addFeature(MFT_RTLighting); - if (mMaterial->isTranslucent()) - fd.features.addFeature(MFT_ReflectionProbes); + fd.features.addFeature(MFT_ReflectionProbes); } if ( mMaterial->mAnimFlags[stageNum] ) @@ -1204,8 +1199,8 @@ void ProcessedShaderMaterial::_setShaderConstants(SceneRenderState * state, cons // Deferred Shading: Determine Material Info Flags S32 matInfoFlags = - (mMaterial->mEmissive[stageNum] ? 1 : 0) | //emissive - (mMaterial->mSubSurface[stageNum] ? 2 : 0); //subsurface + (mMaterial->mReceiveShadows[stageNum] ? 1 : 0) | //ReceiveShadows + (mMaterial->mSubSurface[stageNum] ? 1 << 2 : 0); //subsurface mMaterial->mMatInfoFlags[stageNum] = matInfoFlags / 255.0f; shaderConsts->setSafe(handles->mMatInfoFlagsSC, mMaterial->mMatInfoFlags[stageNum]); if( handles->mAccuScaleSC->isValid() ) diff --git a/Engine/source/renderInstance/renderOcclusionMgr.cpp b/Engine/source/renderInstance/renderOcclusionMgr.cpp index 98be3451b..32c61398d 100644 --- a/Engine/source/renderInstance/renderOcclusionMgr.cpp +++ b/Engine/source/renderInstance/renderOcclusionMgr.cpp @@ -74,7 +74,7 @@ void RenderOcclusionMgr::init() mMaterial = MATMGR->allocateAndRegister( String::EmptyString ); mMaterial->mDiffuse[0] = LinearColorF( 1, 0, 1, 1 ); - mMaterial->mEmissive[0] = true; + mMaterial->mReceiveShadows[0] = false; mMaterial->mAutoGenerated = true; mMatInstance = mMaterial->createMatInstance(); @@ -234,4 +234,4 @@ void RenderOcclusionMgr::render( SceneRenderState *state ) // Call setup one more time to end the pass. mMatInstance->setupPass( state, sgData ); -} \ No newline at end of file +} diff --git a/Templates/BaseGame/game/core/rendering/shaders/lighting/advanced/gl/pointLightP.glsl b/Templates/BaseGame/game/core/rendering/shaders/lighting/advanced/gl/pointLightP.glsl index e40ca8b29..099f21cb4 100644 --- a/Templates/BaseGame/game/core/rendering/shaders/lighting/advanced/gl/pointLightP.glsl +++ b/Templates/BaseGame/game/core/rendering/shaders/lighting/advanced/gl/pointLightP.glsl @@ -146,13 +146,6 @@ void main() //create surface Surface surface = createSurface( normDepth, colorBuffer, matInfoBuffer, uvScene, eyePosWorld, wsEyeRay, cameraToWorld); - - //early out if emissive - if (getFlag(surface.matFlag, 0)) - { - OUT_col = vec4(0, 0, 0, 0); - return; - } vec3 L = lightPosition - surface.P; float dist = length(L); @@ -162,22 +155,22 @@ void main() float distToLight = dist / lightRange; SurfaceToLight surfaceToLight = createSurfaceToLight(surface, L); - #ifdef NO_SHADOW - float shadowed = 1.0; - #else - + float shadow = 1.0; + #ifndef NO_SHADOW + if (getFlag(surface.matFlag, 0)) //also skip if we don't recieve shadows + { #ifdef SHADOW_CUBE // TODO: We need to fix shadow cube to handle soft shadows! float occ = texture( shadowMap, tMul( worldToLightProj, -surfaceToLight.L ) ).r; - float shadowed = saturate( exp( lightParams.y * ( occ - distToLight ) ) ); + shadow = saturate( exp( lightParams.y * ( occ - distToLight ) ) ); #else - vec2 shadowCoord = decodeShadowCoord( tMul( worldToLightProj, -surfaceToLight.L ) ).xy; - float shadowed = softShadow_filter(shadowMap, ssPos.xy/ssPos.w, shadowCoord, shadowSoftness, distToLight, surfaceToLight.NdotL, lightParams.y); + vec2 shadowCoord = decodeShadowCoord( tMul( worldToLightProj, -surfaceToLight.L ) ).xy; + shadow = softShadow_filter(shadowMap, ssPos.xy/ssPos.w, shadowCoord, shadowSoftness, distToLight, surfaceToLight.NdotL, lightParams.y); #endif - - #endif // !NO_SHADOW + } + #endif // !NO_SHADOW vec3 lightCol = lightColor.rgb; #ifdef USE_COOKIE_TEX @@ -225,7 +218,7 @@ void main() #endif //get punctual light contribution - lighting = getPunctualLight(surface, surfaceToLight, lightCol, lightBrightness, lightInvSqrRange, shadowed); + lighting = getPunctualLight(surface, surfaceToLight, lightCol, lightBrightness, lightInvSqrRange, shadow); } OUT_col = vec4(lighting, 0); diff --git a/Templates/BaseGame/game/core/rendering/shaders/lighting/advanced/gl/reflectionProbeArrayP.glsl b/Templates/BaseGame/game/core/rendering/shaders/lighting/advanced/gl/reflectionProbeArrayP.glsl index 50d7a0295..e9e5b1410 100644 --- a/Templates/BaseGame/game/core/rendering/shaders/lighting/advanced/gl/reflectionProbeArrayP.glsl +++ b/Templates/BaseGame/game/core/rendering/shaders/lighting/advanced/gl/reflectionProbeArrayP.glsl @@ -55,13 +55,6 @@ void main() //create surface Surface surface = createSurface(normDepth, colorBuffer, matInfoBuffer, IN_uv0.xy, eyePosWorld, IN_wsEyeRay, cameraToWorld); - - //early out if emissive - if (getFlag(surface.matFlag, 0)) - { - OUT_col = vec4(surface.albedo, 0); - return; - } #ifdef USE_SSAO_MASK float ssao = 1.0 - texture( ssaoMask, viewportCoordToRenderTarget( IN_uv0.xy, rtParams7 ) ).r; diff --git a/Templates/BaseGame/game/core/rendering/shaders/lighting/advanced/gl/spotLightP.glsl b/Templates/BaseGame/game/core/rendering/shaders/lighting/advanced/gl/spotLightP.glsl index b6a29b72e..afe263c9a 100644 --- a/Templates/BaseGame/game/core/rendering/shaders/lighting/advanced/gl/spotLightP.glsl +++ b/Templates/BaseGame/game/core/rendering/shaders/lighting/advanced/gl/spotLightP.glsl @@ -80,13 +80,6 @@ void main() //create surface Surface surface = createSurface( normDepth, colorBuffer,matInfoBuffer, uvScene, eyePosWorld, wsEyeRay, cameraToWorld); - - //early out if emissive - if (getFlag(surface.matFlag, 0)) - { - OUT_col = vec4(0, 0, 0, 0); - return; - } vec3 L = lightPosition - surface.P; float dist = length(L); @@ -96,9 +89,10 @@ void main() SurfaceToLight surfaceToLight = createSurfaceToLight(surface, L); vec3 lightCol = lightColor.rgb; - #ifdef NO_SHADOW - float shadowed = 1.0; - #else + float shadow = 1.0; + #ifndef NO_SHADOW + if (getFlag(surface.matFlag, 0)) //also skip if we don't recieve shadows + { // Get the shadow texture coordinate vec4 pxlPosLightProj = tMul( worldToLightProj, vec4( surface.P, 1 ) ); vec2 shadowCoord = ( ( pxlPosLightProj.xy / pxlPosLightProj.w ) * 0.5 ) + vec2( 0.5, 0.5 ); @@ -106,7 +100,7 @@ void main() //distance to light in shadow map space float distToLight = pxlPosLightProj.z / lightRange; - float shadowed = softShadow_filter(shadowMap, ssPos.xy/ssPos.w, shadowCoord, shadowSoftness, distToLight, surfaceToLight.NdotL, lightParams.y); + shadow = softShadow_filter(shadowMap, ssPos.xy/ssPos.w, shadowCoord, shadowSoftness, distToLight, surfaceToLight.NdotL, lightParams.y); #ifdef USE_COOKIE_TEX // Lookup the cookie sample. vec4 cookie = texture(cookieMap, shadowCoord); @@ -117,6 +111,7 @@ void main() // regions of the cookie texture. lightCol *= max(cookie.r, max(cookie.g, cookie.b)); #endif + } #endif @@ -156,7 +151,7 @@ void main() #endif //get Punctual light contribution - lighting = getPunctualLight(surface, surfaceToLight, lightCol, lightBrightness, lightInvSqrRange, shadowed); + lighting = getPunctualLight(surface, surfaceToLight, lightCol, lightBrightness, lightInvSqrRange, shadow); //get spot angle attenuation lighting *= getSpotAngleAtt(-surfaceToLight.L, lightDirection, lightSpotParams ); } diff --git a/Templates/BaseGame/game/core/rendering/shaders/lighting/advanced/gl/vectorLightP.glsl b/Templates/BaseGame/game/core/rendering/shaders/lighting/advanced/gl/vectorLightP.glsl index a2657fb23..fd86f7b16 100644 --- a/Templates/BaseGame/game/core/rendering/shaders/lighting/advanced/gl/vectorLightP.glsl +++ b/Templates/BaseGame/game/core/rendering/shaders/lighting/advanced/gl/vectorLightP.glsl @@ -186,24 +186,17 @@ void main() //create surface Surface surface = createSurface( normDepth, colorBuffer, matInfoBuffer, uv0, eyePosWorld, wsEyeRay, cameraToWorld); - - //early out if emissive - if (getFlag(surface.matFlag, 0)) - { - OUT_col = vec4(0, 0, 0, 0); - return; - } - + //create surface to light SurfaceToLight surfaceToLight = createSurfaceToLight(surface, -lightDirection); //light color might be changed by PSSM_DEBUG_RENDER vec3 lightingColor = lightColor.rgb; - #ifdef NO_SHADOW - float shadow = 1.0; - #else - + float shadow = 1.0; + #ifndef NO_SHADOW + if (getFlag(surface.matFlag, 0)) //also skip if we don't recieve shadows + { // Fade out the shadow at the end of the range. vec4 zDist = vec4(zNearFarInvNearFar.x + zNearFarInvNearFar.y * surface.depth); float fadeOutAmt = ( zDist.x - fadeStartLength.x ) * fadeStartLength.y; @@ -211,7 +204,7 @@ void main() vec4 shadowed_colors = AL_VectorLightShadowCast( shadowMap, uv0.xy, worldToLightProj, surface.P, scaleX, scaleY, offsetX, offsetY, farPlaneScalePSSM, surfaceToLight.NdotL); - float shadow = shadowed_colors.a; + shadow = shadowed_colors.a; #ifdef PSSM_DEBUG_RENDER lightingColor = shadowed_colors.rgb; @@ -223,7 +216,7 @@ void main() if ( fadeOutAmt > 1.0 ) lightingColor = vec3(1.0,1.0,1.0); #endif - + } #endif //NO_SHADOW #ifdef DIFFUSE_LIGHT_VIZ diff --git a/Templates/BaseGame/game/core/rendering/shaders/lighting/advanced/pointLightP.hlsl b/Templates/BaseGame/game/core/rendering/shaders/lighting/advanced/pointLightP.hlsl index 60d2f2d00..07abf6e0b 100644 --- a/Templates/BaseGame/game/core/rendering/shaders/lighting/advanced/pointLightP.hlsl +++ b/Templates/BaseGame/game/core/rendering/shaders/lighting/advanced/pointLightP.hlsl @@ -162,21 +162,21 @@ float4 main( ConvexConnectP IN ) : SV_TARGET float distToLight = dist / lightRange; SurfaceToLight surfaceToLight = createSurfaceToLight(surface, L); - #ifdef NO_SHADOW - float shadowed = 1.0; - #else - + float shadow = 1.0; + #ifndef NO_SHADOW + if (getFlag(surface.matFlag, 0)) //also skip if we don't recieve shadows + { #ifdef SHADOW_CUBE // TODO: We need to fix shadow cube to handle soft shadows! float occ = TORQUE_TEXCUBE( shadowMap, mul( worldToLightProj, -surfaceToLight.L ) ).r; - float shadowed = saturate( exp( lightParams.y * ( occ - distToLight ) ) ); + shadow = saturate( exp( lightParams.y * ( occ - distToLight ) ) ); #else float2 shadowCoord = decodeShadowCoord( mul( worldToLightProj, -surfaceToLight.L ) ).xy; - float shadowed = softShadow_filter(TORQUE_SAMPLER2D_MAKEARG(shadowMap), ssPos.xy, shadowCoord, shadowSoftness, distToLight, surfaceToLight.NdotL, lightParams.y); + shadow = softShadow_filter(TORQUE_SAMPLER2D_MAKEARG(shadowMap), ssPos.xy, shadowCoord, shadowSoftness, distToLight, surfaceToLight.NdotL, lightParams.y); #endif - + } #endif // !NO_SHADOW float3 lightCol = lightColor.rgb; @@ -221,7 +221,7 @@ float4 main( ConvexConnectP IN ) : SV_TARGET #endif //get punctual light contribution - lighting = getPunctualLight(surface, surfaceToLight, lightCol, lightBrightness, lightInvSqrRange, shadowed); + lighting = getPunctualLight(surface, surfaceToLight, lightCol, lightBrightness, lightInvSqrRange, shadow); } return float4(lighting, 0); diff --git a/Templates/BaseGame/game/core/rendering/shaders/lighting/advanced/reflectionProbeArrayP.hlsl b/Templates/BaseGame/game/core/rendering/shaders/lighting/advanced/reflectionProbeArrayP.hlsl index c6efd8126..e061d4471 100644 --- a/Templates/BaseGame/game/core/rendering/shaders/lighting/advanced/reflectionProbeArrayP.hlsl +++ b/Templates/BaseGame/game/core/rendering/shaders/lighting/advanced/reflectionProbeArrayP.hlsl @@ -51,12 +51,6 @@ float4 main(PFXVertToPix IN) : SV_TARGET Surface surface = createSurface(normDepth, TORQUE_SAMPLER2D_MAKEARG(colorBuffer),TORQUE_SAMPLER2D_MAKEARG(matInfoBuffer), IN.uv0.xy, eyePosWorld, IN.wsEyeRay, cameraToWorld); - //early out if emissive - if (getFlag(surface.matFlag, 0)) - { - return float4(surface.albedo, 0); - } - #ifdef USE_SSAO_MASK float ssao = 1.0 - TORQUE_TEX2D( ssaoMask, viewportCoordToRenderTarget( IN.uv0.xy, rtParams7 ) ).r; surface.ao = min(surface.ao, ssao); diff --git a/Templates/BaseGame/game/core/rendering/shaders/lighting/advanced/spotLightP.hlsl b/Templates/BaseGame/game/core/rendering/shaders/lighting/advanced/spotLightP.hlsl index a0459bfb2..7751820dd 100644 --- a/Templates/BaseGame/game/core/rendering/shaders/lighting/advanced/spotLightP.hlsl +++ b/Templates/BaseGame/game/core/rendering/shaders/lighting/advanced/spotLightP.hlsl @@ -86,11 +86,11 @@ float4 main( ConvexConnectP IN ) : SV_TARGET Surface surface = createSurface( normDepth, TORQUE_SAMPLER2D_MAKEARG(colorBuffer),TORQUE_SAMPLER2D_MAKEARG(matInfoBuffer), uvScene, eyePosWorld, wsEyeRay, cameraToWorld); - //early out if emissive - if (getFlag(surface.matFlag, 0)) - { - return float4(0, 0, 0, 0); - } + //early out if we take no shadows + if (!getFlag(surface.matFlag, 0)) + { + return float4(surface.albedo, 0); + } float3 L = lightPosition - surface.P; float dist = length(L); @@ -100,17 +100,18 @@ float4 main( ConvexConnectP IN ) : SV_TARGET { SurfaceToLight surfaceToLight = createSurfaceToLight(surface, L); float3 lightCol = lightColor.rgb; - - #ifdef NO_SHADOW - float shadowed = 1.0; - #else + + float shadow = 1.0; + #ifndef NO_SHADOW + if (getFlag(surface.matFlag, 0)) //also skip if we don't recieve shadows + { // Get the shadow texture coordinate float4 pxlPosLightProj = mul( worldToLightProj, float4( surface.P, 1 ) ); float2 shadowCoord = ( ( pxlPosLightProj.xy / pxlPosLightProj.w ) * 0.5 ) + float2( 0.5, 0.5 ); shadowCoord.y = 1.0f - shadowCoord.y; //distance to light in shadow map space float distToLight = pxlPosLightProj.z / lightRange; - float shadowed = softShadow_filter(TORQUE_SAMPLER2D_MAKEARG(shadowMap), ssPos.xy, shadowCoord, shadowSoftness, distToLight, surfaceToLight.NdotL, lightParams.y); + shadow = softShadow_filter(TORQUE_SAMPLER2D_MAKEARG(shadowMap), ssPos.xy, shadowCoord, shadowSoftness, distToLight, surfaceToLight.NdotL, lightParams.y); #ifdef USE_COOKIE_TEX // Lookup the cookie sample. float4 cookie = TORQUE_TEX2D(cookieMap, shadowCoord); @@ -121,6 +122,7 @@ float4 main( ConvexConnectP IN ) : SV_TARGET // regions of the cookie texture. lightCol *= max(cookie.r, max(cookie.g, cookie.b)); #endif + } #endif #ifdef DIFFUSE_LIGHT_VIZ @@ -153,7 +155,7 @@ float4 main( ConvexConnectP IN ) : SV_TARGET #endif //get Punctual light contribution - lighting = getPunctualLight(surface, surfaceToLight, lightCol, lightBrightness, lightInvSqrRange, shadowed); + lighting = getPunctualLight(surface, surfaceToLight, lightCol, lightBrightness, lightInvSqrRange, shadow); //get spot angle attenuation lighting *= getSpotAngleAtt(-surfaceToLight.L, lightDirection, lightSpotParams ); } diff --git a/Templates/BaseGame/game/core/rendering/shaders/lighting/advanced/vectorLightP.hlsl b/Templates/BaseGame/game/core/rendering/shaders/lighting/advanced/vectorLightP.hlsl index 6046d6f00..d3c31cb7e 100644 --- a/Templates/BaseGame/game/core/rendering/shaders/lighting/advanced/vectorLightP.hlsl +++ b/Templates/BaseGame/game/core/rendering/shaders/lighting/advanced/vectorLightP.hlsl @@ -176,23 +176,17 @@ float4 main(FarFrustumQuadConnectP IN) : SV_TARGET //create surface Surface surface = createSurface( normDepth, TORQUE_SAMPLER2D_MAKEARG(colorBuffer),TORQUE_SAMPLER2D_MAKEARG(matInfoBuffer), IN.uv0, eyePosWorld, IN.wsEyeRay, cameraToWorld); - - //early out if emissive - if (getFlag(surface.matFlag, 0)) - { - return float4(0, 0, 0, 0); - } - + //create surface to light SurfaceToLight surfaceToLight = createSurfaceToLight(surface, -lightDirection); //light color might be changed by PSSM_DEBUG_RENDER float3 lightingColor = lightColor.rgb; - #ifdef NO_SHADOW - float shadow = 1.0; - #else - + float shadow = 1.0; + #ifndef NO_SHADOW + if (getFlag(surface.matFlag, 0)) //also skip if we don't recieve shadows + { // Fade out the shadow at the end of the range. float4 zDist = (zNearFarInvNearFar.x + zNearFarInvNearFar.y * surface.depth); float fadeOutAmt = ( zDist.x - fadeStartLength.x ) * fadeStartLength.y; @@ -200,7 +194,7 @@ float4 main(FarFrustumQuadConnectP IN) : SV_TARGET float4 shadowed_colors = AL_VectorLightShadowCast( TORQUE_SAMPLER2D_MAKEARG(shadowMap), IN.uv0.xy, worldToLightProj, surface.P, scaleX, scaleY, offsetX, offsetY, farPlaneScalePSSM, surfaceToLight.NdotL); - float shadow = shadowed_colors.a; + shadow = shadowed_colors.a; #ifdef PSSM_DEBUG_RENDER lightingColor = shadowed_colors.rgb; @@ -212,7 +206,7 @@ float4 main(FarFrustumQuadConnectP IN) : SV_TARGET if ( fadeOutAmt > 1.0 ) lightingColor = 1.0; #endif - + } #endif //NO_SHADOW #ifdef DIFFUSE_LIGHT_VIZ diff --git a/Templates/BaseGame/game/tools/materialEditor/gui/guiMaterialPropertiesWindow.ed.gui b/Templates/BaseGame/game/tools/materialEditor/gui/guiMaterialPropertiesWindow.ed.gui index c70006c81..cadf58ad7 100644 --- a/Templates/BaseGame/game/tools/materialEditor/gui/guiMaterialPropertiesWindow.ed.gui +++ b/Templates/BaseGame/game/tools/materialEditor/gui/guiMaterialPropertiesWindow.ed.gui @@ -3156,7 +3156,7 @@ $guiContent = new GuiControl(MaterialEditorGui,EditorGuiGroup) { }; new GuiCheckBoxCtrl() { canSaveDynamicFields = "0"; - internalName = "emissiveCheckbox"; + internalName = "receiveShadowsCheckbox"; Enabled = "1"; isContainer = "0"; Profile = "ToolsGuiCheckBoxProfile"; @@ -3167,11 +3167,11 @@ $guiContent = new GuiControl(MaterialEditorGui,EditorGuiGroup) { MinExtent = "8 2"; canSave = "1"; Visible = "1"; - Command = "MaterialEditorGui.updateActiveMaterial(\"emissive[\" @ MaterialEditorGui.currentLayer @ \"]\",$ThisControl.getValue());"; + Command = "MaterialEditorGui.updateActiveMaterial(\"receiveShadows[\" @ MaterialEditorGui.currentLayer @ \"]\",$ThisControl.getValue());"; tooltipprofile = "ToolsGuiDefaultProfile"; - ToolTip = "Emissive causes an object to not be affected by lights. Good for light sources."; + ToolTip = "Do we recieve shadows?"; hovertime = "1000"; - text = "Emissive"; + text = "receiveShadows"; groupNum = "-1"; buttonType = "ToggleButton"; useMouseEvents = "0"; diff --git a/Templates/BaseGame/game/tools/materialEditor/scripts/materialEditor.ed.tscript b/Templates/BaseGame/game/tools/materialEditor/scripts/materialEditor.ed.tscript index cb093ea21..4f073f7cf 100644 --- a/Templates/BaseGame/game/tools/materialEditor/scripts/materialEditor.ed.tscript +++ b/Templates/BaseGame/game/tools/materialEditor/scripts/materialEditor.ed.tscript @@ -935,7 +935,7 @@ function MaterialEditorGui::guiSync( %this, %material ) MaterialEditorPropertiesWindow-->glowMulTextEdit.setText((%material).glowMul[%layer]); MaterialEditorPropertiesWindow-->glowMulSlider.setValue((%material).glowMul[%layer]); MaterialEditorPropertiesWindow-->glowCheckbox.setValue((%material).glow[%layer]); - MaterialEditorPropertiesWindow-->emissiveCheckbox.setValue((%material).emissive[%layer]); + MaterialEditorPropertiesWindow-->receiveShadowsCheckbox.setValue((%material).receiveShadows[%layer]); MaterialEditorPropertiesWindow-->parallaxTextEdit.setText((%material).parallaxScale[%layer]); MaterialEditorPropertiesWindow-->parallaxSlider.setValue((%material).parallaxScale[%layer]);