本文整理汇总了C++中ShaderConnector类的典型用法代码示例。如果您正苦于以下问题:C++ ShaderConnector类的具体用法?C++ ShaderConnector怎么用?C++ ShaderConnector使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ShaderConnector类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: processPix
void ParaboloidVertTransformHLSL::processPix( Vector<ShaderComponent*> &componentList,
const MaterialFeatureData &fd )
{
ShaderConnector *connectComp = dynamic_cast<ShaderConnector *>( componentList[C_CONNECTOR] );
MultiLine *meta = new MultiLine;
const bool isSinglePass = fd.features[ MFT_IsSinglePassParaboloid ];
if ( isSinglePass )
{
// Cull things on the back side of the map.
Var *isBack = connectComp->getElement( RT_TEXCOORD );
isBack->setName( "isBack" );
isBack->setStructName( "IN" );
isBack->setType( "float" );
meta->addStatement( new GenOp( " clip( abs( @ ) - 0.999 );\r\n", isBack ) );
}
// Cull pixels outside of the valid paraboloid.
Var *posXY = connectComp->getElement( RT_TEXCOORD );
posXY->setName( "posXY" );
posXY->setStructName( "IN" );
posXY->setType( "float2" );
meta->addStatement( new GenOp( " clip( 1.0 - abs(@.x) );\r\n", posXY ) );
output = meta;
}
示例2: processVert
void NormalsOutFeatGLSL::processVert( Vector<ShaderComponent*> &componentList,
const MaterialFeatureData &fd )
{
// If we have normal maps then we can count
// on it to generate the world space normal.
if ( fd.features[MFT_NormalMap] )
return;
MultiLine *meta = new MultiLine;
output = meta;
ShaderConnector *connectComp = dynamic_cast<ShaderConnector *>( componentList[C_CONNECTOR] );
Var *outNormal = connectComp->getElement( RT_TEXCOORD );
outNormal->setName( "wsNormal" );
outNormal->setStructName( "OUT" );
outNormal->setType( "vec3" );
outNormal->mapsToSampler = false;
// Find the incoming vertex normal.
Var *inNormal = (Var*)LangElement::find( "normal" );
if ( inNormal )
{
// Transform the normal to world space.
Var *objTrans = getObjTrans( componentList, fd.features[MFT_UseInstancing], meta );
meta->addStatement( new GenOp( " @ = tMul( @, normalize( vec4(@, 0.0) ) ).xyz;\r\n", outNormal, objTrans, inNormal ) );
}
else
{
// If we don't have a vertex normal... just pass the
// camera facing normal to the pixel shader.
meta->addStatement( new GenOp( " @ = float3( 0.0, 0.0, 1.0 );\r\n", outNormal ) );
}
}
示例3: AssertFatal
void GBufferConditionerGLSL::processVert( Vector<ShaderComponent*> &componentList,
const MaterialFeatureData &fd )
{
output = NULL;
if( !fd.features[MFT_NormalMap] )
{
// grab incoming vert normal
Var *inNormal = (Var*) LangElement::find( "normal" );
AssertFatal( inNormal, "Something went bad with ShaderGen. The normal should be already defined." );
// grab output for gbuffer normal
ShaderConnector *connectComp = dynamic_cast<ShaderConnector *>( componentList[C_CONNECTOR] );
Var *outNormal = connectComp->getElement( RT_TEXCOORD );
outNormal->setName( "gbNormal" );
outNormal->setType( "vec3" );
// create objToWorld variable
Var *objToWorld = (Var*) LangElement::find( "objTrans" );
if( !objToWorld )
{
objToWorld = new Var;
objToWorld->setType( "mat4" );
objToWorld->setName( "objTrans" );
objToWorld->uniform = true;
objToWorld->constSortPos = cspPrimitive;
}
// Kick out the world-space normal
LangElement *statement = new GenOp( " @ = vec3(@ * vec4(normalize(@), 0.0));\r\n", outNormal, objToWorld, inNormal );
output = statement;
}
}
示例4: processVert
void EyeSpaceDepthOutHLSL::processVert( Vector<ShaderComponent*> &componentList,
const MaterialFeatureData &fd )
{
MultiLine *meta = new MultiLine;
output = meta;
// grab output
ShaderConnector *connectComp = dynamic_cast<ShaderConnector *>( componentList[C_CONNECTOR] );
Var *outWSEyeVec = connectComp->getElement( RT_TEXCOORD );
outWSEyeVec->setName( "wsEyeVec" );
outWSEyeVec->setStructName( "OUT" );
// grab incoming vert position
Var *wsPosition = new Var( "depthPos", "float3" );
getWsPosition( componentList, fd.features[MFT_UseInstancing], meta, new DecOp( wsPosition ) );
Var *eyePos = (Var*)LangElement::find( "eyePosWorld" );
if( !eyePos )
{
eyePos = new Var;
eyePos->setType("float3");
eyePos->setName("eyePosWorld");
eyePos->uniform = true;
eyePos->constSortPos = cspPass;
}
meta->addStatement( new GenOp( " @ = float4( @.xyz - @, 1 );\r\n", outWSEyeVec, wsPosition, eyePos ) );
}
示例5: processPix
void TerrainParallaxMapFeatGLSL::processPix( Vector<ShaderComponent*> &componentList,
const MaterialFeatureData &fd )
{
MultiLine *meta = new MultiLine;
ShaderConnector *connectComp = dynamic_cast<ShaderConnector *>( componentList[C_CONNECTOR] );
// We need the negative tangent space view vector
// as in parallax mapping we step towards the camera.
Var *negViewTS = (Var*)LangElement::find( "negViewTS" );
if ( !negViewTS )
{
Var *inNegViewTS = (Var*)LangElement::find( "outNegViewTS" );
if ( !inNegViewTS )
{
inNegViewTS = connectComp->getElement( RT_TEXCOORD );
inNegViewTS->setName( "outNegViewTS" );
inNegViewTS->setType( "vec3" );
}
negViewTS = new Var( "negViewTS", "vec3" );
meta->addStatement( new GenOp( " @ = normalize( @ );\r\n", new DecOp( negViewTS ), inNegViewTS ) );
}
// Get the rest of our inputs.
Var *detailInfo = _getDetailIdStrengthParallax();
Var *normalMap = _getNormalMapTex();
Var *texCoord = _getInDetailCoord( componentList );
// Call the library function to do the rest.
meta->addStatement( new GenOp( " @.xy += parallaxOffset( @, @.xy, @, @.z );\r\n",
texCoord, normalMap, texCoord, negViewTS, detailInfo ) );
output = meta;
}
示例6: _getUniformVar
void TerrainParallaxMapFeatGLSL::processVert( Vector<ShaderComponent*> &componentList,
const MaterialFeatureData &fd )
{
if ( LangElement::find( "outNegViewTS" ) )
return;
MultiLine *meta = new MultiLine;
// Grab the input position.
Var *inPos = (Var*)LangElement::find( "inPosition" );
if ( !inPos )
inPos = (Var*)LangElement::find( "position" );
// Get the object space eye position and the
// object to tangent transform.
Var *eyePos = _getUniformVar( "eyePos", "vec3" , cspPotentialPrimitive );
Var *objToTangentSpace = getOutObjToTangentSpace( componentList, meta,fd );
// Now send the negative view vector in tangent space to the pixel shader.
ShaderConnector *connectComp = dynamic_cast<ShaderConnector *>( componentList[C_CONNECTOR] );
Var *outNegViewTS = connectComp->getElement( RT_TEXCOORD );
outNegViewTS->setName( "outNegViewTS" );
outNegViewTS->setType( "vec3" );
meta->addStatement( new GenOp( " @ = @ * vec3( @ - @.xyz );\r\n",
outNegViewTS, objToTangentSpace, eyePos, inPos ) );
output = meta;
}
示例7: AssertFatal
void ParallaxFeatHLSL::processPix( Vector<ShaderComponent*> &componentList,
const MaterialFeatureData &fd )
{
AssertFatal( GFX->getPixelShaderVersion() >= 2.0,
"ParallaxFeatHLSL::processPix - We don't support SM 1.x!" );
MultiLine *meta = new MultiLine;
// Order matters... get this first!
Var *texCoord = getInTexCoord( "texCoord", "float2", true, componentList );
ShaderConnector *connectComp = dynamic_cast<ShaderConnector *>( componentList[C_CONNECTOR] );
// We need the negative tangent space view vector
// as in parallax mapping we step towards the camera.
Var *negViewTS = (Var*)LangElement::find( "negViewTS" );
if ( !negViewTS )
{
Var *inNegViewTS = (Var*)LangElement::find( "outNegViewTS" );
if ( !inNegViewTS )
{
inNegViewTS = connectComp->getElement( RT_TEXCOORD );
inNegViewTS->setName( "outNegViewTS" );
inNegViewTS->setStructName( "IN" );
inNegViewTS->setType( "float3" );
}
negViewTS = new Var( "negViewTS", "float3" );
meta->addStatement( new GenOp( " @ = normalize( @ );\r\n", new DecOp( negViewTS ), inNegViewTS ) );
}
// Get the rest of our inputs.
Var *parallaxInfo = _getUniformVar( "parallaxInfo", "float", cspPotentialPrimitive );
Var *normalMap = getNormalMapTex();
Var *bumpMapTexture = (Var*)LangElement::find("bumpMapTex");
// Call the library function to do the rest.
if (fd.features.hasFeature(MFT_IsDXTnm, getProcessIndex()))
{
if (mIsDirect3D11)
meta->addStatement(new GenOp(" @.xy += parallaxOffsetDxtnm( @, @, @.xy, @, @ );\r\n",
texCoord, bumpMapTexture, normalMap, texCoord, negViewTS, parallaxInfo));
else
meta->addStatement(new GenOp(" @.xy += parallaxOffsetDxtnm( @, @.xy, @, @ );\r\n",
texCoord, normalMap, texCoord, negViewTS, parallaxInfo));
}
else
{
if (mIsDirect3D11)
meta->addStatement(new GenOp(" @.xy += parallaxOffset( @, @, @.xy, @, @ );\r\n",
texCoord, bumpMapTexture, normalMap, texCoord, negViewTS, parallaxInfo));
else
meta->addStatement(new GenOp(" @.xy += parallaxOffset( @, @.xy, @, @ );\r\n",
texCoord, normalMap, texCoord, negViewTS, parallaxInfo));
}
// TODO: Fix second UV maybe?
output = meta;
}
示例8: processPix
void EyeSpaceDepthOutHLSL::processPix( Vector<ShaderComponent*> &componentList,
const MaterialFeatureData &fd )
{
MultiLine *meta = new MultiLine;
// grab connector position
ShaderConnector *connectComp = dynamic_cast<ShaderConnector *>( componentList[C_CONNECTOR] );
Var *wsEyeVec = connectComp->getElement( RT_TEXCOORD );
wsEyeVec->setName( "wsEyeVec" );
wsEyeVec->setStructName( "IN" );
wsEyeVec->setType( "float4" );
wsEyeVec->mapsToSampler = false;
wsEyeVec->uniform = false;
// get shader constants
Var *vEye = new Var;
vEye->setType("float3");
vEye->setName("vEye");
vEye->uniform = true;
vEye->constSortPos = cspPass;
// Expose the depth to the depth format feature
Var *depthOut = new Var;
depthOut->setType("float");
depthOut->setName(getOutputVarName());
LangElement *depthOutDecl = new DecOp( depthOut );
meta->addStatement( new GenOp( "#ifndef CUBE_SHADOW_MAP\r\n" ) );
if (fd.features.hasFeature(MFT_TerrainBaseMap))
meta->addStatement(new GenOp(" @ =min(0.9999, dot(@, (@.xyz / @.w)));\r\n", depthOutDecl, vEye, wsEyeVec, wsEyeVec));
else
meta->addStatement(new GenOp(" @ = dot(@, (@.xyz / @.w));\r\n", depthOutDecl, vEye, wsEyeVec, wsEyeVec));
meta->addStatement( new GenOp( "#else\r\n" ) );
Var *farDist = (Var*)Var::find( "oneOverFarplane" );
if ( !farDist )
{
farDist = new Var;
farDist->setType("float4");
farDist->setName("oneOverFarplane");
farDist->uniform = true;
farDist->constSortPos = cspPass;
}
meta->addStatement( new GenOp( " @ = length( @.xyz / @.w ) * @.x;\r\n", depthOutDecl, wsEyeVec, wsEyeVec, farDist ) );
meta->addStatement( new GenOp( "#endif\r\n" ) );
// If there isn't an output conditioner for the pre-pass, than just write
// out the depth to rgba and return.
if( !fd.features[MFT_PrePassConditioner] )
meta->addStatement( new GenOp( " @;\r\n", assignColor( new GenOp( "float4(@.rrr,1)", depthOut ), Material::None ) ) );
output = meta;
}
示例9: getProcessIndex
void TerrainMacroMapFeatHLSL::processVert( Vector<ShaderComponent*> &componentList,
const MaterialFeatureData &fd )
{
const S32 detailIndex = getProcessIndex();
// Grab incoming texture coords... the base map feature
// made sure this was created.
Var *inTex = (Var*)LangElement::find( "texCoord" );
AssertFatal( inTex, "The texture coord is missing!" );
// Grab the input position.
Var *inPos = (Var*)LangElement::find( "inPosition" );
if ( !inPos )
inPos = (Var*)LangElement::find( "position" );
// Get the object space eye position.
Var *eyePos = _getUniformVar( "eyePos", "float3", cspPotentialPrimitive );
MultiLine *meta = new MultiLine;
// Get the distance from the eye to this vertex.
Var *dist = (Var*)LangElement::find( "macroDist" );
if ( !dist )
{
dist = new Var;
dist->setType( "float" );
dist->setName( "macroDist" );
meta->addStatement( new GenOp( " @ = distance( @.xyz, @ );\r\n",
new DecOp( dist ), inPos, eyePos ) );
}
// grab connector texcoord register
ShaderConnector *connectComp = dynamic_cast<ShaderConnector *>( componentList[C_CONNECTOR] );
Var *outTex = connectComp->getElement( RT_TEXCOORD );
outTex->setName( String::ToString( "macroCoord%d", detailIndex ) );
outTex->setStructName( "OUT" );
outTex->setType( "float4" );
outTex->mapsToSampler = true;
// Get the detail scale and fade info.
Var *detScaleAndFade = new Var;
detScaleAndFade->setType( "float4" );
detScaleAndFade->setName( String::ToString( "macroScaleAndFade%d", detailIndex ) );
detScaleAndFade->uniform = true;
detScaleAndFade->constSortPos = cspPotentialPrimitive;
// Setup the detail coord.
meta->addStatement( new GenOp( " @.xyz = @ * @.xyx;\r\n", outTex, inTex, detScaleAndFade ) );
// And sneak the detail fade thru the w detailCoord.
meta->addStatement( new GenOp( " @.w = clamp( ( @.z - @ ) * @.w, 0.0, 1.0 );\r\n",
outTex, detScaleAndFade, dist, detScaleAndFade ) );
output = meta;
}
示例10: AssertFatal
void ParallaxFeatGLSL::processVert( Vector<ShaderComponent*> &componentList,
const MaterialFeatureData &fd )
{
AssertFatal( GFX->getPixelShaderVersion() >= 2.0,
"ParallaxFeatGLSL::processVert - We don't support SM 1.x!" );
MultiLine *meta = new MultiLine;
// Add the texture coords.
getOutTexCoord( "texCoord",
"vec2",
true,
fd.features[MFT_TexAnim],
meta,
componentList );
// Grab the input position.
Var *inPos = (Var*)LangElement::find( "inPosition" );
if ( !inPos )
inPos = (Var*)LangElement::find( "position" );
// Get the object space eye position and the
// object to tangent space transform.
Var *eyePos = _getUniformVar( "eyePos", "vec3", cspPrimitive );
Var *objToTangentSpace = getOutObjToTangentSpace( componentList, meta, fd );
// Now send the negative view vector in tangent space to the pixel shader.
ShaderConnector *connectComp = dynamic_cast<ShaderConnector *>( componentList[C_CONNECTOR] );
Var *outNegViewTS = connectComp->getElement( RT_TEXCOORD );
outNegViewTS->setName( "outNegViewTS" );
outNegViewTS->setStructName( "OUT" );
outNegViewTS->setType( "vec3" );
meta->addStatement( new GenOp( " @ = tMul( @, float3( @.xyz - @ ) );\r\n",
outNegViewTS, objToTangentSpace, inPos, eyePos ) );
// TODO: I'm at a loss at why i need to flip the binormal/y coord
// to get a good view vector for parallax. Lighting works properly
// with the TS matrix as is... but parallax does not.
//
// Someone figure this out!
//
meta->addStatement( new GenOp( " @.y = [email protected];\r\n", outNegViewTS, outNegViewTS ) );
// If we have texture anim matrix the tangent
// space view vector may need to be rotated.
Var *texMat = (Var*)LangElement::find( "texMat" );
if ( texMat )
{
meta->addStatement( new GenOp( " @ = tMul(@, float4(@,0)).xyz;\r\n",
outNegViewTS, texMat, outNegViewTS ) );
}
output = meta;
}
示例11: name
Var* TerrainFeatGLSL::_getInDetailCoord( Vector<ShaderComponent*> &componentList )
{
String name( String::ToString( "outDetCoord%d", getProcessIndex() ) );
Var *inDet = (Var*)LangElement::find( name );
if ( !inDet )
{
ShaderConnector *connectComp = dynamic_cast<ShaderConnector *>( componentList[C_CONNECTOR] );
inDet = connectComp->getElement( RT_TEXCOORD );
inDet->setName( name );
inDet->setType( "vec4" );
inDet->mapsToSampler = true;
}
return inDet;
}
示例12: AssertFatal
void GBufferConditionerGLSL::processVert( Vector<ShaderComponent*> &componentList,
const MaterialFeatureData &fd )
{
// If we have a normal map then that feature will
// take care of passing gbNormal to the pixel shader.
if ( fd.features[MFT_NormalMap] )
return;
MultiLine *meta = new MultiLine;
output = meta;
// grab incoming vert normal
Var *inNormal = (Var*) LangElement::find( "normal" );
AssertFatal( inNormal, "Something went bad with ShaderGen. The normal should be already defined." );
// grab output for gbuffer normal
ShaderConnector *connectComp = dynamic_cast<ShaderConnector *>( componentList[C_CONNECTOR] );
Var *outNormal = connectComp->getElement( RT_TEXCOORD );
outNormal->setName( "gbNormal" );
outNormal->setStructName( "OUT" );
outNormal->setType( "float3" );
if( !fd.features[MFT_ParticleNormal] )
{
// Kick out the view-space normal
// TODO: Total hack because Conditioner is directly derived
// from ShaderFeature and not from ShaderFeatureGLSL.
NamedFeatureGLSL dummy( String::EmptyString );
dummy.mInstancingFormat = mInstancingFormat;
Var *worldViewOnly = dummy.getWorldView( componentList, fd.features[MFT_UseInstancing], meta );
meta->addStatement( new GenOp(" @ = tMul(@, float4( normalize(@), 0.0 ) ).xyz;\r\n",
outNormal, worldViewOnly, inNormal ) );
}
else
{
// Assume the particle normal generator has already put this in view space
// and normalized it
meta->addStatement( new GenOp( " @ = @;\r\n", outNormal, inNormal ) );
}
}
示例13: AssertFatal
void EyeSpaceDepthOutHLSL::processVert( Vector<ShaderComponent*> &componentList,
const MaterialFeatureData &fd )
{
// grab incoming vert position
Var *inPosition = (Var*) LangElement::find( "inPosition" );
if ( !inPosition )
inPosition = (Var*) LangElement::find( "position" );
AssertFatal( inPosition, "Something went bad with ShaderGen. The position should be already defined." );
// grab output
ShaderConnector *connectComp = dynamic_cast<ShaderConnector *>( componentList[C_CONNECTOR] );
Var *outWSEyeVec = connectComp->getElement( RT_TEXCOORD );
outWSEyeVec->setName( "wsEyeVec" );
outWSEyeVec->setStructName( "OUT" );
// create modelview variable
Var *objToWorld = (Var*) LangElement::find( "objTrans" );
if( !objToWorld )
{
objToWorld = new Var;
objToWorld->setType( "float4x4" );
objToWorld->setName( "objTrans" );
objToWorld->uniform = true;
objToWorld->constSortPos = cspPrimitive;
}
Var *eyePos = (Var*)LangElement::find( "eyePosWorld" );
if( !eyePos )
{
eyePos = new Var;
eyePos->setType("float3");
eyePos->setName("eyePosWorld");
eyePos->uniform = true;
eyePos->constSortPos = cspPass;
}
LangElement *statement = new GenOp( " @ = mul(@, float4(@.xyz,1)) - float4(@, 0.0);\r\n",
outWSEyeVec, objToWorld, inPosition, eyePos );
output = statement;
}
示例14: processVert
void DeferredRTLightingFeatGLSL::processVert( Vector<ShaderComponent*> &componentList,
const MaterialFeatureData &fd )
{
// Skip deferred features, and use forward shading instead
if ( fd.features[MFT_ForwardShading] )
{
Parent::processVert( componentList, fd );
return;
}
// Pass screen space position to pixel shader to compute a full screen buffer uv
ShaderConnector *connectComp = dynamic_cast<ShaderConnector *>( componentList[C_CONNECTOR] );
Var *ssPos = connectComp->getElement( RT_TEXCOORD );
ssPos->setName( "screenspacePos" );
ssPos->setStructName( "OUT" );
ssPos->setType( "vec4" );
Var *outPosition = (Var*) LangElement::find( "gl_Position" );
AssertFatal( outPosition, "No gl_Position, ohnoes." );
output = new GenOp( " @ = @;\r\n", ssPos, outPosition );
}
示例15: GenOp
void ShaderGen::_processPixFeatures( Vector<GFXShaderMacro> ¯os, bool macrosOnly )
{
const FeatureSet &features = mFeatureData.features;
for( U32 i=0; i < features.getCount(); i++ )
{
S32 index;
const FeatureType &type = features.getAt( i, &index );
ShaderFeature* feature = FEATUREMGR->getByType( type );
if ( feature )
{
feature->setProcessIndex( index );
feature->processPixMacros( macros, mFeatureData );
if ( macrosOnly )
continue;
feature->mInstancingFormat = &mInstancingFormat;
feature->processPix( mComponents, mFeatureData );
String line;
if ( index > -1 )
line = String::ToString( " // %s %d\r\n", feature->getName().c_str(), index );
else
line = String::ToString( " // %s\r\n", feature->getName().c_str() );
mOutput->addStatement( new GenOp( line ) );
if ( feature->getOutput() )
mOutput->addStatement( feature->getOutput() );
feature->reset();
mOutput->addStatement( new GenOp( " \r\n" ) );
}
}
ShaderConnector *connect = dynamic_cast<ShaderConnector *>( mComponents[C_CONNECTOR] );
connect->sortVars();
}