Game Development Community

Shader questions

by David Aiken · in Technical Issues · 02/04/2009 (12:04 am) · 2 replies

I'm implementing a shader and have a few questions which don't seem to be covered by the 1.8.0 "Materials and Shaders" docs.. any help would be appreciated.

I see variables declared as follows:

float4x4 modelview : register(VC_WORLD_PROJ);

and as follows:

v2f main(a2v In, uniform float4x4 modelview : register(VC_WORLD_PROJ))
{
};

Is there any difference in semantics? I'm guessing not based on the Direct3D docs at http://msdn.microsoft.com/en-us/library/bb509706(VS.85).aspx - "global variables are considered uniform by default."


I'm also wondering how to properly transform normals from object to view space. In shdrConsts.h there is a VC_WORLD_PROJ. I think i need the transpose(inverse(register(VC_WORLD_PROJ))).. if so, how do i get it? This may be moot since I think in this case it is ok to assume that the matrix is orthogonal (no non-uniform scaling).


In this case i only have one light source (the sun) and i need its position. Is this VC_LIGHT_POS1? Is this in world space? Just curious, but does VC_LIGHT_TRANS move from world to light space? I think shdrConsts.h is intended to be an interface, but the version i'm looking at from 1.8.0 lacks a description of what the variables do.

In shaders.cs i see declarations like:

samplerNames[1] = "$Amap2D";
samplerNames[2] = "$BmapCube";
samplerNames[3] = "$Cmap2D";

then, in the pixel shader:

float4 main(v2f In,
uniform sampler A : register(S1),
uniform samplerCUBE B : register(S2),
uniform sampler C : register(S3))

It seems there is an assumption that S1.. registers are assigned to the samplers. Is this so? If someone can point me to the documentation it would be appreciated. Maybe in the class reference?

#1
02/13/2009 (12:03 am)
I think I'm getting the hang of it. At this point the best approach i've found is to dive into the existing engine code (C++).
#2
02/16/2009 (10:23 am)
Well.. the CustomMaterial implementation doesn't surface a high-level interface to modify shader parameters (beyond those hardwired into the engine) and i anticipate that Gerhard Botha's contribution to Torque3D will likely result in significant changes so i'll spend time elsewhere.