Jump to content
  • Advertisement
Sign in to follow this  
empodecles

Dynamically creating a TextureCube (Texture2D Array) in SharpDx

This topic is 2146 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


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

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!