Help TGEA creating a new shader
by Yves Albuquerque · in Torque Game Engine Advanced · 03/10/2008 (11:41 am) · 3 replies
Hello,
I Have the following vertex shader that i am trying to put on TGEA
#define IN_HLSL
#include "shdrConsts.h"
struct VS_INPUT
{
float4 Position : POSITION0;
float2 Texcoord : TEXCOORD0;
float3 Normal : NORMAL0;
float3 Binormal : BINORMAL0;
float3 Tangent : TANGENT0;
};
struct VS_OUTPUT
{
float4 Position : POSITION0;
float2 Texcoord : TEXCOORD0;
float3 ViewDirection : TEXCOORD1;
float3 LightDirection: TEXCOORD2;
};
VS_OUTPUT vs_main( VS_INPUT Input ,
float3 fvLightPosition :register(VC_LIGHT_POS1),
float3 fvEyePosition :register(VC_EYE_POS),
float4x4 matView,
float4x4 matViewProjection :register(VC_WORLD_PROJ))
{
VS_OUTPUT Output;
Output.Position = mul( Input.Position, matViewProjection );
Output.Texcoord = Input.Texcoord;
float3 fvObjectPosition = mul( Input.Position, matView );
float3 fvViewDirection = fvEyePosition - fvObjectPosition;
float3 fvLightDirection = fvLightPosition - fvObjectPosition;
float3 fvNormal = mul( Input.Normal, matView );
float3 fvBinormal = mul( Input.Binormal, matView );
float3 fvTangent = mul( Input.Tangent, matView );
Output.ViewDirection.x = dot( fvTangent, fvViewDirection );
Output.ViewDirection.y = dot( fvBinormal, fvViewDirection );
Output.ViewDirection.z = dot( fvNormal, fvViewDirection );
Output.LightDirection.x = dot( fvTangent, fvLightDirection );
Output.LightDirection.y = dot( fvBinormal, fvLightDirection );
Output.LightDirection.z = dot( fvNormal, fvLightDirection );
return( Output );
}
I have some doubts
-How do i get the matView (the view matrix) from the TGEA??
-Does the TGEA provide the float3 Normal : NORMAL0
and float3 Binormal : BINORMAL0
and float3 Tangent : TANGENT0 ???
Thanks
I Have the following vertex shader that i am trying to put on TGEA
#define IN_HLSL
#include "shdrConsts.h"
struct VS_INPUT
{
float4 Position : POSITION0;
float2 Texcoord : TEXCOORD0;
float3 Normal : NORMAL0;
float3 Binormal : BINORMAL0;
float3 Tangent : TANGENT0;
};
struct VS_OUTPUT
{
float4 Position : POSITION0;
float2 Texcoord : TEXCOORD0;
float3 ViewDirection : TEXCOORD1;
float3 LightDirection: TEXCOORD2;
};
VS_OUTPUT vs_main( VS_INPUT Input ,
float3 fvLightPosition :register(VC_LIGHT_POS1),
float3 fvEyePosition :register(VC_EYE_POS),
float4x4 matView,
float4x4 matViewProjection :register(VC_WORLD_PROJ))
{
VS_OUTPUT Output;
Output.Position = mul( Input.Position, matViewProjection );
Output.Texcoord = Input.Texcoord;
float3 fvObjectPosition = mul( Input.Position, matView );
float3 fvViewDirection = fvEyePosition - fvObjectPosition;
float3 fvLightDirection = fvLightPosition - fvObjectPosition;
float3 fvNormal = mul( Input.Normal, matView );
float3 fvBinormal = mul( Input.Binormal, matView );
float3 fvTangent = mul( Input.Tangent, matView );
Output.ViewDirection.x = dot( fvTangent, fvViewDirection );
Output.ViewDirection.y = dot( fvBinormal, fvViewDirection );
Output.ViewDirection.z = dot( fvNormal, fvViewDirection );
Output.LightDirection.x = dot( fvTangent, fvLightDirection );
Output.LightDirection.y = dot( fvBinormal, fvLightDirection );
Output.LightDirection.z = dot( fvNormal, fvLightDirection );
return( Output );
}
I have some doubts
-How do i get the matView (the view matrix) from the TGEA??
-Does the TGEA provide the float3 Normal : NORMAL0
and float3 Binormal : BINORMAL0
and float3 Tangent : TANGENT0 ???
Thanks
About the author
#2
>>Yes, TGEA provides the TBN space.
To get from torque the TBN I have to change the original:
float3 Normal : NORMAL0;
float3 Binormal : BINORMAL0;
float3 Tangent : TANGENT0;
to: (copied from a shader that comes with TGEA)
float4 normal : NORMAL;
float3 T : TEXCOORD2;
float3 B : TEXCOORD3;
float3 N : TEXCOORD4;
Is T the tangent??
Is B the Binormal??
Is N the normal?? If it is whats the diference between the float4 normal and the float3 N???
Also,
>>You can get the view direction that way:
>>Output.viewdir = EyePos - ObjectPos;
but to calculate the viewdir i need the matview
float3 fvObjectPosition = mul( Input.Position, matView );
03/13/2008 (7:54 am)
Thanks for the reply... >>Yes, TGEA provides the TBN space.
To get from torque the TBN I have to change the original:
float3 Normal : NORMAL0;
float3 Binormal : BINORMAL0;
float3 Tangent : TANGENT0;
to: (copied from a shader that comes with TGEA)
float4 normal : NORMAL;
float3 T : TEXCOORD2;
float3 B : TEXCOORD3;
float3 N : TEXCOORD4;
Is T the tangent??
Is B the Binormal??
Is N the normal?? If it is whats the diference between the float4 normal and the float3 N???
Also,
>>You can get the view direction that way:
>>Output.viewdir = EyePos - ObjectPos;
but to calculate the viewdir i need the matview
float3 fvObjectPosition = mul( Input.Position, matView );
#3
I can draw it on a paper, it is a simple vector math.
In TBN you need to mul that direction with the tbnMatrix to get in its space.
Yes, TBN = Tangent, Binormal, Normal.
Look at that shader how the TBN space is passed :
www.garagegames.com/blogs/5030/8346
03/16/2008 (11:50 am)
View_direction = Eye_Position - Object_Position.I can draw it on a paper, it is a simple vector math.
In TBN you need to mul that direction with the tbnMatrix to get in its space.
Yes, TBN = Tangent, Binormal, Normal.
Look at that shader how the TBN space is passed :
www.garagegames.com/blogs/5030/8346
Torque Owner Ivan Mandzhukov
Liman3D
view transform and eye transform is the same.
You can use VC_EYE_POS (in object space) or VC_CUBE_EYE_POS (in cubemap space).
You can get the view direction that way:
Output.viewdir = EyePos - ObjectPos;