Jump to content
  • Advertisement
Sign in to follow this  
NathanRidley

Rendering a texture with transparency

This topic is 1335 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

I've just been working out how to render to a texture and then render that texture back into the scene. I've created a simple exercise project specifically to learn how to do this. So far so good, but I have some questions I'm not quite sure of the answer to.

 

Here's what I have so far:

 

And a still screenshot of the above:

2014-10-16_1811.png

 

Here's the code, all neatly wrapped up into one gist:

https://gist.github.com/axefrog/1946168aebfdbaa1c005

 

The three things I haven't quite worked out how to do are:

 

1) The outer cube is mostly red, because I'm clearing the texture background to red, then rendering the box to the texture. I then render that texture back onto the box for the main swapchain texture. I would like to try and have transparency where the red is, but when I tried to set the background color to transparent, it came out black instead. How do I make the red transparent instead of black, or in other words, how do I clear the texture to transparent instead of a solid color?

 

2) Once I have the transparency stuff figured out, my sample box won't be very graphically substantial. All I'll see are three wooden box images; one for each visible face, with the rest of each face being transparent showing through to whatever is behind it. The other faces of the cube will be invisible from the camera's perspective due to back-face culling, and the inside faces will of course be invisible due to being observed from the wrong side. How do I make it so that the inside faces of the cube render a color or texture when exposed to the camera via transparency or otherwise?

 

3) The inner result of scaling the wooden crate texture is kind of jaggy I assume due to not being affect by the antialiasing sampler. Is there a setting I need to change to alleviate this, or is simply that the wood texture is too large (1024x1024) and I need to use mimapping to achieve a better result?

Share this post


Link to post
Share on other sites
Advertisement

How do I make the red transparent instead of black, or in other words, how do I clear the texture to transparent instead of a solid color?

I think you also need to use ID3D11DeviceContext::OMSetBlendState to enable alpha blending when rendering the second cube.

 

 

 


How do I make it so that the inside faces of the cube render a color or texture when exposed to the camera via transparency or otherwise?

This is the age-old question of how to do order-independent transparency. But for a cube, or any other convex object, it is simple: First, render only your backfaces (draw the object with (counter-)clockwise front faces), then the front faces on top (draw the same object again with the opposite front face setting)... For non-convex objects, you can either split them into convex parts, and draw each one separately using the above method, or sort all of your obejct's faces in back to front order, then draw them in that order without any backface culling. If there are faces that intersect, you'd also have to split them in two separate faces along the intersection line.

 

 


The inner result of scaling the wooden crate texture is kind of jaggy I assume due to not being affect by the antialiasing sampler. Is there a setting I need to change to alleviate this, or is simply that the wood texture is too large (1024x1024) and I need to use mimapping to achieve a better result?

Mipmapping and trilinear (or anisotropic) filtering (both during rendering the first cube to the texture and when rendering the second cube).

Edited by tonemgub

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!