Dynamically creating a TextureCube (Texture2D Array) in SharpDx

Started by
1 comment, last by empodecles 10 years, 7 months ago

Just started learning to use SharpDX instead of XNA.

SharpDX forums have been closed down so I'm asking over hear, hopefully someone will point me in the right direction..

I am trying to create a TextureCube at run-time based on the current camera position (this would only happen on occasion when a specific "dirty" flag has been set) to be used for environment mapping on reflective surfaces.

it was easy and straight forward to do in xna...

Just to be clear...I don't want to be loading the texture from file! They will be coming from a Render Target at run time.

Pretty much all the examples I have seen to do with TextureCubes show loading it from a dds file and that won't work for me.

I have 6 seperate Texture2D objects created (one for each view axis) now I just need to combine them into a TextureCube/Texture2D array so that I can use them in my shader (I already have the shader working when I load the TextureCube from a static dds file, but that is not what I want)

cheers

p

Advertisement

In general you don't want to create 6 separate textures for this. Instead you would create your Texture2DArray with 6 array slices, and use each face directly as a render target when rendering reflections. I've never used SharpDX so this might be a bit incorrect, but I will try to describe the steps you need to take in terms of that library:

  • During initialization, create your Texture2D object with the desired dimensions of your cubemap, specifying 6 as the ArraySize. Make sure that you specify ResourceOptionFlags.TextureCube for the OptionFlags field.
  • Create a single ShaderResourceView for your Texture2D, using default settings. This will be the SRV that you use when sampling the cubemap in a shader.
  • Create 6 RenderTargetView's, one for each face. For the RenderTargetViewDescription, specify the appropriate format for the Format field, and RenderTargetViewDimension.Texture2DArray as the Dimension field. Then fill out the Texture2DArray field with MipSlice = 0, FirstArraySlice = <FaceIndex>, and ArraySize = 1. When you want to render to a specific face, you then bind the RTV for the corresponding the face. The order of the faces is +X, -X, +Y, -Y, +Z, -Z.

Cool thanks! I will give that a shot. :)

This topic is closed to new replies.

Advertisement