Game Development Community

T3D 1.1 Beta 2 - CustomMaterials Broken [RESOLVED]

by Tim Dix (Raverix) · in Torque 3D Professional · 08/05/2010 (10:50 am) · 9 replies

Update, 8/11/10 - It looks like this isn't a bug, but actually an undocumented feature... how often do you get to say that and really mean it?

Instead of having to specify texture in the CustomMaterial, and then samplerName in the shader block, you may now do
sampler['samplerName']


It'll get automagically mapped to the shader variable with that same name like so:

Fragout main(ConnectData IN,  uniform sampler2D samplerName      : register(S0) )


Build: 1.1 Beta 2

Platform: Windows Vista 32 bit

Target: In game

CustomMaterials are broken, despite being specified, they show a back buffer. In Debug mode, I get an assert.

(tell us how to trigger the bug)
Steps to Repeat:
Replace the Gideion Material with this:
singleton ShaderData( UVAnimShader )
{
   DXVertexShaderFile   = "shaders/common/uvAnimV.hlsl";
   DXPixelShaderFile    = "shaders/common/uvAnimP.hlsl";

   pixVersion = 2.0;
};

new GFXStateBlockData( UVAnimShaderState )
{
};

singleton CustomMaterial( actor_gideon_body_material_dts )
{
   shader = UVAnimShader;
   stateBlock = UVAnimShaderState;
   
   version = 2.0;
   
	mapTo = "body_d";
	
	sampler["diffuseMap"] = "body_d";
};

Vertex Shader:
struct VertData
{
   float3 position        : POSITION;
   float2 texCoord        : TEXCOORD0;
};


struct ConnectData
{
   float4 hpos            : POSITION;
   float2 out_texCoord    : TEXCOORD0;
   float4 screenspacePos  : TEXCOORD1;  
};


//-----------------------------------------------------------------------------
// Main
//-----------------------------------------------------------------------------
ConnectData main( VertData IN,
                  uniform float4x4 texMat: register(C0)
)
{
   ConnectData OUT;

   // Vert Position
   OUT.hpos = mul(modelview, float4(IN.position.xyz,1));
   
   // Base Texture
   OUT.out_texCoord = IN.texCoord;
  
   // Screenspace position
   OUT.screenspacePos = OUT.hpos;
     
   return OUT;
}

Pixel Shader
// Dependencies:
#include "shaders/common/lighting.hlsl"
#include "shaders/common/torque.hlsl"

inline void lightinfoUncondition(in float4 bufferSample, out float3 lightColor, out float NL_att, out float specular)
{
   lightColor = bufferSample.rgb;
   NL_att = dot(bufferSample.rgb, float3(0.3576, 0.7152, 0.1192));
   specular = max(bufferSample.a / NL_att, 0.00001f);
}

struct ConnectData
{
   float2 texCoord        : TEXCOORD0;
   float4 screenspacePos  : TEXCOORD1;
};


struct Fragout
{
   float4 col : COLOR0;
};


//-----------------------------------------------------------------------------
// Main
//-----------------------------------------------------------------------------
Fragout main( ConnectData IN,
              uniform sampler2D diffuseMap      : register(S0),
              uniform float4    rtParams1       : register(C1),
              uniform sampler2D lightInfoBuffer : register(S1)
)
{
   Fragout OUT;

   // Vert Position
   
   // Base Texture
   OUT.col = tex2D(diffuseMap, IN.texCoord);
   
   // Deferred RT Lighting
   float2 uvScene = IN.screenspacePos.xy / IN.screenspacePos.w;
   uvScene = ( uvScene + 1.0 ) / 2.0;
   uvScene.y = 1.0 - uvScene.y;
   uvScene = ( uvScene * rtParams1.zw ) + rtParams1.xy;
   float3 d_lightcolor;
   float d_NL_Att;
   float d_specular;
   lightinfoUncondition(tex2D(lightInfoBuffer, uvScene), d_lightcolor, d_NL_Att, d_specular);
   OUT.col *= float4(d_lightcolor, 1.0);
   
   // HDR Output
   hdrEncode( OUT.col );

   return OUT;
}

i34.tinypic.com/jf8aa1.jpg
i37.tinypic.com/2rctnvc.jpg
Link to Console Log: Log

#1
08/05/2010 (10:53 am)
The only modification I made to the source code was to add the following lines to CustomMaterial::onAdd():

logError("SamplerNamecstr: %s", mSamplerNames[i].c_str());
logError("SamplerNameslot: %s", entry->slotName);

Which results in:

CustomMaterial - actor_gideon_body_material_dts(6612) - SamplerNamecstr: $texMat
CustomMaterial - actor_gideon_body_material_dts(6612) - SamplerNameslot: samplertexMat

To try and make sure that it was recognizing my sampler['texMat'] declaration.
#2
08/05/2010 (11:18 am)
I have to say those yellow boots really set off that outfit.
#3
08/05/2010 (11:21 am)
Looks like dyed croc leather. Isn't that illegal?
#4
08/05/2010 (12:37 pm)
I don't think it is... but it should be.
#5
08/05/2010 (12:46 pm)
Well it is kinda... If you go out into the wilds and kill a croc with your bare hands and then work it and dry it in the sun. Then form it into shoes and wear it around THAT is illegal.

But if your a lazy git and just buy them in a random shop where the croc skin came from a lazy croc farm, that went to a rather messy tannery and then to an incredibly boring shoe factory. That is 100% legal.
#6
08/07/2010 (8:55 pm)
Logged for QA team (TQA-763)
#7
08/09/2010 (11:53 pm)
Woohoo! QA team is gonna change the law! Now THAT's what I'm talking about...
#8
08/11/2010 (10:05 pm)
Marking as resolved.
#9
01/31/2011 (1:14 pm)
@Tim

This is indeed a feature for mapping the shader sampler to a particular texture.

Note in your example the problem seems to be that you missed a sampler...

singleton CustomMaterial( actor_gideon_body_material_dts )   
{   
   shader = UVAnimShader;   
   stateBlock = UVAnimShaderState;   
      
   version = 2.0;   
      
    mapTo = "body_d";   
       
    sampler["diffuseMap"] = "body_d";   
    sampler["lightInfoBuffer"] = "#lightinfo"; // ADDED!  
};

... what you were seeing was that instead of looking up lighting in the light buffer it was using whatever random texture was still in sampler S1.

Anyway... i closed this ticket.