mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-01-19 20:24:49 +00:00
Merge pull request #986 from BeamNG/fix_color_mrt
Fix GLSL out fragment shader color.
This commit is contained in:
commit
87f34e3c4f
|
|
@ -451,6 +451,12 @@ bool GFXGLShader::_init()
|
|||
glBindAttribLocation(mProgram, Torque::GL_VertexAttrib_TexCoord8, "vTexCoord8");
|
||||
glBindAttribLocation(mProgram, Torque::GL_VertexAttrib_TexCoord9, "vTexCoord9");
|
||||
|
||||
//bind fragment out color
|
||||
glBindFragDataLocation(mProgram, 0, "OUT_col");
|
||||
glBindFragDataLocation(mProgram, 1, "OUT_col1");
|
||||
glBindFragDataLocation(mProgram, 2, "OUT_col2");
|
||||
glBindFragDataLocation(mProgram, 3, "OUT_col3");
|
||||
|
||||
// Link it!
|
||||
glLinkProgram( mProgram );
|
||||
|
||||
|
|
|
|||
|
|
@ -202,8 +202,21 @@ void _GFXGLTextureTargetFBOImpl::applyState()
|
|||
|
||||
void _GFXGLTextureTargetFBOImpl::makeActive()
|
||||
{
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, mFramebuffer);
|
||||
GFXGL->getOpenglCache()->setCacheBinded(GL_FRAMEBUFFER, mFramebuffer);
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, mFramebuffer);
|
||||
GFXGL->getOpenglCache()->setCacheBinded(GL_FRAMEBUFFER, mFramebuffer);
|
||||
|
||||
int i = 0;
|
||||
GLenum draws[16];
|
||||
for( i = 0; i < GFXGL->getNumRenderTargets(); ++i)
|
||||
{
|
||||
_GFXGLTargetDesc* color = mTarget->getTargetDesc( static_cast<GFXTextureTarget::RenderSlot>(GFXTextureTarget::Color0+i ));
|
||||
if(color)
|
||||
draws[i] = GL_COLOR_ATTACHMENT0 + i;
|
||||
else
|
||||
break;
|
||||
}
|
||||
|
||||
glDrawBuffers( i, draws );
|
||||
}
|
||||
|
||||
void _GFXGLTextureTargetFBOImpl::finish()
|
||||
|
|
|
|||
|
|
@ -89,10 +89,11 @@ LangElement* ShaderFeatureGLSL::assignColor( LangElement *elem,
|
|||
{
|
||||
// create color var
|
||||
color = new Var;
|
||||
color->setName( getOutputTargetVarName( outputTarget ) );
|
||||
color->setType( "vec4" );
|
||||
color->setName( getOutputTargetVarName( outputTarget ) );
|
||||
color->setStructName( "OUT" );
|
||||
|
||||
return new GenOp( "@ = @", new DecOp(color), elem );
|
||||
return new GenOp( "@ = @", color, elem );
|
||||
}
|
||||
|
||||
LangElement *assign;
|
||||
|
|
@ -2186,6 +2187,7 @@ void FogFeatGLSL::processPix( Vector<ShaderComponent*> &componentList,
|
|||
color = new Var;
|
||||
color->setType( "vec4" );
|
||||
color->setName( "col" );
|
||||
color->setStructName("OUT");
|
||||
}
|
||||
|
||||
Var *fogAmount;
|
||||
|
|
|
|||
|
|
@ -22,8 +22,9 @@
|
|||
|
||||
#include "platform/platform.h"
|
||||
#include "shaderGen/GLSL/shaderGenGLSL.h"
|
||||
|
||||
#include "shaderGen/GLSL/shaderCompGLSL.h"
|
||||
#include "shaderGen/featureMgr.h"
|
||||
#include "gfx/gl/tGL/tGL.h"
|
||||
|
||||
|
||||
void ShaderGenPrinterGLSL::printShaderHeader( Stream& stream )
|
||||
|
|
@ -64,13 +65,31 @@ void ShaderGenPrinterGLSL::printVertexShaderCloser( Stream& stream )
|
|||
|
||||
void ShaderGenPrinterGLSL::printPixelShaderOutputStruct( Stream& stream, const MaterialFeatureData &featureData )
|
||||
{
|
||||
// Nothing here
|
||||
// Determine the number of output targets we need
|
||||
U32 numMRTs = 0;
|
||||
for (U32 i = 0; i < FEATUREMGR->getFeatureCount(); i++)
|
||||
{
|
||||
const FeatureInfo &info = FEATUREMGR->getAt(i);
|
||||
if (featureData.features.hasFeature(*info.type))
|
||||
numMRTs |= info.feature->getOutputTargets(featureData);
|
||||
}
|
||||
|
||||
WRITESTR(avar("//Fragment shader OUT\r\n"));
|
||||
//WRITESTR(avar("out vec4 OUT_col;\r\n", i)); // @todo OUT_col defined on hlslCompat.glsl
|
||||
for( U32 i = 1; i < 4; i++ )
|
||||
{
|
||||
if( numMRTs & 1 << i )
|
||||
WRITESTR(avar("out vec4 OUT_col%d;\r\n", i));
|
||||
}
|
||||
|
||||
WRITESTR("\r\n");
|
||||
WRITESTR("\r\n");
|
||||
}
|
||||
|
||||
void ShaderGenPrinterGLSL::printPixelShaderCloser( Stream& stream )
|
||||
{
|
||||
const char *closer = " OUT_FragColor0 = col;\r\n}\r\n";
|
||||
stream.write( dStrlen(closer), closer );
|
||||
const char *closer = " \r\n}\r\n";
|
||||
stream.write( dStrlen(closer), closer );
|
||||
}
|
||||
|
||||
void ShaderGenPrinterGLSL::printLine(Stream& stream, const String& line)
|
||||
|
|
|
|||
|
|
@ -91,7 +91,7 @@ void _initShaderGenGLSL( ShaderGen *shaderGen )
|
|||
|
||||
FEATUREMGR->registerFeature( MFT_ImposterVert, new ImposterVertFeatureGLSL );
|
||||
|
||||
//FEATUREMGR->registerFeature( MFT_LightbufferMRT, new NamedFeatureGLSL( "Lightbuffer MRT" ) );
|
||||
FEATUREMGR->registerFeature( MFT_LightbufferMRT, new NamedFeatureGLSL( "Lightbuffer MRT" ) );
|
||||
//FEATUREMGR->registerFeature( MFT_IsTranslucentZWrite, new NamedFeatureGLSL( "Translucent ZWrite" ) );
|
||||
//FEATUREMGR->registerFeature( MFT_InterlacedPrePass, new NamedFeatureGLSL( "Interlaced Pre Pass" ) );
|
||||
|
||||
|
|
|
|||
|
|
@ -78,9 +78,9 @@ LangElement *ConditionerFeature::assignOutput( Var *unconditionedOutput, ShaderF
|
|||
{
|
||||
color->setName( getOutputTargetVarName(outputTarget) );
|
||||
color->setType( "vec4" );
|
||||
DecOp* colDecl = new DecOp(color);
|
||||
color->setStructName( "OUT" );
|
||||
|
||||
assign = new GenOp( "@ = vec4(@)", colDecl, conditionedOutput );
|
||||
assign = new GenOp( "@ = vec4(@)", color, conditionedOutput );
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
|||
|
|
@ -482,8 +482,8 @@ void TerrainDetailMapFeatGLSL::processPix( Vector<ShaderComponent*> &component
|
|||
outColor = new Var;
|
||||
outColor->setType("float4");
|
||||
outColor->setName("col");
|
||||
meta->addStatement(new GenOp(" @;\r\n", new DecOp(outColor)));
|
||||
//outColor->setStructName("OUT");
|
||||
outColor->setStructName("OUT");
|
||||
meta->addStatement(new GenOp(" @;\r\n", outColor));
|
||||
}
|
||||
|
||||
Var *detailColor = (Var*)LangElement::find("detailColor");
|
||||
|
|
|
|||
|
|
@ -100,6 +100,7 @@ mat4 mat4FromRow( float r0c0, float r0c1, float r0c2, float r0c3,
|
|||
|
||||
#ifdef TORQUE_PIXEL_SHADER
|
||||
void clip(float a) { if(a < 0) discard;}
|
||||
|
||||
out vec4 OUT_FragColor0;
|
||||
|
||||
out vec4 OUT_col;
|
||||
#define OUT_FragColor0 OUT_col
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -100,6 +100,7 @@ mat4 mat4FromRow( float r0c0, float r0c1, float r0c2, float r0c3,
|
|||
|
||||
#ifdef TORQUE_PIXEL_SHADER
|
||||
void clip(float a) { if(a < 0) discard;}
|
||||
|
||||
out vec4 OUT_FragColor0;
|
||||
|
||||
out vec4 OUT_col;
|
||||
#define OUT_FragColor0 OUT_col
|
||||
#endif
|
||||
|
|
|
|||
Loading…
Reference in a new issue