mesh texture color

im using a effects file in my project but it seems when I render some meshes the colors are not comming out right, my render loop is very basic so nothing there should be the problem, so my guess is its in the .fx file here is what I have


float4x4 worldMatrix;

float4x4 worldViewProjection;

texture sceneTexture;

sampler g_samScene =

sampler_state

{

Texture = <sceneTexture>;

MinFilter = Linear;

MagFilter = Linear;

MipFilter = Linear;

};

 

void VertScene( float4 Pos : POSITION,

float2 Tex : TEXCOORD0,

out float4 oPos : POSITION,

out float2 oTex : TEXCOORD0 )

{

oPos = mul( Pos, worldViewProjection );

oTex = Tex;

}

 

float4 PixScene( float2 Tex : TEXCOORD0 ) : COLOR0

{

return tex2D( g_samScene, Tex );

}

 

technique RenderSceneNoPixelShader

{

pass P0

{

VertexShader = compile vs_1_1 VertScene();

PixelShader = NULL;

MaterialAmbient = {1.0, 1.0, 1.0, 1.0};

MaterialDiffuse = {1.0, 1.0, 1.0, 1.0};

MaterialSpecular = {1.0, 1.0, 1.0, 1.0};

MaterialPower = 40.0f;

Texture[0] = <sceneTexture>;

ColorOp[0] = Modulate;

ColorArg1[0] = Texture;

ColorArg2[0] = Diffuse;

AlphaOp[0] = Modulate;

AlphaArg1[0] = Texture;

AlphaArg2[0] = Diffuse;

MinFilter[0] = Linear;

MagFilter[0] = Linear;

MipFilter[0] = Linear;

 

ColorOp[1] = Disable;

AlphaOp[1] = Disable;

}

}


 


any Ideas why this could be happening
thanks a ton


Answer this question

mesh texture color

  • icelock

    material value, durring the creating of the mesh we take a gray texture then add color to the mesh object after the texturing is done, the overlaying color is what is not showing up
  • nhlpens66

    this color change is not done at runtime its done when the actual mesh is created in canvas I belive he is using, but when I load the mesh into the game that overlaying color is lost so every in this case ship is gray.
  • ZeyadRajabi

    I am very new with effect files, and this effect file I basicly took the customUI file because it seemed like a very simple file, added code into it so that you would not need a pix shader to run the client, after digging around abit more its placing the textures fine but all of our textures are used over and over and what we have done is added color to the textures when we created the mesh objects, with this said this code is loading our basic texture but not loading the specific color. now should we color the textures and just load them or is there away to pull out the color from the .x file.
    thanks

  • Jon Asbury

    So, you're using a greyscale texture and then getting the vertex diffuse colour to modify it

    An example being that if you have a red team and a blue team in your game, they both use the same greyscale texture but you change the mesh colour so that they appear shades of red or blue (respectively)

    If I'm right about that, you'd need to introduce a value for COLOR into your vertex shader that can then be used by your pixel shader to modulate the results of the tex2D()...

    I'm still fairly new to effect files myself, so I don't know if you can do that with the fixed function params you seemed to be setting... but it should be possible if you specify either a COLOR property for the input/output semantics of the vertex shader (and add the relevent data into your mesh) or just pass in the colour as a constant to the vertex shader (and switch it around as appropriate when rendering from your application)...

    hth
    Jack


  • Charlemagne

    When you say "from the .x file" do you mean from the vertex stream or as a material value associated with a particular mesh subset

     



  • bataras

     Smacker wrote:
    im using a effects file in my project but it seems when I render some meshes the colors are not comming out right, my render loop is very basic so nothing there should be the problem, so my guess is its in the .fx file here is what I have

    (snipped effect)

    any Ideas why this could be happening
    thanks a ton


    You don't say what you expect, but I took your effect, added Sas bindings and viewed it in DxViewer and saw a texture.  There is a bit of odd stuff in your effect file that might be causing you problems.  For example, you set up Material* effect states but you are using a vertex shader so all of the material and diffuse values will be the result of your vertex shader.  This means that using ColorOp=Modulate and ColorArg2[0]=Diffuse isn't all that meaningful unless you output a vertex color from your vertex shader.   As it is, the color will be white, modulated against the texture, resulting in the texture (which is what I see).  The net result is actually exactly what your PixScene pixel shader does, sample the texture and output that as the pixel color.

    For the record, here is the effect I used which is equivelant to your original effect:



    int GlobalParameter : SasGlobal

    <

    int3 SasVersion = {1, 1, 0};

    bool SasUiVisible = false;

    >;

    float4x4 worldMatrix <string SasBindAddress = "Sas.Skeleton.MeshToJointToWorld[0]"; >;

    float4x4 View <string SasBindAddress = "Sas.Camera.WorldToView"; >;

    float4x4 Projection <string SasBindAddress = "Sas.Camera.Projection"; >;

    float4x4 worldViewProjection;

    texture sceneTexture <string SasResourceAddress = "tiger.bmp"; >;

    void VertScene( float4 Pos : POSITION, float2 Tex : TEXCOORD0, out float4 oPos : POSITION, out float2 oTex : TEXCOORD0 )

    {

    float4x4 worldViewProjection = mul(worldMatrix, mul(View, Projection));

    oPos = mul( Pos, worldViewProjection );

    oTex = Tex;

    }

    technique RenderSceneNoPixelShader

    {

    pass P0

    {

    VertexShader = compile vs_1_1 VertScene();

    PixelShader = NULL;

    Texture[0] = <sceneTexture>;

    ColorOp[0] = SelectArg1;

    ColorArg1[0] = Texture;

    AlphaOp[0] = SelectArg1;

    AlphaArg1[0] = Texture;

    ColorOp[1] = Disable;

    AlphaOp[1] = Disable;

    }

    }

     



  • mesh texture color