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 / REALLY bizarre shader problem with instanced objects

Author
Message
CumQuaT
AGK Master
16
Years of Service
User Offline
Joined: 28th Apr 2010
Location: Tasmania, Australia
Posted: 15th Dec 2012 03:25
Hi all, I'm experiencing a very odd problem. If I apply an alpha-mapped shader to an instanced object in my advanced lighting system, it shows up as black.

To give more detail... If I use, say, a normal map shader on an object, texture it and instance it, the object shows up perfectly fine.

BUT

If I use a normal map shader that allows alpha maps, then I texture the object and then instance it, the object shows up as black, as you can see in this image:



The reason this is so odd is that if I texture the object, apply an alpha mapped shader and then CLONE the object, it works fine. It only happens when I INSTANCE the object...

Any ideas?


Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 15th Dec 2012 12:31 Edited at: 15th Dec 2012 12:34
I'm sure there is a bug introduced in a recent update (not sure which).

Some of my old shader demos had instanced objects and used to work perfectly but will only work correctly if I change instance to clone when I use recent updates.

I'm afraid you'll probably have to work around this issue somehow. I don't think it's been formally reported as a bug yet though.

I can see this will be annoying if you're relying on the performance boost from instancing.

Edit I'll try to find time today to look into your specific issue in case there's a satisfactory solution using instancing - but I don't hold out much hope.
CumQuaT
AGK Master
16
Years of Service
User Offline
Joined: 28th Apr 2010
Location: Tasmania, Australia
Posted: 15th Dec 2012 12:56
Oh man, that's really bad news.....

I hope you find something! Thanks GG!


Chris Tate
DBPro Master
17
Years of Service
User Offline
Joined: 29th Aug 2008
Location: London, England
Posted: 15th Dec 2012 14:22
Does the original object; the one instanced, contain the shader? Has the shader been applied to the source object before instancing? Might make a difference, who knows.

Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 15th Dec 2012 14:26
OK. I've time to look at it now.

Just to clarify things, are you saying that the only difference is the alpha mapping when you say

Quote: "To give more detail... If I use, say, a normal map shader on an object, texture it and instance it, the object shows up perfectly fine.

BUT

If I use a normal map shader that allows alpha maps, then I texture the object and then instance it, the object shows up as black, as you can see in this image:
"
CumQuaT
AGK Master
16
Years of Service
User Offline
Joined: 28th Apr 2010
Location: Tasmania, Australia
Posted: 15th Dec 2012 15:04
@Chris Tate - Yes, I've textured and applied the shader to the base object before instancing

@Green Gandalf - Correct. It only happens when using shaders that require alpha maps.


Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 15th Dec 2012 15:04
I can't reproduce the problem - see attached no frills demo.

The source object is the lower one.

Perhaps Chris Tate is on to something?

Could you provide a simple demo showing the problem? Email me if you prefer so I can look at it.
CumQuaT
AGK Master
16
Years of Service
User Offline
Joined: 28th Apr 2010
Location: Tasmania, Australia
Posted: 15th Dec 2012 15:47
I'll whip something up and post it here


Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 15th Dec 2012 16:15
Quote: "I'll whip something up and post it here"


OK. That's probably safer - my email has decided that today is the day to have a foul up.

In the meantime I'll see if I can reproduce the problem by doing things a bit differently.
CumQuaT
AGK Master
16
Years of Service
User Offline
Joined: 28th Apr 2010
Location: Tasmania, Australia
Posted: 15th Dec 2012 16:18
Cool it's 1:30am here, so I'm gonna have to get some sleep, but I'll jump on this first thing and put together something that clearly illustrates it. And I'll include source!


CumQuaT
AGK Master
16
Years of Service
User Offline
Joined: 28th Apr 2010
Location: Tasmania, Australia
Posted: 16th Dec 2012 02:30
Okay, I've attached a demo.

Check through the code and look for where I've INSTANCED the object. Notice that the tree will appear black, since it uses an alpha map. Change INSTANCE to CLONE and the tree will show up perfectly.


Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 16th Dec 2012 13:09
Just had a chance to check this - and I confirm the symptoms you've described.

I haven't checked the code in detail yet (it always takes me an age to unravel Evolved's code ) but there are two obvious differences between your demo and mine: your demo uses objects with limbs and has different shaders on different limbs. That should not be a problem but may be where the DBPro bug lies assuming there is one.

Do you know whether limbs are involved in each case that fails?

Just done a bit of testing and there seems to be a problem with clone object as well. Itried to see what happened when the shaders were disabled, i.e.



When I do that, instance object works (except for the black background on the leaves of course) but clone object fails. I suspect there's something else going on here. Have you tried asking Evolved about this?

I'll try a few more things and post back - but at the moment I'm as baffled as you are.
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 16th Dec 2012 16:13 Edited at: 16th Dec 2012 17:01
Well, it doesn't seem to have anything to do with the limbs. I get the same problem with simple objects like cubes insted of trees in your demo. This suggests to me the problem is a more fundamental one with the way Evolved's Advanced Lighting works with DBPro.

One other possibility is that DBPro hasn't correctly handled the large number of techniques and/or techniques used in Evolved's shader system when cloned instanced objects are used. I'm not sure of the best way to test that since those are an intrinsic part of Evolved's system which I assume you're hoping to use.

Edit Incidentally that demo doesn't seem to use alpha maps - it simply clips the leaves if the colour is too dark. I don't know whether that's part of the problem. Seems unlikely but not impossible.

Edit2 Hmm? What I've just said isn't quite true. The source image "Tree leaf.BMP" doesn't seem to have an alpha map but the shader uses it. I wonder if DBPro is using the default colorkey to create the alpha map? I'll do a bit more testing.

Edit3 Yes, the alpha map is the default one constructed by DBPro when the image is loaded and as far as I can see has nothing to do with the instancing problem. The precise cause remains a mystery.
CumQuaT
AGK Master
16
Years of Service
User Offline
Joined: 28th Apr 2010
Location: Tasmania, Australia
Posted: 16th Dec 2012 17:25
Hmm. I have had this happen on objects with a PNG channel where I'm using the transparency as the alpha map.

This rabbit hole goes deep! I've asked Evolved on his forum about it. If I end up getting a response I'll post details here.

For now, I'm baffled!


Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 16th Dec 2012 17:31
Quote: "For now, I'm baffled!"


Yes, indeed. At least you have a workaround - but I guess you really want instancing rather than cloning.

I've sent Evolved an email too so hopefully he'll have some suggestions. I doubt the problem is in his system though since cloning works.
david w
20
Years of Service
User Offline
Joined: 18th Dec 2005
Location: U.S.A. Michigan
Posted: 16th Dec 2012 17:49
I'm gonna look into this as well. I want to see what is going on. I love a good mystery!
EVOLVED
23
Years of Service
User Offline
Joined: 9th Feb 2003
Location: unknown
Posted: 16th Dec 2012 19:04 Edited at: 16th Dec 2012 19:08
Try adding the first object "Object_Add(1)". As you are instancing objects, and trees are generally non moving you may not have to use "Object_Add(3)" on your instanced object.
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 16th Dec 2012 19:27 Edited at: 16th Dec 2012 19:50
Thanks. That seems to have fixed it - although the bloom effect (?) seems washed out on my machine. I guess you still need the "3" when it's a cloned object.

Hopefully this will fix it for CumQuat's main application.



Edit Actually this seems to work better on my machines (but I'm not convinced I know what I'm doing). I'm guessing that some parts of the system need the actual object ID but others need the source object ID.

CumQuaT
AGK Master
16
Years of Service
User Offline
Joined: 28th Apr 2010
Location: Tasmania, Australia
Posted: 17th Dec 2012 06:11
Oooooh this is a nice turn of events to wake up to!

I'll check it out! So essentially we're adding the master object to the advanced lighting system before letting the engine instance the object? Sounds like a plan....


CumQuaT
AGK Master
16
Years of Service
User Offline
Joined: 28th Apr 2010
Location: Tasmania, Australia
Posted: 17th Dec 2012 06:38
IT WORKS!!!!

But now I've run into a different issue. Instanced objects won't animate for some reason... Is this normal?


Andrew_Neale
16
Years of Service
User Offline
Joined: 3rd Nov 2009
Location: The Normandy SR-2
Posted: 17th Dec 2012 09:56
As far as I know, the animation would be handled by the master object as well, so either the master object and all instances would animate using the same animation or none of them would animate at all.


Previously TEH_CODERER.
CumQuaT
AGK Master
16
Years of Service
User Offline
Joined: 28th Apr 2010
Location: Tasmania, Australia
Posted: 17th Dec 2012 14:30
Yeah, I've looped an animation on the master object, but none of the instances animate. Strange...

Also, my off-screen culling is visible along the edges of my screen. Objects are being hidden before they fully leave the screen, which only happens with instances, rather than clones.


Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 18th Dec 2012 18:54
Quote: "Yeah, I've looped an animation on the master object, but none of the instances animate. Strange..."


That is odd. I've just amended your earlier demo to include two instances of a boned animated model and they both follow the animation option chosen for the source object.

So something else is happening in your code. Are you sure you tried to loop the correct object ID? I can only reproduce your symptoms if I try to loop one of the instances instead.

For the more general problem of getting differently animated instances I can only think of partial solutions. For example, if you want to animate a horde of 100 instanced orcs (I saw "The Hobbit" film yesterday ) then you could have, say, 10 master orcs and 100 instances, 10 for each source orc. By animating the 10 source orcs differently the repetition might not be very noticeable.

If it's trees and grass you're trying to animate as in your earlier demo then a different solution might be possible (assuming that has the same issue).
Andrew_Neale
16
Years of Service
User Offline
Joined: 3rd Nov 2009
Location: The Normandy SR-2
Posted: 18th Dec 2012 19:03
Out of interest, the master object that was animating...it wasn't hidden or excluded was it? I don't think animation on an object with either of those states actually updates and hence wouldn't update the instances. That is just a semi-educated guess though.


Previously TEH_CODERER.
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 18th Dec 2012 20:41
The master object is hidden in my version.

Here's the code I was using (it uses the "tiny.x" boned model that comes with the DX SDK but I guess you can use your own):



I haven't worked out what's happened to the shadows yet - but the objects which you can see animating are the instances of the hidden object 1.
Matty H
17
Years of Service
User Offline
Joined: 7th Oct 2008
Location: England
Posted: 18th Dec 2012 23:10
I think I reported the instanced animations bug on that '20 bugs to be fixed post'.

I found that if you turn object culling off on the master object then it works fine, if I remember right you do this by setting the objects radius to -1?

Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 19th Dec 2012 02:11
Quote: "if I remember right you do this by setting the objects radius to -1?"


What about set object cull objId, 0?

Actually, I'm having trouble seeing that bug here - and I'm not convinced it's the same problem anyway.
CumQuaT
AGK Master
16
Years of Service
User Offline
Joined: 28th Apr 2010
Location: Tasmania, Australia
Posted: 19th Dec 2012 07:07
Perhaps it is the culling... I'll have to give it a try.


Matty H
17
Years of Service
User Offline
Joined: 7th Oct 2008
Location: England
Posted: 19th Dec 2012 15:27
'Set Object Cull' is for back faces isn't it? I could be wrong.

Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 19th Dec 2012 17:14
Yes it is. I'd forgotten about the object culling when I made that comment.

That could well explain why I get different results - I'll check when I get a moment and report back.
miso
16
Years of Service
User Offline
Joined: 16th Jun 2010
Location: Budapest, Hungary, 127.0.0.1
Posted: 19th Dec 2012 18:09
Try to hid the parent object and position it front of the camera before sync while looping the animation. All your instances should be animated.

If you have clipping problems at the edges with the instances, then you can workaround it. The parent object should be the biggest object in general regarding of size, and the instances can be sized equal or smaller.

(clipping data is get from the parent object, that way you wont see appearing and disappearing objects out of the blue)

No place like 127.0.0.1 .
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 19th Dec 2012 18:42
I can't reproduce that problem - the instanced objects are still visible regardless of where I put the hidden source object.

I've still lost the shadows though.
miso
16
Years of Service
User Offline
Joined: 16th Jun 2010
Location: Budapest, Hungary, 127.0.0.1
Posted: 19th Dec 2012 20:52 Edited at: 19th Dec 2012 20:52
Hmm, I meant the animation with that one. Animation will be applied, if the parent is at the front of the camera. (it would be rendered, if it wasnt hidden.)

No place like 127.0.0.1 .
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 19th Dec 2012 20:58
I don't understand what you mean.

In the code snippet I posted a few posts back (see snippet) the parent object is hidden and it doesn't matter where I place it the instances still show and animate.
miso
16
Years of Service
User Offline
Joined: 16th Jun 2010
Location: Budapest, Hungary, 127.0.0.1
Posted: 19th Dec 2012 21:15
My bad, I missed that one. Didn't try, but I belive you that works too. ( I dont have ideas for the shadow problem though )

No place like 127.0.0.1 .
CumQuaT
AGK Master
16
Years of Service
User Offline
Joined: 28th Apr 2010
Location: Tasmania, Australia
Posted: 20th Dec 2012 10:31
Wow, thanks Miso. I'll give all of these new tips a try asap.


Login to post a reply

Server time is: 2026-07-07 05:16:09
Your offset time is: 2026-07-07 05:16:09