void TerrainParallaxMapFeatGLSL::processVert( Vector<ShaderComponent*> &componentList, const MaterialFeatureData &fd ) { if ( LangElement::find( "outNegViewTS" ) ) return; MultiLine *meta = new MultiLine; // Grab the input position. Var *inPos = (Var*)LangElement::find( "inPosition" ); if ( !inPos ) inPos = (Var*)LangElement::find( "position" ); // Get the object space eye position and the // object to tangent transform. Var *eyePos = _getUniformVar( "eyePos", "vec3" , cspPotentialPrimitive ); Var *objToTangentSpace = getOutObjToTangentSpace( componentList, meta,fd ); // Now send the negative view vector in tangent space to the pixel shader. ShaderConnector *connectComp = dynamic_cast<ShaderConnector *>( componentList[C_CONNECTOR] ); Var *outNegViewTS = connectComp->getElement( RT_TEXCOORD ); outNegViewTS->setName( "outNegViewTS" ); outNegViewTS->setType( "vec3" ); meta->addStatement( new GenOp( " @ = @ * vec3( @ - @.xyz );\r\n", outNegViewTS, objToTangentSpace, eyePos, inPos ) ); output = meta; }
void ParallaxFeatGLSL::processVert( Vector<ShaderComponent*> &componentList, const MaterialFeatureData &fd ) { AssertFatal( GFX->getPixelShaderVersion() >= 2.0, "ParallaxFeatGLSL::processVert - We don't support SM 1.x!" ); MultiLine *meta = new MultiLine; // Add the texture coords. getOutTexCoord( "texCoord", "vec2", true, fd.features[MFT_TexAnim], meta, componentList ); // Grab the input position. Var *inPos = (Var*)LangElement::find( "inPosition" ); if ( !inPos ) inPos = (Var*)LangElement::find( "position" ); // Get the object space eye position and the // object to tangent space transform. Var *eyePos = _getUniformVar( "eyePos", "vec3", cspPrimitive ); Var *objToTangentSpace = getOutObjToTangentSpace( componentList, meta, fd ); // Now send the negative view vector in tangent space to the pixel shader. ShaderConnector *connectComp = dynamic_cast<ShaderConnector *>( componentList[C_CONNECTOR] ); Var *outNegViewTS = connectComp->getElement( RT_TEXCOORD ); outNegViewTS->setName( "outNegViewTS" ); outNegViewTS->setStructName( "OUT" ); outNegViewTS->setType( "vec3" ); meta->addStatement( new GenOp( " @ = tMul( @, float3( @.xyz - @ ) );\r\n", outNegViewTS, objToTangentSpace, inPos, eyePos ) ); // TODO: I'm at a loss at why i need to flip the binormal/y coord // to get a good view vector for parallax. Lighting works properly // with the TS matrix as is... but parallax does not. // // Someone figure this out! // meta->addStatement( new GenOp( " @.y = [email protected];\r\n", outNegViewTS, outNegViewTS ) ); // If we have texture anim matrix the tangent // space view vector may need to be rotated. Var *texMat = (Var*)LangElement::find( "texMat" ); if ( texMat ) { meta->addStatement( new GenOp( " @ = tMul(@, float4(@,0)).xyz;\r\n", outNegViewTS, texMat, outNegViewTS ) ); } output = meta; }
void TerrainDetailMapFeatHLSL::processVert( Vector<ShaderComponent*> &componentList, const MaterialFeatureData &fd ) { const S32 detailIndex = getProcessIndex(); // Grab incoming texture coords... the base map feature // made sure this was created. Var *inTex = (Var*)LangElement::find( "texCoord" ); AssertFatal( inTex, "The texture coord is missing!" ); // Grab the input position. Var *inPos = (Var*)LangElement::find( "inPosition" ); if ( !inPos ) inPos = (Var*)LangElement::find( "position" ); // Get the object space eye position. Var *eyePos = _getUniformVar( "eyePos", "float3", cspPotentialPrimitive ); MultiLine *meta = new MultiLine; // If we have parallax mapping then make sure we've sent // the negative view vector to the pixel shader. if ( fd.features.hasFeature( MFT_TerrainParallaxMap ) && !LangElement::find( "outNegViewTS" ) ) { // Get the object to tangent transform which // will consume 3 output registers. Var *objToTangentSpace = getOutObjToTangentSpace( componentList, meta, fd ); // Now use a single output register to send the negative // view vector in tangent space to the pixel shader. ShaderConnector *connectComp = dynamic_cast<ShaderConnector *>( componentList[C_CONNECTOR] ); Var *outNegViewTS = connectComp->getElement( RT_TEXCOORD ); outNegViewTS->setName( "outNegViewTS" ); outNegViewTS->setStructName( "OUT" ); outNegViewTS->setType( "float3" ); meta->addStatement( new GenOp( " @ = mul( @, float3( @ - @.xyz ) );\r\n", outNegViewTS, objToTangentSpace, eyePos, inPos ) ); } // Get the distance from the eye to this vertex. Var *dist = (Var*)LangElement::find( "dist" ); if ( !dist ) { dist = new Var; dist->setType( "float" ); dist->setName( "dist" ); meta->addStatement( new GenOp( " @ = distance( @.xyz, @ );\r\n", new DecOp( dist ), inPos, eyePos ) ); } // grab connector texcoord register ShaderConnector *connectComp = dynamic_cast<ShaderConnector *>( componentList[C_CONNECTOR] ); Var *outTex = connectComp->getElement( RT_TEXCOORD ); outTex->setName( String::ToString( "detCoord%d", detailIndex ) ); outTex->setStructName( "OUT" ); outTex->setType( "float4" ); outTex->mapsToSampler = true; // Get the detail scale and fade info. Var *detScaleAndFade = new Var; detScaleAndFade->setType( "float4" ); detScaleAndFade->setName( String::ToString( "detailScaleAndFade%d", detailIndex ) ); detScaleAndFade->uniform = true; detScaleAndFade->constSortPos = cspPotentialPrimitive; // Setup the detail coord. // // NOTE: You see here we scale the texture coord by 'xyx' // to generate the detail coord. This y is here because // its scale is flipped to correct for the non negative y // in texCoord. // // See TerrainBaseMapFeatHLSL::processVert(). // meta->addStatement( new GenOp( " @.xyz = @ * @.xyx;\r\n", outTex, inTex, detScaleAndFade ) ); // And sneak the detail fade thru the w detailCoord. meta->addStatement( new GenOp( " @.w = clamp( ( @.z - @ ) * @.w, 0.0, 1.0 );\r\n", outTex, detScaleAndFade, dist, detScaleAndFade ) ); output = meta; }