[C#]Turns black/transparent, Please help!

Hi all,

I have al little problem by loading a bumpmap texture on a simple model. It turns transparent and it's black :s

Know anyone how i can fix this Do i need some extra params or something, please help me with this. My graphicscard has vs 1.1 ps 1.3

The shader works very well with the Nvidia FX Composer.

Screenshot http://codersforcoders.com/Engine/8-250.jpg

############################################# [ Program Code ] #############################################

private Texture texDiffuse;
private Texture texBump;
private Matrix matBox;
private Effect effect;
private Mesh box = null;
private Matrix modelViewIT;
private Matrix modelViewProj;

public StaticMeshEffect3(string FileName, string PathTexture, Microsoft.DirectX.Direct3D.Device EngineDevice)
{
 matBox = Matrix.Translation(0.0f, 0.0f, 0.0f);
 box = Mesh.FromFile(FileName, MeshFlags.Managed, EngineDevice);
 VertexElement[] elements = new VertexElement[]
 {
  new VertexElement(0, 0, DeclarationType.Float3, DeclarationMethod.Default, DeclarationUsage.Position, 0),
  new VertexElement(0, 12, DeclarationType.Float3, DeclarationMethod.Default, DeclarationUsage.Normal, 0),
  new VertexElement(0, 24, DeclarationType.Float3, DeclarationMethod.Default, DeclarationUsage.TextureCoordinate, 0),
  new VertexElement(0, 36, DeclarationType.Float3, DeclarationMethod.Default, DeclarationUsage.Tangent, 0),
  new VertexElement(0, 48, DeclarationType.Float3, DeclarationMethod.Default, DeclarationUsage.BiNormal, 0),
  VertexElement.VertexDeclarationEnd,
 };

 VertexDeclaration decl = new VertexDeclaration(EngineDevice, elements);
 Mesh tempMesh = box.Clone(MeshFlags.Managed, elements, EngineDevice);
 box.Dispose();
 box = tempMesh;
 box.ComputeTangentFrame(0);

 effect = Effect.FromFile(EngineDevice, "Media/bumpps1.fx", null, null, ShaderFlags.PartialPrecision, null);

 //texDiffuse = TextureLoader.FromFile(EngineDevice, "Media/rockwall.dds");
 //texBump = TextureLoader.FromFile(EngineDevice, "Media/rockwall_normal.dds");

 modelViewIT = matBox * EngineDevice.Transform.View * EngineDevice.Transform.Projection;
 modelViewIT = Matrix.Invert(modelViewIT);
 modelViewIT = Matrix.TransposeMatrix(modelViewIT);

 effect.Technique = "NoPixelShader";
}

public void StaticMeshLocation(Microsoft.DirectX.Direct3D.Device EngineDevice, float yaw, float pitch, float roll, float x, float y, float z, float ScalingFactor)
{
 EngineDevice.Transform.World = Matrix.RotationYawPitchRoll(yaw, pitch, roll) * Matrix.Translation(x, y, z);

 if(ScalingFactor != 0.0f || ScalingFactor != 0)
 {
  EngineDevice.Transform.World *= Matrix.Scaling(ScalingFactor,ScalingFactor,ScalingFactor) * Matrix.Translation(x, y, z);
 }

 //effect.SetValue("diffuseTexture", texDiffuse);
 //effect.SetValue("normalMap", texBump);

 effect.SetValue("WorldIMatrix", modelViewIT);
 effect.SetValue( "WorldViewProj", EngineDevice.Transform.World * EngineDevice.Transform.View * EngineDevice.Transform.Projection );

 //Render the box
 effect.Begin(0);
 effect.BeginPass(0);
 box.DrawSubset(0);
 effect.EndPass();
 effect.End();
}


############################################# [ Shader Code] #############################################

float Script : STANDARDSGLOBAL <
    string UIWidget = "none";
    string ScriptClass = "object";
    string ScriptOrder = "standard";
    string ScriptOutput = "color";
    string Script = "Technique=Technique NoPixelShader;";
> = 0.8;

// World Inverse or Model Inverse matrix
float4x4 WorldIMatrix : WorldInverse;

// Model*View*Projection
float4x4 WorldViewProj : WorldViewProjection;


texture diffuseTexture : DIFFUSE
<
    string ResourceName = "rockwall.dds";
    string ResourceType = "2D";
>;

texture normalMap : NORMAL
<
    string ResourceName = "rockwall_normal.dds";
    string ResourceType = "2D";
>;


float4 BumpHeight
<
> = { 1.0, 1.0, 0.5, 0.0};

float4 LightPos : Position
<
    string Object = "PointLight";
    string Space = "World";
> = { 100.0f, 100.0f, 100.0f, 0.0f };


technique NoPixelShader <string Script = "Pass=p0;";>
{
    pass p0 <string Script = "Draw=geometry;";>
    {
        VertexShaderConstant[0] = <WorldIMatrix>;         // c0-c3 is Model matrix
        VertexShaderConstant[4] = <WorldViewProj>;            // c4-c7 is ModelViewProjection matrix
        VertexShaderConstant[ 8] = <WorldIMatrix>;
        VertexShaderConstant[12] = <LightPos>;
        VertexShaderConstant[13] = {0.5, 0.5, 0.5, 1.0};
        VertexShaderConstant[14] = <BumpHeight>;

        VertexShader = asm
        {
            vs.1.1                    // version number

            dcl_position v0
            dcl_normal v3
            dcl_texcoord0 v7
            dcl_tangent0 v8
            dcl_binormal0 v9
            dcl_color0 v5
           
            m4x4 oPos, v0, c4        // pos in screen space.
            mov oT0, v7                // tex coords for normal map
            mov oT1, v7                // tex coords for diffuse tex.

            mov r0, c12
            dp3 r0.w, r0, r0        // normalize light dir.
            rsq r0.w, r0.w
            mul r0, r0, r0.w   

            // Transform Light to Object space
            dp3 r2.x, c8, r0        // Tangent dot Light
            dp3 r2.y, c9, r0        // Binormal dot Light
            dp3 r2.z, c10, r0        // Normal dot Light

            // Transform Light to tangent space.
            dp3 r1.x, v8, r2        // Tangent dot Light
            dp3 r1.y, v9, r2        // Binormal dot Light
            dp3 r1.z, v3, r2        // Normal dot Light
            sge r1.w, r1.x, r1.x

            mov r0, c14
            add r0, r0, r0          // *= 2
            mul r0, r1, r0          // *= bump height

            mad oD0, r0, c13, c13   // put in diffuse
        };

         Zenable = true;
        ZWriteEnable = true;
        CullMode = None;
       
        Texture[0] = <normalMap>;
        MinFilter[0] = Linear;
        MagFilter[0] = Linear;
        MipFilter[0] = Linear;

        Texture[1] = <diffuseTexture>;
        MinFilter[1] = Linear;
        MagFilter[1] = Linear;
        MipFilter[1] = Linear;

        ColorOp[0] = DotProduct3;
        AlphaOp[0] = SelectArg1;
        ColorArg1[0] = Texture;
        ColorArg2[0] = Diffuse;
        AlphaArg1[0] = Texture;
        AlphaArg2[0] = Diffuse;

        ColorOp[1] = Modulate;
        ColorArg1[1] = Current;
        ColorArg2[1] = Texture;

        AlphaOp[1] = SelectArg1;
    }
}

 




Answer this question

[C#]Turns black/transparent, Please help!

  • [C#]Turns black/transparent, Please help!