Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / Draw order and transparency

Author
Message
Dr Tank
15
Years of Service
User Offline
Joined: 1st Apr 2009
Location: Southampton, UK
Posted: 6th Jan 2011 20:11
I know exactly what order I want my objects drawn in, and it never changes. My objects are all planes with normals aligned with the z-axis. My camera looks in this direction, and camera and object z positions are constant. However, as the camera moves sideways, DBP changes its mind about what order to render things in!

Back in the day, I think DBP rendered in order of texture number. For me this would be ideal. Is there a way the return to that, or any other way to manually set in what order things are rendered?

BTW some of my objects use shaders, and some use set camera to image images.
The Slayer
Forum Vice President
14
Years of Service
User Offline
Joined: 9th Nov 2009
Playing: (Hide and) Seek and Destroy on my guitar!
Posted: 6th Jan 2011 20:28
Quote: "BTW some of my objects use shaders, and some use set camera to image images."

Hum, not entirely sure, but I think that might be the problem. I think shaders allways render first, and the DBPro commands secondly. Or, is it vice versa?

Cheers

SLAYER RULES! YEAH, MAN!!
Dr Tank
15
Years of Service
User Offline
Joined: 1st Apr 2009
Location: Southampton, UK
Posted: 6th Jan 2011 21:16 Edited at: 6th Jan 2011 21:32
I don't know. I tried applying the shader to all objects, but DBP still keeps changing its mind about what order the objects are rendered.

Another thing I tried was to disable object zdepth for all objects which works fine, except it screws up my screen shake function that changes the camera matrix.
IanM
Retired Moderator
21
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 6th Jan 2011 21:33
Transparent objects are always sorted into reverse distance-from-the-camera. That's transparency within DBPro, when set using the SET OBJECT TRANSPARENCY command.

For fixed order rendering, disable transparency for the object in DBPro, and enable it yourself within the shader (or leave it enabled if it already is).

Even then though, DBPro will sort by the main object texture id. You can disable all sorting by using SET GLOBAL OBJECT CREATION with a mode of 2 (IIRC).

Dr Tank
15
Years of Service
User Offline
Joined: 1st Apr 2009
Location: Southampton, UK
Posted: 6th Jan 2011 23:41
Thanks.

I tried set global creation and DBP still rendered things in different orders dependent on cam position.

I used
set object transparency objnum,0
and a shader on the relevant objects, and most of them are rendered in texture number order. I have set object numbers in the same order. However, some are still rendered out of order.

Also, strangely, with transparency mode 0 (which should be transparency OFF!), and a shader, black parts of objects are transparent. I'm guessing what's happening is that when the texture is loaded (bmp), the alpha channel is generated. I guess I can write a func to turn an image opaque after loading. Setting the shader to overwrite the alpha output with 1 works too.

Anyway although I still don't know how the rendering order works, it happens to be mostly working OK at the moment!
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 7th Jan 2011 01:50 Edited at: 7th Jan 2011 01:52
Quote: "Transparent objects are always sorted into reverse distance-from-the-camera. That's transparency within DBPro, when set using the SET OBJECT TRANSPARENCY command."


Quote: "My camera looks in this direction, and camera and object z positions are constant. However, as the camera moves sideways, DBP changes its mind about what order to render things in!"


Z-position order is not necessarily the same as order based on distance from the camera when the camera moves sideways. Is it possible to fool the system by messing about with the planes camera X and Y coords so that the object distances relative to the camera are unchanged by camera movement?
Dr Tank
15
Years of Service
User Offline
Joined: 1st Apr 2009
Location: Southampton, UK
Posted: 7th Jan 2011 02:10
Quote: "Z-position order is not necessarily the same as order based on distance from the camera when the camera moves sideways."

I figure that must be true, for whatever criteria is bases its decision on. z-distance is the same, but perhaps it uses actual distance calculated by sqrt(x^2 + y^2 + z^2).

I might try "tricking" it like you say. Maybe by having the centre of my foreground object much closer, but shifting limb 0 back so the polygons remain in place. Alternatively I can do this for x/y co-ords but that's a bigger workaround.

Having to put everyting in shaders is limiting because AFAIK, you can't do ghosting with shaders. Whilst ideally I would be able to set my draw order manually, having DBP recalculate it each frame, but actually get it right, would be acceptable!
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 7th Jan 2011 10:31
I keep having similar problems, just when I think I've got it, something goes wrong. I found a DBP command that determines whether loading order, Index number or z-order affects transparency. However, I can't remember for the life of me what it was!

My problem was that I didn't want index number to have any effect, and by default it did. This may be your problem too.

Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 7th Jan 2011 13:06
Quote: "However, I can't remember for the life of me what it was!"


I'm having exactly the same problem. Lee recently (i.e. within the last 18 months or so ) gave a detailed explanation of how to control render order in current versions of DBPro. I have no idea now where that was. It might have been buried in an upgrade public beta thread, or an editor thread, or the newsletter, or even an email, or somewhere else entirely.

Perhaps someone else remembers where it was?

I vaguely recall Dark Coder being involved so perhaps it was on one of his threads?

Quote: "I figure that must be true, for whatever criteria is bases its decision on. z-distance is the same, but perhaps it uses actual distance calculated by sqrt(x^2 + y^2 + z^2)."


I guess the real question is: how is an object's distance calculated? My guess (which I suppose I could test easily ) is that DBPro assumes the object's position corresponds to the position of the object's (0, 0, 0) coordinate which of course doesn't actually need to be anywhere near the object.
Sven B
19
Years of Service
User Offline
Joined: 5th Jan 2005
Location: Belgium
Posted: 7th Jan 2011 14:36
I just browsed a little in the DBP source code and it seems that the code used is sqrt(x^2 + y^2 + z^2) which is then sorted in reverse order.
That's if you would use Depth sorting.





Just thought I'd throw it in here.

Cheers!
Sven B

IanM
Retired Moderator
21
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 7th Jan 2011 14:47
Let me add emphasis:
Transparent objects are always sorted into reverse distance-from-the-camera.

Quote: "Lee recently ... gave a detailed explanation of how to control render order in current versions of DBPro."

That was probably me, not Lee.

The order of rendering is (and I'm doing this from memory):
- Very early objects (Object transparency mode 7)
- Main layer (Standard objects)
- Reflection layer
- Shadow layer
- Ghosted and transparent layer
- Locked or no-zdepth layer

Objects are sorted according to the select made with SET GLOBAL OBJECT CREATION, except that ghosted/transparent objects are always depth-sorted.

The distance is determined using the actual distance between the current camera, and the object origin.

The only part of that that has been changed since I've been involved (apart from performance increases) is that the camera used is the current camera, but it used to use camera 0.

Quote: "you can't do ghosting with shaders"

Anything you can do in the fixed pipeline, can also be done in the shader pipeline. That doesn't mean that I can do it though

Have a look at this thread in gamedev.net about 3 quarters of teh way down - there's an example shader there that uses alphablending that you should be able to use.

Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 7th Jan 2011 17:56
Quote: "except that ghosted/transparent objects are always depth-sorted"


Isn't that the answer to Dr Tank's problem then?
IanM
Retired Moderator
21
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 7th Jan 2011 18:10
I thought that the answer was to disable transparency and ghosting in DBPro, and enable them within the shader, and then to use the SET GLOBAL OBJECT CREATION mode to specify ordering by texture, object id, or creation order.

At least, that's what I put in my first post

Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 7th Jan 2011 18:16
Quote: "At least, that's what I put in my first post"


I know. Are you saying that depth sorting isn't what's needed here? Seems simpler to be honest.
IanM
Retired Moderator
21
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 7th Jan 2011 19:38
Yes - it seems the best match to what he wants. For example, if he sets the global creation mode to object id order, then he can create his objects furthest away first. Then no matter how the camera moves around on the xy plane, the draw order won't change.

It's because the current order is by-distance that his draw order is changing - I can't quite see how that would be if the camera only moves in the xy plane and the objects only rotate to point towards the camera though, and I can't reproduce it:


Dr Tank
15
Years of Service
User Offline
Joined: 1st Apr 2009
Location: Southampton, UK
Posted: 7th Jan 2011 21:02 Edited at: 8th Jan 2011 05:05
Thanks guys. A lot to think about and try.

Option 1) I can try to get sorting by texture number working, and write a ghost shader.

Option 2) trick it into depth sorting in the order I want, by positioning everything at the same x,y co-ords and offseting limb 0. Alternatively, I could just stretch my world massively along z, make the camera fov hella small, making absolute distance ~ z distance.

Option 3) Modify the DBP source code! Just sort by z distance!




I'll try to go with option 1, since it will give me absolute control, and presumably means less work for the graphics card. Writing a ghost shader is something I'd want to do at some point anyway.



Quote: "I can't quite see how that would be if the camera only moves in the xy plane and the objects only rotate to point towards the camera though"

I'm not pointing objects at the camera. The plains have normals always parralel to the world (and camera) z-axis - they only rotate about the z-axis.
Dr Tank
15
Years of Service
User Offline
Joined: 1st Apr 2009
Location: Southampton, UK
Posted: 8th Jan 2011 05:58 Edited at: 8th Jan 2011 06:06
I've made a test program that works for both a shader with transparency, and for regular textured objects! It sorts by texture number, and you can even mix and match shader and no shader objects!

It seems all is required is transparency mode 1.

Here's my test program:


Here's the shader, although you can just comment out the shader bits in the above and that will work OK anyway!


It doesn't work with DBP ghosted objects. Going to try and write a shader for that. Alternatively, I think one transparency mode works over everything, and I only want one object in front of my ghost stuff, so maybe I'll go with that.

BTW I also noticed there's a "nosort" flag in texture object, but haven't played with that.
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 8th Jan 2011 10:08
Quote: "- Locked or no-zdepth layer"


This is where my problem was isolated. Within the locked objects, I had a sorting problem, and there was definitely a command that determined different ways to sort.

Dr Tank
15
Years of Service
User Offline
Joined: 1st Apr 2009
Location: Southampton, UK
Posted: 10th Jan 2011 23:51 Edited at: 11th Jan 2011 01:00
Ian was totally right - you can do ghosting in shaders. Here's the ghosting shader I'm using. The thing to look at is the bit inside pass p1 - destblend and srcblend.




This page I found useful: [link]

Edit: Maybe those aren't the right settings for proper ghosting- seems to matter in which order objects are rendered. I got better looking results with: DestBlend = ONE;

Now my problems are solved: all my objects use transparency mode 1 and are drawn by texture number.

I did try tricking the distance sorting by moving the object centre positions, but it seems that the distance calculation was working bizarrely. I wasn't able to work out what was wrong but it doesn't matter because transparency in my game works perfectly now. Thanks to everyone who helped.

Login to post a reply

Server time is: 2024-05-18 12:36:40
Your offset time is: 2024-05-18 12:36:40