Advertisement Jump to content
Sign in to follow this  

Setting the Pixel ALU for textures

This topic is 4911 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

After a quick seach through the msdn, the related articles were a bit complicated and not clear on what exactly has to be set in order for a pixel shader to read from the Stages. Well Currently in my program, I have this call to set the sampler:
m_pDevice->SetTexture(0, sometexturevariablename;
according to the msdn this "Assigns a texture to a stage for a device." All this time, I have been used to programming this into my pixel shaders (basic programme)
tex t0         //Sample colour
mul r0,t0,v0   //multiply by the diffuse colour in input register v0
However, version 2 dosn't support the tex command anymore so I tried wipping up something in RenderMonkey:
sampler2D baseMap 	: register(s0);

struct PS_INPUT 
   float2 Texcoord : TEXCOORD0;
   float4 Color 	 : COLOR0;

float4 ps_main( PS_INPUT Input ) : COLOR0
	float4 c1;
	c1 = tex2D( baseMap, Input.Texcoord );
   return mul(c1,Input.Color);
which apparenly dissasembles to this:
    dcl t0.xy
    dcl v0
    dcl_2d s0
    texld r0, t0, s0
    dp4 r0, r0, v0
    mov oC0, r0
But when I run my little test program, I just get a white texture. If I replace the program with the old shader, it works just fine. Now what I need to know is how to write the code in RenderMonkey (I just started fiddling around with it since asm is not to suited to more complex shader program) so that it samples the color at the position sent to it on the stage of my choosing. Well if that made no sense, I just need to take the 1.1 code, and see how to do that same thing with rendermonkey or at the least with ver 2.0 Thanks in Advance :) [Edited by - Mistro on August 14, 2005 5:32:20 PM]

Share this post

Link to post
Share on other sites
I'm not too clear about what you ask here, and i don't have any experience with ASM nor RenderMonkey, but i'll try to help anyway...

For about a year ago i were fiddeling around with GLSL, and if remember correctly, i had to bind a texture unit before beeing able to access it from the shader program. I'm not sure if you have done that...have you?

This i don't rember too well, but you might have to specify the sampler as an input bound to one of the built-in arguments. I mean the same way as you did with float2 Texcoord : TEXCOORD0;.
I really can't remember, and i have my old code on another computer, but i guess you can find out yourself. =)

Share this post

Link to post
Share on other sites
Thanks for trying but this line:

sampler2D baseMap : register(s0);

is what sets the texture. However, the good news is that I believe I have solved this problem but have run into another one while I was at it.

The problem was this line:

return mul(c1,Input.Color);

Apparently the mul Command does a dot product. What I needed aparently was a cross product using "*" which comiles to the asm "mul" command.

The new problem is with the vertex shader.

With shader v1.1 I would use this command in asm:
m4x4 oPos, v0, c0

which is simply a macro for this:

dp4 oPos.x, v0, c0
dp4 oPos.y, v0, c1
dp4 oPos.z, v0, c2
dp4 oPos.w, v0, c3

With RenderMonkey I used this:
Output.Position = mul( matViewProjection, Input.Position );

Which compiles to this:

mul r0, c1, v0.y
mad r0, c0, v0.x, r0
mad r0, c2, v0.z, r0
mad oPos, c3, v0.w, r0

which seems to be teh same thing. However, I get messed up results when running the program. :(

Any help? (with this problem since the original has been solved)

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!