Sign in to follow this  
BlueChip

PS Problem - capricious texture output

Recommended Posts

hi folk, I've met a problem, that I don't understand... this is my simple pixel shader...
// Pixel shader input structure
struct PS_INPUT
{
    float4 Position   	  : POSITION;
    float2 AlphaCoord  	  : TEXCOORD0;
    float2 TexCoord0	  : TEXCOORD1;
    float2 TexCoord1   	  : TEXCOORD2;
    float2 TexCoord2	  : TEXCOORD3;
    float2 TexCoord3   	  : TEXCOORD4;
};

// Pixel shader output structure
struct PS_OUTPUT
{
    float4 Color   : COLOR0;
};

// Global variables
sampler2D AlphaTexture;
sampler2D Texture1;
sampler2D Texture2;
sampler2D Texture3;
sampler2D Texture0;

// Name: Simple Pixel Shader
PS_OUTPUT ps_main( in PS_INPUT In )
{
        PS_OUTPUT Out;                         

  	float4 alphatex = tex2D(AlphaTexture, In.AlphaCoord).rgba;
	float4 texture0 = tex2D(Texture0, In.TexCoord0);
	float4 texture1 = tex2D(Texture1, In.TexCoord1);
	float4 texture2 = tex2D(Texture2, In.TexCoord2);
	float4 texture3 = tex2D(Texture3, In.TexCoord3);

	Out.Color = (texture0 * alphatex.r)+
		    (texture1 * alphatex.g)+
		    (texture2 * alphatex.b)+
		    (texture3 * alphatex.a);
		    
	return(Out);
}
The Alpha texture, is a valid 32bit texture.. so it has 4 values: b,r,g,a It is loaded from a 32bit .bmp file. This shader gives me a compilation error.. the problem is in this line (texture3 * alphatex.a); where appears alphatex.a If I delete it, all works fine. So, I've thought that alphatex was a 24 bit only... but if I add this code, where alphatex.a appears, I don't get errors.
	float4 texture4 = (texture0 * alphatex.r)+
		   	  (texture1 * alphatex.g)+
		   	  (texture2 * alphatex.b)+
		   	  (texture3 * alphatex.a);
So, the problem is not in alphamap.a, because if it was an invalid parameter, I should get an error... The problem comes back if I add Out.Color = texture4; Is like if out.color (a float4 type) doesn't accept the 4th texture4 byte. Why???!? I don't understand... you can see an error? thanks for aids

Share this post


Link to post
Share on other sites
Quote:
Original post by BlueChip
This shader gives me a compilation error..
the problem is in this line (texture3 * alphatex.a); where appears alphatex.a
If I delete it, all works fine.

You fail to mention what the actual error message is, and that makes it very difficult to help you. Could the shader simply be too long for the shader model you are attempting to compile to?

Hope this helps.

Share this post


Link to post
Share on other sites
Ehmmm.. yes sorry...

ok, I've added a bit of debugger code...
the function 'D3DXCompileShaderFromFile' returns 'E_OUTOFMEMORY'
i.e 'Microsoft® Direct3D® could not allocate sufficient memory to complete the call.'

why? and which memory??

and, sorry but I'm a shader newbie, and don't understand what means
'Could the shader simply be too long for the shader model you are attempting to compile to?'

what is the shader model? there is a limit for shader length?

__EDIT__

if usefull, I post my Dx call:

m_pd3dDevice->CreateVertexDeclaration(decl, &m_pVertexDecl);

result = D3DXCompileShaderFromFile("data/shaders/vertex.vsh", //filepath
NULL, //macro's
NULL, //includes
"vs_main", //main function
"vs_1_1", //shader profile
0, //flags
&tempbuffer, //compiled operations
NULL, //errors
&m_pConstantTable); //constants

Share this post


Link to post
Share on other sites
Quote:
Original post by BlueChip
ok, I've added a bit of debugger code...
the function 'D3DXCompileShaderFromFile' returns 'E_OUTOFMEMORY'
i.e 'Microsoft® Direct3D® could not allocate sufficient memory to complete the call.'

Thats not an error, that's the return code.

Enable the DirectX Debug Runtimes (as described in jollyjeffers' new FAQ), and you should get a more detailed error message, which you can actually use.

Quote:
Original post by BlueChip
what is the shader model? there is a limit for shader length?

"vs_1_1" is the shader model you're compiling to. Now, ignoring the fact your code shows you loading a VS when the HLSL is a PS, yes, shaders can be too long. You have a limit on both the number of texture reads you can make, and the total number of instructions in your shader. You might want to try compiling to 2.0, which will let you use longer shaders.

Share this post


Link to post
Share on other sites
I was able to compile it using PS 2.0, and it came out to 10 instructions. As far as I know that shouldn't be too long for any modern hardware. However I should mention that PS 1.x only supports up to four texcoords, so since you have five you'd need at least PS 2.0 to compile the program.

Share this post


Link to post
Share on other sites
I can't belived!!

great... thanks boys.

I belived that ps version, adds only operations and registryes..

sirob, thanks for the link... good point for start..

bye

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this