1

I am trying get 3 new random floats into my pixel shader for each pixel. Based on what I have read here, here, and also here, I believe that I need to generate a large texture containing random RGB values and then during each draw call randomly generate a couple of texture coordinate offset values to produce a pseudo-random effect. Is the only way to do this through the LockRect and UnlockRect API? I hope not.

Community
  • 1
  • 1
Alexander Van Atta
  • 870
  • 11
  • 34

1 Answers1

0

They only way I have found to do this is the lock and unlock rectangle method. But it is much easier then I initially thought. Here is how I filled the texture. 'Create Random texture for dithering shader rando = New Random() randomText = New Texture(device, 1000, 1000, 1, Usage.Dynamic, Format.A16B16G16R16, Pool.Default) '89599 '89510 Dim data(1000 * 1000 * 8 + 1000 * 63 + 936) As Byte rando.NextBytes(data)

    Dim dataBox As DataRectangle =
randomText.GetSurfaceLevel(0).LockRectangle(LockFlags.None)
    dataBox.Data.Seek(0, IO.SeekOrigin.Begin)
    dataBox.Data.Write(data, 0, data.Length)
    dataBox.Data.Close()

As you can see from the code I had to add a lot of extra bytes to completely fill the texture with random values. I used a 1000 x 1000 64bit texture so you would think I would need 1000*1000*8 Bytes of data but I need an extra 63936 Bytes to fill the texture and I am not sure why. But it seems to work for my needs.

Alexander Van Atta
  • 870
  • 11
  • 34