diff --git a/Engine/source/shaderGen/GLSL/shaderFeatureGLSL.cpp b/Engine/source/shaderGen/GLSL/shaderFeatureGLSL.cpp index f6503768b..650b3c799 100644 --- a/Engine/source/shaderGen/GLSL/shaderFeatureGLSL.cpp +++ b/Engine/source/shaderGen/GLSL/shaderFeatureGLSL.cpp @@ -438,29 +438,18 @@ Var* ShaderFeatureGLSL::getInColor( const char *name, Var* ShaderFeatureGLSL::addOutVpos( MultiLine *meta, Vector &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" ); if ( !outVpos ) { - ShaderConnector *connectComp = dynamic_cast( componentList[C_CONNECTOR] ); - - outVpos = connectComp->getElement( RT_TEXCOORD ); - outVpos->setName( "outVpos" ); - outVpos->setStructName( "OUT" ); - outVpos->setType( "vec4" ); + ShaderConnector* connectComp = dynamic_cast(componentList[C_CONNECTOR]); + outVpos = connectComp->getElement(RT_TEXCOORD); + outVpos->setName("outVpos"); + outVpos->setStructName("OUT"); + outVpos->setType("vec4"); Var *outPosition = (Var*) LangElement::find( "gl_Position" ); - AssertFatal( outPosition, "ShaderFeatureGLSL::addOutVpos - Didn't find the output position." ); - - meta->addStatement( new GenOp( " @ = @;\r\n", outVpos, outPosition ) ); + AssertFatal( outPosition, "ShaderFeatureGLSL::addOutVpos - gl_Position somehow undefined?." ); + meta->addStatement(new GenOp(" @ = @;\r\n", outVpos, outPosition)); } return outVpos; @@ -469,15 +458,34 @@ Var* ShaderFeatureGLSL::addOutVpos( MultiLine *meta, Var* ShaderFeatureGLSL::getInVpos( MultiLine *meta, Vector &componentList ) { - Var *inVpos = (Var*)LangElement::find( "vpos" ); - if ( inVpos ) + Var* inVpos = (Var*)LangElement::find("inVpos"); + if (inVpos) return inVpos; - ShaderConnector *connectComp = dynamic_cast( componentList[C_CONNECTOR] ); - inVpos = connectComp->getElement( RT_TEXCOORD ); - inVpos->setName( "inVpos" ); - inVpos->setStructName( "IN" ); - inVpos->setType( "vec4" ); + ShaderConnector* connectComp = dynamic_cast(componentList[C_CONNECTOR]); + inVpos = connectComp->getElement(RT_TEXCOORD); + inVpos->setName("inVpos"); + inVpos->setStructName("IN"); + 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; } @@ -2429,15 +2437,15 @@ void VisibilityFeatGLSL::processPix( Vector &componentList, else { visibility = (Var*)LangElement::find( "visibility" ); - - if ( !visibility ) - { - visibility = new Var(); - visibility->setType( "float" ); - visibility->setName( "visibility" ); - visibility->uniform = true; - visibility->constSortPos = cspPotentialPrimitive; - } + + if (!visibility) + { + visibility = new Var(); + visibility->setType("float"); + visibility->setName("visibility"); + visibility->uniform = true; + visibility->constSortPos = cspPotentialPrimitive; + } } MultiLine* meta = new MultiLine;