Author Topic: Model transparency  (Read 2790 times)

Angelo

  • Jr. Member
  • **
  • Posts: 32
Model transparency
« on: May 18, 2012, 04:40:24 PM »
Is there a fast way of changing the transparency of an entire model or mesh? I guess I could manipulate the transparency values of its materials, but by doing so I would lose the original transparency values, or I should find a way to store them, which can get very complex. I need to create a simple slider control which goes from 0% to 100%, and such value should multiply the original transparency values of the model, for the rendering.

jerome_j

  • Administrator
  • *****
  • Posts: 116
    • Bonzai Engine
Re: Model transparency
« Reply #1 on: May 19, 2012, 09:38:33 AM »
You can use RenderOptions:
and to restore to solid:

By default, the transparency percentage is 0.2. It can however be set to any value you want (between 0 to 1) with RenderPipeline.alpha.
For next build, I will certainly move static RenderPipeline.alpha in a field of RenderOptions.
« Last Edit: May 19, 2012, 09:40:58 AM by jerome_j »

Angelo

  • Jr. Member
  • **
  • Posts: 32
Re: Model transparency
« Reply #2 on: May 19, 2012, 05:48:58 PM »
I tried. But I get weird results, similar to those I got when I tried using antialiasing. Here is a snapshot:

http://dl.dropbox.com/u/14911350/2012-05-19%2017.39.52.jpg

It was the result of just writing:


I was expecting to see no changes. Instead, normals appear flipped.

Angelo

  • Jr. Member
  • **
  • Posts: 32
Re: Model transparency
« Reply #3 on: May 19, 2012, 06:10:39 PM »
I am working on an Acer Iconia Tab A500, which mounts an 1 GHz Nvidia Tegra 250 CPU.
I managed to make CSAA work. The antialiasing now works fine. I am just telling you because I had encountered this same flipped-normals problem when I was trying to make antialiasing work. I don't know if CSAA is somehow related to this flipped-normals problem.

jerome_j

  • Administrator
  • *****
  • Posts: 116
    • Bonzai Engine
Re: Model transparency
« Reply #4 on: May 19, 2012, 07:00:38 PM »
When you use Transparent render mode, depth test is disabled to render polygon with blending.

This works fine for small value of alpha, but when you get close to 1, then you got your weird result. Under 0.7 it should give satisfying result but above that it will start looking bad/weird. This is not a bug, but exactly what is expected when depth test is disabled (this looks similar to what you have whith antialiasing when depth buffer was not created).

When you set 1, the engine currently still use blending and disable depth buffer. I'll change that for next release so it will looks looks the same than in Solid (default) mode.
Anyway, I'll suggest to use Solid render instead of Transparent also when alpha value is close to 1.
« Last Edit: May 19, 2012, 07:04:23 PM by jerome_j »

Angelo

  • Jr. Member
  • **
  • Posts: 32
Re: Model transparency
« Reply #5 on: May 19, 2012, 07:07:31 PM »
I see. My problem is that, since I use a slider to modify the transparency, I would like to get a continuous transition from 0% to 100%. Is there a way to avoid this discontinuity introduced by suddenly shifting from Transparent mode to Solid mode?

jerome_j

  • Administrator
  • *****
  • Posts: 116
    • Bonzai Engine
Re: Model transparency
« Reply #6 on: May 19, 2012, 07:35:37 PM »
Depending on your exact need, there are some solutions usable in realtime which may give you better result.
What effect and on which model of you're scene did you need to have then transparent ?

When you deal with blending, to get perfect rendering, you must sort each triangle by depth from back to front. And when you have triangle which interesect together you should split then for proper sorting. Doing it in realtime sorting is very consuming, therefore most of the time only the mesh/model are sorted.

Here's one solution which will give you continuity, proper sorting but back faces will not be visible:
1) Render all opaque models of your scene
2) Sort transparent model back to front, and for each model do:
2.1) Render the model solid but with color writting disabled. This will write depth of front faces, and keep original color.
2.2) Render the model with blending (transparent) with color writting and depth test enabled.
The renderer set some default state so possibly some state can't be controlled, I'll check to see if this is possible with the current release.

If this solution is suitable for what you need, but you have issues implementing this, just let me know. We can eventually implement it directly in the engine, or at least provide utilities to help you out (such as sorting, ...).
« Last Edit: May 19, 2012, 07:39:21 PM by jerome_j »

jerome_j

  • Administrator
  • *****
  • Posts: 116
    • Bonzai Engine
Re: Model transparency
« Reply #7 on: May 20, 2012, 12:37:19 PM »
I have added in the today's build RenderOptions.SurfaceTransparent which implements transparent rendering as described above.
You can give a try:
Let me know if you find this options usefull.
« Last Edit: May 20, 2012, 01:01:07 PM by jerome_j »

Angelo

  • Jr. Member
  • **
  • Posts: 32
Re: Model transparency
« Reply #8 on: May 20, 2012, 12:58:11 PM »
I just tried it. It works well with alpha = 1 (same rendering as Solid mode), but I still get that flipped-normals rendering with alpha < 1.

jerome_j

  • Administrator
  • *****
  • Posts: 116
    • Bonzai Engine
Re: Model transparency
« Reply #9 on: May 20, 2012, 01:03:12 PM »
Did you have a screenshot ?

Make sur you're using SurfaceTransparent and, in the case you have more than one model transparent, to sort them from back to front relatively to the camera (opaque models must be rendered first too).

We don't provide yet utilities for sorting model by their distance to the camera, let me know if you need.

Angelo

  • Jr. Member
  • **
  • Posts: 32
Re: Model transparency
« Reply #10 on: May 20, 2012, 01:08:41 PM »
I was not sorting. I thought your last build made sorting not necessary. I am afraid I cannot use the sorting technique. I have a model which include desks that are positions in this side and on the other side of a wall. I cannot sort this model with the models of the walls.

jerome_j

  • Administrator
  • *****
  • Posts: 116
    • Bonzai Engine
Re: Model transparency
« Reply #11 on: May 20, 2012, 01:23:33 PM »
You don't need sorting on the side but only on depth, to ensure (or at least minimize with an approcimatesorting) that a transparent model behind is rendered after a transparent model in the front.
Transparent model on same depth level but on two sides of the screen can be rendered in any order.

jerome_j

  • Administrator
  • *****
  • Posts: 116
    • Bonzai Engine
Re: Model transparency
« Reply #12 on: May 26, 2012, 03:45:40 PM »
The today's build adds utility to sort model and model instance.

You may find it usefull for rendering your transparent objects.
You can use something similarly to this:
« Last Edit: May 26, 2012, 03:48:05 PM by jerome_j »