Custom Material Process
by Joshua Horns · in Torque 3D Professional · 08/09/2009 (5:24 pm) · 24 replies
Do I have this process correct for applying materials to DTS?
1. Create a DTS object (in my case in Houdini).
1a. Attach a DTS material (call it theMat)
2a. Export the DTS object
The DTS exporter reports the names of all of the materials exported.
2. Create a singleton CustomMaterial( CustomMaterialName )
2a. mapTo="theMat"
2b. diffuseMap[0]= anyTextureIWant;
2c. shader=anyShaderIwant;
... more properties
For the life of me I can't get consistent results. Sometimes the custom materials don't seem to update the object in torque (especially when I don't use the name and location of texture referenced in Houdini). This is such a simple thing but I have spent all day on it. I thought as long as you "mapTo" the name of the exported material I could use any textures I wanted.
1. Create a DTS object (in my case in Houdini).
1a. Attach a DTS material (call it theMat)
2a. Export the DTS object
The DTS exporter reports the names of all of the materials exported.
2. Create a singleton CustomMaterial( CustomMaterialName )
2a. mapTo="theMat"
2b. diffuseMap[0]= anyTextureIWant;
2c. shader=anyShaderIwant;
... more properties
For the life of me I can't get consistent results. Sometimes the custom materials don't seem to update the object in torque (especially when I don't use the name and location of texture referenced in Houdini). This is such a simple thing but I have spent all day on it. I thought as long as you "mapTo" the name of the exported material I could use any textures I wanted.
About the author
#4
I thought mapTo pointed to the texture you specified in your material for the object and then you could use any texture you wanted as an input. The resulting material would then be applied to the texture you mapped to.
08/10/2009 (5:51 am)
The documentation for TGEA says mapTo is a requirement for custom materials, yet it's not used above...I thought mapTo pointed to the texture you specified in your material for the object and then you could use any texture you wanted as an input. The resulting material would then be applied to the texture you mapped to.
#6
** Of course a third possibility remains.. that I am doing something wrong.
The result from the custom material I posted above is that there is no texture applied.
Houdini's definition of DTS material is a combination of texture maps and other settings.
08/10/2009 (6:37 am)
You have explained it very well. This is exactly how I thought it was supposed to work. However, based on my experimentation, it does not work this way or it is broken.** Of course a third possibility remains.. that I am doing something wrong.
The result from the custom material I posted above is that there is no texture applied.
Houdini's definition of DTS material is a combination of texture maps and other settings.
#8
08/10/2009 (7:49 am)
Sounds like a plan. I'll try it when I get home. Maybe the custom material requires a shader. I intend to use a shader, but I wanted to test that I could make a change to the texture and see it update on the model first. Perhaps I need a pass thru shader for that.
#9
In theory with a normal material you could then use mapTo = "Stone"; to apply your material to that material of the mesh. This works for me when using a regular Material, I don't see that CustomMaterial should be any different.
08/10/2009 (9:59 am)
When he means that he exported a material he means that he mapped a named DTSMat SOP in Houdini to a part of his mesh. The exporter reports this like so:Shape Hierarchy:
Details:
detail2, Subtree 0, objectDetail 0, size 2
Subtrees:
Subtree 0
Ball2 --> Object Ball with following details: 2
Sequences:
Material list:
material #0: "Stone".In theory with a normal material you could then use mapTo = "Stone"; to apply your material to that material of the mesh. This works for me when using a regular Material, I don't see that CustomMaterial should be any different.
#10
08/10/2009 (4:08 pm)
OK so the material construct works flawlessly.. I'll try custom material again with a "pass through" shader
#11
*** I didn't see anything in the TGEA docs that pointed this out (although the entire page is about shaders)
*** This would be a great type of thing to cover to improve documentation at release. Ambiguity in documentation is my personal pet peeve. Although I guess the other 99% of people would have been able to infer the correct requirements from reading the page.
08/10/2009 (4:29 pm)
Yep if you don't include a shader in the custom material you get, in my case, a cube that is textured with what looks like the cube map for the skybox.*** I didn't see anything in the TGEA docs that pointed this out (although the entire page is about shaders)
*** This would be a great type of thing to cover to improve documentation at release. Ambiguity in documentation is my personal pet peeve. Although I guess the other 99% of people would have been able to infer the correct requirements from reading the page.
#12
"mapTo" is optional, but it is usually desired. If you export a model that uses a texture called "Rock" than Torque will use Rock.jpg/png/tga/bmp/etc if there is no material which uses 'Rock.jpg/png/etc' as a base texture. A material which has:
mapTo = "Rock";
Will trump all that.
08/10/2009 (5:33 pm)
Edit: Just realized that was not useful information."mapTo" is optional, but it is usually desired. If you export a model that uses a texture called "Rock" than Torque will use Rock.jpg/png/tga/bmp/etc if there is no material which uses 'Rock.jpg/png/etc' as a base texture. A material which has:
mapTo = "Rock";
Will trump all that.
#13
What I meant was just a shader that puts the texture on the material.
08/11/2009 (3:27 am)
I make up my own terms... =What I meant was just a shader that puts the texture on the material.
#14
This WILL shade my object with the original texture (if the texture exists in the directory), but I want to figure out how to pass different texture maps and eventually a distortion map to my shaders.
Script
Vertex Shader
Pixel Shader
08/11/2009 (3:55 am)
Can anyone tell me why my Custom Material is not mapping my texture to the DTS material? I suspect it has to do with the name of my sampler but I don't know what all the constants are for them.This WILL shade my object with the original texture (if the texture exists in the directory), but I want to figure out how to pass different texture maps and eventually a distortion map to my shaders.
Script
new ShaderData( SimpleShader )
{
DXVertexShaderFile = "shaders/common/simpleV.hlsl";
DXPixelShaderFile = "shaders/common/simpleP.hlsl";
samplerNames[0] = "$diffuseMap";
pixVersion = 2.0;
};
singleton CustomMaterial( doesntMapToPolka )
{
mapTo = "polka";
texture[0] = "/art/shapes/polka2";
shader = SimpleShader;
};Vertex Shader
//*****************************************************************************
// SimpleShader
//*****************************************************************************
#define IN_HLSL
#include "shdrConsts.h"
#include "hlslStructs.h"
struct Conn
{
float4 HPOS : POSITION;
float2 uv0 : TEXCOORD0;
};
uniform float4x4 modelview : register(VC_WORLD_PROJ);
//-----------------------------------------------------------------------------
// Main
//-----------------------------------------------------------------------------
Conn main( VertexIn_PT In )
{
Conn Out;
Out.HPOS = mul(modelview, In.pos);
Out.uv0 = In.uv0;
return Out;
}Pixel Shader
//*****************************************************************************
// Simple Pixel Shader
//*****************************************************************************
//-----------------------------------------------------------------------------
// Data
//-----------------------------------------------------------------------------
struct Conn
{
float4 HPOS : POSITION;
float2 uv0 : TEXCOORD0;
};
uniform sampler2D diffuseMap : register(S0);
struct Fragout
{
float4 col : COLOR0;
};
//-----------------------------------------------------------------------------
// Main
//-----------------------------------------------------------------------------
Fragout main(Conn IN)
{
Fragout OUT;
float4 base = tex2D(diffuseMap, IN.uv0);
OUT.col = base;
return OUT;
}
#15
08/11/2009 (5:58 am)
I "think" the concept I am missing is how do I map to the SamplerName from the custom material.
#16
08/11/2009 (6:08 am)
You have forgotten part of the semantics in both pixel and vertex shaders.
#17
Is this not mapping the output to color0?
Again, the shader works if the original polka file exists.(I can manipulate the uvs and watch the output change in the editor).
Please elaborate.
08/11/2009 (6:12 am)
float4 col : COLOR0; Is this not mapping the output to color0?
Again, the shader works if the original polka file exists.(I can manipulate the uvs and watch the output change in the editor).
Please elaborate.
#18
each shader (pixel or vertex) needs an input and output semantics.
msdn.microsoft.com/en-us/library/bb509647(VS.85).aspx
It is those structs Conn,VertexIn_PT,...
I don't know what you are trying to do in your shaders,but i see some of the semantics is missing.
08/11/2009 (12:09 pm)
Joshua,each shader (pixel or vertex) needs an input and output semantics.
msdn.microsoft.com/en-us/library/bb509647(VS.85).aspx
It is those structs Conn,VertexIn_PT,...
I don't know what you are trying to do in your shaders,but i see some of the semantics is missing.
#19
To the best of my knowledge, having the semantics attached to the structure members is acceptable.
Edit: I think the shaders are fine ... can anyone address the original question about why the above code isn't working? I really believe it's a problem with the Custom Material.
Edit Edit: wait.. maybe I do need to add the connect structure to the argument list of the vertex shader. You make me doubt myself!!
Edit Edit Edit: no... I think I have it right.
Can anyone address the problem above with the Custom Material? I have a hunch it's a sampler mapping problem.
08/11/2009 (12:16 pm)
Can anyone confirm or clarify what he's saying?To the best of my knowledge, having the semantics attached to the structure members is acceptable.
Edit: I think the shaders are fine ... can anyone address the original question about why the above code isn't working? I really believe it's a problem with the Custom Material.
Edit Edit: wait.. maybe I do need to add the connect structure to the argument list of the vertex shader. You make me doubt myself!!
Edit Edit Edit: no... I think I have it right.
Can anyone address the problem above with the Custom Material? I have a hunch it's a sampler mapping problem.
#20
i think you don't need the position (in Conn) in the pixel shader.
in the shader data you don't need:
samplerNames[0] = "$diffuseMap";
08/11/2009 (12:35 pm)
hmmm ok,i think you don't need the position (in Conn) in the pixel shader.
in the shader data you don't need:
samplerNames[0] = "$diffuseMap";
Torque 3D Owner Joshua Horns
Either this interface has changed from what is listed in the documentation... I have lost many IQ points... or some combination of the two.
I can't get it to work.
The material name exported from Houdini is "polka"
singleton CustomMaterial( wtf ) { mapTo = "polka"; texture[0] = "/art/shapes/polka"; //shader = HeatRefractVert; specularPower[0] = "32"; pixelSpecular[0] = "1"; };