Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Devel #2917

Merged
merged 5 commits into from
Aug 19, 2023
Merged

Devel #2917

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions Components/RTShaderSystem/include/OgreShaderFunction.h
Original file line number Diff line number Diff line change
Expand Up @@ -176,10 +176,11 @@ class _OgreRTSSExport Function : public RTShaderSystemAlloc

local parameters do not have index or semantic.
@param name The name of the parameter.
@param type The type of the desired parameter.
@param type The type of the desired parameter.
@param arraySize If > 0, the parameter will be an array of the given size.
@return parameter instance in case of that resolve operation succeeded.
*/
ParameterPtr resolveLocalParameter(GpuConstantType type, const String& name);
ParameterPtr resolveLocalParameter(GpuConstantType type, const String& name, size_t arraySize = 0);

/** Resolve local parameter of this function

Expand Down
4 changes: 3 additions & 1 deletion Components/RTShaderSystem/include/OgreShaderSubRenderState.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,10 @@ _OgreRTSSExport extern const String SRS_PER_VERTEX_LIGHTING;
_OgreRTSSExport extern const String SRS_FOG;
/// Enables alpha-testing
_OgreRTSSExport extern const String SRS_ALPHA_TEST;
/// PSSM shadow receiver with up to 3 splits. Custom split points.
/// @deprecated use #SRS_SHADOW_MAPPING
_OgreRTSSExport extern const String SRS_INTEGRATED_PSSM3;
/// shadow mapping receiver with multiple lights or single PSSM light with up to 3 custom splits.
_OgreRTSSExport extern const String SRS_SHADOW_MAPPING;
/// Adds per-pixel lighting calulations (Phong Shading)
_OgreRTSSExport extern const String SRS_PER_PIXEL_LIGHTING;
/// Use metal roughness parametrisation for lighting calulations
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,6 @@ bool CookTorranceLighting::createCpuSubPrograms(ProgramSet* programSet)
if (auto shadowFactor = psMain->getLocalParameter("lShadowFactor"))
{
params.insert(params.begin(), In(shadowFactor));
psProgram->addPreprocessorDefines("HAVE_SHADOW_FACTOR");
}

fstage.callFunction("PBR_Lights", params);
Expand Down
68 changes: 58 additions & 10 deletions Components/RTShaderSystem/src/OgreShaderExIntegratedPSSM3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ THE SOFTWARE.
#ifdef RTSHADER_SYSTEM_BUILD_EXT_SHADERS

#define SGX_LIB_INTEGRATEDPSSM "SGXLib_IntegratedPSSM"
#define SGX_FUNC_COMPUTE_SHADOW_COLOUR3 "SGX_ComputeShadowFactor_PSSM3"

namespace Ogre {
namespace RTShader {
Expand All @@ -39,6 +38,7 @@ namespace RTShader {
/************************************************************************/
String IntegratedPSSM3::Type = "SGX_IntegratedPSSM3";
const String SRS_INTEGRATED_PSSM3 = "SGX_IntegratedPSSM3";
const String SRS_SHADOW_MAPPING = "SGX_IntegratedPSSM3";

//-----------------------------------------------------------------------
IntegratedPSSM3::IntegratedPSSM3()
Expand All @@ -49,6 +49,7 @@ IntegratedPSSM3::IntegratedPSSM3()
mDebug = false;
mIsD3D9 = false;
mShadowTextureParamsList.resize(1); // normal single texture depth shadowmapping
mMultiLightCount = 1;
}

//-----------------------------------------------------------------------
Expand All @@ -62,6 +63,9 @@ void IntegratedPSSM3::updateGpuProgramsParams(Renderable* rend, const Pass* pass
const AutoParamDataSource* source,
const LightList* pLightList)
{
if (mMultiLightCount > 1)
return;

Vector4 vSplitPoints;

for(size_t i = 0; i < mShadowTextureParamsList.size() - 1; i++)
Expand Down Expand Up @@ -92,6 +96,7 @@ void IntegratedPSSM3::copyFrom(const SubRenderState& rhs)
mUseTextureCompare = rhsPssm.mUseTextureCompare;
mUseColourShadows = rhsPssm.mUseColourShadows;
mDebug = rhsPssm.mDebug;
mMultiLightCount = rhsPssm.mMultiLightCount;
mShadowTextureParamsList.resize(rhsPssm.mShadowTextureParamsList.size());

ShadowTextureParamsConstIterator itSrc = rhsPssm.mShadowTextureParamsList.begin();
Expand Down Expand Up @@ -123,6 +128,9 @@ bool IntegratedPSSM3::preAddToRenderState(const RenderState* renderState,
mUseTextureCompare = PixelUtil::isDepth(shadowTexFormat) && !mIsD3D9;
mUseColourShadows = PixelUtil::getComponentType(shadowTexFormat) == PCT_BYTE; // use colour shadowmaps for byte textures

if(mMultiLightCount > 1)
mShadowTextureParamsList.resize(mMultiLightCount);

ShadowTextureParamsIterator it = mShadowTextureParamsList.begin();

auto shadowSampler = TextureManager::getSingleton().getSampler(mUseTextureCompare ? "Ogre/DepthShadowSampler"
Expand Down Expand Up @@ -169,6 +177,13 @@ bool IntegratedPSSM3::setParameter(const String& name, const String& value)
mPCFxSamples = 4;
else
return false;

return true;
}
else if (name == "light_count")
{
mMultiLightCount = StringConverter::parseInt(value);
return true;
}

return false;
Expand Down Expand Up @@ -215,7 +230,7 @@ bool IntegratedPSSM3::resolveParameters(ProgramSet* programSet)
mPSInDepth = psMain->resolveInputParameter(mVSOutPos);

// Resolve computed local shadow colour parameter.
mPSLocalShadowFactor = psMain->resolveLocalParameter(GCT_FLOAT1, "lShadowFactor");
mPSLocalShadowFactor = psMain->resolveLocalParameter(GCT_FLOAT1, "lShadowFactor", mMultiLightCount);

// Resolve computed local shadow colour parameter.
mPSSplitPoints = psProgram->resolveParameter(GCT_FLOAT4, "pssm_split_points");
Expand Down Expand Up @@ -252,8 +267,8 @@ bool IntegratedPSSM3::resolveDependencies(ProgramSet* programSet)
Program* psProgram = programSet->getCpuProgram(GPT_FRAGMENT_PROGRAM);
psProgram->addDependency(SGX_LIB_INTEGRATEDPSSM);

psProgram->addPreprocessorDefines(StringUtil::format("PROJ_SPACE_SPLITS,PSSM_NUM_SPLITS=%zu,PCF_XSAMPLES=%.1f",
mShadowTextureParamsList.size(), mPCFxSamples));
psProgram->addPreprocessorDefines(StringUtil::format("PSSM_NUM_SPLITS=%zu,PCF_XSAMPLES=%.1f,SHADOWLIGHT_COUNT=%d",
mShadowTextureParamsList.size(), mPCFxSamples, mMultiLightCount));

if(mDebug)
psProgram->addPreprocessorDefines("DEBUG_PSSM");
Expand Down Expand Up @@ -314,12 +329,15 @@ bool IntegratedPSSM3::addPSInvocation(Program* psProgram, const int groupOrder)
Function* psMain = psProgram->getEntryPointFunction();
auto stage = psMain->getStage(groupOrder);

if(mShadowTextureParamsList.size() < 2)
if(mShadowTextureParamsList.size() < 2 || mMultiLightCount > 1)
{
ShadowTextureParams& splitParams0 = mShadowTextureParamsList[0];
stage.callFunction("SGX_ShadowPCF4",
{In(splitParams0.mTextureSampler), In(splitParams0.mPSInLightPosition),
In(splitParams0.mInvTextureSize).xy(), Out(mPSLocalShadowFactor)});
for(uchar i = 0; i < mMultiLightCount; ++i)
{
ShadowTextureParams& params = mShadowTextureParamsList[i];
stage.callFunction("SGX_ShadowPCF4",
{In(params.mTextureSampler), In(params.mPSInLightPosition),
In(params.mInvTextureSize).xy(), Out(mPSLocalShadowFactor), At(i)});
}
}
else
{
Expand All @@ -338,9 +356,16 @@ bool IntegratedPSSM3::addPSInvocation(Program* psProgram, const int groupOrder)
}

params.push_back(Out(mPSLocalShadowFactor));
params.push_back(At(0));

if(mDebug)
{
auto sceneCol = psProgram->resolveParameter(GpuProgramParameters::ACT_DERIVED_SCENE_COLOUR);
params.push_back(InOut(sceneCol));
}

// Compute shadow factor.
stage.callFunction(SGX_FUNC_COMPUTE_SHADOW_COLOUR3, params);
stage.callFunction("SGX_ComputeShadowFactor_PSSM3", params);
}

// shadow factor is applied by lighting stages
Expand All @@ -353,6 +378,8 @@ SubRenderState* IntegratedPSSM3Factory::createInstance(ScriptCompiler* compiler,
{
if (prop->name == "integrated_pssm4")
{
compiler->addError(ScriptCompiler::CE_DEPRECATEDSYMBOL, prop->file, prop->line, "integrated_pssm4. Use shadow_mapping instead.");

SubRenderState* subRenderState = createOrRetrieveInstance(translator);

auto it = prop->values.begin();
Expand Down Expand Up @@ -383,6 +410,27 @@ SubRenderState* IntegratedPSSM3Factory::createInstance(ScriptCompiler* compiler,
return subRenderState;
}

if (prop->name == "shadow_mapping")
{
SubRenderState* subRenderState = createOrRetrieveInstance(translator);

auto it = prop->values.begin();
while(it != prop->values.end())
{
String paramName = (*it)->getString();
String paramValue = (*++it)->getString();

if (!subRenderState->setParameter(paramName, paramValue))
{
compiler->addError(ScriptCompiler::CE_INVALIDPARAMETERS, prop->file, prop->line, paramName);
return subRenderState;
}
it++;
}

return subRenderState;
}

return NULL;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ class IntegratedPSSM3 : public SubRenderState
bool mUseColourShadows;
bool mDebug;
bool mIsD3D9;
uchar mMultiLightCount;
};


Expand Down
13 changes: 2 additions & 11 deletions Components/RTShaderSystem/src/OgreShaderExPerPixelLighting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -237,21 +237,12 @@ bool PerPixelLighting::addFunctionInvocations(ProgramSet* programSet)
if(mFrontFacing)
stage.callFunction("SGX_Flip_Backface_Normal", mFrontFacing, mTargetFlipped, mViewNormal);

mShadowFactor = psMain->getLocalParameter("lShadowFactor");

// Add per light functions.
for (int i = 0; i < mLightCount; i++)
{
addIlluminationInvocation(i, stage);

if(i > 0) // directional lights are in front
continue;

if (auto shadowFactor = psMain->getLocalParameter("lShadowFactor"))
{
stage.callFunction("SGX_ApplyShadowFactor_Diffuse",
{In(mDerivedSceneColour), In(shadowFactor), InOut(mOutDiffuse)});
if(mSpecularEnable)
stage.mul(mOutSpecular, shadowFactor, mOutSpecular);
}
}

// Assign back temporary variables
Expand Down
21 changes: 18 additions & 3 deletions Components/RTShaderSystem/src/OgreShaderFFPLighting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,9 @@ bool FFPLighting::resolveDependencies(ProgramSet* programSet)

addDefines(vsProgram);

if(mSpecularEnable)
programSet->getCpuProgram(GPT_FRAGMENT_PROGRAM)->addPreprocessorDefines("USE_SPECULAR");

return true;
}

Expand Down Expand Up @@ -200,14 +203,18 @@ bool FFPLighting::addFunctionInvocations(ProgramSet* programSet)
auto psOutDiffuse = psMain->resolveOutputParameter(Parameter::SPC_COLOR_DIFFUSE);

auto fstage = psMain->getStage(FFP_PS_COLOUR_BEGIN);
fstage.callFunction("SGX_ApplyShadowFactor_Diffuse", {In(ambient), In(shadowFactor), InOut(psOutDiffuse)});

std::vector<Operand> args = {In(ambient), In(shadowFactor),InOut(psOutDiffuse)};

if (mSpecularEnable)
{
auto psSpecular = psMain->getInputParameter(Parameter::SPC_COLOR_SPECULAR);
if (!psSpecular)
psMain->getLocalParameter(Parameter::SPC_COLOR_SPECULAR);
fstage.mul(psSpecular, shadowFactor, psSpecular);
psSpecular = psMain->getLocalParameter(Parameter::SPC_COLOR_SPECULAR);
args.push_back(InOut(psSpecular));
}

fstage.callFunction("SGX_ApplyShadowFactor_Modulative", args);
}

return true;
Expand Down Expand Up @@ -271,6 +278,14 @@ void FFPLighting::addIlluminationInvocation(int i, const FunctionStageRef& stage
args.insert(args.end(), {In(mSpecularColours), At(i), In(mSurfaceShininess), InOut(mOutSpecular).xyz()});
}

if (mShadowFactor)
{
if(i < int(mShadowFactor->getSize()))
args.insert(args.end(), {In(mShadowFactor), At(i)});
else
args.push_back(In(1));
}

if(mLTCLUT1)
{
args.insert(args.end(), {In(mLTCLUT1), In(mLTCLUT2)});
Expand Down
2 changes: 2 additions & 0 deletions Components/RTShaderSystem/src/OgreShaderFFPLighting.h
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,8 @@ class FFPLighting : public SubRenderState

UniformParameterPtr mLTCLUT1;
UniformParameterPtr mLTCLUT2;

ParameterPtr mShadowFactor;
};


Expand Down
6 changes: 3 additions & 3 deletions Components/RTShaderSystem/src/OgreShaderFunction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -364,14 +364,14 @@ ParameterPtr Function::resolveOutputParameter(Parameter::Semantic semantic,
}

//-----------------------------------------------------------------------------
ParameterPtr Function::resolveLocalParameter(GpuConstantType type, const String& name)
ParameterPtr Function::resolveLocalParameter(GpuConstantType type, const String& name, size_t arraySize)
{
ParameterPtr param;

param = _getParameterByName(mLocalParameters, name);
if (param.get() != NULL)
{
if (param->getType() == type)
if (param->getType() == type && param->getSize() == arraySize)
{
return param;
}
Expand All @@ -382,7 +382,7 @@ ParameterPtr Function::resolveLocalParameter(GpuConstantType type, const String&
}
}

param = std::make_shared<Parameter>(type, name, Parameter::SPS_UNKNOWN, 0, Parameter::SPC_UNKNOWN);
param = std::make_shared<Parameter>(type, name, Parameter::SPS_UNKNOWN, 0, Parameter::SPC_UNKNOWN, arraySize);
addParameter(mLocalParameters, param);

return param;
Expand Down
4 changes: 2 additions & 2 deletions Components/Terrain/src/OgreTerrainMaterialGeneratorA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ namespace Ogre
surface->setParameter("use_specular_mapping", std::to_string(mLayerSpecularMappingEnabled));
if(isShadowingEnabled(HIGH_LOD, terrain))
{
auto pssm = ShaderGenerator::getSingleton().createSubRenderState(SRS_INTEGRATED_PSSM3);
auto pssm = ShaderGenerator::getSingleton().createSubRenderState(SRS_SHADOW_MAPPING);
if(mPSSM)
pssm->setParameter("split_points", mPSSM->getSplitPoints());
pssm->preAddToRenderState(mainRenderState.get(), pass, pass);
Expand Down Expand Up @@ -333,7 +333,7 @@ namespace Ogre
{
// light count needed to enable PSSM3
lod1RenderState->setLightCount(1);
auto pssm = ShaderGenerator::getSingleton().createSubRenderState(SRS_INTEGRATED_PSSM3);
auto pssm = ShaderGenerator::getSingleton().createSubRenderState(SRS_SHADOW_MAPPING);
if(mPSSM)
pssm->setParameter("split_points", mPSSM->getSplitPoints());
pssm->preAddToRenderState(lod1RenderState.get(), pass, pass);
Expand Down
11 changes: 8 additions & 3 deletions Components/Terrain/src/OgreTerrainRTShaderSRS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -298,12 +298,17 @@ bool TerrainSurface::createCpuSubPrograms(ProgramSet* programSet)

if(lightMap)
{
auto shadowFactor = psMain->resolveLocalParameter(GCT_FLOAT1, "lShadowFactor");
auto shadowFactor = psMain->getLocalParameter("lShadowFactor");
if(!shadowFactor)
{
shadowFactor = psMain->resolveLocalParameter(GCT_FLOAT1, "lShadowFactor", 1);
psProgram->addPreprocessorDefines("SHADOWLIGHT_COUNT=1");
}
stage = psMain->getStage(FFP_PS_COLOUR_BEGIN - 1); // before the PSSM stage
stage.assign(1, shadowFactor);
stage.assign({In(1), Out(shadowFactor), At(0)});

stage = psMain->getStage(FFP_PS_COLOUR_BEGIN + 1); // after the PSSM stage
stage.callFunction("getShadowFactor", {In(lightMap), In(uvPS), InOut(shadowFactor)});
stage.callFunction("getShadowFactor", {In(lightMap), In(uvPS), InOut(shadowFactor), At(0)});
}

if(globalColourMap)
Expand Down
9 changes: 9 additions & 0 deletions Docs/src/rtss.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ Here are the attributes you can use in a `rtshader_system` block of a `pass {}`:
- [fog_stage](#fog_stage)
- [light_count](#light_count)
- [triplanarTexturing](#triplanarTexturing)
- [shadow_mapping](#shadow_mapping)
- [integrated_pssm4](#integrated_pssm4)
- [hardware_skinning](#hardware_skinning)
- [layered_blend](#layered_blend)
Expand Down Expand Up @@ -187,6 +188,14 @@ Format: `integrated_pssm4 <znear> <sp0> <sp1> <zfar> [debug] [filter]`
@param debug visualize the active shadow-splits in the scene
@param filter one of `pcf4, pcf16` (default: @c pcf4)

## shadow_mapping {#shadow_mapping}
@copybrief Ogre::RTShader::SRS_SHADOW_MAPPING

@par
Format: `shadow_mapping [light_count <num>] [filter <type>]`
@param filter one of `pcf4, pcf16` (default: @c pcf4)
@param light_count number of lights to support (default: 1)

<a name="hardware_skinning"></a>

## hardware_skinning
Expand Down
Loading