shifts glowmap out of the composite and to it's own texture, as well as featureset. (GL port pending design finalization)

This commit is contained in:
AzaezelX 2019-11-01 19:29:31 -05:00
parent ac6fdf884e
commit d034895e8f
12 changed files with 180 additions and 198 deletions

View file

@ -37,7 +37,7 @@
//****************************************************************************
U32 PBRConfigMapHLSL::getOutputTargets(const MaterialFeatureData& fd) const
{
return fd.features[MFT_isDeferred] ? ShaderFeature::RenderTarget3 : ShaderFeature::DefaultTarget;
return fd.features[MFT_isDeferred] ? ShaderFeature::RenderTarget2 : ShaderFeature::DefaultTarget;
}
void PBRConfigMapHLSL::processPix( Vector<ShaderComponent*> &componentList, const MaterialFeatureData &fd )
@ -104,24 +104,6 @@ void PBRConfigMapHLSL::processPix( Vector<ShaderComponent*> &componentList, cons
meta->addStatement(new GenOp(" @ = @.g;\r\n", new DecOp(ao), pbrConfig));
meta->addStatement(new GenOp(" @ = @.a;\r\n", new DecOp(metalness), pbrConfig));
if (fd.features[MFT_GlowMap])
{
Var* glowMul = new Var("glowMul", "float");
glowMul->uniform = true;
glowMul->constSortPos = cspPotentialPrimitive;
ShaderFeature::OutputTarget inTarg = ShaderFeature::DefaultTarget;
ShaderFeature::OutputTarget outTarg = ShaderFeature::DefaultTarget;
if (fd.features[MFT_isDeferred])
{
inTarg = ShaderFeature::RenderTarget1;
outTarg = ShaderFeature::RenderTarget3;
}
Var* diffuseColor = (Var*)LangElement::find(getOutputTargetVarName(inTarg));
Var* emissionColor = (Var*)LangElement::find(getOutputTargetVarName(outTarg));
meta->addStatement(new GenOp(" @.rgb += @.rgb*float3(@,@,@)*@.aaa;\r\n", emissionColor, diffuseColor, glowMul, glowMul, glowMul, texOp));
}
output = meta;
}
@ -241,24 +223,80 @@ void PBRConfigVarsHLSL::processPix( Vector<ShaderComponent*> &componentList, con
output = meta;
}
//deferred emissive
void DeferredEmissiveHLSL::processPix(Vector<ShaderComponent*> &componentList, const MaterialFeatureData &fd)
U32 GlowMapHLSL::getOutputTargets(const MaterialFeatureData& fd) const
{
//for now emission just uses the diffuse color, we could plug in a separate texture for emission at some stage
Var *diffuseTargetVar = (Var*)LangElement::find(getOutputTargetVarName(ShaderFeature::RenderTarget1));
if (!diffuseTargetVar)
return; //oh dear something is not right, maybe we should just write 0's instead
return fd.features[MFT_isDeferred] ? ShaderFeature::RenderTarget3 : ShaderFeature::DefaultTarget;
}
// search for scene color target var
Var *sceneColorVar = (Var*)LangElement::find(getOutputTargetVarName(ShaderFeature::RenderTarget3));
if (!sceneColorVar)
//deferred emissive
void GlowMapHLSL::processPix(Vector<ShaderComponent*> &componentList, const MaterialFeatureData &fd)
{
Var* texCoord = getInTexCoord("texCoord", "float2", componentList);
// create texture var
Var* glowMap = new Var;
glowMap->setType("SamplerState");
glowMap->setName("glowMap");
glowMap->uniform = true;
glowMap->sampler = true;
glowMap->constNum = Var::getTexUnitNum();
Var* glowMapTex = new Var;
glowMapTex->setName("glowMapTex");
glowMapTex->setType("Texture2D");
glowMapTex->uniform = true;
glowMapTex->texture = true;
glowMapTex->constNum = glowMap->constNum;
LangElement* texOp = new GenOp("@.Sample(@, @)", glowMapTex, glowMap, texCoord);
Var* glowMul = new Var("glowMul", "float");
glowMul->uniform = true;
glowMul->constSortPos = cspPotentialPrimitive;
Var *targ = (Var*)LangElement::find(getOutputTargetVarName(ShaderFeature::DefaultTarget));
if (fd.features[MFT_isDeferred])
{
// create scene color target var
sceneColorVar = new Var;
sceneColorVar->setType("fragout");
sceneColorVar->setName(getOutputTargetVarName(ShaderFeature::RenderTarget3));
sceneColorVar->setStructName("OUT");
targ = (Var*)LangElement::find(getOutputTargetVarName(ShaderFeature::RenderTarget3));
if (!targ)
{
// create scene color target var
targ = new Var;
targ->setType("fragout");
targ->setName(getOutputTargetVarName(ShaderFeature::RenderTarget3));
targ->setStructName("OUT");
output = new GenOp("@ = float4(@.rgb*@,0);", targ, texOp, glowMul);
}
else
{
output = new GenOp("@ += float4(@.rgb*@,0);", targ, texOp, glowMul);
}
}
else
{
output = new GenOp("@ += float4(@.rgb*@,@.a);", targ, texOp, glowMul, targ);
}
output = new GenOp("@ = float4(@.rgb,0);", sceneColorVar, diffuseTargetVar);
}
ShaderFeature::Resources GlowMapHLSL::getResources(const MaterialFeatureData& fd)
{
Resources res;
res.numTex = 1;
res.numTexReg = 1;
return res;
}
void GlowMapHLSL::setTexData(Material::StageData& stageDat,
const MaterialFeatureData& fd,
RenderPassData& passData,
U32& texIndex)
{
GFXTextureObject* tex = stageDat.getTex(MFT_GlowMap);
if (tex)
{
passData.mTexType[texIndex] = Material::Standard;
passData.mSamplerNames[texIndex] = "glowMap";
passData.mTexSlot[texIndex++].texObject = tex;
}
}

View file

@ -70,15 +70,23 @@ public:
const MaterialFeatureData &fd );
};
class DeferredEmissiveHLSL : public ShaderFeatureHLSL
class GlowMapHLSL : public ShaderFeatureHLSL
{
public:
virtual String getName() { return "Deferred Shading: Emissive"; }
virtual String getName() { return "Glow Map"; }
virtual void processPix(Vector<ShaderComponent*> &componentList,
const MaterialFeatureData &fd);
virtual U32 getOutputTargets(const MaterialFeatureData &fd) const { return ShaderFeature::RenderTarget3; }
virtual U32 getOutputTargets(const MaterialFeatureData& fd) const;
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);
};
#endif

View file

@ -128,7 +128,7 @@ Material::Material()
mSmoothnessChan[i] = 0;
mAOChan[i] = 1;
mMetalChan[i] = 2;
mGlowChan[i] = 3;
mAccuEnabled[i] = false;
mAccuScale[i] = 1.0f;
mAccuDirection[i] = 1.0f;
@ -325,8 +325,6 @@ void Material::initPersistFields()
addField("glowMap", TypeImageFilename, Offset(mGlowMapFilename, Material), MAX_STAGES,
"Metalness map. will be packed into the B channel of a packed 'specular' map");
addField("glowChan", TypeF32, Offset(mGlowChan, Material), MAX_STAGES,
"The input channel metalness maps use.");
addField("glowMul", TypeF32, Offset(mGlowMul, Material), MAX_STAGES,
"The input channel metalness maps use.");
addField("glow", TypeBool, Offset(mGlow, Material), MAX_STAGES,

View file

@ -256,7 +256,6 @@ public:
FileName mGlowMapFilename[MAX_STAGES];
StringTableEntry mGlowMapAssetId[MAX_STAGES];
AssetPtr<ImageAsset> mGlowMapAsset[MAX_STAGES];
F32 mGlowChan[MAX_STAGES];
F32 mGlowMul[MAX_STAGES];
/// A second normal map which repeats at the detail map
/// scale and blended with the base normal map.

View file

@ -47,7 +47,6 @@ ImplementFeatureType( MFT_InvertSmoothness, U32(-1), -1, true);
ImplementFeatureType( MFT_PBRConfigMap, MFG_Texture, 8.0f, true);
ImplementFeatureType( MFT_PBRConfigVars, MFG_Texture, 8.0f, true);
ImplementFeatureType( MFT_MatInfoFlags, MFG_Texture, 9.0f, true);
ImplementFeatureType( MFT_GlowMap, MFG_Texture, 10.0f, true );
ImplementFeatureType( MFT_NormalMap, MFG_Texture, 11.0f, true );
ImplementFeatureType( MFT_DetailNormalMap, MFG_Texture, 12.0f, true );
ImplementFeatureType( MFT_Imposter, U32(-1), -1, true );
@ -56,9 +55,10 @@ ImplementFeatureType( MFT_AccuMap, MFG_PreLighting, 2.0f, true );
ImplementFeatureType(MFT_ReflectionProbes, MFG_Lighting, 1.0f, true);
ImplementFeatureType( MFT_RTLighting, MFG_Lighting, 2.0f, true );
ImplementFeatureType( MFT_LightMap, MFG_Lighting, 3.0f, true );
ImplementFeatureType( MFT_ToneMap, MFG_Lighting, 4.0f, true );
ImplementFeatureType( MFT_VertLitTone, MFG_Lighting, 5.0f, false );
ImplementFeatureType( MFT_GlowMap, MFG_Lighting, 3.0f, true );
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_StaticCubemap, U32(-1), -1.0, true );
ImplementFeatureType( MFT_CubeMap, MFG_Lighting, 7.0f, true );
ImplementFeatureType( MFT_SubSurface, MFG_Lighting, 8.0f, true );
@ -104,7 +104,5 @@ ImplementFeatureType( MFT_ImposterVert, MFG_PreTransform, 1.0, false );
// Deferred Shading
ImplementFeatureType( MFT_isDeferred, U32(-1), -1, true );
ImplementFeatureType( MFT_SkyBox, MFG_Transform, 1.0f, false );
ImplementFeatureType( MFT_DeferredEmissive, MFG_Texture, 8.9f, false);
ImplementFeatureType( MFT_HardwareSkinning, MFG_Transform,-2.0, false );

View file

@ -192,5 +192,4 @@ DeclareFeatureType( MFT_HardwareSkinning );
DeclareFeatureType( MFT_isDeferred );
DeclareFeatureType( MFT_SkyBox );
DeclareFeatureType( MFT_MatInfoFlags );
DeclareFeatureType( MFT_DeferredEmissive );
#endif // _MATERIALFEATURETYPES_H_

View file

@ -487,14 +487,20 @@ void ProcessedMaterial::_setStageData()
inputKey[0] = mMaterial->mSmoothnessChan[i];
inputKey[1] = mMaterial->mAOChan[i];
inputKey[2] = mMaterial->mMetalChan[i];
inputKey[3] = mMaterial->mGlowChan[i];
inputKey[3] = 0;
mStages[i].setTex(MFT_PBRConfigMap, _createCompositeTexture(mMaterial->mRoughMapFilename[i], mMaterial->mAOMapFilename[i],
mMaterial->mMetalMapFilename[i], mMaterial->mGlowMapFilename[i],
mMaterial->mMetalMapFilename[i], "",
inputKey, profile));
if (!mStages[i].getTex(MFT_PBRConfigMap))
mMaterial->logError("Failed to load PBR Config map %s for stage %i", _getTexturePath(mMaterial->mPBRConfigMapFilename[i]).c_str(), i);
}
}
if (mMaterial->mGlowMapFilename[i].isNotEmpty())
{
mStages[i].setTex(MFT_GlowMap, _createTexture(mMaterial->mGlowMapFilename[i], &GFXStaticTextureProfile));
if (!mStages[i].getTex(MFT_GlowMap))
mMaterial->logError("Failed to load glow map %s for stage %i", _getTexturePath(mMaterial->mGlowMapFilename[i]).c_str(), i);
}
}
mMaterial->mCubemapData = dynamic_cast<CubemapData*>(Sim::findObject(mMaterial->mCubemapName));

View file

@ -437,8 +437,6 @@ void ProcessedShaderMaterial::_determineFeatures( U32 stageNum,
if (mStages[stageNum].getTex(MFT_PBRConfigMap))
{
fd.features.addFeature(MFT_PBRConfigMap);
if (mStages[stageNum].getTex(MFT_PBRConfigMap)->mHasTransparency)
fd.features.addFeature(MFT_GlowMap);
}
else
fd.features.addFeature(MFT_PBRConfigVars);

View file

@ -644,6 +644,11 @@ void ProcessedDeferredMaterial::_determineFeatures( U32 stageNum,
else
newFeatures.addFeature( MFT_PBRConfigVars );
if (mStages[stageNum].getTex(MFT_GlowMap))
{
newFeatures.addFeature(MFT_GlowMap);
}
// Deferred Shading : Material Info Flags
newFeatures.addFeature( MFT_MatInfoFlags );
@ -743,9 +748,7 @@ void ProcessedDeferredMaterial::_determineFeatures( U32 stageNum,
else
{
// If this object isn't lightmapped or emissive, add a zero-output feature for render target 3
if (fd.features.hasFeature(MFT_IsEmissive))
newFeatures.addFeature(MFT_DeferredEmissive);
else
if (!fd.features.hasFeature(MFT_IsEmissive)&&(!fd.features.hasFeature(MFT_GlowMap)))
newFeatures.addFeature( MFT_RenderTarget3_Zero );
}
}

View file

@ -66,7 +66,6 @@ void _initShaderGenGLSL( ShaderGen *shaderGen )
FEATUREMGR->registerFeature( MFT_CubeMap, new ReflectCubeFeatGLSL );
FEATUREMGR->registerFeature( MFT_InvertSmoothness, new NamedFeatureGLSL("Roughest = 1.0"));
FEATUREMGR->registerFeature( MFT_AccuMap, new AccuTexFeatGLSL );
FEATUREMGR->registerFeature( MFT_GlowMap, new NamedFeatureGLSL( "Glow Map" ) );
FEATUREMGR->registerFeature( MFT_IsTranslucent, new NamedFeatureGLSL( "Translucent" ) );
FEATUREMGR->registerFeature( MFT_IsTranslucentZWrite, new NamedFeatureGLSL( "Translucent ZWrite" ) );
FEATUREMGR->registerFeature( MFT_Visibility, new VisibilityFeatGLSL );

View file

@ -70,7 +70,6 @@ void _initShaderGenHLSL( ShaderGen *shaderGen )
FEATUREMGR->registerFeature( MFT_Visibility, new VisibilityFeatHLSL );
FEATUREMGR->registerFeature( MFT_Fog, new FogFeatHLSL );
FEATUREMGR->registerFeature( MFT_AccuMap, new AccuTexFeatHLSL );
FEATUREMGR->registerFeature( MFT_GlowMap, new NamedFeatureHLSL( "Glow 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 ) );
@ -105,7 +104,7 @@ void _initShaderGenHLSL( ShaderGen *shaderGen )
FEATUREMGR->registerFeature( MFT_PBRConfigMap, new PBRConfigMapHLSL);
FEATUREMGR->registerFeature( MFT_PBRConfigVars, new PBRConfigVarsHLSL);
FEATUREMGR->registerFeature( MFT_MatInfoFlags, new MatInfoFlagsHLSL );
FEATUREMGR->registerFeature( MFT_DeferredEmissive, new DeferredEmissiveHLSL);
FEATUREMGR->registerFeature( MFT_GlowMap, new GlowMapHLSL);
FEATUREMGR->registerFeature( MFT_SkyBox, new NamedFeatureHLSL( "skybox" ) );
FEATUREMGR->registerFeature( MFT_HardwareSkinning, new HardwareSkinningFeatureHLSL );
}

View file

@ -571,7 +571,7 @@
profile = "ToolsGuiTransparentProfile";
isContainer = "1";
position = "0 0";
Extent = "185 68";
Extent = "185 50";
HorizSizing = "width";
new GuiTextCtrl() {
@ -592,15 +592,6 @@
Profile = "ToolsGuiTextProfile";
};
new GuiTextCtrl() {
HorizSizing = "right";
VertSizing = "bottom";
position = "9 48";
Extent = "72 16";
text = "GlowMul";
Profile = "ToolsGuiTextProfile";
};
new GuiControl() {
class = "AggregateControl";
position = "91 4";
@ -700,55 +691,6 @@
text = "0";
};
};
new GuiControl() {
class = "AggregateControl";
position = "91 48";
Extent = "96 20";
new GuiSliderCtrl() {
canSaveDynamicFields = "0";
internalName = "GlowMulSlider";
Enabled = "1";
isContainer = "0";
Profile = "ToolsGuiSliderProfile";
HorizSizing = "right";
VertSizing = "bottom";
position = "0 1";
Extent = "61 14";
MinExtent = "8 2";
canSave = "1";
Visible = "1";
Command = "MaterialEditorGui.updateActiveMaterial(\"GlowMul[\" @ MaterialEditorGui.currentLayer @ \"]\", $ThisControl.getValue(), true, true);";
AltCommand = "$ThisControl.getParent().updateFromChild($ThisControl); MaterialEditorGui.updateActiveMaterial(\"GlowMul[\" @ MaterialEditorGui.currentLayer @ \"]\", $ThisControl.getValue(), true, false);";
tooltipprofile = "ToolsGuiDefaultProfile";
ToolTip = "Sets GlowMul.";
hovertime = "1000";
range = "0 1";
ticks = "0";
value = "0";
};
new GuiTextEditCtrl() {
canSaveDynamicFields = "0";
internalName = "GlowMulTextEdit";
Enabled = "1";
isContainer = "0";
Profile = "ToolsGuiTextEditProfile";
HorizSizing = "right";
VertSizing = "bottom";
position = "64 0";
Extent = "29 18";
MinExtent = "8 2";
canSave = "1";
Visible = "1";
Command = "$ThisControl.getParent().updateFromChild($ThisControl); MaterialEditorGui.updateActiveMaterial(\"GlowMul[\" @ MaterialEditorGui.currentLayer @ \"]\", $ThisControl.getValue());";
hovertime = "1000";
AnchorTop = "1";
AnchorBottom = "0";
AnchorLeft = "1";
AnchorRight = "0";
text = "0";
};
};
};
new GuiContainer(){ // spec Map options
@ -1736,6 +1678,23 @@
canSaveDynamicFields = "0";
};
};
new GuiBitmapCtrl() {
bitmap = "tools/gui/images/separator-v";
wrap = "0";
position = "6 75";
extent = "175 2";
minExtent = "8 2";
horizSizing = "width";
vertSizing = "bottom";
profile = "ToolsGuiButtonProfile";
visible = "1";
active = "1";
tooltipProfile = "GuiToolTipProfile";
hovertime = "1000";
isContainer = "0";
canSave = "1";
canSaveDynamicFields = "0";
};
new GuiContainer() {
margin = "0 0 0 0";
padding = "0 0 0 0";
@ -1744,7 +1703,7 @@
anchorLeft = "1";
anchorRight = "0";
position = "6 364";
extent = "185 52";
extent = "185 67";
minExtent = "8 2";
horizSizing = "width";
vertSizing = "bottom";
@ -1890,86 +1849,64 @@
canSave = "1";
canSaveDynamicFields = "0";
};
new GuiRadioCtrl(glowChanBtn0) {
text = "R";
groupNum = "4";
buttonType = "RadioButton";
useMouseEvents = "0";
position = "100 5";
extent = "20 10";
minExtent = "8 2";
horizSizing = "right";
vertSizing = "bottom";
profile = "ToolsGuiRadioProfile";
visible = "1";
active = "1";
command = "MaterialEditorGui.setglowChan(0);";
tooltipProfile = "GuiToolTipProfile";
hovertime = "1000";
isContainer = "0";
canSave = "1";
canSaveDynamicFields = "0";
};
new GuiRadioCtrl(glowChanBtn1) {
text = "G";
groupNum = "4";
buttonType = "RadioButton";
useMouseEvents = "0";
position = "121 5";
extent = "20 10";
minExtent = "8 2";
horizSizing = "right";
vertSizing = "bottom";
profile = "ToolsGuiRadioProfile";
visible = "1";
active = "1";
command = "MaterialEditorGui.setglowChan(1);";
tooltipProfile = "GuiToolTipProfile";
hovertime = "1000";
isContainer = "0";
canSave = "1";
canSaveDynamicFields = "0";
};
new GuiRadioCtrl(glowChanBtn2) {
text = "B";
groupNum = "4";
buttonType = "RadioButton";
useMouseEvents = "0";
position = "142 5";
extent = "20 10";
minExtent = "8 2";
horizSizing = "right";
vertSizing = "bottom";
profile = "ToolsGuiRadioProfile";
visible = "1";
active = "1";
command = "MaterialEditorGui.setglowChan(2);";
tooltipProfile = "GuiToolTipProfile";
hovertime = "1000";
isContainer = "0";
canSave = "1";
canSaveDynamicFields = "0";
};
new GuiRadioCtrl(glowChanBtn3) {
text = "A";
groupNum = "4";
buttonType = "RadioButton";
useMouseEvents = "0";
position = "163 5";
extent = "20 10";
minExtent = "8 2";
horizSizing = "right";
vertSizing = "bottom";
profile = "ToolsGuiRadioProfile";
visible = "1";
active = "1";
command = "MaterialEditorGui.setglowChan(3);";
tooltipProfile = "GuiToolTipProfile";
hovertime = "1000";
isContainer = "0";
canSave = "1";
canSaveDynamicFields = "0";
};
new GuiTextCtrl() {
HorizSizing = "right";
VertSizing = "bottom";
position = "9 48";
Extent = "72 16";
text = "GlowMul";
Profile = "ToolsGuiTextProfile";
};
new GuiControl() {
class = "AggregateControl";
position = "91 48";
Extent = "96 20";
new GuiSliderCtrl() {
canSaveDynamicFields = "0";
internalName = "GlowMulSlider";
Enabled = "1";
isContainer = "0";
Profile = "ToolsGuiSliderProfile";
HorizSizing = "right";
VertSizing = "bottom";
position = "0 1";
Extent = "61 14";
MinExtent = "8 2";
canSave = "1";
Visible = "1";
Command = "MaterialEditorGui.updateActiveMaterial(\"GlowMul[\" @ MaterialEditorGui.currentLayer @ \"]\", $ThisControl.getValue(), true, true);";
AltCommand = "$ThisControl.getParent().updateFromChild($ThisControl); MaterialEditorGui.updateActiveMaterial(\"GlowMul[\" @ MaterialEditorGui.currentLayer @ \"]\", $ThisControl.getValue(), true, false);";
tooltipprofile = "ToolsGuiDefaultProfile";
ToolTip = "Sets GlowMul.";
hovertime = "1000";
range = "0 20";
ticks = "0";
value = "0";
};
new GuiTextEditCtrl() {
canSaveDynamicFields = "0";
internalName = "GlowMulTextEdit";
Enabled = "1";
isContainer = "0";
Profile = "ToolsGuiTextEditProfile";
HorizSizing = "right";
VertSizing = "bottom";
position = "64 0";
Extent = "29 18";
MinExtent = "8 2";
canSave = "1";
Visible = "1";
Command = "$ThisControl.getParent().updateFromChild($ThisControl); MaterialEditorGui.updateActiveMaterial(\"GlowMul[\" @ MaterialEditorGui.currentLayer @ \"]\", $ThisControl.getValue());";
hovertime = "1000";
AnchorTop = "1";
AnchorBottom = "0";
AnchorLeft = "1";
AnchorRight = "0";
text = "0";
};
};
};
};
};