Jump to content
  • Advertisement
Sign in to follow this  
PixelShader

Why I got error "cannot map expression to pixel shader instruction set"?

This topic is 4448 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

When I wrote like this: float3 combinedNormal; combinedNormal = tex2D(NormalSampler, texCoord); combinedNormal = normalize(2 * combinedNormal - 1); I got error says "cannot map expression to pixel shader instruction set" on the last line. Would you like to tell me what's wrong here? Many Thanks!

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by PixelShader
When I wrote like this:
float3 combinedNormal;
combinedNormal = tex2D(NormalSampler, texCoord);
combinedNormal = normalize(2 * combinedNormal - 1);

I got error says "cannot map expression to pixel shader instruction set" on the last line. Would you like to tell me what's wrong here?

Many Thanks!

I would guess it doesn't understand what 2 * combinedNormal - 1. Subtraction of a scalar from a vector isn't really defined. I don't know what you want, but if it's componentwise subtraction you should:

float3 correctedNormal = float3(2.0*combinedNormal.x - 1.0, 2.0*combinedNormal.y - 1.0, 2.0*combinedNormal.z - 1.0);

if Cg or HLSL (what you are using) allows explicit construction like that.

Share this post


Link to post
Share on other sites
Quote:
I would guess it doesn't understand what 2 * combinedNormal - 1. Subtraction of a scalar from a vector isn't really defined.


Nah, HLSL recognizes that statement. It loosely translates into this:

float3 Temp;
Temp.x = 2*combinedNormal.x-1;
Temp.y = 2*comibnedNormal.y-1;
Temp.z = 2*combinedNormal.z-1;
combinedNormal = normalize(Temp);

Share this post


Link to post
Share on other sites
Quote:
Original post by Cypher19
Quote:
I would guess it doesn't understand what 2 * combinedNormal - 1. Subtraction of a scalar from a vector isn't really defined.


Nah, HLSL recognizes that statement. It loosely translates into this:

float3 Temp;
Temp.x = 2*combinedNormal.x-1;
Temp.y = 2*comibnedNormal.y-1;
Temp.z = 2*combinedNormal.z-1;
combinedNormal = normalize(Temp);

Oh I see! All a big mistake then, thanks for pointing that out, Cypher! :)

Share this post


Link to post
Share on other sites

You can create a cubemap for emulating the vector normalization. It eats one texture sampler though.

Try to look for "normalization cubemap" from the web.

Share this post


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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!