Welcome! Log In Create A New Profile

Advanced

[SOLVED] How do I properly setup multiple TEV stages?

Posted by TheCodingBrony 
[SOLVED] How do I properly setup multiple TEV stages?
August 10, 2015 04:18PM
I'm currently working on a test program that demonstrates environment mapping (such as chrome) and cel-shading through the use of Texture matrices and certain TexGen settings. I wanted to be able to render a texture mapped model with cel-shading through the use of the TEV to blend both textures together but I can't figure out how to do it properly at the moment.

What I want to do is to have my cel-shading texture blend over the model's base texture through the use of multiple TEV stages but I can't figure out how to do it properly. TexGens work properly but not the TEV stages as I always get bunch of black and white pixels jumbled all over the geometry. Am I missing some necessary parameters?

Here's some pseudo-code on how I setup the TEV stages before rendering the model:
GX_LoadTexObj(BarbTex.Texture.TexObj(), GX_TEXMAP0);
GX_LoadTexObj(CelTex.Texture.TexObj(), GX_TEXMAP1);

GX_SetNumTexGens(2);
GX_SetTexCoordGen(GX_TEXCOORD0, GX_TG_MTX2x4, GX_TG_TEX0, GX_IDENTITY);
GX_SetTexCoordGen(GX_TEXCOORD1, GX_TG_SRTG, GX_TG_COLOR0, GX_IDENTITY);

GX_SetNumTevStages(2);
GX_SetTevOrder(GX_TEVSTAGE0, GX_TEXCOORD0, GX_TEXMAP0, GX_COLOR0A0);
GX_SetTevOrder(GX_TEVSTAGE1, GX_TEXCOORD1, GX_TEXMAP1, GX_COLOR0A0);

object.RenderModel();

I can't really release the full source code as it uses MTek-GDL and is a tad bit cluttered up but I can release it if the full source is absolutely necessary for solving this problem.

Any useful help will be gladly appreciated! And no, don't discourage me from finding a way on how to use TEV stages properly as I want to make Wii homebrew that would look pretty as ever in the future.



Edited 1 time(s). Last edit at 09/13/2015 06:17AM by TheCodingBrony.
Re: How do I properly setup multiple TEV stages?
August 11, 2015 04:21AM
found this sometime ago. its in Spanish be easy to translate;

[www.elotrolado.net]
Re: How do I properly setup multiple TEV stages?
August 11, 2015 05:09AM
That is just what I needed! I'll post a message once I figure out how to setup multiple TEVs which should be easier to figure out now that I have that precious bit of example code.
Re: How do I properly setup multiple TEV stages?
August 12, 2015 03:24AM
Okay, I finally figured it out... Here's how you modulate a texture based on another texture's color intensities which is what I needed to do cel-shading with texture mapping:
/* NOTE: Set a working light source so that GX_TG_SRTG will work correctly */

// Texture mapped with Cel-shading (using 2 TEV stages)
GX_LoadTexObj(BarbTex.Texture.TexObj(), GX_TEXMAP0); // Load model texture to GX_TEXMAP0
GX_LoadTexObj(CelTex.Texture.TexObj(), GX_TEXMAP1);  // Load cel shader texture to GX_TEXMAP1

// Prepare TexGens for cel-shading and texture mapping
GX_SetNumTexGens(2);
GX_SetTexCoordGen(GX_TEXCOORD0, GX_TG_MTX2x4, GX_TG_TEX0, GX_IDENTITY); // Model texture coords
GX_SetTexCoordGen(GX_TEXCOORD1, GX_TG_SRTG, GX_TG_COLOR0, GX_IDENTITY); // For cel-shading


// Set TEV stages for cel shading with texture mapping
GX_SetNumTevStages(2);


// Prepare TEV stage 0 (cel texture)
GX_SetTevOrder(GX_TEVSTAGE0, GX_TEXCOORD1, GX_TEXMAP1, GX_COLORNULL);

// Get TEV color input to texture color
GX_SetTevColorIn(GX_TEVSTAGE0, GX_CC_TEXC, GX_CC_C0, GX_CC_ZERO, GX_CC_ZERO);

// We don't need the alpha channel of the cel texture as we'll be modulating its intensity to the model's texture
GX_SetTevAlphaIn(GX_TEVSTAGE0, GX_CA_ZERO, GX_CA_ZERO, GX_CA_ZERO, GX_CA_ZERO);

// Set TEV operators to ADD and use default bias and scale values
GX_SetTevColorOp(GX_TEVSTAGE0, GX_TEV_ADD, GX_TB_ZERO, GX_CS_SCALE_2, GX_TRUE, GX_TEVPREV);
GX_SetTevAlphaOp(GX_TEVSTAGE0, GX_TEV_ADD, GX_TB_ZERO, GX_CS_SCALE_2, GX_TRUE, GX_TEVPREV);

// We'll be ignoring vertex colors since we're going for cel shading based on a texture map so we'll just use GX_REPLACE
GX_SetTevOp(GX_TEVSTAGE0, GX_REPLACE);


// Prepare TEV stage 1 (model texture)
GX_SetTevOrder(GX_TEVSTAGE1, GX_TEXCOORD0, GX_TEXMAP0, GX_COLOR0A0);

// Take color and alpha values from texture
GX_SetTevColorIn(GX_TEVSTAGE1, GX_CC_TEXC, GX_CC_C0, GX_CC_ZERO, GX_CC_ZERO);
GX_SetTevAlphaIn(GX_TEVSTAGE1, GX_CA_TEXA, GX_CA_A0, GX_CA_ZERO, GX_CA_ZERO);

// Same operator values as TEV stage 0
GX_SetTevColorOp(GX_TEVSTAGE1, GX_TEV_ADD, GX_TB_ZERO, GX_CS_SCALE_1, GX_TRUE, GX_TEVPREV);
GX_SetTevAlphaOp(GX_TEVSTAGE1, GX_TEV_ADD, GX_TB_ZERO, GX_CS_SCALE_1, GX_TRUE, GX_TEVPREV);

// Modulate the final pixel color relative to the cel shader texture
GX_SetTevOp(GX_TEVSTAGE1, GX_MODULATE);


// Render model (must have normals)
object.RenderModel();

And here's the result (model on the top left is chrome/reflection mapped, top right is cel-shaded and the one on the bottom is cel-shaded with texture mapping through 2 TEV stages):



Full example of this test program will be included in the next release of MTek-GDL...
Re: How do I properly setup multiple TEV stages?
August 12, 2015 04:28AM
Will u attempt to do shadows?
Re: How do I properly setup multiple TEV stages?
August 12, 2015 05:41AM
Eventually... The spanish example you provided demonstrates drop shadows if you really wanna know how to do it.



Edited 1 time(s). Last edit at 08/12/2015 05:42AM by TheCodingBrony.
Re: How do I properly setup multiple TEV stages?
August 13, 2015 04:31AM
You've got a fair bit of redundant code in there.
GX_SetTevOp() is just an easy wrapper to avoid manually calling all of GX_SetTevAlphaIn() + GX_SetTevColorIn() + GX_SetTevAlphaOp() + GX_SetTevColorOp(), so it's pointless to call them all before it.
You're enabling the raster input channels for tev stage 1 (GX_COLOR0A0) but it's not being used as an input.
Sorry, only registered users may post in this forum.

Click here to login