texture won't show up

Started by
7 comments, last by RhoneRanger 18 years, 6 months ago
This is my first time using HLSL so I decided to try a really simple shader that positions the vertex and adds a texture using both vertex and pixel shaders. The problem is that my texture won't show up, it just shows up a dull white color. Here's the shader ( i got it from the DXSDK:

//--------------------------------------------------------------------------------------
// Global variables
//--------------------------------------------------------------------------------------
float	 g_fTime;					// App's time in seconds
float4x4 g_mWorld;					// World matrix for object
float4x4 g_mWorldViewProjection;	// World * View * Projection matrix
texture  g_txScene;
sampler  g_samScene =
sampler_state
{
    Texture = <g_txScene>;
    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, g_mWorldViewProjection );
    oTex = Tex;
}
float4 PixScene( float2 Tex : TEXCOORD0 ) : COLOR0
{
    return tex2D( g_samScene, Tex );
}
//--------------------------------------------------------------------------------------
// Techniques
//--------------------------------------------------------------------------------------
technique RenderScene
{
    pass P0
    {    
        VertexShader = compile vs_1_1 VertScene();
        PixelShader = compile ps_1_1 PixScene();
    }
}

Does anyone know what might be causing the problem? Thanks

---------------------------------darkzim

Advertisement

sampler g_samScene .......

should be

sampler2D g_samScene, as the keyword sampler is not compatible with ps 1_1.
TechleadEnilno, the Ultima 2 projectwww.dr-code.org/enilno
Thanks for the reply
I changed it, but the texture still isn't showing up.
Here's my code that I use to render the thing:
shader->SetProj( NULL );shader->SetWorld( NULL );shader->SetView( NULL );shader->CalculateWVP();shader->GetEffect()->SetTechnique( "RenderScene" );UINT cPasses;shader->GetEffect()->Begin( &cPasses, 0 );for( UINT p = 0; p < cPasses; ++p ){	shader->GetEffect()->BeginPass( p );	// This is not a skinned mesh, so render it like a static mesh.	for( unsigned long m = 0; m < meshContainer->NumMaterials; m++)	{		if( meshContainer->materials[m] )		{			g_engine->GetDevice()->SetMaterial( meshContainer->materials[m]->GetLighting() );			shader->GetEffect()->SetTexture( "g_txScene", meshContainer->materials[m]->GetTexture() );			shader->GetEffect()->CommitChanges();			meshContainer->MeshData.pMesh->DrawSubset( m );		}					}					shader->GetEffect()->EndPass();}shader->GetEffect()->End();


"shader" is just my effect-file wrapper-class.
Sorry about the late reply, I didn't have access to a computer.
EDIT:
Sorry, but i just realized that the forum changed all my arrows to &'s. Anyone know how to fix this?

---------------------------------darkzim

Couple of things i'm sure you've thought of:

There is definately a valid texture being passed to your effect->SetTexture()? (Just check the pointer).

Your texture coordinates are perfectly valid, and not pointing to some white patch of the texture (you could test this by changing the texture to a solid colour for instance).
Also make sure that your shaders are compiling, and the data into the app is proper.

For example, does your stream supply a float4 as it's position data? Or is it a float3 (x, y, and z)
TechleadEnilno, the Ultima 2 projectwww.dr-code.org/enilno
Source: Yeah I checked those things. The function returns a pointer to an IDirect3DTexture9 and the function calls for LPDIRECT3DBASETEXTURE9, so I'm assuming it should work based on the samples I've seen. The texture and texture coordinates are fine; when I render using the fixed function pipeline everything turns out Ok.

Edit:
RhoneRanger: My shaders aren't returning any errors during the compilation process. Transforming the vertex works fine (float4), but the texture just won't show up (am I passing in the right semantic for texture coords?).

---------------------------------darkzim

The only thing I see as something potentially an error is this

oPos = mul( Pos, g_mWorldViewProjection );

where I would do

oPos=mul(g_mWorldViewProjection,Pos);


Besides that, just change the Sampler to Sampler2D and everything would appear to be correct as long as your texture is valid.
TechleadEnilno, the Ultima 2 projectwww.dr-code.org/enilno
Ok well this was bugging me so I copied it word for word into one of my engines, and it works just fine.

The sampler command is perfectly valid either way (and with any version) - this is the effect framework and not dependant on the pixel/vertex shader version.

So really that only leaves two possibilities that I can see:

a) The texture really isn't valid - or becomes invalid - or is white.
b) Your graphics hardware either doesnt support the pixel shader, or your drivers aren't up to date.

Sorry I couldn't be of more help =(
from the dx9 docs

Sampler
A sampler is a input pseudo-register for a pixel shader, which is used to identify the sampling stage. There are 16 pixel shader sampling stage registers: s0 to s15. Therefore, up to 16 texture surfaces can be read in a single shader pass. The instructions that use a sampler register are texld and texldp.

Remarks
Sampler must be declared before use with the dcl_samplerType - ps instruction.

Pixel shader versions 1_1 1_2 1_3 1_4 2_0 2_sw 2_x 3_0 3_sw Sampler                                 x   x   x   x   x     

TechleadEnilno, the Ultima 2 projectwww.dr-code.org/enilno

This topic is closed to new replies.

Advertisement