mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-04-24 05:45:40 +00:00
cleaned up variant of https://github.com/GarageGames/Torque3D/pull/768 alterations: opengl support, in-shader bug-reporting, direction vector fit to material slider-bar.
This commit is contained in:
parent
949251b988
commit
c6cdfafe4e
42 changed files with 2680 additions and 8 deletions
238
Engine/source/shaderGen/HLSL/accuFeatureHLSL.cpp
Normal file
238
Engine/source/shaderGen/HLSL/accuFeatureHLSL.cpp
Normal file
|
|
@ -0,0 +1,238 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) 2012 GarageGames, LLC
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to
|
||||
// deal in the Software without restriction, including without limitation the
|
||||
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
// sell copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
// IN THE SOFTWARE.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#include "shaderGen/HLSL/accuFeatureHLSL.h"
|
||||
#include "shaderGen/shaderFeature.h"
|
||||
#include "shaderGen/shaderOp.h"
|
||||
#include "shaderGen/featureMgr.h"
|
||||
#include "materials/materialFeatureTypes.h"
|
||||
#include "gfx/gfxDevice.h"
|
||||
#include "materials/processedMaterial.h"
|
||||
|
||||
//****************************************************************************
|
||||
// Accu Texture
|
||||
//****************************************************************************
|
||||
void AccuTexFeatHLSL::processVert( Vector<ShaderComponent*> &componentList,
|
||||
const MaterialFeatureData &fd )
|
||||
{
|
||||
MultiLine *meta = new MultiLine;
|
||||
getOutTexCoord( "texCoord",
|
||||
"float2",
|
||||
true,
|
||||
false,
|
||||
meta,
|
||||
componentList );
|
||||
|
||||
getOutObjToTangentSpace( componentList, meta, fd );
|
||||
addOutAccuVec( componentList, meta );
|
||||
|
||||
output = meta;
|
||||
}
|
||||
|
||||
void AccuTexFeatHLSL::processPix( Vector<ShaderComponent*> &componentList,
|
||||
const MaterialFeatureData &fd )
|
||||
{
|
||||
MultiLine *meta = new MultiLine;
|
||||
|
||||
output = meta;
|
||||
|
||||
// OUT.col
|
||||
Var *color = (Var*) LangElement::find( "col" );
|
||||
if (!color)
|
||||
{
|
||||
output = new GenOp(" //NULL COLOR!");
|
||||
return;
|
||||
}
|
||||
|
||||
// accu map
|
||||
Var *accuMap = new Var;
|
||||
accuMap->setType( "sampler2D" );
|
||||
accuMap->setName( "accuMap" );
|
||||
accuMap->uniform = true;
|
||||
accuMap->sampler = true;
|
||||
accuMap->constNum = Var::getTexUnitNum(); // used as texture unit num here
|
||||
|
||||
// accuColor var
|
||||
Var *accuColor = new Var;
|
||||
accuColor->setType( "float4" );
|
||||
accuColor->setName( "accuColor" );
|
||||
LangElement *colorAccuDecl = new DecOp( accuColor );
|
||||
|
||||
// plc (placement)
|
||||
Var *accuPlc = new Var;
|
||||
accuPlc->setType( "float4" );
|
||||
accuPlc->setName( "plc" );
|
||||
LangElement *plcAccu = new DecOp( accuPlc );
|
||||
|
||||
// accu constants
|
||||
Var *accuScale = (Var*)LangElement::find( "accuScale" );
|
||||
if ( !accuScale ) {
|
||||
accuScale = new Var;
|
||||
accuScale->setType( "float" );
|
||||
accuScale->setName( "accuScale" );
|
||||
accuScale->uniform = true;
|
||||
accuScale->sampler = false;
|
||||
accuScale->constSortPos = cspPotentialPrimitive;
|
||||
}
|
||||
Var *accuDirection = (Var*)LangElement::find( "accuDirection" );
|
||||
if ( !accuDirection ) {
|
||||
accuDirection = new Var;
|
||||
accuDirection->setType( "float" );
|
||||
accuDirection->setName( "accuDirection" );
|
||||
accuDirection->uniform = true;
|
||||
accuDirection->sampler = false;
|
||||
accuDirection->constSortPos = cspPotentialPrimitive;
|
||||
}
|
||||
Var *accuStrength = (Var*)LangElement::find( "accuStrength" );
|
||||
if ( !accuStrength ) {
|
||||
accuStrength = new Var;
|
||||
accuStrength->setType( "float" );
|
||||
accuStrength->setName( "accuStrength" );
|
||||
accuStrength->uniform = true;
|
||||
accuStrength->sampler = false;
|
||||
accuStrength->constSortPos = cspPotentialPrimitive;
|
||||
}
|
||||
Var *accuCoverage = (Var*)LangElement::find( "accuCoverage" );
|
||||
if ( !accuCoverage ) {
|
||||
accuCoverage = new Var;
|
||||
accuCoverage->setType( "float" );
|
||||
accuCoverage->setName( "accuCoverage" );
|
||||
accuCoverage->uniform = true;
|
||||
accuCoverage->sampler = false;
|
||||
accuCoverage->constSortPos = cspPotentialPrimitive;
|
||||
}
|
||||
Var *accuSpecular = (Var*)LangElement::find( "accuSpecular" );
|
||||
if ( !accuSpecular ) {
|
||||
accuSpecular = new Var;
|
||||
accuSpecular->setType( "float" );
|
||||
accuSpecular->setName( "accuSpecular" );
|
||||
accuSpecular->uniform = true;
|
||||
accuSpecular->sampler = false;
|
||||
accuSpecular->constSortPos = cspPotentialPrimitive;
|
||||
}
|
||||
|
||||
Var *inTex = getInTexCoord( "texCoord", "float2", true, componentList );
|
||||
Var *accuVec = getInTexCoord( "accuVec", "float3", true, componentList );
|
||||
Var *bumpNorm = (Var *)LangElement::find( "bumpSample" );
|
||||
if( bumpNorm == NULL ) {
|
||||
bumpNorm = (Var *)LangElement::find( "bumpNormal" );
|
||||
if (!bumpNorm)
|
||||
return;
|
||||
}
|
||||
|
||||
// get the accu pixel color
|
||||
meta->addStatement( new GenOp( " @ = tex2D(@, @ * @);\r\n", colorAccuDecl, accuMap, inTex, accuScale ) );
|
||||
|
||||
// scale up normals
|
||||
meta->addStatement( new GenOp( " @.xyz = @.xyz * 2.0 - 0.5;\r\n", bumpNorm, bumpNorm ) );
|
||||
|
||||
// assign direction
|
||||
meta->addStatement( new GenOp( " @.z *= @*2.0;\r\n", accuVec, accuDirection ) );
|
||||
|
||||
// saturate based on strength
|
||||
meta->addStatement( new GenOp( " @ = saturate( dot( @, @.xyz * pow(@, 5) ) );\r\n", plcAccu, bumpNorm, accuVec, accuStrength ) );
|
||||
|
||||
// add coverage
|
||||
meta->addStatement( new GenOp( " @.a += (2 * pow(@/2, 5)) - 0.5;\r\n", accuPlc, accuCoverage ) );
|
||||
|
||||
// clamp to a sensible value
|
||||
meta->addStatement( new GenOp( " @.a = clamp(@.a, 0, 1);\r\n", accuPlc, accuPlc ) );
|
||||
|
||||
// light
|
||||
Var *lightColor = (Var*) LangElement::find( "d_lightcolor" );
|
||||
if(lightColor != NULL)
|
||||
meta->addStatement( new GenOp( " @ *= float4(@, 1.0);\r\n\r\n", accuColor, lightColor ) );
|
||||
|
||||
// lerp with current pixel - use the accu alpha as well
|
||||
meta->addStatement( new GenOp( " @ = lerp( @, @, @.a * @.a);\r\n", color, color, accuColor, accuPlc, accuColor ) );
|
||||
|
||||
// the result should always be opaque
|
||||
meta->addStatement( new GenOp( " @.a = 1.0;\r\n", color ) );
|
||||
|
||||
}
|
||||
|
||||
void AccuTexFeatHLSL::setTexData( Material::StageData &stageDat,
|
||||
const MaterialFeatureData &fd,
|
||||
RenderPassData &passData,
|
||||
U32 &texIndex )
|
||||
{
|
||||
//GFXTextureObject *tex = stageDat.getTex( MFT_AccuMap );
|
||||
//if ( tex )
|
||||
//{
|
||||
passData.mSamplerNames[ texIndex ] = "AccuMap";
|
||||
passData.mTexType[ texIndex++ ] = Material::AccuMap;
|
||||
//}
|
||||
}
|
||||
|
||||
|
||||
void AccuTexFeatHLSL::getAccuVec( MultiLine *meta, LangElement *accuVec )
|
||||
{
|
||||
// Get the transform to world space.
|
||||
Var *objTrans = (Var*)LangElement::find( "objTrans" );
|
||||
if ( !objTrans )
|
||||
{
|
||||
objTrans = new Var;
|
||||
objTrans->setType( "float4x4" );
|
||||
objTrans->setName( "objTrans" );
|
||||
objTrans->uniform = true;
|
||||
objTrans->constSortPos = cspPrimitive;
|
||||
}
|
||||
|
||||
// accu obj trans
|
||||
Var *aobjTrans = new Var;
|
||||
aobjTrans->setType( "float4x4" );
|
||||
aobjTrans->setName( "accuObjTrans" );
|
||||
LangElement *accuObjTransDecl = new DecOp( aobjTrans );
|
||||
|
||||
Var *outObjToTangentSpace = (Var*)LangElement::find( "objToTangentSpace" );
|
||||
|
||||
Var *tav = new Var;
|
||||
tav->setType( "float4" );
|
||||
tav->setName( "tAccuVec" );
|
||||
LangElement *tavDecl = new DecOp( tav );
|
||||
|
||||
meta->addStatement( new GenOp( " @ = float4(0,0,1,0);\r\n", tavDecl ) );
|
||||
meta->addStatement( new GenOp( " @ = transpose(@);\r\n", accuObjTransDecl, objTrans ) );
|
||||
meta->addStatement( new GenOp( " @ = mul(@, @);\r\n", tav, aobjTrans, tav ) );
|
||||
meta->addStatement( new GenOp( " @.xyz = mul(@, @.xyz);\r\n", tav, outObjToTangentSpace, tav ) );
|
||||
meta->addStatement( new GenOp( " @.y *= -1;\r\n", tav ) );
|
||||
meta->addStatement( new GenOp( " @ = @.xyz;\r\n", accuVec, tav ) );
|
||||
}
|
||||
|
||||
Var* AccuTexFeatHLSL::addOutAccuVec( Vector<ShaderComponent*> &componentList, MultiLine *meta )
|
||||
{
|
||||
Var *outAccuVec = (Var*)LangElement::find( "accuVec" );
|
||||
if ( !outAccuVec )
|
||||
{
|
||||
// Setup the connector.
|
||||
ShaderConnector *connectComp = dynamic_cast<ShaderConnector *>( componentList[C_CONNECTOR] );
|
||||
outAccuVec = connectComp->getElement( RT_TEXCOORD );
|
||||
outAccuVec->setName( "accuVec" );
|
||||
outAccuVec->setStructName( "OUT" );
|
||||
outAccuVec->setType( "float3" );
|
||||
outAccuVec->mapsToSampler = false;
|
||||
|
||||
getAccuVec( meta, outAccuVec );
|
||||
}
|
||||
|
||||
return outAccuVec;
|
||||
}
|
||||
185
Engine/source/shaderGen/HLSL/accuFeatureHLSL.h
Normal file
185
Engine/source/shaderGen/HLSL/accuFeatureHLSL.h
Normal file
|
|
@ -0,0 +1,185 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) 2012 GarageGames, LLC
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to
|
||||
// deal in the Software without restriction, including without limitation the
|
||||
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
// sell copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
// IN THE SOFTWARE.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#ifndef _ACCUFEATUREHLSL_H_
|
||||
#define _ACCUFEATUREHLSL_H_
|
||||
|
||||
#ifndef _SHADERGEN_HLSL_SHADERFEATUREHLSL_H_
|
||||
#include "shaderGen/HLSL/shaderFeatureHLSL.h"
|
||||
#endif
|
||||
#ifndef _LANG_ELEMENT_H_
|
||||
#include "shaderGen/langElement.h"
|
||||
#endif
|
||||
#ifndef _GFXDEVICE_H_
|
||||
#include "gfx/gfxDevice.h"
|
||||
#endif
|
||||
#ifndef _FEATUREMGR_H_
|
||||
#include "shaderGen/featureMgr.h"
|
||||
#endif
|
||||
#ifndef _MATERIALFEATURETYPES_H_
|
||||
#include "materials/materialFeatureTypes.h"
|
||||
#endif
|
||||
#ifndef _MATERIALFEATUREDATA_H_
|
||||
#include "materials/materialFeatureData.h"
|
||||
#endif
|
||||
|
||||
/// Accu texture
|
||||
class AccuTexFeatHLSL : public ShaderFeatureHLSL
|
||||
{
|
||||
public:
|
||||
|
||||
//****************************************************************************
|
||||
// Accu Texture
|
||||
//****************************************************************************
|
||||
virtual void processVert( Vector<ShaderComponent*> &componentList,
|
||||
const MaterialFeatureData &fd );
|
||||
|
||||
virtual void processPix( Vector<ShaderComponent*> &componentList,
|
||||
const MaterialFeatureData &fd );
|
||||
|
||||
void getAccuVec( MultiLine *meta, LangElement *accuVec );
|
||||
|
||||
Var* addOutAccuVec( Vector<ShaderComponent*> &componentList, MultiLine *meta );
|
||||
|
||||
virtual Material::BlendOp getBlendOp(){ return Material::LerpAlpha; }
|
||||
|
||||
virtual Resources getResources( const MaterialFeatureData &fd )
|
||||
{
|
||||
Resources res;
|
||||
res.numTex = 1;
|
||||
res.numTexReg = 1;
|
||||
return res;
|
||||
}
|
||||
|
||||
virtual void setTexData( Material::StageData &stageDat,
|
||||
const MaterialFeatureData &fd,
|
||||
RenderPassData &passData,
|
||||
U32 &texIndex );
|
||||
|
||||
virtual String getName()
|
||||
{
|
||||
return "Accu Texture";
|
||||
}
|
||||
};
|
||||
|
||||
class AccuScaleFeature : public ShaderFeatureHLSL
|
||||
{
|
||||
public:
|
||||
virtual void processPix( Vector<ShaderComponent*> &componentList, const MaterialFeatureData &fd )
|
||||
{
|
||||
// Find the constant value
|
||||
Var *accuScale = (Var *)( LangElement::find("accuScale") );
|
||||
if( accuScale == NULL )
|
||||
{
|
||||
accuScale = new Var;
|
||||
accuScale->setType( "float" );
|
||||
accuScale->setName( "accuScale" );
|
||||
accuScale->constSortPos = cspPotentialPrimitive;
|
||||
accuScale->uniform = true;
|
||||
}
|
||||
}
|
||||
|
||||
virtual String getName() { return "Accu Scale"; }
|
||||
};
|
||||
|
||||
class AccuDirectionFeature : public ShaderFeatureHLSL
|
||||
{
|
||||
public:
|
||||
virtual void processPix( Vector<ShaderComponent*> &componentList, const MaterialFeatureData &fd )
|
||||
{
|
||||
// Find the constant value
|
||||
Var *accuDirection = (Var *)( LangElement::find("accuDirection") );
|
||||
if( accuDirection == NULL )
|
||||
{
|
||||
accuDirection = new Var;
|
||||
accuDirection->setType( "float" );
|
||||
accuDirection->setName( "accuDirection" );
|
||||
accuDirection->constSortPos = cspPotentialPrimitive;
|
||||
accuDirection->uniform = true;
|
||||
}
|
||||
}
|
||||
|
||||
virtual String getName() { return "Accu Direction"; }
|
||||
};
|
||||
|
||||
class AccuStrengthFeature : public ShaderFeatureHLSL
|
||||
{
|
||||
public:
|
||||
virtual void processPix( Vector<ShaderComponent*> &componentList, const MaterialFeatureData &fd )
|
||||
{
|
||||
// Find the constant value
|
||||
Var *accuStrength = (Var *)( LangElement::find("accuStrength") );
|
||||
if( accuStrength == NULL )
|
||||
{
|
||||
accuStrength = new Var;
|
||||
accuStrength->setType( "float" );
|
||||
accuStrength->setName( "accuStrength" );
|
||||
accuStrength->constSortPos = cspPotentialPrimitive;
|
||||
accuStrength->uniform = true;
|
||||
}
|
||||
}
|
||||
|
||||
virtual String getName() { return "Accu Strength"; }
|
||||
};
|
||||
|
||||
class AccuCoverageFeature : public ShaderFeatureHLSL
|
||||
{
|
||||
public:
|
||||
virtual void processPix( Vector<ShaderComponent*> &componentList, const MaterialFeatureData &fd )
|
||||
{
|
||||
// Find the constant value
|
||||
Var *accuCoverage = (Var *)( LangElement::find("accuCoverage") );
|
||||
if( accuCoverage == NULL )
|
||||
{
|
||||
accuCoverage = new Var;
|
||||
accuCoverage->setType( "float" );
|
||||
accuCoverage->setName( "accuCoverage" );
|
||||
accuCoverage->constSortPos = cspPotentialPrimitive;
|
||||
accuCoverage->uniform = true;
|
||||
}
|
||||
}
|
||||
|
||||
virtual String getName() { return "Accu Coverage"; }
|
||||
};
|
||||
|
||||
|
||||
class AccuSpecularFeature : public ShaderFeatureHLSL
|
||||
{
|
||||
public:
|
||||
virtual void processPix( Vector<ShaderComponent*> &componentList, const MaterialFeatureData &fd )
|
||||
{
|
||||
// Find the constant value
|
||||
Var *accuSpecular = (Var *)( LangElement::find("accuSpecular") );
|
||||
if( accuSpecular == NULL )
|
||||
{
|
||||
accuSpecular = new Var;
|
||||
accuSpecular->setType( "float" );
|
||||
accuSpecular->setName( "accuSpecular" );
|
||||
accuSpecular->constSortPos = cspPotentialPrimitive;
|
||||
accuSpecular->uniform = true;
|
||||
}
|
||||
}
|
||||
|
||||
virtual String getName() { return "Accu Specular"; }
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
@ -32,7 +32,7 @@
|
|||
#include "shaderGen/HLSL/paraboloidHLSL.h"
|
||||
#include "materials/materialFeatureTypes.h"
|
||||
#include "core/module.h"
|
||||
|
||||
#include "shaderGen/HLSL/accuFeatureHLSL.h"
|
||||
|
||||
static ShaderGen::ShaderGenInitDelegate sInitDelegate;
|
||||
|
||||
|
|
@ -66,6 +66,7 @@ void _initShaderGenHLSL( ShaderGen *shaderGen )
|
|||
FEATUREMGR->registerFeature( MFT_Visibility, new VisibilityFeatHLSL );
|
||||
FEATUREMGR->registerFeature( MFT_Fog, new FogFeatHLSL );
|
||||
FEATUREMGR->registerFeature( MFT_SpecularMap, new SpecularMapHLSL );
|
||||
FEATUREMGR->registerFeature( MFT_AccuMap, new AccuTexFeatHLSL );
|
||||
FEATUREMGR->registerFeature( MFT_GlossMap, new NamedFeatureHLSL( "Gloss Map" ) );
|
||||
FEATUREMGR->registerFeature( MFT_LightbufferMRT, new NamedFeatureHLSL( "Lightbuffer MRT" ) );
|
||||
FEATUREMGR->registerFeature( MFT_RenderTarget1_Zero, new RenderTargetZeroHLSL( ShaderFeature::RenderTarget1 ) );
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue