Sign in to follow this  
WebsiteWill

HLSL Texture Sampler Question

Recommended Posts

I want a pixel shader that blends textures A and B based on a color I export from my modeling program. For every vertex in my model I export Position, UV, Color1, Normal. I can get single texture working just fine using the UV and setting the color to Output.Color = tex2D(TextureSampler1, PSIn.cTextureCoords0)*clamp(PSIn.cLightingFactor + xAmbient,0,1); Now, I want to take the sample from two textures and combine them based on a value I export with my mesh (in this case the X component of Color1). However, doing the following: vector tex1 = tex2D(TextureSampler1, PSIn.cTextureCoords0)*clamp(PSIn.cLightingFactor + xAmbient,0,1); vector tex2 = tex2D(TextureSampler2, PSIn.cTextureCoords0)*clamp(PSIn.cLightingFactor + xAmbient,0,1); I get the error stating " In ps_1_1, each sampler must have a unique TEXCOORD" I've googled and don't see anything relevant or even close to this error. DO I need to duplicate my UVs for each sampler I need? Or am I going about this the wrong way? Thanks, Webby

Share this post


Link to post
Share on other sites
Yes, you'll either have to pass down two copies of the same texture coordinate or switch to ps_2_0.

Share this post


Link to post
Share on other sites
To expand on what Jalibr said... In ps.1.1 you can't use the same texcoord input twice. Add a second texcoord in your vertex output/pixel input. In your vertex shader, simply write your single input texcoord into both outputs.

Share this post


Link to post
Share on other sites
Gah. The code I was playing with came from a demo online, I never thought to check the pixel shader version, obviously 1.0. The vertex shader was 2.0 and I just made the assumption.

So in PS 2.0 I can use the same UV pair for multiple samplers? Or do I still have to pass them down.

Even better, is there a document that specifies things like this?

Thanks,
Webby

Share this post


Link to post
Share on other sites
The DirectX documentation does. Section DirectGraphics -> (opt. DirectX9) -> Reference -> HLSL

PS2.0 allows to sample arbitrary textures (samplers) using arbitrary texture coords up to 32 times per pixel shader. Even texture coords calculated in the pixel shader itsself can be used, but only to an indirection level of 6 AFAIK.

Share this post


Link to post
Share on other sites
Thanks guys, I'm downloading the April 2007 SDK now. I've been using XNA so my need recently for the actual DX SDK has been nil. I wish you could download the documents separately. Ohh well.

Webby

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