Game Development Community

How to modify texture coordinates in a ShaderFeature?

by 7nMs23fF · in Torque 3D Professional · 04/13/2011 (9:22 am) · 3 replies

I struggled to find documentation on this subject, but only found Pat Wilson's articles at gameclay.com. They were pretty straight-forward, but left me clueless as they only covered how to change the color of the material.

So my question is - how would I grab the texture coordinates, modify them, and feed them back to the shader? My goal is to scale the texture per axis.

Thanks in advance.

#1
04/13/2011 (12:06 pm)
Check out this resource:
http://www.garagegames.com/community/resources/view/19161

Now,as I understand,you want to implement a scale on each axis.
Well, your processVert() should look like:

Var *inTex = getVertTexCoord( "texCoord" );

ShaderConnector *connectComp = dynamic_cast<ShaderConnector *>( componentList[C_CONNECTOR] );
Var *outTex = connectComp->getElement( RT_TEXCOORD );
outTex->setName( "texCoord" );
outTex->setStructName( "OUT" );
outTex->setType( "float2" );
outTex->mapsToSampler = true;

Var *texScale= (Var *)( LangElement::find("texScale") );  
if( !texScale)  
 {   
   texScale= new Var;  
   texScale->setType( "float2" );  
   texScale->setName( "texScale" );  
   texScale->constSortPos = cspPotentialPrimitive;  
   texScale->uniform = true;  
 } 

meta->addStatement( new GenOp( "@ = @ * @;", outTex, inTex , texScale ) );

Now your new multipliers are texScale.x and texScale.y
#2
04/15/2011 (10:00 am)
Cheers. Didn't get it to work yet, but I probably will after some experimenting.
#3
04/17/2011 (10:43 am)
Works perfectly now. Thanks a lot.