Home Tutorials Download Beta Store Forum Documentation KnowledgeBase Wiki Blog

ShiVa3D

Return to Bugs

Texture alpha and depth testing(?)  [FIXED]

Report bugs and issues

Texture alpha and depth testing(?)

Postby Rayzer2 » 18 Jun 2011, 19:19

Hi, working on a new project now, it is a side view scrolling game. Faced the problem i could not solve by my self so posting about it here. All models in game are flat, consists of several quads (for animation purpose), and have texture with alpha channel. I guess it will be better to show, as with my poor english its really hard to explain the origin of the problem. Image. On the edge of alpha channel there is holes, which apears only when loking at object from slight angle (and as there is no orthogonal camera available in Shiva, when object is near the edge of the screen we'v got the same effect). The only way i found to overcome this issue is to turn off depth testing of the model material, but it messes the quads rendering order.
User avatar
Rayzer2
Senior Boarder
Senior Boarder
 
Posts: 42

Re: Texture alpha and depth testing(?)

Postby makkar » 19 Jun 2011, 09:04

You can increase "Alpha Ref" for materials and/or turn on "Opacity No Blend" option for your textures.
User avatar
makkar
Platinum Boarder
Platinum Boarder
 
Posts: 1516

Re: Texture alpha and depth testing(?)  [FIXED]

Postby NiCoX » 19 Jun 2011, 09:05

Hi,

You have many solutions, including:

1. use depth testing and "one bit transparency" (you can set it up in the MaterialEditor module, from the texture parameters dialog)

2. use depth testing and set up correctly "alpha ref" value of your materials

3. use no depth testing and set up correctly the "rendering priority" parameter for your materials

If you target mobile devices, the #3 method is the faster one.
User avatar
NiCoX
Platinum Boarder
Platinum Boarder
 
Posts: 5647
Location: France

Re: Texture alpha and depth testing(?)

Postby Rayzer2 » 19 Jun 2011, 14:37

Thanks, the third one seems to be a good solution (i did'nt know i can assign separate material to each individual subnode of the model), but will not that mean additional draw calls event with the same texture as texture map 0 for each body part i need to sort? With alpha reference unfortunately is really hard to find the "golden middle". Once again, thanks for a quick reply on weekend guys :)
User avatar
Rayzer2
Senior Boarder
Senior Boarder
 
Posts: 42

Re: Texture alpha and depth testing(?)

Postby NiCoX » 19 Jun 2011, 16:45

but will not that mean additional draw calls event with the same texture as texture map 0 for each body part i need to sort?

Yes indeed. Now that is a case that the engine runtime batcher could handle in the future (same material setup except priority).
User avatar
NiCoX
Platinum Boarder
Platinum Boarder
 
Posts: 5647
Location: France

Re: Texture alpha and depth testing(?)

Postby Zdrobot » 05 Jul 2012, 09:26

Guys, I ran into the same problem, but I want to understand my options better, please help me.

I have a very simple model, representing a patch of grass as viewed from the side. It consists of two polygons one behind the other (this is to enable simple skeletal animation - two rows of grass move side to side one in front, the other in the back). The grass is a texture applied to the polygons, with transparent areas.

As you can see in the close-up of the texture from 2d image editor, the pixels on the edges of the blades of grass are semi-transparent (their alpha values are neither 255 nor 0) -
Image

This is exactly what I want to see in Shiva - nice smooth blending with background objects. However, by default I get this -
Image

Adjusting Alpha Ref helps, but it looks to me as if it just sets some kind of transparency threshold, cutting off texels with alpha below certain value (but still >0) -
Image
The edges of the blades still don't look nice (although better).

If I disable Depth Write, everything is great, except that I can't use the same material on overlapping (from camera's point of view) objects that are located one behind the other -
Image
(There are 3 "grass" objects here, the one in the center is behind the other two)

I'm sorry for the long post, but isn't there a simple option to have textures with alpha-blending that doesn't disable z-buffer?
Zdrobot
Fresh Boarder
Fresh Boarder
 
Posts: 8

Re: Texture alpha and depth testing(?)

Postby Rayzer2 » 05 Jul 2012, 12:37

a.t.m. you'l have to use different materials with manually set depths for each layer (mesh on a specific depth) the materials are going to be applied. And sign the pettition so Stonetrip guys implements orthographic projection camera, or atleast provide the ability to generate projection matrix by yourself, it can be represented by a simple 1 dimensional array after all...
User avatar
Rayzer2
Senior Boarder
Senior Boarder
 
Posts: 42

Re: Texture alpha and depth testing(?)

Postby Zdrobot » 05 Jul 2012, 21:50

Rayzer2 wrote:a.t.m. you'l have to use different materials with manually set depths for each layer (mesh on a specific depth) the materials are going to be applied.

Well, that could solve the problem, but only in certain cases - 2d/2.5d games. What about proper 3d games, where you can look at objects from different angles?!

Rayzer2 wrote:And sign the pettition so Stonetrip guys implements orthographic projection camera, or atleast provide the ability to generate projection matrix by yourself, it can be represented by a simple 1 dimensional array after all...

I would gladly sign it if you could provide the link. Not being able to set up a proper orthographic camera is very strange indeed, although I don't understand how having it would solve this alpha-related issue.
Zdrobot
Fresh Boarder
Fresh Boarder
 
Posts: 8

Re: Texture alpha and depth testing(?)

Postby Rayzer2 » 06 Jul 2012, 07:48

I have explained regardless orthographic projection in one of my previous posts, the problem is with Z sorting of the surfaces which texture contains alpha channel, and which are rendered using perspective projection, it is not a Shiva specific issue. As for a complete 3D scene unfortunately the only solution i can think of now, is having you'r own sorting algorithm, which switches materials of the surface when needed. But still, there is a problem with non flat objects. The real solution to this is using programmable rendering pipeline, which is currently only planned.
User avatar
Rayzer2
Senior Boarder
Senior Boarder
 
Posts: 42

Re: Texture alpha and depth testing(?)

Postby Zdrobot » 06 Jul 2012, 08:06

Okay, so I've decided to see how this affects objects in other conditions.

Here's a simple "house" model with a window area that goes from fully opaque (white) to pretty transparent -
Image
What do you know, it works nicely, no problems at all!

And here are two houses, you can see the grass through their windows (faintly), works fine! -
Image

And here's how "Alpha Ref" parameter works (just as expected) -
Image

So I couldn't reproduce the problem in this case. Now I don't understand it at all.. oh well.
Zdrobot
Fresh Boarder
Fresh Boarder
 
Posts: 8


Return to Bugs