Game Development Community

Simple shader help

by Michael Taylor · in Torque 3D Professional · 04/26/2012 (9:51 pm) · 2 replies

I've been tying to get a shader to render a custom material to a mesh for awhile now, with little success. I tried several shaders but could only get something rendering with some code I borrowed from another thread: www.garagegames.com/community/forums/viewthread/99185/1. The thread is old and the author doesn't recall much about it. For convenience I'll post the code here.
The results I get with this depend on the location and (mostly) the orientation of the camera. As the camera pans, the rendered texture cycles between four or five textures in the current level. And I've tried it in different levels, even a clean install of Deathball Desert Demo.
The only thing I know about shaders is what little I've read (and understood) around here. I'm hoping one of you shader pros will see right away what I'm doing wrong.
Please help a guy out.

Script
new ShaderData( SimpleShader )  
    {  
       DXVertexShaderFile   = "shaders/common/simpleV.hlsl";  
       DXPixelShaderFile    = "shaders/common/simpleP.hlsl";  
                       
       pixVersion = 2.0;  
    };  
      
     singleton CustomMaterial( theBlock_Rock_Shiver3_diff_dds )  
     {  
       mapTo = "Rock_Shiver3-diff_dds";  
       texture[0] = "/art/shapes/Rock_Shiver3-diff";  
       shader = SimpleShader;  
        
    };



Vertex shader

//*****************************************************************************  
    // SimpleShader  
    //*****************************************************************************  
    #define IN_HLSL  
    #include "shdrConsts.h"  
    #include "hlslStructs.h"  
      
      
    struct Conn  
    {  
       float4 HPOS             : POSITION;  
       float2 uv0              : TEXCOORD0;  
    };  
    uniform float4x4 modelview : register(VC_WORLD_PROJ);  
      
      
    //-----------------------------------------------------------------------------  
    // Main  
    //-----------------------------------------------------------------------------  
    Conn main( VertexIn_PT In )  
    {  
       Conn Out;  
       Out.HPOS = mul(modelview, In.pos);  
       Out.uv0 = In.uv0;  
       return Out;  
    }



Pixel shader

//*****************************************************************************  
    // Simple Pixel Shader  
    //*****************************************************************************  
      
    //-----------------------------------------------------------------------------  
    // Data   
    //-----------------------------------------------------------------------------  
    struct Conn  
    {  
       float4 HPOS             : POSITION;  
       float2 uv0              : TEXCOORD0;  
    };  
      
    uniform sampler2D diffuseMap : register(S0);  
    struct Fragout  
    {  
       float4 col : COLOR0;  
    };  
      
    //-----------------------------------------------------------------------------  
    // Main  
    //-----------------------------------------------------------------------------  
    Fragout main(Conn IN)   
    {  
        Fragout OUT;  
      
         
       float4 base = tex2D(diffuseMap, IN.uv0);  
      
        
       OUT.col = base;  
      
      
        return OUT;  
    }


#1
04/27/2012 (3:56 am)
replace:
texture[0] = "/art/shapes/Rock_Shiver3-diff";

with:
sampler["diffuseMap"] = "Rock_Shiver3-diff_dds";
#2
04/27/2012 (7:42 am)
OK, I tried that but still getting the same results.
Can you see anything else?