[Help] T3D - Align Shader Inputs
by Aldavidson · in Torque 3D Professional · 05/19/2009 (8:25 am) · 6 replies
Can anyone help me "align" the inputs of this Vertex shader with TSE? It is actually the post_glowBalloon effect from the Nvidia shader labs.
My problem is that i dont know what to set these too, so that they work in the TSE:
The original Vertex shader looks like this (with all the Pixel shader stuff taken out). And it is the Vertex shader that is playing up, aka not working as it should, it compiles fine tho xD.
Just for continuity here is the pixel shader (which has not been modified).
And the ShaderStateBlock
And the Shader Deffinition
And the Material
Thanks for the help as usual guys =]
My problem is that i dont know what to set these too, so that they work in the TSE:
// transform object vertices to world-space: float4x4 gWorldXf : World ; // transform object normals, tangents, & binormals to world-space: float4x4 gWorldITXf : WorldInverseTranspose ; // transform object vertices to view space and project them in perspective: float4x4 gWvpXf : WorldViewProjection ; //sdhrConsts has a a reference to this!!!! // provide tranform from "view" or "eye" coords back to world-space: float4x4 gViewIXf : ViewInverse ;
The original Vertex shader looks like this (with all the Pixel shader stuff taken out). And it is the Vertex shader that is playing up, aka not working as it should, it compiles fine tho xD.
http://developer.nvidia.com/forums/
*******************************************************************************
******************************************************************************/
/**** UNTWEAKABLES: Hidden & Automatically-Tracked Parameters **********/
// transform object vertices to world-space:
float4x4 gWorldXf : World ;
// transform object normals, tangents, & binormals to world-space:
float4x4 gWorldITXf : WorldInverseTranspose ;
// transform object vertices to view space and project them in perspective:
float4x4 gWvpXf : WorldViewProjection ;
// provide tranform from "view" or "eye" coords back to world-space:
float4x4 gViewIXf : ViewInverse ;
// color and depth used for full-screen clears
float4 gClearColor = {0,0,0,0};
float gClearDepth = 1.0;
/************* TWEAKABLES **************/
float gInflate = 0.06;
float3 gGlowColor = {1.0f, 0.9f, 0.3f};
float gGlowExpon = 1.3;
///////////////////////////////////
/* data from application vertex buffer */
struct appdata {
float3 Position : POSITION;
float4 UV : TEXCOORD0;
float4 Normal : NORMAL;
float4 Tangent : TANGENT0;
float4 Binormal : BINORMAL0;
};
/* data passed from vertex shader to pixel shader */
struct gloVertOut {
float4 HPosition : POSITION;
float3 WorldNormal : TEXCOORD0;
float3 WorldView : TEXCOORD1;
};
/*********** vertex shader ******/
gloVertOut main(appdata IN,
uniform float Inflate,
uniform float4x4 WorldITXf, // our four standard "untweakable" xforms
uniform float4x4 WorldXf,
uniform float4x4 ViewIXf,
uniform float4x4 WvpXf
) {
gloVertOut OUT = (gloVertOut)0;
OUT.WorldNormal = mul(IN.Normal,WorldITXf).xyz;
float4 Po = float4(IN.Position.xyz,1);
Po += (Inflate*normalize(float4(IN.Normal.xyz,0))); // the balloon effect
float4 Pw = mul(Po,WorldXf);
OUT.WorldView = normalize(ViewIXf[3].xyz - Pw.xyz);
OUT.HPosition = mul(Po,WvpXf);
return OUT;
}Just for continuity here is the pixel shader (which has not been modified).
/**** UNTWEAKABLES: Hidden & Automatically-Tracked Parameters **********/
// transform object vertices to world-space:
float4x4 gWorldXf : World ;
// transform object normals, tangents, & binormals to world-space:
float4x4 gWorldITXf : WorldInverseTranspose ;
// transform object vertices to view space and project them in perspective:
float4x4 gWvpXf : WorldViewProjection ;
// provide tranform from "view" or "eye" coords back to world-space:
float4x4 gViewIXf : ViewInverse ;
// color and depth used for full-screen clears
float4 gClearColor = {0,0,0,0};
float gClearDepth = 1.0;
/************* TWEAKABLES **************/
float gInflate = 0.06;
float3 gGlowColor = {1.0f, 0.9f, 0.3f};
float gGlowExpon = 1.3;
///////////////////////////////////
/* data passed from vertex shader to pixel shader */
struct gloVertOut {
float4 HPosition : POSITION;
float3 WorldNormal : TEXCOORD0;
float3 WorldView : TEXCOORD1;
};
/********* pixel shaders ********/
float4 main(gloVertOut IN,
uniform float3 GlowColor,
uniform float GlowExpon
) : COLOR {
float3 Nn = normalize(IN.WorldNormal);
float3 Vn = normalize(IN.WorldView);
float edge = 1.0 - dot(Nn,Vn);
edge = pow(edge,GlowExpon);
float3 result = edge * GlowColor.rgb;
return float4(result,edge);
}And the ShaderStateBlock
singleton GFXStateBlockData( AtmosphereStateBlock )
{
blendDefined = true;
blendEnable = true;
blendSrc = GFXBlendSrcAlpha;
blendDest = GFXBlendInvSrcAlpha; //blenddest = one?
zDefined = true;
zEnable = false;
zWriteEnable = false;
};And the Shader Deffinition
new ShaderData( Atmosphere )
{
DXVertexShaderFile = "shaders/common/planet_atmosphere/atmosV.hlsl";
DXPixelShaderFile = "shaders/common/planet_atmosphere/atmosP.hlsl";
pixVersion = 2.0;
};And the Material
singleton CustomMaterial( CloudLayerMaterial2 ) //custom shaders only work on custom materials!!
{
mapTo = "_7_-_Default-material";
shader = Atmosphere;
stateBlock = AtmosphereStateBlock;
version = 2.0;
};Thanks for the help as usual guys =]
#2
// transform object vertices to world-space:
float4x4 gWorldXf : World ;
Should be named...
uniform float4x4 modelMat;
// transform object normals, tangents, & binormals to world-space:
float4x4 gWorldITXf : WorldInverseTranspose ;
Not sure if this exists, I think it would be like the modelMat
but without the position.
// transform object vertices to view space and project them in perspective:
float4x4 gWvpXf : WorldViewProjection ;
// Should be named...
uniform float4x4 modelView;
// provide tranform from "view" or "eye" coords back to world-space:
float4x4 gViewIXf : ViewInverse ;
CustomMaterial probably has a shaderconst it looks for, for this too, if so its going to be in the same place it sets the others.
I recommend stepping into where it calls setupPass, down as low as you can until you see it trying to set shaderConsts. Note that you can set your own (which CloudLayer is doing) but some of these common ones that all shaders/materials tend to need are already done for you.
05/22/2009 (2:48 am)
CustomMaterial will set some shaderconsts like these for you when you call setupPass if you name them what torque expects in the shader and pass the right data in to setup pass.// transform object vertices to world-space:
float4x4 gWorldXf : World ;
Should be named...
uniform float4x4 modelMat;
// transform object normals, tangents, & binormals to world-space:
float4x4 gWorldITXf : WorldInverseTranspose ;
Not sure if this exists, I think it would be like the modelMat
but without the position.
// transform object vertices to view space and project them in perspective:
float4x4 gWvpXf : WorldViewProjection ;
// Should be named...
uniform float4x4 modelView;
// provide tranform from "view" or "eye" coords back to world-space:
float4x4 gViewIXf : ViewInverse ;
CustomMaterial probably has a shaderconst it looks for, for this too, if so its going to be in the same place it sets the others.
I recommend stepping into where it calls setupPass, down as low as you can until you see it trying to set shaderConsts. Note that you can set your own (which CloudLayer is doing) but some of these common ones that all shaders/materials tend to need are already done for you.
#3
05/22/2009 (2:51 am)
You are also going to need to prefix your globals with "static".
#4
What does that syntax even mean... " : World"... is World defined as a register somewhere or what is it?
Yeah, I probably shouldn't have tried... don't know enough myself.
05/22/2009 (2:58 am)
Actually, it looks like that shader is already passing in those matrices as uniforms, so I don't know what those globals are suppose to be.... What does that syntax even mean... " : World"... is World defined as a register somewhere or what is it?
Yeah, I probably shouldn't have tried... don't know enough myself.
#5
well all these global variables are just variables defined in FX Composer, i imagine they are registers, but i cant seem to find out what they are registered too >.<
i *think* the syntax;
I thought TSE has everything in local object space or something, and all these variables talk about world space so i am allmightily confused xD
05/22/2009 (3:19 am)
Thanks for the input james, where does the code call setupPass?well all these global variables are just variables defined in FX Composer, i imagine they are registers, but i cant seem to find out what they are registered too >.<
i *think* the syntax;
float4x4 gWorldXf : World ;means create a float4x4 call it gWorld and give it the same value as the World register...
I thought TSE has everything in local object space or something, and all these variables talk about world space so i am allmightily confused xD
#6
Normal objects do pass their verts to the shader in object space, but this is really dependent on the individual object. The cloud layer for example renders in camera-space.
This shader looks like it is working in a similar way. The "World" part of the matrix names is meaning "the matrix transforms 'into' world space".
Rendering itself doesn't happen in world space it happens in screen space "always". So if the verts come in, in object space, they have to go on the object -> world -> screen ride.
05/22/2009 (1:02 pm)
I'm referring to CloudLayer::prepRenderImage where it calls setupPass on the material instance.Normal objects do pass their verts to the shader in object space, but this is really dependent on the individual object. The cloud layer for example renders in camera-space.
This shader looks like it is working in a similar way. The "World" part of the matrix names is meaning "the matrix transforms 'into' world space".
Rendering itself doesn't happen in world space it happens in screen space "always". So if the verts come in, in object space, they have to go on the object -> world -> screen ride.
Torque 3D Owner Aldavidson