• Advertisement
Sign in to follow this  

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

This topic is 4270 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
No it doesn't. VS 1.1 and PS 2.0 are the minimum.

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
A good paper regarding vector normalization is Normalization Heuristics from nVidia. If you decide to do normalization in ps1_4 using normalization cube map I recommend to take a look at that paper.

Share this post


Link to post
Share on other sites
I have tried cube-map normalization like this:

Texture cubemap_normalize< string ResourceName = "normalize.dds";
string TextureType = "CUBE"; >;
samplerCUBE normalize_sampler = sampler_state {texture = <cubemap_normalize>;
AddressU = CLAMP;
AddressV = CLAMP;
AddressW = CLAMP;
MIPFILTER = LINEAR;
MINFILTER = LINEAR;
MAGFILTER = LINEAR;
};
inline float3 my_normalize(float3 V)
{
return (float3) texCUBE( normalize_sampler, V ) * 2.0 - 1.0;
}

then I got error say "dependent texture read chain cannot exceed 1 in ps_1_4" at texCUBE(..) line. Is the mistake in the cube-map?
and what is normalize.dds looks like?

Share this post


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

  • Advertisement