outlining
by David Horn · in Torque X 2D · 07/25/2009 (8:12 pm) · 12 replies
Could someone help me out? I have a t2dshape3d and it's so flat looking since there is no basic lighting available, I'd like to at least outline it.
I have found some tutorials on toon, outlining, and other .fx examples, but it all deals with specific meshes and models overriding the Draw function and so far I don't think it can be specifically done with the t2dshape3d.
basically like the cartoon shading or especially the edge enhancement of:
creators.xna.com/en-US/sample/nonrealisticrendering
Would I be able to add an outlining post-processing affect on the t2dshape3d or on the meshes of the t2dshape3d?
I have found some tutorials on toon, outlining, and other .fx examples, but it all deals with specific meshes and models overriding the Draw function and so far I don't think it can be specifically done with the t2dshape3d.
basically like the cartoon shading or especially the edge enhancement of:
creators.xna.com/en-US/sample/nonrealisticrendering
Would I be able to add an outlining post-processing affect on the t2dshape3d or on the meshes of the t2dshape3d?
About the author
#2
07/27/2009 (8:44 am)
Well I tried, but the T2DShape3D is looking for a material and I think I have to use the SimpleMaterial. so it doesn't look promising.
#3
Maybe it will help you
09/03/2009 (8:53 pm)
Was looking for shader stuff and saw this: tdn.garagegames.com/wiki/TorqueX/CustomMaterialsMaybe it will help you
#4
I looked through that and I think my problem is that it gets back to the fact that you have to use a SimpleMaterial and T2DShape3D just uses the "material"
I don't know how to apply a custom shader to the T2DShape3D
09/03/2009 (9:30 pm)
Thanks man,I appreciate it.I looked through that and I think my problem is that it gets back to the fact that you have to use a SimpleMaterial and T2DShape3D just uses the "material"
I don't know how to apply a custom shader to the T2DShape3D
#5
Oh, here's the post...
www.garagegames.com/community/forums/viewthread/68777
John K.
www.envygames.com
09/03/2009 (9:49 pm)
The SimpleMaterial will only use the SimpleEffect shader. To use a custom shader, you need to use the GenericMaterial. I wrote an earlier post about this somewhere in the forums. The GenericMaterial is mapped to the shape by way of the texture filename. So, if BigWrestler.dts has a BigWrestler.png diffuse texture, then you would creata a new GenericMaterial definition that points to the BigWrestler.png file and sets the properties of the custom shader. Oh, here's the post...
www.garagegames.com/community/forums/viewthread/68777
John K.
www.envygames.com
#6
So let me see if I get this conceptually before I dive into the code, because my guess is, it's going to be just too much work both on me and the processor the way I have it set up.
For my wrestler BigWrestler.dts, he doesn't have just BigWrestler.png diffuse texture. he is broken up into roughly 20 different materials in the material list. This way, I can have a customizing create-a-wrestler feature. So the user can determine that material[2] (the face) will be set to face01.png, face02.png,face03.png...etc.
John, based on your post, do I have to have 200 GenericMaterials for all 200 png files that represent the create-a-wrestler parts so that all of them would have a black outline?
Or do I tell each of the 20 materials in the material list to use a particular GenericMaterial?
09/04/2009 (10:40 am)
Thank you both for your help. And I found a toon outline fx file on the nVidia site.So let me see if I get this conceptually before I dive into the code, because my guess is, it's going to be just too much work both on me and the processor the way I have it set up.
For my wrestler BigWrestler.dts, he doesn't have just BigWrestler.png diffuse texture. he is broken up into roughly 20 different materials in the material list. This way, I can have a customizing create-a-wrestler feature. So the user can determine that material[2] (the face) will be set to face01.png, face02.png,face03.png...etc.
//if they select face number 1...
T2DShape3D shape = (T2DShape3D)TorqueObjectDatabase.Instance.FindObject("wrestler");
Material m = new Material();
m.Name = "face01.png";
shape.Shape.MaterialList[20] = m;John, based on your post, do I have to have 200 GenericMaterials for all 200 png files that represent the create-a-wrestler parts so that all of them would have a black outline?
Or do I tell each of the 20 materials in the material list to use a particular GenericMaterial?
#7
John K.
www.envygames.com
09/04/2009 (12:58 pm)
Hmmm, I didn't realize that. I'll need to see the shader itself, I'll follow the links you've posted earlier. If these are really material shaders, then this wont work as each material will be outlined separately. And if this is a full-screen post-process shader effect, then the custom material definition that I described earlier is not relevant - instead you need to create a PostProcessor derrived class.John K.
www.envygames.com
#8
www.homebrewwrestling.com/scene_toonEdges.zip
It said that it was a toon outline, but i can't even confirm that because it didn't have a really clear thumbnail.
The other one on that page that I thought might do the trick is the glow effect, and then maybe just have the glow color set to black. But I chose this one instead.
Would the PostProcessor class be able to only effect T2DShape3D objects? the rest of the items on my screen already have a black stroke.
09/04/2009 (2:29 pm)
And this is the actual shader that I downloaded from the nVidia site:www.homebrewwrestling.com/scene_toonEdges.zip
It said that it was a toon outline, but i can't even confirm that because it didn't have a really clear thumbnail.
The other one on that page that I thought might do the trick is the glow effect, and then maybe just have the glow color set to black. But I chose this one instead.
Would the PostProcessor class be able to only effect T2DShape3D objects? the rest of the items on my screen already have a black stroke.
#9
and change the PixelLightingTechnique3_0 technique to
if you are using normal maps and or specular maps you also need to change those techniques also
*EDIT*
Removed the PixelShader = NULL line in the first Pass
09/05/2009 (8:03 am)
Here's a mod for the LightingEffect3D.fx file. It'll only affect the T2DShape3D objects since it's only used for them, as far as I know. Just add the code to the Per Pixel Lighting Sectionstruct PixelOutlineInput
{
float4 Position : POSITION;
float4 Normal : NORMAL;
};
struct PixelOutlineOutput
{
float4 Position : POSITION;
float3 Normal : TEXCOORD4;
float4 Diffuse : COLOR;
};
PixelOutlineOutput PixelOutlineVS(PixelOutlineInput input)
{
PixelOutlineOutput output;
// Offset value controls the line thickness
float offset = 0.5;
output.Normal = normalize(mul(input.Normal, (float3x3)_worldMatrix));
output.Position = mul(input.Position, _worldViewProjectionMatrix) + mul(offset, mul(input.Normal, _worldViewProjectionMatrix));
// Line color
output.Diffuse = float4(0, 0, 0, 1);
return output;
}and change the PixelLightingTechnique3_0 technique to
pass P0
{
CullMode = CW;
VertexShader = compile vs_3_0 PixelOutlineVS();
}
pass P1
{
CullMode = NONE;
VertexShader = compile vs_3_0 PixelLightingVS(false);
PixelShader = compile ps_3_0 PixelLightingPS(8, false, false);
}if you are using normal maps and or specular maps you also need to change those techniques also
*EDIT*
Removed the PixelShader = NULL line in the first Pass
#10
I implemented the code above and when I load in the shape, i get an error on this line of code in the baserendermanager.cs file:
the error is:
System.InvalidOperationException was unhandled
Message="Both a valid vertex shader and pixel shader (or valid effect) must be set on the device before any draw operations may be performed."
EDIT:
I believe it has something to do with the PixelShader = NULL; on the first pass.
09/05/2009 (11:38 am)
Alex,I implemented the code above and when I load in the shape, i get an error on this line of code in the baserendermanager.cs file:
d3d.DrawIndexedPrimitives(ri.PrimitiveType, ri.BaseVertex, 0, ri.VertexCount, ri.StartIndex, ri.PrimitiveCount);
the error is:
System.InvalidOperationException was unhandled
Message="Both a valid vertex shader and pixel shader (or valid effect) must be set on the device before any draw operations may be performed."
EDIT:
I believe it has something to do with the PixelShader = NULL; on the first pass.
#11
*EDIT*
Ok, got the error, yeah the PixelShader = NULL was the problem, deleted that line and I stopped getting the error. Sorry about that...
09/05/2009 (6:49 pm)
I'll check it out, but it seems to be working on my end*EDIT*
Ok, got the error, yeah the PixelShader = NULL was the problem, deleted that line and I stopped getting the error. Sorry about that...
#12
02/15/2010 (2:00 pm)
Sorry to bump such an old post, but I just tried to implement this with a new model, and the black outline is only happening with one of the meshes within my model. The hair. Any idea why that might happen?
Torque Owner Lucas Shinkovich
I don't know know much about the technical details of T2DShape3D's implementation, however I believe the non-realistic rendering technique is all done in the shader.
You should be able to do all of the shader work within a custom material and then apply that material to your T2DShape3D to give it your effect.
In my current game, I actually have a custom full screen postprocessing shockwave / exposion effect that currently works in Torque X (still figuring out problems with it on Xbox 360 though). So if you have trouble hooking the shader up in Torque, let me know.