http://stackoverflow.com/questions/5149544/can-i-generate-a-random-number-inside-a-pixel-shader
What you generally do when you want a random value in a pixel shader is to pass in a texture containing noise. While it's not actually "random" - it looks random.
For example, here's some code from a pixel shader I have lying around:
float3 random = (tex2D(noiseTexture, texCoord * noiseScale + noiseOffset));
The texture I use is an RGB-noise texture, which can come in handy some times. But the same technique would work for a grayscale one.
By scaling it I ensure that the pixels in the noise texture line up to on-screen pixels (you may also want to set the texture sampler to "point" mode so you don't blur the noise texture).
By using an offset you can scroll the texture - which is kind of like seeding a random number generator. Use a random offset if you want to avoid that "scrolling" look.
'그래픽스(Graphics) > Shader' 카테고리의 다른 글
반투명처리하기위해서 켜야하는 옵션 (0) | 2013.04.16 |
---|---|
기초 : 스카이박스(Adding a Skybox to RenderMonkey) (0) | 2013.01.19 |
렌더몽키 텍스처, 렌더타겟 경로 읽어오지 못할때 (0) | 2013.01.13 |
DirectX 9.0 셰이더 프로그래밍 강의 (0) | 2013.01.08 |
셰이더[Effect] 함수들 ID3DXBaseEffect 인터페이스 (0) | 2013.01.08 |