Game Development Community

How to apply a shader to a dts

by Nigel Hungerford-Symes · in Torque Game Engine Advanced · 05/10/2006 (5:09 am) · 3 replies

Ok I've searched and looked around but no luck - I only have a couple of hours after work so humour me and point me to a post, tutorial etc that shows how to apply a texture to a DTS object.

I did find a forum post but it was 2004 and out of date.

TDN has a great (but slightly out of date) article showing how to get a shader from RenderMonkey to Torque but falls short telling you how to actually apply it to anything.

What line of code where do I change in what .cs?

#1
05/10/2006 (7:37 am)
I haven't been thru the entire process of this yet as im still stuck in the code but i think its done
automaticly if you put it in the material editor of 3dsmax (applying it to your mesh (dts), naming the material correctly), or else it would be set in the script for this object. Check old documentation about exporting/importing DTS and refer to a sample script to check if there isnt a line refering to the shader.

i know this might not be the actual "answer" to your problem, but you never know if youll get replies
here, so if youre stuck at finding it yourself... this could help-
#2
05/10/2006 (8:02 am)
OK. I'll try to explain and give a quick example. Shaders are applied to materials.
* client/scripts/shaders.cs contains a list of shaders available to use(HLSL files in the shaders folder). This is where you would place code to load any custom HLSL (shader) files that you have created. It already has many shaders already delivered by GG.
* you will notice that a materials.cs file exists in several folders. This is where we map a texture to a material and define the properties of the shader for each matrial. Open data\shapes\spaceOrc\materials.cs. This file
shows how to map a texture to a regular material(not custom material). The space orc has bump, glow, emissive... All kinds of shaders applied to different textures.

new Material(OrcSkin)
{
   baseTex[0] = "~/data/shapes/spaceOrc/orc_ID1_skin";
   bumpTex[0] = "~/data/shapes/spaceOrc/orc_ID1_skin_bump";
   pixelSpecular[0] = true;
   specular[0] = "1.0 1.0 1.0 1.0";
   specularPower[0] = 4.0;
   refract = true;

};
you will find a list of the delivered shader properties here

if you want to apply a custom shader, you must:
1. create the HLSL files and place them in the shaders folder.
2. Then define the shader in clinet/scripts/shaders.cs.
3. Then create a custom material that uses that custom shader(material.cs in a folder where your texture exists)
I suggest using this resource for learning custom shader basics. here's what your custom shader mapping should look like:
new CustomMaterial(OrcSkin)
{
	mapTo = orc_ID1_skin;
	texture[0] = "~/data/shapes/spaceOrc/orc_ID1_skin";
	shader = redShader;
	version = 1.1;
};
if you need the red shader redShaderV.hlsl and redShaderP.hlsl. This is the vertext and pixel shader from one of the resources here. Save these to examples/shaders folder.

hope that helps
#3
05/18/2006 (5:47 am)
Thanks very much, I got it working and I think I understand now how Torque compiles in the shaders.

Thanks again,

Nigel