Sign in to follow this  
skyman_cn

How to use noise() in HLSL

Recommended Posts

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!

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

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