Torque3D/Engine/source/lighting/advanced/hlsl/deferredShadingFeaturesHLSL.cpp

303 lines
10 KiB
C++
Raw Normal View History

engine: defines and alters a series of material features for deferred shading in order to define a fully fleshed out multiple render target gbuffer patterned after the general principles outlined http://www.catalinzima.com/xna/tutorials/deferred-rendering-in-xna/creating-the-g-buffer/ (though I cannot stress enough *not* using the identical layout) script: removes dead material features (ie: those that never functioned to begin with) shader: bool getFlag(float flags, int num) definition for retreiving data from the 3rd (matinfo) gbuffer slot's red channel (more on that shortly) purpose: _A)_ Small primer on how material features function: When a https://github.com/GarageGames/Torque3D/search?utf8=%E2%9C%93&q=_determineFeatures call is executed, certain conditions trigger a given .addFeature(MFT_SOMEFEATURE) call based upon material definition entries, be it a value, a texture reference, or even the presence or lack thereof for another feature. In general terms, the first to be executed is ProcessedShaderMaterial::_determineFeatures followed by ProcessedPrePassMaterial::_determineFeatures. The next commit will provide the bindings there. For now it's enough to understand that one of those two will trigger the shadergen subsystem, when rendering a material, to check it's associated list of features and spit out a shader if one is not already defined, or reference a pre-existing one that includes codelines determined by that list of features. Relevant execution of this is as follows: DeclareFeatureType( MFT_DeferredDiffuseMap ); - Name ImplementFeatureType( MFT_DeferredDiffuseMap, MFG_Texture, 2.0f, false ); - Codeline Insertion Order FEATUREMGR->registerFeature( MFT_DeferredDiffuseMap, new DeferredDiffuseMapHLSL ); - Hook to class which actually generates code alternately FEATUREMGR->registerFeature( MFT_Imposter, new NamedFeatureHLSL( "Imposter" ) ); - a simple feature that serves no purpose further than as a test of it's existence (to modify other features for instance) class DeferredDiffuseMapHLSL : public ShaderFeatureHLSL - Class definition { getName -embeded in the proceedural shader as a remline both up top and before actual code insertions processPix - pixel shader codeline insertions getOutputTargets - used to determine which buffer is written to (assumes only one. depending on branched logic, older features that may be run for either forward or deferred rendering depending on circumstance may have a logical switch based on additional feature flags. as an example: TerrainBaseMapFeatHLSL::getOutputTargets) getResources - associated with the Resources struct, closely aligned with the hardware regestry getBlendOp - used to determine what blend operation to use if a material requires a second pass (defaults to overwriting) setTexData - ??? processVert - vertex shader codeline insertions }; _B)_ The resultant Gbuffer layout defined by the previous commit therefore is as follows: defaultrendertarget (referred to in shaders as out.col or col depending on GFX plugin) contains either lighting and normal data, or color data depending on if it is used in a deferred or forward lit manner (note for forward lit, this data is replaced as a second step with color. why custommaterials have traditionally had problems with lighting) color1 (referred to in shaders as out.col1 or col1 depending on GFX plugin) RGB color data and an A for blending operations (including transparency) color2 (referred to in shaders as out.col2 or col2 depending on GFX plugin) contains: red channel comprising material flags such as metalness, emissive, ect, green channel for translucency (light shining through, as oposed to see-through transparency), blue for blue for specular strength (how much light influences net color) alpha for specular power (generally how reflective/glossy an object is) long term purpose: further down the line, these will be used to condition data for use with a PBR subsystem, with further corrections to the underlying mathematics, strength being replaced by roughness, and power by metalness
2016-02-16 08:23:23 +00:00
//-----------------------------------------------------------------------------
// 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/renderDeferredMgr.h"
engine: defines and alters a series of material features for deferred shading in order to define a fully fleshed out multiple render target gbuffer patterned after the general principles outlined http://www.catalinzima.com/xna/tutorials/deferred-rendering-in-xna/creating-the-g-buffer/ (though I cannot stress enough *not* using the identical layout) script: removes dead material features (ie: those that never functioned to begin with) shader: bool getFlag(float flags, int num) definition for retreiving data from the 3rd (matinfo) gbuffer slot's red channel (more on that shortly) purpose: _A)_ Small primer on how material features function: When a https://github.com/GarageGames/Torque3D/search?utf8=%E2%9C%93&q=_determineFeatures call is executed, certain conditions trigger a given .addFeature(MFT_SOMEFEATURE) call based upon material definition entries, be it a value, a texture reference, or even the presence or lack thereof for another feature. In general terms, the first to be executed is ProcessedShaderMaterial::_determineFeatures followed by ProcessedPrePassMaterial::_determineFeatures. The next commit will provide the bindings there. For now it's enough to understand that one of those two will trigger the shadergen subsystem, when rendering a material, to check it's associated list of features and spit out a shader if one is not already defined, or reference a pre-existing one that includes codelines determined by that list of features. Relevant execution of this is as follows: DeclareFeatureType( MFT_DeferredDiffuseMap ); - Name ImplementFeatureType( MFT_DeferredDiffuseMap, MFG_Texture, 2.0f, false ); - Codeline Insertion Order FEATUREMGR->registerFeature( MFT_DeferredDiffuseMap, new DeferredDiffuseMapHLSL ); - Hook to class which actually generates code alternately FEATUREMGR->registerFeature( MFT_Imposter, new NamedFeatureHLSL( "Imposter" ) ); - a simple feature that serves no purpose further than as a test of it's existence (to modify other features for instance) class DeferredDiffuseMapHLSL : public ShaderFeatureHLSL - Class definition { getName -embeded in the proceedural shader as a remline both up top and before actual code insertions processPix - pixel shader codeline insertions getOutputTargets - used to determine which buffer is written to (assumes only one. depending on branched logic, older features that may be run for either forward or deferred rendering depending on circumstance may have a logical switch based on additional feature flags. as an example: TerrainBaseMapFeatHLSL::getOutputTargets) getResources - associated with the Resources struct, closely aligned with the hardware regestry getBlendOp - used to determine what blend operation to use if a material requires a second pass (defaults to overwriting) setTexData - ??? processVert - vertex shader codeline insertions }; _B)_ The resultant Gbuffer layout defined by the previous commit therefore is as follows: defaultrendertarget (referred to in shaders as out.col or col depending on GFX plugin) contains either lighting and normal data, or color data depending on if it is used in a deferred or forward lit manner (note for forward lit, this data is replaced as a second step with color. why custommaterials have traditionally had problems with lighting) color1 (referred to in shaders as out.col1 or col1 depending on GFX plugin) RGB color data and an A for blending operations (including transparency) color2 (referred to in shaders as out.col2 or col2 depending on GFX plugin) contains: red channel comprising material flags such as metalness, emissive, ect, green channel for translucency (light shining through, as oposed to see-through transparency), blue for blue for specular strength (how much light influences net color) alpha for specular power (generally how reflective/glossy an object is) long term purpose: further down the line, these will be used to condition data for use with a PBR subsystem, with further corrections to the underlying mathematics, strength being replaced by roughness, and power by metalness
2016-02-16 08:23:23 +00:00
#include "materials/processedMaterial.h"
#include "materials/materialFeatureTypes.h"
//****************************************************************************
// Deferred Shading Features
//****************************************************************************
2020-09-30 18:51:12 +00:00
U32 DeferredOrmMapHLSL::getOutputTargets(const MaterialFeatureData& fd) const
{
return fd.features[MFT_isDeferred] ? ShaderFeature::RenderTarget2 : ShaderFeature::DefaultTarget;
}
engine: defines and alters a series of material features for deferred shading in order to define a fully fleshed out multiple render target gbuffer patterned after the general principles outlined http://www.catalinzima.com/xna/tutorials/deferred-rendering-in-xna/creating-the-g-buffer/ (though I cannot stress enough *not* using the identical layout) script: removes dead material features (ie: those that never functioned to begin with) shader: bool getFlag(float flags, int num) definition for retreiving data from the 3rd (matinfo) gbuffer slot's red channel (more on that shortly) purpose: _A)_ Small primer on how material features function: When a https://github.com/GarageGames/Torque3D/search?utf8=%E2%9C%93&q=_determineFeatures call is executed, certain conditions trigger a given .addFeature(MFT_SOMEFEATURE) call based upon material definition entries, be it a value, a texture reference, or even the presence or lack thereof for another feature. In general terms, the first to be executed is ProcessedShaderMaterial::_determineFeatures followed by ProcessedPrePassMaterial::_determineFeatures. The next commit will provide the bindings there. For now it's enough to understand that one of those two will trigger the shadergen subsystem, when rendering a material, to check it's associated list of features and spit out a shader if one is not already defined, or reference a pre-existing one that includes codelines determined by that list of features. Relevant execution of this is as follows: DeclareFeatureType( MFT_DeferredDiffuseMap ); - Name ImplementFeatureType( MFT_DeferredDiffuseMap, MFG_Texture, 2.0f, false ); - Codeline Insertion Order FEATUREMGR->registerFeature( MFT_DeferredDiffuseMap, new DeferredDiffuseMapHLSL ); - Hook to class which actually generates code alternately FEATUREMGR->registerFeature( MFT_Imposter, new NamedFeatureHLSL( "Imposter" ) ); - a simple feature that serves no purpose further than as a test of it's existence (to modify other features for instance) class DeferredDiffuseMapHLSL : public ShaderFeatureHLSL - Class definition { getName -embeded in the proceedural shader as a remline both up top and before actual code insertions processPix - pixel shader codeline insertions getOutputTargets - used to determine which buffer is written to (assumes only one. depending on branched logic, older features that may be run for either forward or deferred rendering depending on circumstance may have a logical switch based on additional feature flags. as an example: TerrainBaseMapFeatHLSL::getOutputTargets) getResources - associated with the Resources struct, closely aligned with the hardware regestry getBlendOp - used to determine what blend operation to use if a material requires a second pass (defaults to overwriting) setTexData - ??? processVert - vertex shader codeline insertions }; _B)_ The resultant Gbuffer layout defined by the previous commit therefore is as follows: defaultrendertarget (referred to in shaders as out.col or col depending on GFX plugin) contains either lighting and normal data, or color data depending on if it is used in a deferred or forward lit manner (note for forward lit, this data is replaced as a second step with color. why custommaterials have traditionally had problems with lighting) color1 (referred to in shaders as out.col1 or col1 depending on GFX plugin) RGB color data and an A for blending operations (including transparency) color2 (referred to in shaders as out.col2 or col2 depending on GFX plugin) contains: red channel comprising material flags such as metalness, emissive, ect, green channel for translucency (light shining through, as oposed to see-through transparency), blue for blue for specular strength (how much light influences net color) alpha for specular power (generally how reflective/glossy an object is) long term purpose: further down the line, these will be used to condition data for use with a PBR subsystem, with further corrections to the underlying mathematics, strength being replaced by roughness, and power by metalness
2016-02-16 08:23:23 +00:00
2020-09-30 18:51:12 +00:00
void DeferredOrmMapHLSL::processPix( Vector<ShaderComponent*> &componentList, const MaterialFeatureData &fd )
engine: defines and alters a series of material features for deferred shading in order to define a fully fleshed out multiple render target gbuffer patterned after the general principles outlined http://www.catalinzima.com/xna/tutorials/deferred-rendering-in-xna/creating-the-g-buffer/ (though I cannot stress enough *not* using the identical layout) script: removes dead material features (ie: those that never functioned to begin with) shader: bool getFlag(float flags, int num) definition for retreiving data from the 3rd (matinfo) gbuffer slot's red channel (more on that shortly) purpose: _A)_ Small primer on how material features function: When a https://github.com/GarageGames/Torque3D/search?utf8=%E2%9C%93&q=_determineFeatures call is executed, certain conditions trigger a given .addFeature(MFT_SOMEFEATURE) call based upon material definition entries, be it a value, a texture reference, or even the presence or lack thereof for another feature. In general terms, the first to be executed is ProcessedShaderMaterial::_determineFeatures followed by ProcessedPrePassMaterial::_determineFeatures. The next commit will provide the bindings there. For now it's enough to understand that one of those two will trigger the shadergen subsystem, when rendering a material, to check it's associated list of features and spit out a shader if one is not already defined, or reference a pre-existing one that includes codelines determined by that list of features. Relevant execution of this is as follows: DeclareFeatureType( MFT_DeferredDiffuseMap ); - Name ImplementFeatureType( MFT_DeferredDiffuseMap, MFG_Texture, 2.0f, false ); - Codeline Insertion Order FEATUREMGR->registerFeature( MFT_DeferredDiffuseMap, new DeferredDiffuseMapHLSL ); - Hook to class which actually generates code alternately FEATUREMGR->registerFeature( MFT_Imposter, new NamedFeatureHLSL( "Imposter" ) ); - a simple feature that serves no purpose further than as a test of it's existence (to modify other features for instance) class DeferredDiffuseMapHLSL : public ShaderFeatureHLSL - Class definition { getName -embeded in the proceedural shader as a remline both up top and before actual code insertions processPix - pixel shader codeline insertions getOutputTargets - used to determine which buffer is written to (assumes only one. depending on branched logic, older features that may be run for either forward or deferred rendering depending on circumstance may have a logical switch based on additional feature flags. as an example: TerrainBaseMapFeatHLSL::getOutputTargets) getResources - associated with the Resources struct, closely aligned with the hardware regestry getBlendOp - used to determine what blend operation to use if a material requires a second pass (defaults to overwriting) setTexData - ??? processVert - vertex shader codeline insertions }; _B)_ The resultant Gbuffer layout defined by the previous commit therefore is as follows: defaultrendertarget (referred to in shaders as out.col or col depending on GFX plugin) contains either lighting and normal data, or color data depending on if it is used in a deferred or forward lit manner (note for forward lit, this data is replaced as a second step with color. why custommaterials have traditionally had problems with lighting) color1 (referred to in shaders as out.col1 or col1 depending on GFX plugin) RGB color data and an A for blending operations (including transparency) color2 (referred to in shaders as out.col2 or col2 depending on GFX plugin) contains: red channel comprising material flags such as metalness, emissive, ect, green channel for translucency (light shining through, as oposed to see-through transparency), blue for blue for specular strength (how much light influences net color) alpha for specular power (generally how reflective/glossy an object is) long term purpose: further down the line, these will be used to condition data for use with a PBR subsystem, with further corrections to the underlying mathematics, strength being replaced by roughness, and power by metalness
2016-02-16 08:23:23 +00:00
{
// Get the texture coord.
2017-05-28 21:51:31 +00:00
Var *texCoord = getInTexCoord( "texCoord", "float2", componentList );
engine: defines and alters a series of material features for deferred shading in order to define a fully fleshed out multiple render target gbuffer patterned after the general principles outlined http://www.catalinzima.com/xna/tutorials/deferred-rendering-in-xna/creating-the-g-buffer/ (though I cannot stress enough *not* using the identical layout) script: removes dead material features (ie: those that never functioned to begin with) shader: bool getFlag(float flags, int num) definition for retreiving data from the 3rd (matinfo) gbuffer slot's red channel (more on that shortly) purpose: _A)_ Small primer on how material features function: When a https://github.com/GarageGames/Torque3D/search?utf8=%E2%9C%93&q=_determineFeatures call is executed, certain conditions trigger a given .addFeature(MFT_SOMEFEATURE) call based upon material definition entries, be it a value, a texture reference, or even the presence or lack thereof for another feature. In general terms, the first to be executed is ProcessedShaderMaterial::_determineFeatures followed by ProcessedPrePassMaterial::_determineFeatures. The next commit will provide the bindings there. For now it's enough to understand that one of those two will trigger the shadergen subsystem, when rendering a material, to check it's associated list of features and spit out a shader if one is not already defined, or reference a pre-existing one that includes codelines determined by that list of features. Relevant execution of this is as follows: DeclareFeatureType( MFT_DeferredDiffuseMap ); - Name ImplementFeatureType( MFT_DeferredDiffuseMap, MFG_Texture, 2.0f, false ); - Codeline Insertion Order FEATUREMGR->registerFeature( MFT_DeferredDiffuseMap, new DeferredDiffuseMapHLSL ); - Hook to class which actually generates code alternately FEATUREMGR->registerFeature( MFT_Imposter, new NamedFeatureHLSL( "Imposter" ) ); - a simple feature that serves no purpose further than as a test of it's existence (to modify other features for instance) class DeferredDiffuseMapHLSL : public ShaderFeatureHLSL - Class definition { getName -embeded in the proceedural shader as a remline both up top and before actual code insertions processPix - pixel shader codeline insertions getOutputTargets - used to determine which buffer is written to (assumes only one. depending on branched logic, older features that may be run for either forward or deferred rendering depending on circumstance may have a logical switch based on additional feature flags. as an example: TerrainBaseMapFeatHLSL::getOutputTargets) getResources - associated with the Resources struct, closely aligned with the hardware regestry getBlendOp - used to determine what blend operation to use if a material requires a second pass (defaults to overwriting) setTexData - ??? processVert - vertex shader codeline insertions }; _B)_ The resultant Gbuffer layout defined by the previous commit therefore is as follows: defaultrendertarget (referred to in shaders as out.col or col depending on GFX plugin) contains either lighting and normal data, or color data depending on if it is used in a deferred or forward lit manner (note for forward lit, this data is replaced as a second step with color. why custommaterials have traditionally had problems with lighting) color1 (referred to in shaders as out.col1 or col1 depending on GFX plugin) RGB color data and an A for blending operations (including transparency) color2 (referred to in shaders as out.col2 or col2 depending on GFX plugin) contains: red channel comprising material flags such as metalness, emissive, ect, green channel for translucency (light shining through, as oposed to see-through transparency), blue for blue for specular strength (how much light influences net color) alpha for specular power (generally how reflective/glossy an object is) long term purpose: further down the line, these will be used to condition data for use with a PBR subsystem, with further corrections to the underlying mathematics, strength being replaced by roughness, and power by metalness
2016-02-16 08:23:23 +00:00
MultiLine* meta = new MultiLine;
2020-09-30 18:51:12 +00:00
Var* ormConfig;
if (fd.features[MFT_isDeferred])
{
2020-09-30 18:51:12 +00:00
ormConfig = (Var*)LangElement::find(getOutputTargetVarName(ShaderFeature::RenderTarget2));
if (!ormConfig)
{
// create material var
2020-09-30 18:51:12 +00:00
ormConfig = new Var;
ormConfig->setType("fragout");
ormConfig->setName(getOutputTargetVarName(ShaderFeature::RenderTarget2));
ormConfig->setStructName("OUT");
}
}
else
engine: defines and alters a series of material features for deferred shading in order to define a fully fleshed out multiple render target gbuffer patterned after the general principles outlined http://www.catalinzima.com/xna/tutorials/deferred-rendering-in-xna/creating-the-g-buffer/ (though I cannot stress enough *not* using the identical layout) script: removes dead material features (ie: those that never functioned to begin with) shader: bool getFlag(float flags, int num) definition for retreiving data from the 3rd (matinfo) gbuffer slot's red channel (more on that shortly) purpose: _A)_ Small primer on how material features function: When a https://github.com/GarageGames/Torque3D/search?utf8=%E2%9C%93&q=_determineFeatures call is executed, certain conditions trigger a given .addFeature(MFT_SOMEFEATURE) call based upon material definition entries, be it a value, a texture reference, or even the presence or lack thereof for another feature. In general terms, the first to be executed is ProcessedShaderMaterial::_determineFeatures followed by ProcessedPrePassMaterial::_determineFeatures. The next commit will provide the bindings there. For now it's enough to understand that one of those two will trigger the shadergen subsystem, when rendering a material, to check it's associated list of features and spit out a shader if one is not already defined, or reference a pre-existing one that includes codelines determined by that list of features. Relevant execution of this is as follows: DeclareFeatureType( MFT_DeferredDiffuseMap ); - Name ImplementFeatureType( MFT_DeferredDiffuseMap, MFG_Texture, 2.0f, false ); - Codeline Insertion Order FEATUREMGR->registerFeature( MFT_DeferredDiffuseMap, new DeferredDiffuseMapHLSL ); - Hook to class which actually generates code alternately FEATUREMGR->registerFeature( MFT_Imposter, new NamedFeatureHLSL( "Imposter" ) ); - a simple feature that serves no purpose further than as a test of it's existence (to modify other features for instance) class DeferredDiffuseMapHLSL : public ShaderFeatureHLSL - Class definition { getName -embeded in the proceedural shader as a remline both up top and before actual code insertions processPix - pixel shader codeline insertions getOutputTargets - used to determine which buffer is written to (assumes only one. depending on branched logic, older features that may be run for either forward or deferred rendering depending on circumstance may have a logical switch based on additional feature flags. as an example: TerrainBaseMapFeatHLSL::getOutputTargets) getResources - associated with the Resources struct, closely aligned with the hardware regestry getBlendOp - used to determine what blend operation to use if a material requires a second pass (defaults to overwriting) setTexData - ??? processVert - vertex shader codeline insertions }; _B)_ The resultant Gbuffer layout defined by the previous commit therefore is as follows: defaultrendertarget (referred to in shaders as out.col or col depending on GFX plugin) contains either lighting and normal data, or color data depending on if it is used in a deferred or forward lit manner (note for forward lit, this data is replaced as a second step with color. why custommaterials have traditionally had problems with lighting) color1 (referred to in shaders as out.col1 or col1 depending on GFX plugin) RGB color data and an A for blending operations (including transparency) color2 (referred to in shaders as out.col2 or col2 depending on GFX plugin) contains: red channel comprising material flags such as metalness, emissive, ect, green channel for translucency (light shining through, as oposed to see-through transparency), blue for blue for specular strength (how much light influences net color) alpha for specular power (generally how reflective/glossy an object is) long term purpose: further down the line, these will be used to condition data for use with a PBR subsystem, with further corrections to the underlying mathematics, strength being replaced by roughness, and power by metalness
2016-02-16 08:23:23 +00:00
{
2020-09-30 18:51:12 +00:00
ormConfig = (Var*)LangElement::find("ORMConfig");
if (!ormConfig)
{
2020-09-30 18:51:12 +00:00
ormConfig = new Var("ORMConfig", "float4");
meta->addStatement(new GenOp(" @;\r\n", new DecOp(ormConfig)));
}
engine: defines and alters a series of material features for deferred shading in order to define a fully fleshed out multiple render target gbuffer patterned after the general principles outlined http://www.catalinzima.com/xna/tutorials/deferred-rendering-in-xna/creating-the-g-buffer/ (though I cannot stress enough *not* using the identical layout) script: removes dead material features (ie: those that never functioned to begin with) shader: bool getFlag(float flags, int num) definition for retreiving data from the 3rd (matinfo) gbuffer slot's red channel (more on that shortly) purpose: _A)_ Small primer on how material features function: When a https://github.com/GarageGames/Torque3D/search?utf8=%E2%9C%93&q=_determineFeatures call is executed, certain conditions trigger a given .addFeature(MFT_SOMEFEATURE) call based upon material definition entries, be it a value, a texture reference, or even the presence or lack thereof for another feature. In general terms, the first to be executed is ProcessedShaderMaterial::_determineFeatures followed by ProcessedPrePassMaterial::_determineFeatures. The next commit will provide the bindings there. For now it's enough to understand that one of those two will trigger the shadergen subsystem, when rendering a material, to check it's associated list of features and spit out a shader if one is not already defined, or reference a pre-existing one that includes codelines determined by that list of features. Relevant execution of this is as follows: DeclareFeatureType( MFT_DeferredDiffuseMap ); - Name ImplementFeatureType( MFT_DeferredDiffuseMap, MFG_Texture, 2.0f, false ); - Codeline Insertion Order FEATUREMGR->registerFeature( MFT_DeferredDiffuseMap, new DeferredDiffuseMapHLSL ); - Hook to class which actually generates code alternately FEATUREMGR->registerFeature( MFT_Imposter, new NamedFeatureHLSL( "Imposter" ) ); - a simple feature that serves no purpose further than as a test of it's existence (to modify other features for instance) class DeferredDiffuseMapHLSL : public ShaderFeatureHLSL - Class definition { getName -embeded in the proceedural shader as a remline both up top and before actual code insertions processPix - pixel shader codeline insertions getOutputTargets - used to determine which buffer is written to (assumes only one. depending on branched logic, older features that may be run for either forward or deferred rendering depending on circumstance may have a logical switch based on additional feature flags. as an example: TerrainBaseMapFeatHLSL::getOutputTargets) getResources - associated with the Resources struct, closely aligned with the hardware regestry getBlendOp - used to determine what blend operation to use if a material requires a second pass (defaults to overwriting) setTexData - ??? processVert - vertex shader codeline insertions }; _B)_ The resultant Gbuffer layout defined by the previous commit therefore is as follows: defaultrendertarget (referred to in shaders as out.col or col depending on GFX plugin) contains either lighting and normal data, or color data depending on if it is used in a deferred or forward lit manner (note for forward lit, this data is replaced as a second step with color. why custommaterials have traditionally had problems with lighting) color1 (referred to in shaders as out.col1 or col1 depending on GFX plugin) RGB color data and an A for blending operations (including transparency) color2 (referred to in shaders as out.col2 or col2 depending on GFX plugin) contains: red channel comprising material flags such as metalness, emissive, ect, green channel for translucency (light shining through, as oposed to see-through transparency), blue for blue for specular strength (how much light influences net color) alpha for specular power (generally how reflective/glossy an object is) long term purpose: further down the line, these will be used to condition data for use with a PBR subsystem, with further corrections to the underlying mathematics, strength being replaced by roughness, and power by metalness
2016-02-16 08:23:23 +00:00
}
// create texture var
2020-09-30 18:51:12 +00:00
Var * ormMap = new Var;
ormMap->setType( "SamplerState" );
ormMap->setName( "ORMConfigMap" );
ormMap->uniform = true;
ormMap->sampler = true;
ormMap->constNum = Var::getTexUnitNum();
Var* ormMapTex = new Var;
ormMapTex->setName("ORMConfigMapTex");
ormMapTex->setType("Texture2D");
ormMapTex->uniform = true;
ormMapTex->texture = true;
ormMapTex->constNum = ormMap->constNum;
LangElement *texOp = new GenOp("@.Sample(@, @)", ormMapTex, ormMap, texCoord);
Var *metalness = (Var*)LangElement::find("metalness");
if (!metalness) metalness = new Var("metalness", "float");
2020-09-30 18:51:12 +00:00
Var *roughness = (Var*)LangElement::find("roughness");
if (!roughness) roughness = new Var("roughness", "float");
Var* ao = (Var*)LangElement::find("ao");
if (!ao) ao = new Var("ao", "float");
engine: defines and alters a series of material features for deferred shading in order to define a fully fleshed out multiple render target gbuffer patterned after the general principles outlined http://www.catalinzima.com/xna/tutorials/deferred-rendering-in-xna/creating-the-g-buffer/ (though I cannot stress enough *not* using the identical layout) script: removes dead material features (ie: those that never functioned to begin with) shader: bool getFlag(float flags, int num) definition for retreiving data from the 3rd (matinfo) gbuffer slot's red channel (more on that shortly) purpose: _A)_ Small primer on how material features function: When a https://github.com/GarageGames/Torque3D/search?utf8=%E2%9C%93&q=_determineFeatures call is executed, certain conditions trigger a given .addFeature(MFT_SOMEFEATURE) call based upon material definition entries, be it a value, a texture reference, or even the presence or lack thereof for another feature. In general terms, the first to be executed is ProcessedShaderMaterial::_determineFeatures followed by ProcessedPrePassMaterial::_determineFeatures. The next commit will provide the bindings there. For now it's enough to understand that one of those two will trigger the shadergen subsystem, when rendering a material, to check it's associated list of features and spit out a shader if one is not already defined, or reference a pre-existing one that includes codelines determined by that list of features. Relevant execution of this is as follows: DeclareFeatureType( MFT_DeferredDiffuseMap ); - Name ImplementFeatureType( MFT_DeferredDiffuseMap, MFG_Texture, 2.0f, false ); - Codeline Insertion Order FEATUREMGR->registerFeature( MFT_DeferredDiffuseMap, new DeferredDiffuseMapHLSL ); - Hook to class which actually generates code alternately FEATUREMGR->registerFeature( MFT_Imposter, new NamedFeatureHLSL( "Imposter" ) ); - a simple feature that serves no purpose further than as a test of it's existence (to modify other features for instance) class DeferredDiffuseMapHLSL : public ShaderFeatureHLSL - Class definition { getName -embeded in the proceedural shader as a remline both up top and before actual code insertions processPix - pixel shader codeline insertions getOutputTargets - used to determine which buffer is written to (assumes only one. depending on branched logic, older features that may be run for either forward or deferred rendering depending on circumstance may have a logical switch based on additional feature flags. as an example: TerrainBaseMapFeatHLSL::getOutputTargets) getResources - associated with the Resources struct, closely aligned with the hardware regestry getBlendOp - used to determine what blend operation to use if a material requires a second pass (defaults to overwriting) setTexData - ??? processVert - vertex shader codeline insertions }; _B)_ The resultant Gbuffer layout defined by the previous commit therefore is as follows: defaultrendertarget (referred to in shaders as out.col or col depending on GFX plugin) contains either lighting and normal data, or color data depending on if it is used in a deferred or forward lit manner (note for forward lit, this data is replaced as a second step with color. why custommaterials have traditionally had problems with lighting) color1 (referred to in shaders as out.col1 or col1 depending on GFX plugin) RGB color data and an A for blending operations (including transparency) color2 (referred to in shaders as out.col2 or col2 depending on GFX plugin) contains: red channel comprising material flags such as metalness, emissive, ect, green channel for translucency (light shining through, as oposed to see-through transparency), blue for blue for specular strength (how much light influences net color) alpha for specular power (generally how reflective/glossy an object is) long term purpose: further down the line, these will be used to condition data for use with a PBR subsystem, with further corrections to the underlying mathematics, strength being replaced by roughness, and power by metalness
2016-02-16 08:23:23 +00:00
2016-03-20 11:52:11 +00:00
2020-09-30 18:51:12 +00:00
meta->addStatement(new GenOp(" @.gba = @.rgb;\r\n", ormConfig, texOp));
2020-09-30 18:51:12 +00:00
meta->addStatement(new GenOp(" @ = @.g;\r\n", new DecOp(ao), ormConfig));
meta->addStatement(new GenOp(" @ = @.b;\r\n", new DecOp(roughness), ormConfig));
if (fd.features[MFT_InvertRoughness])
{
2020-09-30 18:51:12 +00:00
meta->addStatement(new GenOp(" @.b = 1.0-@.b;\r\n", ormConfig, ormConfig));
meta->addStatement(new GenOp(" @ = 1.0-@;\r\n", roughness, roughness));
}
2020-09-30 18:51:12 +00:00
meta->addStatement(new GenOp(" @ = @.a;\r\n", new DecOp(metalness), ormConfig));
engine: defines and alters a series of material features for deferred shading in order to define a fully fleshed out multiple render target gbuffer patterned after the general principles outlined http://www.catalinzima.com/xna/tutorials/deferred-rendering-in-xna/creating-the-g-buffer/ (though I cannot stress enough *not* using the identical layout) script: removes dead material features (ie: those that never functioned to begin with) shader: bool getFlag(float flags, int num) definition for retreiving data from the 3rd (matinfo) gbuffer slot's red channel (more on that shortly) purpose: _A)_ Small primer on how material features function: When a https://github.com/GarageGames/Torque3D/search?utf8=%E2%9C%93&q=_determineFeatures call is executed, certain conditions trigger a given .addFeature(MFT_SOMEFEATURE) call based upon material definition entries, be it a value, a texture reference, or even the presence or lack thereof for another feature. In general terms, the first to be executed is ProcessedShaderMaterial::_determineFeatures followed by ProcessedPrePassMaterial::_determineFeatures. The next commit will provide the bindings there. For now it's enough to understand that one of those two will trigger the shadergen subsystem, when rendering a material, to check it's associated list of features and spit out a shader if one is not already defined, or reference a pre-existing one that includes codelines determined by that list of features. Relevant execution of this is as follows: DeclareFeatureType( MFT_DeferredDiffuseMap ); - Name ImplementFeatureType( MFT_DeferredDiffuseMap, MFG_Texture, 2.0f, false ); - Codeline Insertion Order FEATUREMGR->registerFeature( MFT_DeferredDiffuseMap, new DeferredDiffuseMapHLSL ); - Hook to class which actually generates code alternately FEATUREMGR->registerFeature( MFT_Imposter, new NamedFeatureHLSL( "Imposter" ) ); - a simple feature that serves no purpose further than as a test of it's existence (to modify other features for instance) class DeferredDiffuseMapHLSL : public ShaderFeatureHLSL - Class definition { getName -embeded in the proceedural shader as a remline both up top and before actual code insertions processPix - pixel shader codeline insertions getOutputTargets - used to determine which buffer is written to (assumes only one. depending on branched logic, older features that may be run for either forward or deferred rendering depending on circumstance may have a logical switch based on additional feature flags. as an example: TerrainBaseMapFeatHLSL::getOutputTargets) getResources - associated with the Resources struct, closely aligned with the hardware regestry getBlendOp - used to determine what blend operation to use if a material requires a second pass (defaults to overwriting) setTexData - ??? processVert - vertex shader codeline insertions }; _B)_ The resultant Gbuffer layout defined by the previous commit therefore is as follows: defaultrendertarget (referred to in shaders as out.col or col depending on GFX plugin) contains either lighting and normal data, or color data depending on if it is used in a deferred or forward lit manner (note for forward lit, this data is replaced as a second step with color. why custommaterials have traditionally had problems with lighting) color1 (referred to in shaders as out.col1 or col1 depending on GFX plugin) RGB color data and an A for blending operations (including transparency) color2 (referred to in shaders as out.col2 or col2 depending on GFX plugin) contains: red channel comprising material flags such as metalness, emissive, ect, green channel for translucency (light shining through, as oposed to see-through transparency), blue for blue for specular strength (how much light influences net color) alpha for specular power (generally how reflective/glossy an object is) long term purpose: further down the line, these will be used to condition data for use with a PBR subsystem, with further corrections to the underlying mathematics, strength being replaced by roughness, and power by metalness
2016-02-16 08:23:23 +00:00
output = meta;
}
2020-09-30 18:51:12 +00:00
ShaderFeature::Resources DeferredOrmMapHLSL::getResources( const MaterialFeatureData &fd )
engine: defines and alters a series of material features for deferred shading in order to define a fully fleshed out multiple render target gbuffer patterned after the general principles outlined http://www.catalinzima.com/xna/tutorials/deferred-rendering-in-xna/creating-the-g-buffer/ (though I cannot stress enough *not* using the identical layout) script: removes dead material features (ie: those that never functioned to begin with) shader: bool getFlag(float flags, int num) definition for retreiving data from the 3rd (matinfo) gbuffer slot's red channel (more on that shortly) purpose: _A)_ Small primer on how material features function: When a https://github.com/GarageGames/Torque3D/search?utf8=%E2%9C%93&q=_determineFeatures call is executed, certain conditions trigger a given .addFeature(MFT_SOMEFEATURE) call based upon material definition entries, be it a value, a texture reference, or even the presence or lack thereof for another feature. In general terms, the first to be executed is ProcessedShaderMaterial::_determineFeatures followed by ProcessedPrePassMaterial::_determineFeatures. The next commit will provide the bindings there. For now it's enough to understand that one of those two will trigger the shadergen subsystem, when rendering a material, to check it's associated list of features and spit out a shader if one is not already defined, or reference a pre-existing one that includes codelines determined by that list of features. Relevant execution of this is as follows: DeclareFeatureType( MFT_DeferredDiffuseMap ); - Name ImplementFeatureType( MFT_DeferredDiffuseMap, MFG_Texture, 2.0f, false ); - Codeline Insertion Order FEATUREMGR->registerFeature( MFT_DeferredDiffuseMap, new DeferredDiffuseMapHLSL ); - Hook to class which actually generates code alternately FEATUREMGR->registerFeature( MFT_Imposter, new NamedFeatureHLSL( "Imposter" ) ); - a simple feature that serves no purpose further than as a test of it's existence (to modify other features for instance) class DeferredDiffuseMapHLSL : public ShaderFeatureHLSL - Class definition { getName -embeded in the proceedural shader as a remline both up top and before actual code insertions processPix - pixel shader codeline insertions getOutputTargets - used to determine which buffer is written to (assumes only one. depending on branched logic, older features that may be run for either forward or deferred rendering depending on circumstance may have a logical switch based on additional feature flags. as an example: TerrainBaseMapFeatHLSL::getOutputTargets) getResources - associated with the Resources struct, closely aligned with the hardware regestry getBlendOp - used to determine what blend operation to use if a material requires a second pass (defaults to overwriting) setTexData - ??? processVert - vertex shader codeline insertions }; _B)_ The resultant Gbuffer layout defined by the previous commit therefore is as follows: defaultrendertarget (referred to in shaders as out.col or col depending on GFX plugin) contains either lighting and normal data, or color data depending on if it is used in a deferred or forward lit manner (note for forward lit, this data is replaced as a second step with color. why custommaterials have traditionally had problems with lighting) color1 (referred to in shaders as out.col1 or col1 depending on GFX plugin) RGB color data and an A for blending operations (including transparency) color2 (referred to in shaders as out.col2 or col2 depending on GFX plugin) contains: red channel comprising material flags such as metalness, emissive, ect, green channel for translucency (light shining through, as oposed to see-through transparency), blue for blue for specular strength (how much light influences net color) alpha for specular power (generally how reflective/glossy an object is) long term purpose: further down the line, these will be used to condition data for use with a PBR subsystem, with further corrections to the underlying mathematics, strength being replaced by roughness, and power by metalness
2016-02-16 08:23:23 +00:00
{
Resources res;
res.numTex = 1;
res.numTexReg = 1;
return res;
}
2020-09-30 18:51:12 +00:00
void DeferredOrmMapHLSL::setTexData( Material::StageData &stageDat,
engine: defines and alters a series of material features for deferred shading in order to define a fully fleshed out multiple render target gbuffer patterned after the general principles outlined http://www.catalinzima.com/xna/tutorials/deferred-rendering-in-xna/creating-the-g-buffer/ (though I cannot stress enough *not* using the identical layout) script: removes dead material features (ie: those that never functioned to begin with) shader: bool getFlag(float flags, int num) definition for retreiving data from the 3rd (matinfo) gbuffer slot's red channel (more on that shortly) purpose: _A)_ Small primer on how material features function: When a https://github.com/GarageGames/Torque3D/search?utf8=%E2%9C%93&q=_determineFeatures call is executed, certain conditions trigger a given .addFeature(MFT_SOMEFEATURE) call based upon material definition entries, be it a value, a texture reference, or even the presence or lack thereof for another feature. In general terms, the first to be executed is ProcessedShaderMaterial::_determineFeatures followed by ProcessedPrePassMaterial::_determineFeatures. The next commit will provide the bindings there. For now it's enough to understand that one of those two will trigger the shadergen subsystem, when rendering a material, to check it's associated list of features and spit out a shader if one is not already defined, or reference a pre-existing one that includes codelines determined by that list of features. Relevant execution of this is as follows: DeclareFeatureType( MFT_DeferredDiffuseMap ); - Name ImplementFeatureType( MFT_DeferredDiffuseMap, MFG_Texture, 2.0f, false ); - Codeline Insertion Order FEATUREMGR->registerFeature( MFT_DeferredDiffuseMap, new DeferredDiffuseMapHLSL ); - Hook to class which actually generates code alternately FEATUREMGR->registerFeature( MFT_Imposter, new NamedFeatureHLSL( "Imposter" ) ); - a simple feature that serves no purpose further than as a test of it's existence (to modify other features for instance) class DeferredDiffuseMapHLSL : public ShaderFeatureHLSL - Class definition { getName -embeded in the proceedural shader as a remline both up top and before actual code insertions processPix - pixel shader codeline insertions getOutputTargets - used to determine which buffer is written to (assumes only one. depending on branched logic, older features that may be run for either forward or deferred rendering depending on circumstance may have a logical switch based on additional feature flags. as an example: TerrainBaseMapFeatHLSL::getOutputTargets) getResources - associated with the Resources struct, closely aligned with the hardware regestry getBlendOp - used to determine what blend operation to use if a material requires a second pass (defaults to overwriting) setTexData - ??? processVert - vertex shader codeline insertions }; _B)_ The resultant Gbuffer layout defined by the previous commit therefore is as follows: defaultrendertarget (referred to in shaders as out.col or col depending on GFX plugin) contains either lighting and normal data, or color data depending on if it is used in a deferred or forward lit manner (note for forward lit, this data is replaced as a second step with color. why custommaterials have traditionally had problems with lighting) color1 (referred to in shaders as out.col1 or col1 depending on GFX plugin) RGB color data and an A for blending operations (including transparency) color2 (referred to in shaders as out.col2 or col2 depending on GFX plugin) contains: red channel comprising material flags such as metalness, emissive, ect, green channel for translucency (light shining through, as oposed to see-through transparency), blue for blue for specular strength (how much light influences net color) alpha for specular power (generally how reflective/glossy an object is) long term purpose: further down the line, these will be used to condition data for use with a PBR subsystem, with further corrections to the underlying mathematics, strength being replaced by roughness, and power by metalness
2016-02-16 08:23:23 +00:00
const MaterialFeatureData &fd,
RenderPassData &passData,
U32 &texIndex )
{
2020-09-30 18:51:12 +00:00
GFXTextureObject *tex = stageDat.getTex(MFT_OrmMap);
engine: defines and alters a series of material features for deferred shading in order to define a fully fleshed out multiple render target gbuffer patterned after the general principles outlined http://www.catalinzima.com/xna/tutorials/deferred-rendering-in-xna/creating-the-g-buffer/ (though I cannot stress enough *not* using the identical layout) script: removes dead material features (ie: those that never functioned to begin with) shader: bool getFlag(float flags, int num) definition for retreiving data from the 3rd (matinfo) gbuffer slot's red channel (more on that shortly) purpose: _A)_ Small primer on how material features function: When a https://github.com/GarageGames/Torque3D/search?utf8=%E2%9C%93&q=_determineFeatures call is executed, certain conditions trigger a given .addFeature(MFT_SOMEFEATURE) call based upon material definition entries, be it a value, a texture reference, or even the presence or lack thereof for another feature. In general terms, the first to be executed is ProcessedShaderMaterial::_determineFeatures followed by ProcessedPrePassMaterial::_determineFeatures. The next commit will provide the bindings there. For now it's enough to understand that one of those two will trigger the shadergen subsystem, when rendering a material, to check it's associated list of features and spit out a shader if one is not already defined, or reference a pre-existing one that includes codelines determined by that list of features. Relevant execution of this is as follows: DeclareFeatureType( MFT_DeferredDiffuseMap ); - Name ImplementFeatureType( MFT_DeferredDiffuseMap, MFG_Texture, 2.0f, false ); - Codeline Insertion Order FEATUREMGR->registerFeature( MFT_DeferredDiffuseMap, new DeferredDiffuseMapHLSL ); - Hook to class which actually generates code alternately FEATUREMGR->registerFeature( MFT_Imposter, new NamedFeatureHLSL( "Imposter" ) ); - a simple feature that serves no purpose further than as a test of it's existence (to modify other features for instance) class DeferredDiffuseMapHLSL : public ShaderFeatureHLSL - Class definition { getName -embeded in the proceedural shader as a remline both up top and before actual code insertions processPix - pixel shader codeline insertions getOutputTargets - used to determine which buffer is written to (assumes only one. depending on branched logic, older features that may be run for either forward or deferred rendering depending on circumstance may have a logical switch based on additional feature flags. as an example: TerrainBaseMapFeatHLSL::getOutputTargets) getResources - associated with the Resources struct, closely aligned with the hardware regestry getBlendOp - used to determine what blend operation to use if a material requires a second pass (defaults to overwriting) setTexData - ??? processVert - vertex shader codeline insertions }; _B)_ The resultant Gbuffer layout defined by the previous commit therefore is as follows: defaultrendertarget (referred to in shaders as out.col or col depending on GFX plugin) contains either lighting and normal data, or color data depending on if it is used in a deferred or forward lit manner (note for forward lit, this data is replaced as a second step with color. why custommaterials have traditionally had problems with lighting) color1 (referred to in shaders as out.col1 or col1 depending on GFX plugin) RGB color data and an A for blending operations (including transparency) color2 (referred to in shaders as out.col2 or col2 depending on GFX plugin) contains: red channel comprising material flags such as metalness, emissive, ect, green channel for translucency (light shining through, as oposed to see-through transparency), blue for blue for specular strength (how much light influences net color) alpha for specular power (generally how reflective/glossy an object is) long term purpose: further down the line, these will be used to condition data for use with a PBR subsystem, with further corrections to the underlying mathematics, strength being replaced by roughness, and power by metalness
2016-02-16 08:23:23 +00:00
if ( tex )
{
passData.mTexType[ texIndex ] = Material::Standard;
2020-09-30 18:51:12 +00:00
passData.mSamplerNames[ texIndex ] = "ORMConfigMap";
engine: defines and alters a series of material features for deferred shading in order to define a fully fleshed out multiple render target gbuffer patterned after the general principles outlined http://www.catalinzima.com/xna/tutorials/deferred-rendering-in-xna/creating-the-g-buffer/ (though I cannot stress enough *not* using the identical layout) script: removes dead material features (ie: those that never functioned to begin with) shader: bool getFlag(float flags, int num) definition for retreiving data from the 3rd (matinfo) gbuffer slot's red channel (more on that shortly) purpose: _A)_ Small primer on how material features function: When a https://github.com/GarageGames/Torque3D/search?utf8=%E2%9C%93&q=_determineFeatures call is executed, certain conditions trigger a given .addFeature(MFT_SOMEFEATURE) call based upon material definition entries, be it a value, a texture reference, or even the presence or lack thereof for another feature. In general terms, the first to be executed is ProcessedShaderMaterial::_determineFeatures followed by ProcessedPrePassMaterial::_determineFeatures. The next commit will provide the bindings there. For now it's enough to understand that one of those two will trigger the shadergen subsystem, when rendering a material, to check it's associated list of features and spit out a shader if one is not already defined, or reference a pre-existing one that includes codelines determined by that list of features. Relevant execution of this is as follows: DeclareFeatureType( MFT_DeferredDiffuseMap ); - Name ImplementFeatureType( MFT_DeferredDiffuseMap, MFG_Texture, 2.0f, false ); - Codeline Insertion Order FEATUREMGR->registerFeature( MFT_DeferredDiffuseMap, new DeferredDiffuseMapHLSL ); - Hook to class which actually generates code alternately FEATUREMGR->registerFeature( MFT_Imposter, new NamedFeatureHLSL( "Imposter" ) ); - a simple feature that serves no purpose further than as a test of it's existence (to modify other features for instance) class DeferredDiffuseMapHLSL : public ShaderFeatureHLSL - Class definition { getName -embeded in the proceedural shader as a remline both up top and before actual code insertions processPix - pixel shader codeline insertions getOutputTargets - used to determine which buffer is written to (assumes only one. depending on branched logic, older features that may be run for either forward or deferred rendering depending on circumstance may have a logical switch based on additional feature flags. as an example: TerrainBaseMapFeatHLSL::getOutputTargets) getResources - associated with the Resources struct, closely aligned with the hardware regestry getBlendOp - used to determine what blend operation to use if a material requires a second pass (defaults to overwriting) setTexData - ??? processVert - vertex shader codeline insertions }; _B)_ The resultant Gbuffer layout defined by the previous commit therefore is as follows: defaultrendertarget (referred to in shaders as out.col or col depending on GFX plugin) contains either lighting and normal data, or color data depending on if it is used in a deferred or forward lit manner (note for forward lit, this data is replaced as a second step with color. why custommaterials have traditionally had problems with lighting) color1 (referred to in shaders as out.col1 or col1 depending on GFX plugin) RGB color data and an A for blending operations (including transparency) color2 (referred to in shaders as out.col2 or col2 depending on GFX plugin) contains: red channel comprising material flags such as metalness, emissive, ect, green channel for translucency (light shining through, as oposed to see-through transparency), blue for blue for specular strength (how much light influences net color) alpha for specular power (generally how reflective/glossy an object is) long term purpose: further down the line, these will be used to condition data for use with a PBR subsystem, with further corrections to the underlying mathematics, strength being replaced by roughness, and power by metalness
2016-02-16 08:23:23 +00:00
passData.mTexSlot[ texIndex++ ].texObject = tex;
}
}
2020-09-30 18:51:12 +00:00
void DeferredOrmMapHLSL::processVert( Vector<ShaderComponent*> &componentList,
engine: defines and alters a series of material features for deferred shading in order to define a fully fleshed out multiple render target gbuffer patterned after the general principles outlined http://www.catalinzima.com/xna/tutorials/deferred-rendering-in-xna/creating-the-g-buffer/ (though I cannot stress enough *not* using the identical layout) script: removes dead material features (ie: those that never functioned to begin with) shader: bool getFlag(float flags, int num) definition for retreiving data from the 3rd (matinfo) gbuffer slot's red channel (more on that shortly) purpose: _A)_ Small primer on how material features function: When a https://github.com/GarageGames/Torque3D/search?utf8=%E2%9C%93&q=_determineFeatures call is executed, certain conditions trigger a given .addFeature(MFT_SOMEFEATURE) call based upon material definition entries, be it a value, a texture reference, or even the presence or lack thereof for another feature. In general terms, the first to be executed is ProcessedShaderMaterial::_determineFeatures followed by ProcessedPrePassMaterial::_determineFeatures. The next commit will provide the bindings there. For now it's enough to understand that one of those two will trigger the shadergen subsystem, when rendering a material, to check it's associated list of features and spit out a shader if one is not already defined, or reference a pre-existing one that includes codelines determined by that list of features. Relevant execution of this is as follows: DeclareFeatureType( MFT_DeferredDiffuseMap ); - Name ImplementFeatureType( MFT_DeferredDiffuseMap, MFG_Texture, 2.0f, false ); - Codeline Insertion Order FEATUREMGR->registerFeature( MFT_DeferredDiffuseMap, new DeferredDiffuseMapHLSL ); - Hook to class which actually generates code alternately FEATUREMGR->registerFeature( MFT_Imposter, new NamedFeatureHLSL( "Imposter" ) ); - a simple feature that serves no purpose further than as a test of it's existence (to modify other features for instance) class DeferredDiffuseMapHLSL : public ShaderFeatureHLSL - Class definition { getName -embeded in the proceedural shader as a remline both up top and before actual code insertions processPix - pixel shader codeline insertions getOutputTargets - used to determine which buffer is written to (assumes only one. depending on branched logic, older features that may be run for either forward or deferred rendering depending on circumstance may have a logical switch based on additional feature flags. as an example: TerrainBaseMapFeatHLSL::getOutputTargets) getResources - associated with the Resources struct, closely aligned with the hardware regestry getBlendOp - used to determine what blend operation to use if a material requires a second pass (defaults to overwriting) setTexData - ??? processVert - vertex shader codeline insertions }; _B)_ The resultant Gbuffer layout defined by the previous commit therefore is as follows: defaultrendertarget (referred to in shaders as out.col or col depending on GFX plugin) contains either lighting and normal data, or color data depending on if it is used in a deferred or forward lit manner (note for forward lit, this data is replaced as a second step with color. why custommaterials have traditionally had problems with lighting) color1 (referred to in shaders as out.col1 or col1 depending on GFX plugin) RGB color data and an A for blending operations (including transparency) color2 (referred to in shaders as out.col2 or col2 depending on GFX plugin) contains: red channel comprising material flags such as metalness, emissive, ect, green channel for translucency (light shining through, as oposed to see-through transparency), blue for blue for specular strength (how much light influences net color) alpha for specular power (generally how reflective/glossy an object is) long term purpose: further down the line, these will be used to condition data for use with a PBR subsystem, with further corrections to the underlying mathematics, strength being replaced by roughness, and power by metalness
2016-02-16 08:23:23 +00:00
const MaterialFeatureData &fd )
{
MultiLine *meta = new MultiLine;
getOutTexCoord( "texCoord",
"float2",
fd.features[MFT_TexAnim],
meta,
componentList );
output = meta;
}
U32 MatInfoFlagsHLSL::getOutputTargets(const MaterialFeatureData& fd) const
{
return fd.features[MFT_isDeferred] ? ShaderFeature::RenderTarget2 : ShaderFeature::DefaultTarget;
}
engine: defines and alters a series of material features for deferred shading in order to define a fully fleshed out multiple render target gbuffer patterned after the general principles outlined http://www.catalinzima.com/xna/tutorials/deferred-rendering-in-xna/creating-the-g-buffer/ (though I cannot stress enough *not* using the identical layout) script: removes dead material features (ie: those that never functioned to begin with) shader: bool getFlag(float flags, int num) definition for retreiving data from the 3rd (matinfo) gbuffer slot's red channel (more on that shortly) purpose: _A)_ Small primer on how material features function: When a https://github.com/GarageGames/Torque3D/search?utf8=%E2%9C%93&q=_determineFeatures call is executed, certain conditions trigger a given .addFeature(MFT_SOMEFEATURE) call based upon material definition entries, be it a value, a texture reference, or even the presence or lack thereof for another feature. In general terms, the first to be executed is ProcessedShaderMaterial::_determineFeatures followed by ProcessedPrePassMaterial::_determineFeatures. The next commit will provide the bindings there. For now it's enough to understand that one of those two will trigger the shadergen subsystem, when rendering a material, to check it's associated list of features and spit out a shader if one is not already defined, or reference a pre-existing one that includes codelines determined by that list of features. Relevant execution of this is as follows: DeclareFeatureType( MFT_DeferredDiffuseMap ); - Name ImplementFeatureType( MFT_DeferredDiffuseMap, MFG_Texture, 2.0f, false ); - Codeline Insertion Order FEATUREMGR->registerFeature( MFT_DeferredDiffuseMap, new DeferredDiffuseMapHLSL ); - Hook to class which actually generates code alternately FEATUREMGR->registerFeature( MFT_Imposter, new NamedFeatureHLSL( "Imposter" ) ); - a simple feature that serves no purpose further than as a test of it's existence (to modify other features for instance) class DeferredDiffuseMapHLSL : public ShaderFeatureHLSL - Class definition { getName -embeded in the proceedural shader as a remline both up top and before actual code insertions processPix - pixel shader codeline insertions getOutputTargets - used to determine which buffer is written to (assumes only one. depending on branched logic, older features that may be run for either forward or deferred rendering depending on circumstance may have a logical switch based on additional feature flags. as an example: TerrainBaseMapFeatHLSL::getOutputTargets) getResources - associated with the Resources struct, closely aligned with the hardware regestry getBlendOp - used to determine what blend operation to use if a material requires a second pass (defaults to overwriting) setTexData - ??? processVert - vertex shader codeline insertions }; _B)_ The resultant Gbuffer layout defined by the previous commit therefore is as follows: defaultrendertarget (referred to in shaders as out.col or col depending on GFX plugin) contains either lighting and normal data, or color data depending on if it is used in a deferred or forward lit manner (note for forward lit, this data is replaced as a second step with color. why custommaterials have traditionally had problems with lighting) color1 (referred to in shaders as out.col1 or col1 depending on GFX plugin) RGB color data and an A for blending operations (including transparency) color2 (referred to in shaders as out.col2 or col2 depending on GFX plugin) contains: red channel comprising material flags such as metalness, emissive, ect, green channel for translucency (light shining through, as oposed to see-through transparency), blue for blue for specular strength (how much light influences net color) alpha for specular power (generally how reflective/glossy an object is) long term purpose: further down the line, these will be used to condition data for use with a PBR subsystem, with further corrections to the underlying mathematics, strength being replaced by roughness, and power by metalness
2016-02-16 08:23:23 +00:00
// Material Info Flags -> Red ( Flags ) of Material Info Buffer.
void MatInfoFlagsHLSL::processPix( Vector<ShaderComponent*> &componentList, const MaterialFeatureData &fd )
engine: defines and alters a series of material features for deferred shading in order to define a fully fleshed out multiple render target gbuffer patterned after the general principles outlined http://www.catalinzima.com/xna/tutorials/deferred-rendering-in-xna/creating-the-g-buffer/ (though I cannot stress enough *not* using the identical layout) script: removes dead material features (ie: those that never functioned to begin with) shader: bool getFlag(float flags, int num) definition for retreiving data from the 3rd (matinfo) gbuffer slot's red channel (more on that shortly) purpose: _A)_ Small primer on how material features function: When a https://github.com/GarageGames/Torque3D/search?utf8=%E2%9C%93&q=_determineFeatures call is executed, certain conditions trigger a given .addFeature(MFT_SOMEFEATURE) call based upon material definition entries, be it a value, a texture reference, or even the presence or lack thereof for another feature. In general terms, the first to be executed is ProcessedShaderMaterial::_determineFeatures followed by ProcessedPrePassMaterial::_determineFeatures. The next commit will provide the bindings there. For now it's enough to understand that one of those two will trigger the shadergen subsystem, when rendering a material, to check it's associated list of features and spit out a shader if one is not already defined, or reference a pre-existing one that includes codelines determined by that list of features. Relevant execution of this is as follows: DeclareFeatureType( MFT_DeferredDiffuseMap ); - Name ImplementFeatureType( MFT_DeferredDiffuseMap, MFG_Texture, 2.0f, false ); - Codeline Insertion Order FEATUREMGR->registerFeature( MFT_DeferredDiffuseMap, new DeferredDiffuseMapHLSL ); - Hook to class which actually generates code alternately FEATUREMGR->registerFeature( MFT_Imposter, new NamedFeatureHLSL( "Imposter" ) ); - a simple feature that serves no purpose further than as a test of it's existence (to modify other features for instance) class DeferredDiffuseMapHLSL : public ShaderFeatureHLSL - Class definition { getName -embeded in the proceedural shader as a remline both up top and before actual code insertions processPix - pixel shader codeline insertions getOutputTargets - used to determine which buffer is written to (assumes only one. depending on branched logic, older features that may be run for either forward or deferred rendering depending on circumstance may have a logical switch based on additional feature flags. as an example: TerrainBaseMapFeatHLSL::getOutputTargets) getResources - associated with the Resources struct, closely aligned with the hardware regestry getBlendOp - used to determine what blend operation to use if a material requires a second pass (defaults to overwriting) setTexData - ??? processVert - vertex shader codeline insertions }; _B)_ The resultant Gbuffer layout defined by the previous commit therefore is as follows: defaultrendertarget (referred to in shaders as out.col or col depending on GFX plugin) contains either lighting and normal data, or color data depending on if it is used in a deferred or forward lit manner (note for forward lit, this data is replaced as a second step with color. why custommaterials have traditionally had problems with lighting) color1 (referred to in shaders as out.col1 or col1 depending on GFX plugin) RGB color data and an A for blending operations (including transparency) color2 (referred to in shaders as out.col2 or col2 depending on GFX plugin) contains: red channel comprising material flags such as metalness, emissive, ect, green channel for translucency (light shining through, as oposed to see-through transparency), blue for blue for specular strength (how much light influences net color) alpha for specular power (generally how reflective/glossy an object is) long term purpose: further down the line, these will be used to condition data for use with a PBR subsystem, with further corrections to the underlying mathematics, strength being replaced by roughness, and power by metalness
2016-02-16 08:23:23 +00:00
{
// search for material var
2020-09-30 18:51:12 +00:00
Var* ormConfig;
if (fd.features[MFT_isDeferred])
engine: defines and alters a series of material features for deferred shading in order to define a fully fleshed out multiple render target gbuffer patterned after the general principles outlined http://www.catalinzima.com/xna/tutorials/deferred-rendering-in-xna/creating-the-g-buffer/ (though I cannot stress enough *not* using the identical layout) script: removes dead material features (ie: those that never functioned to begin with) shader: bool getFlag(float flags, int num) definition for retreiving data from the 3rd (matinfo) gbuffer slot's red channel (more on that shortly) purpose: _A)_ Small primer on how material features function: When a https://github.com/GarageGames/Torque3D/search?utf8=%E2%9C%93&q=_determineFeatures call is executed, certain conditions trigger a given .addFeature(MFT_SOMEFEATURE) call based upon material definition entries, be it a value, a texture reference, or even the presence or lack thereof for another feature. In general terms, the first to be executed is ProcessedShaderMaterial::_determineFeatures followed by ProcessedPrePassMaterial::_determineFeatures. The next commit will provide the bindings there. For now it's enough to understand that one of those two will trigger the shadergen subsystem, when rendering a material, to check it's associated list of features and spit out a shader if one is not already defined, or reference a pre-existing one that includes codelines determined by that list of features. Relevant execution of this is as follows: DeclareFeatureType( MFT_DeferredDiffuseMap ); - Name ImplementFeatureType( MFT_DeferredDiffuseMap, MFG_Texture, 2.0f, false ); - Codeline Insertion Order FEATUREMGR->registerFeature( MFT_DeferredDiffuseMap, new DeferredDiffuseMapHLSL ); - Hook to class which actually generates code alternately FEATUREMGR->registerFeature( MFT_Imposter, new NamedFeatureHLSL( "Imposter" ) ); - a simple feature that serves no purpose further than as a test of it's existence (to modify other features for instance) class DeferredDiffuseMapHLSL : public ShaderFeatureHLSL - Class definition { getName -embeded in the proceedural shader as a remline both up top and before actual code insertions processPix - pixel shader codeline insertions getOutputTargets - used to determine which buffer is written to (assumes only one. depending on branched logic, older features that may be run for either forward or deferred rendering depending on circumstance may have a logical switch based on additional feature flags. as an example: TerrainBaseMapFeatHLSL::getOutputTargets) getResources - associated with the Resources struct, closely aligned with the hardware regestry getBlendOp - used to determine what blend operation to use if a material requires a second pass (defaults to overwriting) setTexData - ??? processVert - vertex shader codeline insertions }; _B)_ The resultant Gbuffer layout defined by the previous commit therefore is as follows: defaultrendertarget (referred to in shaders as out.col or col depending on GFX plugin) contains either lighting and normal data, or color data depending on if it is used in a deferred or forward lit manner (note for forward lit, this data is replaced as a second step with color. why custommaterials have traditionally had problems with lighting) color1 (referred to in shaders as out.col1 or col1 depending on GFX plugin) RGB color data and an A for blending operations (including transparency) color2 (referred to in shaders as out.col2 or col2 depending on GFX plugin) contains: red channel comprising material flags such as metalness, emissive, ect, green channel for translucency (light shining through, as oposed to see-through transparency), blue for blue for specular strength (how much light influences net color) alpha for specular power (generally how reflective/glossy an object is) long term purpose: further down the line, these will be used to condition data for use with a PBR subsystem, with further corrections to the underlying mathematics, strength being replaced by roughness, and power by metalness
2016-02-16 08:23:23 +00:00
{
2020-09-30 18:51:12 +00:00
ormConfig = (Var*)LangElement::find(getOutputTargetVarName(ShaderFeature::RenderTarget2));
if (!ormConfig)
{
// create material var
2020-09-30 18:51:12 +00:00
ormConfig = new Var;
ormConfig->setType("fragout");
ormConfig->setName(getOutputTargetVarName(ShaderFeature::RenderTarget2));
ormConfig->setStructName("OUT");
}
}
else
{
2020-09-30 18:51:12 +00:00
ormConfig = (Var*)LangElement::find("ORMConfig");
if (!ormConfig) ormConfig = new Var("ORMConfig", "float4");
engine: defines and alters a series of material features for deferred shading in order to define a fully fleshed out multiple render target gbuffer patterned after the general principles outlined http://www.catalinzima.com/xna/tutorials/deferred-rendering-in-xna/creating-the-g-buffer/ (though I cannot stress enough *not* using the identical layout) script: removes dead material features (ie: those that never functioned to begin with) shader: bool getFlag(float flags, int num) definition for retreiving data from the 3rd (matinfo) gbuffer slot's red channel (more on that shortly) purpose: _A)_ Small primer on how material features function: When a https://github.com/GarageGames/Torque3D/search?utf8=%E2%9C%93&q=_determineFeatures call is executed, certain conditions trigger a given .addFeature(MFT_SOMEFEATURE) call based upon material definition entries, be it a value, a texture reference, or even the presence or lack thereof for another feature. In general terms, the first to be executed is ProcessedShaderMaterial::_determineFeatures followed by ProcessedPrePassMaterial::_determineFeatures. The next commit will provide the bindings there. For now it's enough to understand that one of those two will trigger the shadergen subsystem, when rendering a material, to check it's associated list of features and spit out a shader if one is not already defined, or reference a pre-existing one that includes codelines determined by that list of features. Relevant execution of this is as follows: DeclareFeatureType( MFT_DeferredDiffuseMap ); - Name ImplementFeatureType( MFT_DeferredDiffuseMap, MFG_Texture, 2.0f, false ); - Codeline Insertion Order FEATUREMGR->registerFeature( MFT_DeferredDiffuseMap, new DeferredDiffuseMapHLSL ); - Hook to class which actually generates code alternately FEATUREMGR->registerFeature( MFT_Imposter, new NamedFeatureHLSL( "Imposter" ) ); - a simple feature that serves no purpose further than as a test of it's existence (to modify other features for instance) class DeferredDiffuseMapHLSL : public ShaderFeatureHLSL - Class definition { getName -embeded in the proceedural shader as a remline both up top and before actual code insertions processPix - pixel shader codeline insertions getOutputTargets - used to determine which buffer is written to (assumes only one. depending on branched logic, older features that may be run for either forward or deferred rendering depending on circumstance may have a logical switch based on additional feature flags. as an example: TerrainBaseMapFeatHLSL::getOutputTargets) getResources - associated with the Resources struct, closely aligned with the hardware regestry getBlendOp - used to determine what blend operation to use if a material requires a second pass (defaults to overwriting) setTexData - ??? processVert - vertex shader codeline insertions }; _B)_ The resultant Gbuffer layout defined by the previous commit therefore is as follows: defaultrendertarget (referred to in shaders as out.col or col depending on GFX plugin) contains either lighting and normal data, or color data depending on if it is used in a deferred or forward lit manner (note for forward lit, this data is replaced as a second step with color. why custommaterials have traditionally had problems with lighting) color1 (referred to in shaders as out.col1 or col1 depending on GFX plugin) RGB color data and an A for blending operations (including transparency) color2 (referred to in shaders as out.col2 or col2 depending on GFX plugin) contains: red channel comprising material flags such as metalness, emissive, ect, green channel for translucency (light shining through, as oposed to see-through transparency), blue for blue for specular strength (how much light influences net color) alpha for specular power (generally how reflective/glossy an object is) long term purpose: further down the line, these will be used to condition data for use with a PBR subsystem, with further corrections to the underlying mathematics, strength being replaced by roughness, and power by metalness
2016-02-16 08:23:23 +00:00
}
Var *matInfoFlags = new Var;
matInfoFlags->setType( "float" );
matInfoFlags->setName( "matInfoFlags" );
matInfoFlags->uniform = true;
matInfoFlags->constSortPos = cspPotentialPrimitive;
2020-09-30 18:51:12 +00:00
output = new GenOp( " @.r = @;\r\n", ormConfig, matInfoFlags );
}
2020-09-30 18:51:12 +00:00
U32 ORMConfigVarsHLSL::getOutputTargets(const MaterialFeatureData& fd) const
{
return fd.features[MFT_isDeferred] ? ShaderFeature::RenderTarget2 : ShaderFeature::DefaultTarget;
engine: defines and alters a series of material features for deferred shading in order to define a fully fleshed out multiple render target gbuffer patterned after the general principles outlined http://www.catalinzima.com/xna/tutorials/deferred-rendering-in-xna/creating-the-g-buffer/ (though I cannot stress enough *not* using the identical layout) script: removes dead material features (ie: those that never functioned to begin with) shader: bool getFlag(float flags, int num) definition for retreiving data from the 3rd (matinfo) gbuffer slot's red channel (more on that shortly) purpose: _A)_ Small primer on how material features function: When a https://github.com/GarageGames/Torque3D/search?utf8=%E2%9C%93&q=_determineFeatures call is executed, certain conditions trigger a given .addFeature(MFT_SOMEFEATURE) call based upon material definition entries, be it a value, a texture reference, or even the presence or lack thereof for another feature. In general terms, the first to be executed is ProcessedShaderMaterial::_determineFeatures followed by ProcessedPrePassMaterial::_determineFeatures. The next commit will provide the bindings there. For now it's enough to understand that one of those two will trigger the shadergen subsystem, when rendering a material, to check it's associated list of features and spit out a shader if one is not already defined, or reference a pre-existing one that includes codelines determined by that list of features. Relevant execution of this is as follows: DeclareFeatureType( MFT_DeferredDiffuseMap ); - Name ImplementFeatureType( MFT_DeferredDiffuseMap, MFG_Texture, 2.0f, false ); - Codeline Insertion Order FEATUREMGR->registerFeature( MFT_DeferredDiffuseMap, new DeferredDiffuseMapHLSL ); - Hook to class which actually generates code alternately FEATUREMGR->registerFeature( MFT_Imposter, new NamedFeatureHLSL( "Imposter" ) ); - a simple feature that serves no purpose further than as a test of it's existence (to modify other features for instance) class DeferredDiffuseMapHLSL : public ShaderFeatureHLSL - Class definition { getName -embeded in the proceedural shader as a remline both up top and before actual code insertions processPix - pixel shader codeline insertions getOutputTargets - used to determine which buffer is written to (assumes only one. depending on branched logic, older features that may be run for either forward or deferred rendering depending on circumstance may have a logical switch based on additional feature flags. as an example: TerrainBaseMapFeatHLSL::getOutputTargets) getResources - associated with the Resources struct, closely aligned with the hardware regestry getBlendOp - used to determine what blend operation to use if a material requires a second pass (defaults to overwriting) setTexData - ??? processVert - vertex shader codeline insertions }; _B)_ The resultant Gbuffer layout defined by the previous commit therefore is as follows: defaultrendertarget (referred to in shaders as out.col or col depending on GFX plugin) contains either lighting and normal data, or color data depending on if it is used in a deferred or forward lit manner (note for forward lit, this data is replaced as a second step with color. why custommaterials have traditionally had problems with lighting) color1 (referred to in shaders as out.col1 or col1 depending on GFX plugin) RGB color data and an A for blending operations (including transparency) color2 (referred to in shaders as out.col2 or col2 depending on GFX plugin) contains: red channel comprising material flags such as metalness, emissive, ect, green channel for translucency (light shining through, as oposed to see-through transparency), blue for blue for specular strength (how much light influences net color) alpha for specular power (generally how reflective/glossy an object is) long term purpose: further down the line, these will be used to condition data for use with a PBR subsystem, with further corrections to the underlying mathematics, strength being replaced by roughness, and power by metalness
2016-02-16 08:23:23 +00:00
}
2020-09-30 18:51:12 +00:00
void ORMConfigVarsHLSL::processPix( Vector<ShaderComponent*> &componentList, const MaterialFeatureData &fd )
engine: defines and alters a series of material features for deferred shading in order to define a fully fleshed out multiple render target gbuffer patterned after the general principles outlined http://www.catalinzima.com/xna/tutorials/deferred-rendering-in-xna/creating-the-g-buffer/ (though I cannot stress enough *not* using the identical layout) script: removes dead material features (ie: those that never functioned to begin with) shader: bool getFlag(float flags, int num) definition for retreiving data from the 3rd (matinfo) gbuffer slot's red channel (more on that shortly) purpose: _A)_ Small primer on how material features function: When a https://github.com/GarageGames/Torque3D/search?utf8=%E2%9C%93&q=_determineFeatures call is executed, certain conditions trigger a given .addFeature(MFT_SOMEFEATURE) call based upon material definition entries, be it a value, a texture reference, or even the presence or lack thereof for another feature. In general terms, the first to be executed is ProcessedShaderMaterial::_determineFeatures followed by ProcessedPrePassMaterial::_determineFeatures. The next commit will provide the bindings there. For now it's enough to understand that one of those two will trigger the shadergen subsystem, when rendering a material, to check it's associated list of features and spit out a shader if one is not already defined, or reference a pre-existing one that includes codelines determined by that list of features. Relevant execution of this is as follows: DeclareFeatureType( MFT_DeferredDiffuseMap ); - Name ImplementFeatureType( MFT_DeferredDiffuseMap, MFG_Texture, 2.0f, false ); - Codeline Insertion Order FEATUREMGR->registerFeature( MFT_DeferredDiffuseMap, new DeferredDiffuseMapHLSL ); - Hook to class which actually generates code alternately FEATUREMGR->registerFeature( MFT_Imposter, new NamedFeatureHLSL( "Imposter" ) ); - a simple feature that serves no purpose further than as a test of it's existence (to modify other features for instance) class DeferredDiffuseMapHLSL : public ShaderFeatureHLSL - Class definition { getName -embeded in the proceedural shader as a remline both up top and before actual code insertions processPix - pixel shader codeline insertions getOutputTargets - used to determine which buffer is written to (assumes only one. depending on branched logic, older features that may be run for either forward or deferred rendering depending on circumstance may have a logical switch based on additional feature flags. as an example: TerrainBaseMapFeatHLSL::getOutputTargets) getResources - associated with the Resources struct, closely aligned with the hardware regestry getBlendOp - used to determine what blend operation to use if a material requires a second pass (defaults to overwriting) setTexData - ??? processVert - vertex shader codeline insertions }; _B)_ The resultant Gbuffer layout defined by the previous commit therefore is as follows: defaultrendertarget (referred to in shaders as out.col or col depending on GFX plugin) contains either lighting and normal data, or color data depending on if it is used in a deferred or forward lit manner (note for forward lit, this data is replaced as a second step with color. why custommaterials have traditionally had problems with lighting) color1 (referred to in shaders as out.col1 or col1 depending on GFX plugin) RGB color data and an A for blending operations (including transparency) color2 (referred to in shaders as out.col2 or col2 depending on GFX plugin) contains: red channel comprising material flags such as metalness, emissive, ect, green channel for translucency (light shining through, as oposed to see-through transparency), blue for blue for specular strength (how much light influences net color) alpha for specular power (generally how reflective/glossy an object is) long term purpose: further down the line, these will be used to condition data for use with a PBR subsystem, with further corrections to the underlying mathematics, strength being replaced by roughness, and power by metalness
2016-02-16 08:23:23 +00:00
{
MultiLine* meta = new MultiLine;
2020-09-30 18:51:12 +00:00
Var* ormConfig;
if (fd.features[MFT_isDeferred])
engine: defines and alters a series of material features for deferred shading in order to define a fully fleshed out multiple render target gbuffer patterned after the general principles outlined http://www.catalinzima.com/xna/tutorials/deferred-rendering-in-xna/creating-the-g-buffer/ (though I cannot stress enough *not* using the identical layout) script: removes dead material features (ie: those that never functioned to begin with) shader: bool getFlag(float flags, int num) definition for retreiving data from the 3rd (matinfo) gbuffer slot's red channel (more on that shortly) purpose: _A)_ Small primer on how material features function: When a https://github.com/GarageGames/Torque3D/search?utf8=%E2%9C%93&q=_determineFeatures call is executed, certain conditions trigger a given .addFeature(MFT_SOMEFEATURE) call based upon material definition entries, be it a value, a texture reference, or even the presence or lack thereof for another feature. In general terms, the first to be executed is ProcessedShaderMaterial::_determineFeatures followed by ProcessedPrePassMaterial::_determineFeatures. The next commit will provide the bindings there. For now it's enough to understand that one of those two will trigger the shadergen subsystem, when rendering a material, to check it's associated list of features and spit out a shader if one is not already defined, or reference a pre-existing one that includes codelines determined by that list of features. Relevant execution of this is as follows: DeclareFeatureType( MFT_DeferredDiffuseMap ); - Name ImplementFeatureType( MFT_DeferredDiffuseMap, MFG_Texture, 2.0f, false ); - Codeline Insertion Order FEATUREMGR->registerFeature( MFT_DeferredDiffuseMap, new DeferredDiffuseMapHLSL ); - Hook to class which actually generates code alternately FEATUREMGR->registerFeature( MFT_Imposter, new NamedFeatureHLSL( "Imposter" ) ); - a simple feature that serves no purpose further than as a test of it's existence (to modify other features for instance) class DeferredDiffuseMapHLSL : public ShaderFeatureHLSL - Class definition { getName -embeded in the proceedural shader as a remline both up top and before actual code insertions processPix - pixel shader codeline insertions getOutputTargets - used to determine which buffer is written to (assumes only one. depending on branched logic, older features that may be run for either forward or deferred rendering depending on circumstance may have a logical switch based on additional feature flags. as an example: TerrainBaseMapFeatHLSL::getOutputTargets) getResources - associated with the Resources struct, closely aligned with the hardware regestry getBlendOp - used to determine what blend operation to use if a material requires a second pass (defaults to overwriting) setTexData - ??? processVert - vertex shader codeline insertions }; _B)_ The resultant Gbuffer layout defined by the previous commit therefore is as follows: defaultrendertarget (referred to in shaders as out.col or col depending on GFX plugin) contains either lighting and normal data, or color data depending on if it is used in a deferred or forward lit manner (note for forward lit, this data is replaced as a second step with color. why custommaterials have traditionally had problems with lighting) color1 (referred to in shaders as out.col1 or col1 depending on GFX plugin) RGB color data and an A for blending operations (including transparency) color2 (referred to in shaders as out.col2 or col2 depending on GFX plugin) contains: red channel comprising material flags such as metalness, emissive, ect, green channel for translucency (light shining through, as oposed to see-through transparency), blue for blue for specular strength (how much light influences net color) alpha for specular power (generally how reflective/glossy an object is) long term purpose: further down the line, these will be used to condition data for use with a PBR subsystem, with further corrections to the underlying mathematics, strength being replaced by roughness, and power by metalness
2016-02-16 08:23:23 +00:00
{
2020-09-30 18:51:12 +00:00
ormConfig = (Var*)LangElement::find(getOutputTargetVarName(ShaderFeature::RenderTarget2));
if (!ormConfig)
{
// create material var
2020-09-30 18:51:12 +00:00
ormConfig = new Var;
ormConfig->setType("fragout");
ormConfig->setName(getOutputTargetVarName(ShaderFeature::RenderTarget2));
ormConfig->setStructName("OUT");
}
}
else
{
2020-09-30 18:51:12 +00:00
ormConfig = (Var*)LangElement::find("ORMConfig");
if (!ormConfig) ormConfig = new Var("ORMConfig", "float4");
meta->addStatement(new GenOp(" @;\r\n", new DecOp(ormConfig)));
engine: defines and alters a series of material features for deferred shading in order to define a fully fleshed out multiple render target gbuffer patterned after the general principles outlined http://www.catalinzima.com/xna/tutorials/deferred-rendering-in-xna/creating-the-g-buffer/ (though I cannot stress enough *not* using the identical layout) script: removes dead material features (ie: those that never functioned to begin with) shader: bool getFlag(float flags, int num) definition for retreiving data from the 3rd (matinfo) gbuffer slot's red channel (more on that shortly) purpose: _A)_ Small primer on how material features function: When a https://github.com/GarageGames/Torque3D/search?utf8=%E2%9C%93&q=_determineFeatures call is executed, certain conditions trigger a given .addFeature(MFT_SOMEFEATURE) call based upon material definition entries, be it a value, a texture reference, or even the presence or lack thereof for another feature. In general terms, the first to be executed is ProcessedShaderMaterial::_determineFeatures followed by ProcessedPrePassMaterial::_determineFeatures. The next commit will provide the bindings there. For now it's enough to understand that one of those two will trigger the shadergen subsystem, when rendering a material, to check it's associated list of features and spit out a shader if one is not already defined, or reference a pre-existing one that includes codelines determined by that list of features. Relevant execution of this is as follows: DeclareFeatureType( MFT_DeferredDiffuseMap ); - Name ImplementFeatureType( MFT_DeferredDiffuseMap, MFG_Texture, 2.0f, false ); - Codeline Insertion Order FEATUREMGR->registerFeature( MFT_DeferredDiffuseMap, new DeferredDiffuseMapHLSL ); - Hook to class which actually generates code alternately FEATUREMGR->registerFeature( MFT_Imposter, new NamedFeatureHLSL( "Imposter" ) ); - a simple feature that serves no purpose further than as a test of it's existence (to modify other features for instance) class DeferredDiffuseMapHLSL : public ShaderFeatureHLSL - Class definition { getName -embeded in the proceedural shader as a remline both up top and before actual code insertions processPix - pixel shader codeline insertions getOutputTargets - used to determine which buffer is written to (assumes only one. depending on branched logic, older features that may be run for either forward or deferred rendering depending on circumstance may have a logical switch based on additional feature flags. as an example: TerrainBaseMapFeatHLSL::getOutputTargets) getResources - associated with the Resources struct, closely aligned with the hardware regestry getBlendOp - used to determine what blend operation to use if a material requires a second pass (defaults to overwriting) setTexData - ??? processVert - vertex shader codeline insertions }; _B)_ The resultant Gbuffer layout defined by the previous commit therefore is as follows: defaultrendertarget (referred to in shaders as out.col or col depending on GFX plugin) contains either lighting and normal data, or color data depending on if it is used in a deferred or forward lit manner (note for forward lit, this data is replaced as a second step with color. why custommaterials have traditionally had problems with lighting) color1 (referred to in shaders as out.col1 or col1 depending on GFX plugin) RGB color data and an A for blending operations (including transparency) color2 (referred to in shaders as out.col2 or col2 depending on GFX plugin) contains: red channel comprising material flags such as metalness, emissive, ect, green channel for translucency (light shining through, as oposed to see-through transparency), blue for blue for specular strength (how much light influences net color) alpha for specular power (generally how reflective/glossy an object is) long term purpose: further down the line, these will be used to condition data for use with a PBR subsystem, with further corrections to the underlying mathematics, strength being replaced by roughness, and power by metalness
2016-02-16 08:23:23 +00:00
}
Var *metalness = new Var("metalness", "float");
metalness->uniform = true;
metalness->constSortPos = cspPotentialPrimitive;
engine: defines and alters a series of material features for deferred shading in order to define a fully fleshed out multiple render target gbuffer patterned after the general principles outlined http://www.catalinzima.com/xna/tutorials/deferred-rendering-in-xna/creating-the-g-buffer/ (though I cannot stress enough *not* using the identical layout) script: removes dead material features (ie: those that never functioned to begin with) shader: bool getFlag(float flags, int num) definition for retreiving data from the 3rd (matinfo) gbuffer slot's red channel (more on that shortly) purpose: _A)_ Small primer on how material features function: When a https://github.com/GarageGames/Torque3D/search?utf8=%E2%9C%93&q=_determineFeatures call is executed, certain conditions trigger a given .addFeature(MFT_SOMEFEATURE) call based upon material definition entries, be it a value, a texture reference, or even the presence or lack thereof for another feature. In general terms, the first to be executed is ProcessedShaderMaterial::_determineFeatures followed by ProcessedPrePassMaterial::_determineFeatures. The next commit will provide the bindings there. For now it's enough to understand that one of those two will trigger the shadergen subsystem, when rendering a material, to check it's associated list of features and spit out a shader if one is not already defined, or reference a pre-existing one that includes codelines determined by that list of features. Relevant execution of this is as follows: DeclareFeatureType( MFT_DeferredDiffuseMap ); - Name ImplementFeatureType( MFT_DeferredDiffuseMap, MFG_Texture, 2.0f, false ); - Codeline Insertion Order FEATUREMGR->registerFeature( MFT_DeferredDiffuseMap, new DeferredDiffuseMapHLSL ); - Hook to class which actually generates code alternately FEATUREMGR->registerFeature( MFT_Imposter, new NamedFeatureHLSL( "Imposter" ) ); - a simple feature that serves no purpose further than as a test of it's existence (to modify other features for instance) class DeferredDiffuseMapHLSL : public ShaderFeatureHLSL - Class definition { getName -embeded in the proceedural shader as a remline both up top and before actual code insertions processPix - pixel shader codeline insertions getOutputTargets - used to determine which buffer is written to (assumes only one. depending on branched logic, older features that may be run for either forward or deferred rendering depending on circumstance may have a logical switch based on additional feature flags. as an example: TerrainBaseMapFeatHLSL::getOutputTargets) getResources - associated with the Resources struct, closely aligned with the hardware regestry getBlendOp - used to determine what blend operation to use if a material requires a second pass (defaults to overwriting) setTexData - ??? processVert - vertex shader codeline insertions }; _B)_ The resultant Gbuffer layout defined by the previous commit therefore is as follows: defaultrendertarget (referred to in shaders as out.col or col depending on GFX plugin) contains either lighting and normal data, or color data depending on if it is used in a deferred or forward lit manner (note for forward lit, this data is replaced as a second step with color. why custommaterials have traditionally had problems with lighting) color1 (referred to in shaders as out.col1 or col1 depending on GFX plugin) RGB color data and an A for blending operations (including transparency) color2 (referred to in shaders as out.col2 or col2 depending on GFX plugin) contains: red channel comprising material flags such as metalness, emissive, ect, green channel for translucency (light shining through, as oposed to see-through transparency), blue for blue for specular strength (how much light influences net color) alpha for specular power (generally how reflective/glossy an object is) long term purpose: further down the line, these will be used to condition data for use with a PBR subsystem, with further corrections to the underlying mathematics, strength being replaced by roughness, and power by metalness
2016-02-16 08:23:23 +00:00
2020-09-30 18:51:12 +00:00
Var *roughness = new Var("roughness", "float");
roughness->uniform = true;
roughness->constSortPos = cspPotentialPrimitive;
engine: defines and alters a series of material features for deferred shading in order to define a fully fleshed out multiple render target gbuffer patterned after the general principles outlined http://www.catalinzima.com/xna/tutorials/deferred-rendering-in-xna/creating-the-g-buffer/ (though I cannot stress enough *not* using the identical layout) script: removes dead material features (ie: those that never functioned to begin with) shader: bool getFlag(float flags, int num) definition for retreiving data from the 3rd (matinfo) gbuffer slot's red channel (more on that shortly) purpose: _A)_ Small primer on how material features function: When a https://github.com/GarageGames/Torque3D/search?utf8=%E2%9C%93&q=_determineFeatures call is executed, certain conditions trigger a given .addFeature(MFT_SOMEFEATURE) call based upon material definition entries, be it a value, a texture reference, or even the presence or lack thereof for another feature. In general terms, the first to be executed is ProcessedShaderMaterial::_determineFeatures followed by ProcessedPrePassMaterial::_determineFeatures. The next commit will provide the bindings there. For now it's enough to understand that one of those two will trigger the shadergen subsystem, when rendering a material, to check it's associated list of features and spit out a shader if one is not already defined, or reference a pre-existing one that includes codelines determined by that list of features. Relevant execution of this is as follows: DeclareFeatureType( MFT_DeferredDiffuseMap ); - Name ImplementFeatureType( MFT_DeferredDiffuseMap, MFG_Texture, 2.0f, false ); - Codeline Insertion Order FEATUREMGR->registerFeature( MFT_DeferredDiffuseMap, new DeferredDiffuseMapHLSL ); - Hook to class which actually generates code alternately FEATUREMGR->registerFeature( MFT_Imposter, new NamedFeatureHLSL( "Imposter" ) ); - a simple feature that serves no purpose further than as a test of it's existence (to modify other features for instance) class DeferredDiffuseMapHLSL : public ShaderFeatureHLSL - Class definition { getName -embeded in the proceedural shader as a remline both up top and before actual code insertions processPix - pixel shader codeline insertions getOutputTargets - used to determine which buffer is written to (assumes only one. depending on branched logic, older features that may be run for either forward or deferred rendering depending on circumstance may have a logical switch based on additional feature flags. as an example: TerrainBaseMapFeatHLSL::getOutputTargets) getResources - associated with the Resources struct, closely aligned with the hardware regestry getBlendOp - used to determine what blend operation to use if a material requires a second pass (defaults to overwriting) setTexData - ??? processVert - vertex shader codeline insertions }; _B)_ The resultant Gbuffer layout defined by the previous commit therefore is as follows: defaultrendertarget (referred to in shaders as out.col or col depending on GFX plugin) contains either lighting and normal data, or color data depending on if it is used in a deferred or forward lit manner (note for forward lit, this data is replaced as a second step with color. why custommaterials have traditionally had problems with lighting) color1 (referred to in shaders as out.col1 or col1 depending on GFX plugin) RGB color data and an A for blending operations (including transparency) color2 (referred to in shaders as out.col2 or col2 depending on GFX plugin) contains: red channel comprising material flags such as metalness, emissive, ect, green channel for translucency (light shining through, as oposed to see-through transparency), blue for blue for specular strength (how much light influences net color) alpha for specular power (generally how reflective/glossy an object is) long term purpose: further down the line, these will be used to condition data for use with a PBR subsystem, with further corrections to the underlying mathematics, strength being replaced by roughness, and power by metalness
2016-02-16 08:23:23 +00:00
//matinfo.g slot reserved for AO later
2020-09-30 18:51:12 +00:00
meta->addStatement(new GenOp(" @.g = 1.0;\r\n", ormConfig));
meta->addStatement(new GenOp(" @.b = @;\r\n", ormConfig, roughness));
if (fd.features[MFT_InvertRoughness])
meta->addStatement(new GenOp(" @ = 1.0-@;\r\n", roughness, roughness));
meta->addStatement(new GenOp(" @.a = @;\r\n", ormConfig, metalness));
engine: defines and alters a series of material features for deferred shading in order to define a fully fleshed out multiple render target gbuffer patterned after the general principles outlined http://www.catalinzima.com/xna/tutorials/deferred-rendering-in-xna/creating-the-g-buffer/ (though I cannot stress enough *not* using the identical layout) script: removes dead material features (ie: those that never functioned to begin with) shader: bool getFlag(float flags, int num) definition for retreiving data from the 3rd (matinfo) gbuffer slot's red channel (more on that shortly) purpose: _A)_ Small primer on how material features function: When a https://github.com/GarageGames/Torque3D/search?utf8=%E2%9C%93&q=_determineFeatures call is executed, certain conditions trigger a given .addFeature(MFT_SOMEFEATURE) call based upon material definition entries, be it a value, a texture reference, or even the presence or lack thereof for another feature. In general terms, the first to be executed is ProcessedShaderMaterial::_determineFeatures followed by ProcessedPrePassMaterial::_determineFeatures. The next commit will provide the bindings there. For now it's enough to understand that one of those two will trigger the shadergen subsystem, when rendering a material, to check it's associated list of features and spit out a shader if one is not already defined, or reference a pre-existing one that includes codelines determined by that list of features. Relevant execution of this is as follows: DeclareFeatureType( MFT_DeferredDiffuseMap ); - Name ImplementFeatureType( MFT_DeferredDiffuseMap, MFG_Texture, 2.0f, false ); - Codeline Insertion Order FEATUREMGR->registerFeature( MFT_DeferredDiffuseMap, new DeferredDiffuseMapHLSL ); - Hook to class which actually generates code alternately FEATUREMGR->registerFeature( MFT_Imposter, new NamedFeatureHLSL( "Imposter" ) ); - a simple feature that serves no purpose further than as a test of it's existence (to modify other features for instance) class DeferredDiffuseMapHLSL : public ShaderFeatureHLSL - Class definition { getName -embeded in the proceedural shader as a remline both up top and before actual code insertions processPix - pixel shader codeline insertions getOutputTargets - used to determine which buffer is written to (assumes only one. depending on branched logic, older features that may be run for either forward or deferred rendering depending on circumstance may have a logical switch based on additional feature flags. as an example: TerrainBaseMapFeatHLSL::getOutputTargets) getResources - associated with the Resources struct, closely aligned with the hardware regestry getBlendOp - used to determine what blend operation to use if a material requires a second pass (defaults to overwriting) setTexData - ??? processVert - vertex shader codeline insertions }; _B)_ The resultant Gbuffer layout defined by the previous commit therefore is as follows: defaultrendertarget (referred to in shaders as out.col or col depending on GFX plugin) contains either lighting and normal data, or color data depending on if it is used in a deferred or forward lit manner (note for forward lit, this data is replaced as a second step with color. why custommaterials have traditionally had problems with lighting) color1 (referred to in shaders as out.col1 or col1 depending on GFX plugin) RGB color data and an A for blending operations (including transparency) color2 (referred to in shaders as out.col2 or col2 depending on GFX plugin) contains: red channel comprising material flags such as metalness, emissive, ect, green channel for translucency (light shining through, as oposed to see-through transparency), blue for blue for specular strength (how much light influences net color) alpha for specular power (generally how reflective/glossy an object is) long term purpose: further down the line, these will be used to condition data for use with a PBR subsystem, with further corrections to the underlying mathematics, strength being replaced by roughness, and power by metalness
2016-02-16 08:23:23 +00:00
output = meta;
}
2018-11-21 05:53:02 +00:00
U32 GlowMapHLSL::getOutputTargets(const MaterialFeatureData& fd) const
{
return fd.features[MFT_isDeferred] ? ShaderFeature::RenderTarget3 : ShaderFeature::DefaultTarget;
}
2018-11-21 05:53:02 +00:00
//deferred emissive
void GlowMapHLSL::processPix(Vector<ShaderComponent*> &componentList, const MaterialFeatureData &fd)
2018-11-21 05:53:02 +00:00
{
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])
2018-11-21 05:53:02 +00:00
{
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);
}
2018-11-21 05:53:02 +00:00
}
else
{
output = new GenOp("@ += float4(@.rgb*@,@.a);", targ, texOp, glowMul, targ);
}
}
ShaderFeature::Resources GlowMapHLSL::getResources(const MaterialFeatureData& fd)
{
Resources res;
res.numTex = 1;
res.numTexReg = 1;
2018-11-21 05:53:02 +00:00
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;
}
}