LoLJester Posted November 11, 2015 Share Posted November 11, 2015 Hello,I'm trying to create a Tank vehicle with animated UV tracks.Material animation is not an option as I'm to understand that Materials are not instanced per mesh, but one material applies to all meshes that have this material mapped to them.Is it "tverts" that I must modify for the UV to displace in real time? Quote Link to comment Share on other sites More sharing options...
Azaezel Posted November 11, 2015 Share Posted November 11, 2015 https://github.com/Azaezel/Torque3D/blob/2480e3cb954b87f9bca945acaccd788520f114f0/Engine/source/T3D/laser.cpp#L249-L250https://github.com/Azaezel/Torque3D/blob/2480e3cb954b87f9bca945acaccd788520f114f0/Engine/source/T3D/laser.cpp#L305-L314 Quote Link to comment Share on other sites More sharing options...
LoLJester Posted November 11, 2015 Author Share Posted November 11, 2015 Hi Azaezel, the video looks pretty good.I can see what you did, but the code seems to only apply to quads that you create from point A to point B.How do I apply this to sceneObjects that are already mapped?What I'm trying to do is modify the positioning of a texture already mapped to the tank tracks.I see that "tverts" is assigned the UVs of the mesh in assembleMesh() and assembleShape(), but once I modify it, where is it updated?Am I even on the right path? Quote Link to comment Share on other sites More sharing options...
LoLJester Posted November 12, 2015 Author Share Posted November 12, 2015 Anybody, please?I'm sure there's been a situation similar to this that someone must have encountered. Nobody's ever worked with the UVs in T3D before? I'm tempted to animate the tracks themselves, but they are already animated for suspension. Quote Link to comment Share on other sites More sharing options...
Azaezel Posted November 12, 2015 Share Posted November 12, 2015 Honestly, what I'd do is hack into something like https://github.com/GarageGames/Torque3D/blob/2044b2691e1a29fa65d1bdd163f0d834995433ce/Engine/source/materials/processedShaderMaterial.cpp#L887with https://github.com/Azaezel/Torque3D/commit/178703f19a601c3ca370514930ef6e39fa405ba7The per-instance material damage in the vid was an older version that used that mMaterialDamage being passed around to modify the pre-existing detail feature alpha blend, for instance. So in your case...https://github.com/Azaezel/Torque3D/commit/178703f19a601c3ca370514930ef6e39fa405ba7#diff-ee63be9e1180cd38f5b10d798839b5f1R2604 would be something along the lines of rdata.setMaterialSpeed(getVelocity().len());https://github.com/Azaezel/Torque3D/commit/178703f19a601c3ca370514930ef6e39fa405ba7#diff-8c164601ef835960f8dd7a4931f78792R161 for you setMaterialSpeed definitionshttps://github.com/Azaezel/Torque3D/commit/178703f19a601c3ca370514930ef6e39fa405ba7#diff-5507520a39aa2d8c9d489a38d0d85565R215 + https://github.com/Azaezel/Torque3D/commit/178703f19a601c3ca370514930ef6e39fa405ba7#diff-1edd3e647b9fb79d7c959cd66c077883R37 + https://github.com/Azaezel/Torque3D/commit/178703f19a601c3ca370514930ef6e39fa405ba7#diff-e344db6d2836ae639d06783f2388d090R175 for your glue codeprobably will need to alt https://github.com/GarageGames/Torque3D/blob/2044b2691e1a29fa65d1bdd163f0d834995433ce/Engine/source/materials/processedShaderMaterial.cpp#L783 to pass the sgData along so you can do the equivalent of https://github.com/Azaezel/Torque3D/commit/178703f19a601c3ca370514930ef6e39fa405ba7#diff-b7123dc2958b63669f99f0cd9ee534a5R1240 for your offset multiplier. (also probably want to add a flag to materials that conrols whether or not they're multiplied by velocity so you don't end up grinding the rest to a halt)Edit: further reading: http://wiki.torque3d.org/coder:extending-the-torque3d-material-system probably does a much better job of handling the whys. Quote Link to comment Share on other sites More sharing options...
LoLJester Posted November 13, 2015 Author Share Posted November 13, 2015 Thanks, Azaezel! It looks like something that might just work. Quote Link to comment Share on other sites More sharing options...
LoLJester Posted November 30, 2015 Author Share Posted November 30, 2015 Ok. I got it to somewhat work, but strangely only in Debug. For some odd reason, I can't get the shader to work in Release or Optimized Debug mode. Is there something I'm missing? Quote Link to comment Share on other sites More sharing options...
Azaezel Posted November 30, 2015 Share Posted November 30, 2015 Only working in debug sounds like somethings not getting initialized properly. Got a fork up to look it over? Quote Link to comment Share on other sites More sharing options...
LoLJester Posted November 30, 2015 Author Share Posted November 30, 2015 No. I'm on the road right now, always on the move. :) I will double check if everything gets initialized properly. I basically looked at how WindDeform and Visibility do it. Is there a way to Debug the Shaders through Torque? Quote Link to comment Share on other sites More sharing options...
LoLJester Posted November 30, 2015 Author Share Posted November 30, 2015 The Vert and Pix shaders: void uvAnimFeatureHLSL::processVert( Vector &componentList, const MaterialFeatureData &fd ) { MultiLine *meta = new MultiLine; if(fd.features[MFT_UseInstancing]) { // We pass the uvOffset to the pixel shader via // another output register. // // TODO: We should see if we can share this register // with some other common instanced data. // ShaderConnector *conn = dynamic_cast( componentList[C_CONNECTOR] ); Var *out_UV_Offset = conn->getElement( RT_TEXCOORD ); out_UV_Offset->setStructName( "OUT" ); out_UV_Offset->setName( "uvOffset" ); out_UV_Offset->setType( "float" ); ShaderConnector *vertStruct = dynamic_cast( componentList[C_VERT_STRUCT] ); Var *inst_UV_Offset = vertStruct->getElement( RT_TEXCOORD, 1 ); inst_UV_Offset->setStructName( "IN" ); inst_UV_Offset->setName( "inst_uvOffset" ); inst_UV_Offset->setType( "float" ); mInstancingFormat->addElement( "uvOffset", GFXDeclType_Float, inst_UV_Offset->constNum ); meta->addStatement( new GenOp( " @ = @; // Instancing!\r\n", out_UV_Offset, inst_UV_Offset ) ); } getOutTexCoord("texCoord", "float2", true, false, meta, componentList); output = meta; } //------------------------------------------------------------------------------------------------------- void uvAnimFeatureHLSL::processPix( Vector &componentList, const MaterialFeatureData &fd ) { //Sorin D: Get the uvOffset constant. Var *uvOffset = NULL; if(fd.features[MFT_UseInstancing]) uvOffset = getInTexCoord( "uvOffset", "float", false, componentList ); else { uvOffset = (Var*)LangElement::find( "uvOffset" ); if(!uvOffset) { uvOffset = new Var(); uvOffset->setType( "float" ); uvOffset->setName( "uvOffset" ); uvOffset->uniform = true; uvOffset->constSortPos = cspPotentialPrimitive; } } MultiLine *meta = new MultiLine; //Sorin D: Get the texture coordinate UV0. Var *inUV = getInTexCoord( "texCoord", "float2", true, componentList ); //Sorin D: Calculate and set the UV's offset. meta->addStatement(new GenOp( " @ = float2( @.x, @.y + @ );\r\n", inUV, inUV, inUV, uvOffset)); output = meta; } Quote Link to comment Share on other sites More sharing options...
JeffR Posted November 30, 2015 Share Posted November 30, 2015 Very cool!Also, as a heads up, you can format a block of code via the code2 tags, like:Open the block with code2=cpp, for cpp-style syntax highlighting(with it in brackets, of course) and then close with /code2(also in brackets)Went ahead and did that for your post :) Quote Link to comment Share on other sites More sharing options...
Azaezel Posted November 30, 2015 Share Posted November 30, 2015 No. I'm on the road right now, always on the move. :) I will double check if everything gets initialized properly. I basically looked at how WindDeform and Visibility do it. Is there a way to Debug the Shaders through Torque? Through torque itself no, though (except for Macs. Because Apple.) If there's an error, you should get console spew if for whatever reason a generated shader is non-compiling. If it's tacking the code-inserts on right, I'd look to the variable pass-along chain. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.