mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-07-13 15:44:36 +00:00
Merge pull request #1220 from Azaezel/alpha41/fixGLVisibility
fizzle fix for gl
This commit is contained in:
commit
ecd75bdc06
1 changed files with 42 additions and 34 deletions
|
|
@ -438,29 +438,18 @@ Var* ShaderFeatureGLSL::getInColor( const char *name,
|
||||||
Var* ShaderFeatureGLSL::addOutVpos( MultiLine *meta,
|
Var* ShaderFeatureGLSL::addOutVpos( MultiLine *meta,
|
||||||
Vector<ShaderComponent*> &componentList )
|
Vector<ShaderComponent*> &componentList )
|
||||||
{
|
{
|
||||||
/*
|
|
||||||
// Nothing to do if we're on SM 3.0... we use the real vpos.
|
|
||||||
if ( GFX->getPixelShaderVersion() >= 3.0f )
|
|
||||||
return NULL;
|
|
||||||
*/
|
|
||||||
|
|
||||||
// For SM 2.x we need to generate the vpos in the vertex shader
|
|
||||||
// and pass it as a texture coord to the pixel shader.
|
|
||||||
|
|
||||||
Var *outVpos = (Var*)LangElement::find( "outVpos" );
|
Var *outVpos = (Var*)LangElement::find( "outVpos" );
|
||||||
if ( !outVpos )
|
if ( !outVpos )
|
||||||
{
|
{
|
||||||
ShaderConnector *connectComp = dynamic_cast<ShaderConnector *>( componentList[C_CONNECTOR] );
|
ShaderConnector* connectComp = dynamic_cast<ShaderConnector*>(componentList[C_CONNECTOR]);
|
||||||
|
outVpos = connectComp->getElement(RT_TEXCOORD);
|
||||||
outVpos = connectComp->getElement( RT_TEXCOORD );
|
outVpos->setName("outVpos");
|
||||||
outVpos->setName( "outVpos" );
|
outVpos->setStructName("OUT");
|
||||||
outVpos->setStructName( "OUT" );
|
outVpos->setType("vec4");
|
||||||
outVpos->setType( "vec4" );
|
|
||||||
|
|
||||||
Var *outPosition = (Var*) LangElement::find( "gl_Position" );
|
Var *outPosition = (Var*) LangElement::find( "gl_Position" );
|
||||||
AssertFatal( outPosition, "ShaderFeatureGLSL::addOutVpos - Didn't find the output position." );
|
AssertFatal( outPosition, "ShaderFeatureGLSL::addOutVpos - gl_Position somehow undefined?." );
|
||||||
|
meta->addStatement(new GenOp(" @ = @;\r\n", outVpos, outPosition));
|
||||||
meta->addStatement( new GenOp( " @ = @;\r\n", outVpos, outPosition ) );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return outVpos;
|
return outVpos;
|
||||||
|
|
@ -469,15 +458,34 @@ Var* ShaderFeatureGLSL::addOutVpos( MultiLine *meta,
|
||||||
Var* ShaderFeatureGLSL::getInVpos( MultiLine *meta,
|
Var* ShaderFeatureGLSL::getInVpos( MultiLine *meta,
|
||||||
Vector<ShaderComponent*> &componentList )
|
Vector<ShaderComponent*> &componentList )
|
||||||
{
|
{
|
||||||
Var *inVpos = (Var*)LangElement::find( "vpos" );
|
Var* inVpos = (Var*)LangElement::find("inVpos");
|
||||||
if ( inVpos )
|
if (inVpos)
|
||||||
return inVpos;
|
return inVpos;
|
||||||
|
|
||||||
ShaderConnector *connectComp = dynamic_cast<ShaderConnector*>( componentList[C_CONNECTOR] );
|
ShaderConnector* connectComp = dynamic_cast<ShaderConnector*>(componentList[C_CONNECTOR]);
|
||||||
inVpos = connectComp->getElement( RT_TEXCOORD );
|
inVpos = connectComp->getElement(RT_TEXCOORD);
|
||||||
inVpos->setName( "inVpos" );
|
inVpos->setName("inVpos");
|
||||||
inVpos->setStructName( "IN" );
|
inVpos->setStructName("IN");
|
||||||
inVpos->setType( "vec4" );
|
inVpos->setType("vec4");
|
||||||
|
|
||||||
|
Var* targetSize = (Var*)LangElement::find("targetSize");
|
||||||
|
if (!targetSize)
|
||||||
|
{
|
||||||
|
targetSize = new Var();
|
||||||
|
targetSize->setType("vec2");
|
||||||
|
targetSize->setName("targetSize");
|
||||||
|
targetSize->uniform = true;
|
||||||
|
targetSize->constSortPos = cspPotentialPrimitive;
|
||||||
|
}
|
||||||
|
|
||||||
|
// transform projection space to screen space, needs to be done per-pixel. D3D automatically does this with SV_POSITION semantic types (note GLSL doesn't have semantics, even though Torque still uses the RT_ enums for them for some shaderconnector business)
|
||||||
|
// optional: OGL provides this data as gl_FragCoord automatically
|
||||||
|
// Note: for 100% parity with gl_FragCoord (but NOT with vpos in D3D) set .w = 1/.w
|
||||||
|
meta->addStatement(new GenOp(" @.xyz = @.xyz / @.w;\r\n", inVpos, inVpos, inVpos));
|
||||||
|
meta->addStatement(new GenOp(" @.w = @.w;\r\n", inVpos, inVpos)); // for parity w/ gl_FragCoord set: meta->addStatement(new GenOp(" @.w = 1.0 / @.w;\r\n", inVpos, inVpos));
|
||||||
|
meta->addStatement(new GenOp(" @.xy = @.xy * 0.5 + vec2(0.5,0.5);\r\n", inVpos, inVpos)); // get the screen coord to 0 to 1
|
||||||
|
meta->addStatement(new GenOp(" @.y = 1.0 - @.y;\r\n", inVpos, inVpos)); // flip the y axis
|
||||||
|
meta->addStatement(new GenOp(" @.xy *= @;\r\n", inVpos, targetSize)); // scale to monitor
|
||||||
return inVpos;
|
return inVpos;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -2429,15 +2437,15 @@ void VisibilityFeatGLSL::processPix( Vector<ShaderComponent*> &componentList,
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
visibility = (Var*)LangElement::find( "visibility" );
|
visibility = (Var*)LangElement::find( "visibility" );
|
||||||
|
|
||||||
if ( !visibility )
|
if (!visibility)
|
||||||
{
|
{
|
||||||
visibility = new Var();
|
visibility = new Var();
|
||||||
visibility->setType( "float" );
|
visibility->setType("float");
|
||||||
visibility->setName( "visibility" );
|
visibility->setName("visibility");
|
||||||
visibility->uniform = true;
|
visibility->uniform = true;
|
||||||
visibility->constSortPos = cspPotentialPrimitive;
|
visibility->constSortPos = cspPotentialPrimitive;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
MultiLine* meta = new MultiLine;
|
MultiLine* meta = new MultiLine;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue