TGEA Shader Constants Help
by Quentin Headen · in Torque Game Engine · 05/16/2008 (10:01 am) · 9 replies
Hello everyone! I want to make some shaders in TGEA. I would like an explanation of the shader constants with TGEA. I know how to pass World Vew Projection matrices to shaders in regular DirectX, but TGEA, I don't know which one to pass. For example, how would I get the World matrix in TGEA shaders? Please let me know.
Thanks.
Thanks.
About the author
Just your average programmer who tries to finish the projects he starts. :) I am currently focused on creating games with Torque engines. My website is http://phaseshiftsoftware.com
#2
You seem to be looking for the Obj->World transform. This matrix is stored, for each render instance, in the 'RenderInst::objXform' member. This matrix is stored in Torque (row major) format, so transpose as needed.
If you are looking for the World->Camera transform, that is set up, and pushed onto the world matrix stack in GuiTSCtrl::onRender.
05/16/2008 (11:02 am)
There are several cases where you want the world transform in a shader.You seem to be looking for the Obj->World transform. This matrix is stored, for each render instance, in the 'RenderInst::objXform' member. This matrix is stored in Torque (row major) format, so transpose as needed.
If you are looking for the World->Camera transform, that is set up, and pushed onto the world matrix stack in GuiTSCtrl::onRender.
#3
05/16/2008 (11:28 am)
Okay. I am used to making shaders in XNA. XNA makes you have to manualy feed Matrix data to the shader. I want to make a simple Diffuse lighting shader in TGEA. So how (in code) would I transform the model's normals into World space? And how would I get the light direction of the sun? Please let me know.
#4
In some examples I've seen in place of worldview they use modelView.
05/16/2008 (12:51 pm)
I'm been trying to find out the same stuff, but unfortunately nobody has yet gave me a direct answer. In some examples I've seen in place of worldview they use modelView.
#5
Thanks. :)
05/16/2008 (1:00 pm)
Yeah. I would like to know what constants in TGEA are the same in regular DirectX shaders. It is harder to know because Torque does all of the Matrix creation, and you don't know how it is creating it and what data is going where. It is easier when you are doing it yourself. So, if anyone has answers, please post it in this thread.Thanks. :)
#6
Object->World->Camera->Screen
The ModelViewProjection/WorldViewProjection refer to the same thing. It's the transform which moves from object space into screen space.
You could transform the model's normals into world space, which would mean that, for each vertex (or worse, pixel) you are doing a matrix multiply. A better solution would be to transform the light into object space.
05/16/2008 (1:04 pm)
Transforms work like this:Object->World->Camera->Screen
The ModelViewProjection/WorldViewProjection refer to the same thing. It's the transform which moves from object space into screen space.
You could transform the model's normals into world space, which would mean that, for each vertex (or worse, pixel) you are doing a matrix multiply. A better solution would be to transform the light into object space.
#7
05/16/2008 (1:06 pm)
Okay, I understand all of that. I have worked with shaders before. But, what variable names in the "shdrconst.h" file should I use to get these transforms?
#8
Look at 'ProcessedShaderMaterial::setObjectXForm'
05/16/2008 (1:22 pm)
VC_OBJ_TRANS is Object->World, you want World->Object, so you're going to have to edit the source, invert this transform, and then assign it to a shader constant. Look at 'ProcessedShaderMaterial::setObjectXForm'
#9
And you do not need the world transform for that.
05/17/2008 (11:28 am)
VC_LIGHT_DIR1 can be used for the sun's direction.And you do not need the world transform for that.
Torque Owner Ivan Mandzhukov
Liman3D