How to use noise() in HLSL

Started by
3 comments, last by skyman_cn 17 years ago
hi all, I use it this way: fragout Out; float4 color=tex2D(TextureSampler, TexCoord); float cc=noise(color); Out.color=float4(cc,0.0,0.0,1.0); Then it prompts this error:"error X4532: cannot map expression to pixel shader instruction set." but when I change "Out.color=float4(cc,0.0,0.0,1.0);" to "Out.color=float4(1.0,0.0,0.0,1.0);", it will be OK: fragout Out; float4 color=tex2D(TextureSampler, TexCoord); float cc=noise(color); Out.color=float4(1.0,0.0,0.0,1.0); Can anyone tell me why? And give me an sample source code to show how to use noise()? Thanks!
Advertisement
noise() is only supported in Texture Shaders. From the wording of your error, you're trying to use it in a Pixel Shader. That won't work.

When you change your shader to not use the value generated by noise, the HLSL compiler optimizes that function out (since you don't use the value) and thus doesn't give you an error.

Hope this helps.
Sirob Yes.» - status: Work-O-Rama.
Thanks.
Can you give me an example to show how to use noise() function? having sourcecode is best.
3x
Quote:Original post by skyman_cn
Can you give me an example to show how to use noise() function?
A texture shader is pretty much the same thing (iirc no reading from samplers though) just you run it via D3DXFillTextureTX() instead of via the normal pipeline. Pull up the docs on that function and you should be ready to go [smile]

hth
Jack

<hr align="left" width="25%" />
Jack Hoxley <small>[</small><small> Forum FAQ | Revised FAQ | MVP Profile | Developer Journal ]</small>

Thank you!
I go to try it.

This topic is closed to new replies.

Advertisement