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 / Dark Lights and Dynamic Lights

Author
Message
MateiSoft Romania
10
Years of Service
User Offline
Joined: 16th Oct 2013
Location:
Posted: 8th Apr 2016 11:37
By testing out the code i found these graphics errors though. See how the lights are not evenly distributed and it rendered also on the back of the object and the light is not there. Sometimes it does not even render a few lights or objects. (See attachments)
Alex Matei CEO
www.alexmatei.com

Attachments

Login to view attachments
MateiSoft Romania
10
Years of Service
User Offline
Joined: 16th Oct 2013
Location:
Posted: 8th Apr 2016 11:37 Edited at: 8th Apr 2016 11:49
By testing out the code i found these graphics errors though. See how the lights are not evenly distributed and it rendered also on the back of the object and the light is not there. Sometimes it does not even render a few lights or objects. (See attachments)

[EDIT]

Forgot to mention, at re render this error with the lights it gives me.
Alex Matei CEO
www.alexmatei.com

Attachments

Login to view attachments
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 8th Apr 2016 16:09
MateiSoft Romania
I don't know what sort of objects you are using, but if you are using multiple copies ("clones") of a smaller number of source objects then the scene could consist of clones with the source objects loaded but hidden or excluded. In that case you wouldn't need to load the objects again - just make new clones which is far quicker. Hopefully I'll find time to look at your latest demo later today. Sounds like good news anyway.

VanB

In some of my tests I merely tried to recalculate the light map. That worked fine without a shader applied but failed when the bumpmapping shader is used. I haven't had time to narrow down the problem further but it is possible that the extra data such as tangents and binormals are causing the problem rather than the mere fact of a shader. Just a thought.


Powered by Free Banners
MateiSoft Romania
10
Years of Service
User Offline
Joined: 16th Oct 2013
Location:
Posted: 8th Apr 2016 17:38
I don't use clones though, i had some big problems with them if i remember, at scaling or something so I reload them through a temp file which contains their .x location.
Alex Matei CEO
www.alexmatei.com
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 8th Apr 2016 17:59 Edited at: 8th Apr 2016 18:06
Quote: "I don't use clones though, i had some big problems with them "


Strange. I use them a lot without problems.

Edit Sorry. Only just seen your two posts with the screenshots showing lighting errors. Could you supply code showing the problem?


Powered by Free Banners
MateiSoft Romania
10
Years of Service
User Offline
Joined: 16th Oct 2013
Location:
Posted: 8th Apr 2016 19:30
Of course, here you have the WHOLE light adding and light rendering code from my engine.

Alex Matei CEO
www.alexmatei.com
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 8th Apr 2016 20:02
Er, yes. That code might contain the problem but it doesn't show the problem. Perhaps I should have said: "Could you supply simple runnable code showing the probem?" I don't have time or energy to get to grips with the whole of your engine.


Powered by Free Banners
MateiSoft Romania
10
Years of Service
User Offline
Joined: 16th Oct 2013
Location:
Posted: 8th Apr 2016 22:13
Green Gandalf,

Please forgive me, i couldn't make the application work as in my engine but i created something to show... Maybe you can guess where the problem it will be. Sorry again and thank you!
Alex Matei CEO
www.alexmatei.com

Attachments

Login to view attachments
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 9th Apr 2016 11:20
Quote: "Please forgive me, i couldn't make the application work as in my engine but i created something to show"


No problem. I know how awkward it can be to devise a short demo of a problem. Thanks for the demo, I'll take a look.


Powered by Free Banners
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 9th Apr 2016 14:29
MateiSoft Romania

I couldn't get your code to work. I think it was trying to load non-existent media files before doing the lightmapping.

You seem to be doing a lot of unnecessary deleting and reloading.

Anyway, the following simplified version of your code works perfectly for me.

I've used clones instead of reloading objects but you can reload if you prefer.





Powered by Free Banners
WickedX
15
Years of Service
User Offline
Joined: 8th Feb 2009
Location: A Mile High
Posted: 9th Apr 2016 18:55
Sorry, off topic. I use DBPro version 7.4 and don’t have the Object Scale functions. Just curious if this would work the same. Thank you.


MateiSoft Romania
10
Years of Service
User Offline
Joined: 16th Oct 2013
Location:
Posted: 9th Apr 2016 19:53
Green Gandalf,

I tested out your example but at re calculation, still, the lights dissappears. First time is ok, the lights are there as it should when adding for the first time the lights, but the second time, it ruins the lights, some appears and some don't or sometimes, no lights appear at all. So currious why this is happening though
Alex Matei CEO
www.alexmatei.com
MateiSoft Romania
10
Years of Service
User Offline
Joined: 16th Oct 2013
Location:
Posted: 9th Apr 2016 20:01
WickedX,

I will try your code soon.
Alex Matei CEO
www.alexmatei.com
WickedX
15
Years of Service
User Offline
Joined: 8th Feb 2009
Location: A Mile High
Posted: 9th Apr 2016 21:35 Edited at: 10th Apr 2016 23:42
Thank you, Alex. No hurry.

Edit: Never mind, it works the same.
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 10th Apr 2016 11:49
Quote: "Anyway, the following simplified version of your code works perfectly for me. "


Well, it did yesterday.

Quote: "First time is ok, the lights are there as it should when adding for the first time the lights, but the second time, it ruins the lights, some appears and some don't or sometimes, no lights appear at all."


Yes, that's happening here now as well (see attached screenshots).

Quote: "So currious why this is happening though"


So am I! I thought I'd fixed those issues - obviously I haven't . I'll take a look and see if I accidentally changed something back to what it was. However, I suspect there is some residual stuff in memory behind the scenes when we delete objects. There was a post a while back about a memory leak when deleting objects and/or shaders. Perhaps this is related. If that's the problem perhaps we need to use different object IDs for the new objects? It won't cure any memory leak if there is one but might bypass your particular problem. I'll do a bit more experimenting. You're lucky it's a wet and windy Sunday here so coding seems a good option.


Powered by Free Banners

Attachments

Login to view attachments
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 10th Apr 2016 16:32 Edited at: 10th Apr 2016 16:33
Quote: "If that's the problem perhaps we need to use different object IDs for the new objects? It won't cure any memory leak if there is one but might bypass your particular problem."


Looks like that hack works. It's not an ideal solution because it requires careful housekeeping to keep track of object IDs. But it does seem to work. Try this version:



Powered by Free Banners
MateiSoft Romania
10
Years of Service
User Offline
Joined: 16th Oct 2013
Location:
Posted: 11th Apr 2016 10:15
Hello Green Gandalf,

It works PERFECTLY! I will struggle to implement this code and after that message here.

Thank You!!!
Alex Matei CEO
www.alexmatei.com
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 11th Apr 2016 11:01
You're welcome.


Powered by Free Banners
MateiSoft Romania
10
Years of Service
User Offline
Joined: 16th Oct 2013
Location:
Posted: 11th Apr 2016 14:16
It seems like when i try to update the code the actual shader does not appear on the object. I can't spot any errors in this code, I know for sure that i am doing something wrong...

Alex Matei CEO
www.alexmatei.com
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 11th Apr 2016 15:29
Have you tried putting some simple debug code after recalculating the lightmap but before applying the shader and bump map? The objects should appear textured and lightmapped. Do they?

Your use of texture IDs puzzled me. When you rebuild the objects you use:



but later on when you apply the shader you use this:



That looks wrong for two reasons: (1) why is the base texture a fixed ID (=1) whereas the bump map has a variable value? and (2) why do you load the bump map twice?


Powered by Free Banners
MateiSoft Romania
10
Years of Service
User Offline
Joined: 16th Oct 2013
Location:
Posted: 11th Apr 2016 18:28
I re organised the code and saw the issues,

Unfortunately now it throws me an error that a specific object does not exist when building the lightmaps.

I am confused regarding this part of code(and the lines that look like this):



Here is the reorgranised code:

Alex Matei CEO
www.alexmatei.com
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 11th Apr 2016 19:49 Edited at: 11th Apr 2016 20:12
Quote: "Unfortunately now it throws me an error that a specific object does not exist when building the lightmaps."


Which specific object?

My original snippet (which could be improved by the way ) works as follows:

Suppose for simplicity the scene consists of objects 1 to 6 before being lightmapped.

If you press <control> to calculate the first lightmap the code first deletes those 6 objects and then creates new copies numbered 1001 to 1006. (You will obviously have to choose a value more appropriate to your application - 1000 was just an example.) These six new objects are then lightmapped before applying the shader.

Suppose you then make changes to the lights and then recalculate the lightmap. The code will first create a new scene and lightmap as above but now the objects will be numbered 2001 to 2006 and so on.

If at some point you have made 5 lightmaps then the scene objects will be numbered 5001 to 5006 unless you have also changed the scene. If you also add or delete scene objects you should probably add or delete them using IDs in the same range otherwise you will get into a coding nightmare. For example, you might delete the 3rd object, currently object ID 5003 say, and add a new seventh object. It would make sense perhaps to number the new object 5007 rather than 7 so everything stays in step. You can them recalculate the lightmap in the same way as before, i.e. first delete the current scene objects numbered 5001, 5002, 5004 to 5007. Then reconstruct the scene with copies numbered 6001, 6002, 6004 to 6007. Then recalculate the lightmap followed by the normal mapping as before.

Incidentally your snippet will start to go wrong after 8 or 9 lightmaps because you've tried to use the range 9000 upwards for something else. You'll obviously need to plan in advance for the suitable ranges for the lightmapping process and adjust the code accordingly. Perhaps reserve low object IDs for the light objects (which don't need to change unless they are actual scene objects) and then the original set of scene objects. Then use multiples of some sensible large number for the offset copies of the scene (I used 1000 but you might think 10000 is better, etc).

Can you see an obvious way of improving my original snippet? [It should be obvious - but whether it's worth doing is another matter. ]

Edit: Haven't checked your revised snippet yet.

[Edit2: I see you are saving your scene objects using names based on the IDs offset by multiples of 1000. It would probably be tidier not to do that. Then when you close and restart your editor you can start the lightmapping numbering afresh. The offset IDs are simply a way of bypassing the ligtmapping/shader bug and should be hidden from the user I guess.]


Powered by Free Banners
MateiSoft Romania
10
Years of Service
User Offline
Joined: 16th Oct 2013
Location:
Posted: 11th Apr 2016 21:19 Edited at: 11th Apr 2016 21:19
The last object added in the scene, if the last is 6 then the 6 will give error and so on.

As for the counter i set the counter to: counter*1 because my scene objects and light objects and so on are numbered specifically in order

I understood the idea of the snipper indeed. Only that is so damn hard to implement it into my editor
Alex Matei CEO
www.alexmatei.com
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 11th Apr 2016 23:22
Quote: "The last object added in the scene, if the last is 6 then the 6 will give error and so on."


But which line in the code gives the error? Not sure what you mean by "and so on".

Quote: "As for the counter i set the counter to: counter*1"


Sorry, I don't understand what you mean. Which part of your code are you referring to?


Powered by Free Banners
MateiSoft Romania
10
Years of Service
User Offline
Joined: 16th Oct 2013
Location:
Posted: 12th Apr 2016 00:27
The code that I am reffering to is:



As for the line, I do not compile and run the application in DBPRO, I copy and paste the executable near the C# interface executable and see the engine reaction there so i cannot see the line of the error occured, so the line I am guessing that is somewhere here:



I do am really sorry for this fuzziness, i am really struggling to get this code adapted in my engine...
Alex Matei CEO
www.alexmatei.com
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 12th Apr 2016 13:51
Have you tried putting some diagnostic printout to help you narrow down the problem? I guess you have an object incorrectly labelled somewhere in your code.


Powered by Free Banners
MateiSoft Romania
10
Years of Service
User Offline
Joined: 16th Oct 2013
Location:
Posted: 12th Apr 2016 20:32
Ok so i managed to trace the error, the syntax problem was:



I noticed indeed that the objects are created as 1000 + as you said as the number. However my engine depends on some files that reads their properties and stuff, how can we change this code to re initilize the objects as with their old number? I mean if we deleted 1 the objects must be again 1, not 1001 or something, is that possible Green Gandalf?

Thank you very much for your time and for helping me sort this mess in my engine!

Again thank you!
Alex Matei CEO
www.alexmatei.com
MateiSoft Romania
10
Years of Service
User Offline
Joined: 16th Oct 2013
Location:
Posted: 15th Apr 2016 14:56
Green Gandalf,

Another question, how can i translate the colour codes from rgb to rgba?

set vector4 1, 255.0/val(lightcolorr$), 255.0/val(lightcolorg$), 255.0/val(lightcolorb$), 255.0/val(lightcolorb$) <-"A"
Alex Matei CEO
www.alexmatei.com
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 15th Apr 2016 15:52
Quote: "how can i translate the colour codes from rgb to rgba?"


Not sure what you mean. But if you mean how can I translate rgb byte values to the rgb values used in a shader then the answer might be something like the following (note the reversal of your ratios)



where ??? is any alpha value relevant to the pixel in question such as 0.0 for fully transparent and 1.0 for fully opaque. Following your code then I guess a sensible value would be 1.0 for the alpha component of a light colour since transparency is usually irrelevant.


Powered by Free Banners
MateiSoft Romania
10
Years of Service
User Offline
Joined: 16th Oct 2013
Location:
Posted: 16th Apr 2016 12:52
Well the colours does not look good though when settings it to 1.0 neither to 0.0

The blue looks green and the purple looks red.

See the attachement please

Thank You!
Alex Matei CEO
www.alexmatei.com

Attachments

Login to view attachments
MateiSoft Romania
10
Years of Service
User Offline
Joined: 16th Oct 2013
Location:
Posted: 19th Apr 2016 12:32
Any thoughts GG?
Alex Matei CEO
www.alexmatei.com
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 19th Apr 2016 22:31
Quote: "Not sure what you mean. But if you mean how can I translate rgb byte values to the rgb values used in a shader then the answer might be something like the following"


Since you haven't explained what your code is doing or even shown your code I can't help you. My earlier suggestion quoted above was just a guess at what you're trying to do. Your picture suggests that you select a colour from your palette and then try to light your object using that selected colour - but that is also a guess since you haven't told us the code which does all this. In fact I can't see why you don't simply print out some values from your colour selector and compare those with the values you are supplying to a shader (again I'm guessing that is what you are doing). If they differ then it shouldn't be hard to work out why, surely?


Powered by Free Banners
MateiSoft Romania
10
Years of Service
User Offline
Joined: 16th Oct 2013
Location:
Posted: 19th Apr 2016 23:03
Excuse me GG,

I didn't realized that you wanted a piece of code, here is the light adding method:



You see there the update code for the shaded light that receives values from a file and the last variable is 1.0 there i think is the problem why basically when i select blue value like is 0.0.255 it goes green.
Alex Matei CEO
www.alexmatei.com
Van B
Moderator
21
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 20th Apr 2016 10:27
This..... 255.0/val(lightcolorb$),

You are taking a colour value and dividing 255.0 by it.... why?

This doesn't make sense, this means that when lightcolorb$ is 128, you are setting the vector to 2.0!

Shaders expect colour values as floats in the 0.0-1.0 range, and you have it all ass-backwards as far as I can tell, and this doesn't occur to you - despite being told by GG already?

To take a value from 0 - 255 to a float value suitable for a shader, divide it by 255... so val(lightcolorb$) / 255.0

So 0 is 0.0, 128 is 0.5, and 255 is 1.0 - Your bug is probably caused by that - for example, if you want a yellow/orange light, you might use RGB(255,200,50)...

With your conversion, the shader gets RGB( 1.0 , 1.25 , 5.1 ) - giving a blue colour about 5 times stronger than what it should be. Is it any wonder your colours are messed up?
By dividing by 255, the shader gets RGB( 1.0 , 0.78 , 0.20 )
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 20th Apr 2016 16:45
Quote: "Shaders expect colour values as floats in the 0.0-1.0 range, and you have it all ass-backwards as far as I can tell, and this doesn't occur to you - despite being told by GG already?

To take a value from 0 - 255 to a float value suitable for a shader, divide it by 255... so val(lightcolorb$) / 255.0

So 0 is 0.0, 128 is 0.5, and 255 is 1.0 - Your bug is probably caused by that - for example, if you want a yellow/orange light, you might use RGB(255,200,50)...

With your conversion, the shader gets RGB( 1.0 , 1.25 , 5.1 ) - giving a blue colour about 5 times stronger than what it should be. Is it any wonder your colours are messed up?
By dividing by 255, the shader gets RGB( 1.0 , 0.78 , 0.20 )"


Spot on, VanB.

I think people don't always read what they've been told. Perhaps we'll be third time lucky...


Powered by Free Banners
MateiSoft Romania
10
Years of Service
User Offline
Joined: 16th Oct 2013
Location:
Posted: 25th Apr 2016 11:14
Hello good people,

First of all sorry for the delay. I surely wasn't paying attention to what it has been explained to me. The inversed method worked beautifully!

Thank you very much! Awesome help, awesome people as always!
Alex Matei CEO
www.alexmatei.com
MateiSoft Romania
10
Years of Service
User Offline
Joined: 16th Oct 2013
Location:
Posted: 6th May 2016 11:51
Green Gandalf,

Does your shader support texture scaling? If it is possible to have texture scaling and after that output by a command in dbpro with the values.

Thank you!
Alex Matei CEO
www.alexmatei.com
MateiSoft Romania
10
Years of Service
User Offline
Joined: 16th Oct 2013
Location:
Posted: 10th May 2016 11:52
Any ideas GG?

Thank you very much for all!
Alex Matei CEO
www.alexmatei.com

Login to post a reply

Server time is: 2024-04-19 04:53:14
Your offset time is: 2024-04-19 04:53:14