Merge remote-tracking branch 'upstream/development' into ShaderConstBuffer-CleanupRefactor

This commit is contained in:
marauder2k7 2024-02-26 18:51:40 +00:00
commit dfe4bcd01e
2 changed files with 43 additions and 39 deletions

View file

@ -1729,11 +1729,7 @@ void SceneObject::updateRenderChangesByParent(){
//add the "offset" caused by the parents change, and add it to it's own //add the "offset" caused by the parents change, and add it to it's own
// This is needed by objects that update their own render transform thru interpolate tick // This is needed by objects that update their own render transform thru interpolate tick
// Mostly for stationary objects. // Mostly for stationary objects.
if (getClassName() == StringTable->insert("Player"))
mat.mul(offset,getRenderTransform()); mat.mul(offset,getRenderTransform());
else
mat.mul(offset,getTransform());
setRenderTransform(mat); setRenderTransform(mat);
} }
} }

View file

@ -438,28 +438,17 @@ 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));
} }
@ -469,7 +458,7 @@ 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;
@ -478,6 +467,25 @@ Var* ShaderFeatureGLSL::getInVpos( MultiLine *meta,
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;
} }