Merge pull request #1220 from Azaezel/alpha41/fixGLVisibility

fizzle fix for gl
This commit is contained in:
Brian Roberts 2024-02-24 12:31:06 -06:00 committed by GitHub
commit ecd75bdc06
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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;