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 Discussion / [STICKY] DBC 1.20 Commands Explained

Author
Message
Latch
18
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 30th Oct 2007 21:06 Edited at: 31st Oct 2007 18:04
This is an attempt to explain how the new commands work that have been added to DBC v1.20. I have attached a file that includes examples of each command. Any comments or suggestions on how to improve this reference is appreciated. I hope this information is helpful.

Because color is made of three values, Red, Green, and Blue, I use the RGB convention when referencing color or color components even though it is a single integer value. The function RGB(r,g,b) returns an integer.

First off,
What are the New Commands?

SET OBJECT AMBIENT <int obj>,<int color>
SET OBJECT DIFFUSE <int obj>,<int color>
SET OBJECT EMISSIVE <int obj>,<int color>
SET OBJECT SPECULAR <int obj>,<int color>,<float power>


obj is an integer value and represent the object number that is being affected. Range is from 1 to 65535.

color is an integer value and can be a single value or calculated using the RGB() function from DarkBASIC where there is a:
Red component from 0 - 255
Green component from 0 - 255
Blue component from 0 - 255
ex: rgb(255,123,45)

power is a float value representing the dispersal of Specular light. This can be any float value. The lower the value, the larger the dispersal of the reflection of light. The higher the value, the more concentrated the dispersal and smaller the area of reflection. Negative power values have an inverse affect.

These new commands for DarkBASIC Classic v1.20 are commands that control how the material of an object responds to and reflects light. Think of material as what an object is made out of - maybe wood, maybe steel, maybe glass, maybe rubber... By setting various combinations of color and commands, one strives to have the object appear to be made out of some kind of substance. This is a little different than texturing, which pastes a picture onto a 3d object. While you can make something have the characteristics of a material
with a well made texture, these material settings allow for the dynamic control of the reflectivity of light on an object in any color and from any direction there may be a light source. Using these material commands in combination with good textures and colors can create very interesting and even realistic effects.

SET OBJECT AMBIENT <objnumber>,<color>
The Ambient setting controls how an object reflects ambient light. That is to say, light that represents the general illumination of the object. Ambient light has no real direction so it is dispersed in all directions around an object equally. This paired with the object color and/or texture emphasizes the object's basic color and that color's brightness.

You may be used to the old ambient light control from 1.13 and earlier versions of DBC, which was a global setting and affected all of the 3d world; but because the ambient property is now object specific in DBC v1.20, SET OBJECT AMBIENT will control how a single object responds to the colors within the ambient light. You control the intensity of the color by setting the specific color values. If you set the Ambient color to RGB(255,255,255), then the object's ambient color will reflect Red fully, Green fully, and Blue fully.
I believe the default for SET OBJECT AMBIENT if you do not set it is
rgb(128,128,128)

SET OBJECT DIFFUSE <objnumber>,<color>
Diffuse light reflection can be looked at as the color of the object that is shown by lights other than Ambient in the 3d world. I probably could've worded that better - maybe: whatever color this is set to will be the color that shows when there is no Ambient light. Any better?

One thing to note: in a directx file, the diffuse setting will be the color of the object if there is no texture loaded. This behavior is a little different than the approach in DBC where the color can be set by SET OBJECT COLOR and the strength of that color is based on the ambient setting. SET OBJECT DIFFUSE in combination with the lighting in the scene will produce more subtle effects than setting the object color alone.

The color values in SET OBJECT DIFFUSE describe the intensity of the individual color components. Most often, Diffuse is set to the same value as Ambient light. However, when ambient light is high, the color of the object and/or the texture is prevalent and it's very hard to see the result of the Diffuse settings.

As the Ambient color moves closer to black, the colors set in SET OBJECT DIFFUSE become more evident. The Diffuse color will still respond to any other lights in the 3d world. The other lights that have a source and/or a direction will cause the Diffuse color to appear brighter where ever there is light reflecting on the object, thus showing more of whatever color is set using SET OBJECT DIFFUSE.

As SET OBJECT AMBIENT can influence the color of an object and intensify those particular color components, I usually set the RGB values of AMBIENT (rgb(128,128,128)) to the same number so that all of the color components of the texture/material are visible. This way I can raise the ambient light or lower it by changing all of the rgb values at once.

I use a function in many of the examples to control the ambient with one value similar to the old SET AMBIENT LIGHT command.

If the object has a texture that contains multiple colors these colors will be as bright as those colors matching the Ambient color setting. Though, if the Diffuse color is set differently than the texture color, the Diffuse color will become evident as the Ambient light diminishes as long as there is another light in the scene.
I believe the default for SET OBJECT DIFFUSE if you do not set it is
rgb(128,128,128)

So as my general rule of thumb, I set the Ambient light for the object to
SET OBJECT AMBIENT <obj>,RGB(100,100,100)
and then raise it or lower it depending on how the object looks.

SET OBJECT EMISSIVE <objnumber>,<color>
The other two settings:
SET OBJECT EMISSIVE and SET OBJECT SPECULAR are a little bit different.

The Emissive property of a material is the amount of "glow" that is generated by the material itself. Think of glowing eyes or lava or the lights on a digital consul where the light source is from the object itself. This light source only illuminates the material and does not project onto other objects - so you couldn't use it as a torch or some other source that casts light.

As Ambient light diminishes, the Emissive will maintain the brightness of whatever color it is set to. So you could fade out the ambient light of a robot object but have anything on it that is red for example, stay bright:
SET OBJECT EMISSIVE <obj>,RGB(255,0,0)
The effect with this setting would be as the body of the object get's darker, red eyes or red lights on the texture would look like they are still lit.
I believe the default for SET OBJECT EMISSIVE is
rgb(0,0,0)

SET OBJECT SPECULAR <objnumber>,<color>,<power>
SET OBJECT SPECULAR is the shininess of a material. This setting controls highlights on objects. <power> is a float value that represents the dispersal of the specular effect. A higher value concentrates the reflectivity to a smaller area. A lower value disperses the Specular effect over a wider area.

For a metallic or plastic effect, try matching the color of the Specular reflection to the color of the object. Change the power to control the size of the shine.
I believe the default for SET OBJECT SPECULAR is
rgb(0,0,0),0

Controlling light in a scene is a balancing act. There are many factors that influence how things look. A high polygon mesh will have a better response to light settings than a low polygon one. The normals are crucial... if they are not set properly you can end up getting very strange lighting or shadowing results. As these details are beyond the scope of this reference, I encourage you to read up on lighting, normals, and 3d in general.

The Examples:
In the attached file there are 5 examples. As all of the examples use SET OBJECT AMBIENT and 3 of them:
diffuse_test
emmisive_test
specular_ball_test
Allow you to control ambient directly to see the results, there is no individual ambient light test.

I had the most fun with the specular settings but these tests don't really show this control's full potential, but they can give you an idea of what can be done.

For two of the examples I used a library made by Kelebrindae. This library allows you to make a grid or a matrix from a memblock and use it as an object. This is an excellent library and even has a height map importer. I highly recommend using it. Your version of DarkBASIC will have to be able to use memblock commands to use the library.

http://www.thegamecreators.com/?m=codebase_view&i=892220bac2a253d568e672d05f608c00

specular_crinkle_metal
creates two bumpy matrixes that rotate in and out of two light sources - a blue light and a white light. As the surfaces become more aligned with the light sources, the specular reflection becomes more evident and the surfaces appear to shine.

height_map
Creates a terrain lanscape using the height map function from Kelebrindae's library (height map function originally written by Phaelax for DBPro).

I wrote a small colorizor script to convert the greyscale height map to a texture with a few colors (only six). Does the trick - nothing too fancy. The real goal of this demo is to show how the specular settings can be used like sunlight. You'll see shadowed areas where the light does not hit, and bright areas where the light is hitting directly. By using a low power (8 in this case) the specular dispersion is wide. You can rotate the landscape using the arrow keys. Pay close attention to how areas move in and out of shadows and how the sunlight seems to move across the ground and up the mountain slopes. Try changing the power to different values.

Enjoy your day.

Attachments

Login to view attachments
Muddleglum
22
Years of Service
User Offline
Joined: 3rd Nov 2002
Location: New Zealand
Posted: 31st Oct 2007 02:16
Brilliant latch .

david L.
Ron Erickson
Moderator
21
Years of Service
User Offline
Joined: 6th Dec 2002
Location: Pittsburgh, PA, USA
Posted: 31st Oct 2007 17:10 Edited at: 31st Oct 2007 17:10
Very NICE!

Thank you for doing this Latch. This thread deserves to be stickied. Here is some glue.


a.k.a WOLF!
Latch
18
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 31st Oct 2007 18:07
@Muddleglum

Thank you!

@Ron

Thanks! and you're welcome! Just let me know if you notice any inaccuracies.

Enjoy your day.
Yodaman Jer
User Banned
Posted: 7th Dec 2007 21:17 Edited at: 7th Dec 2007 21:18
WOw..so if I used the SET AMBIENT OBJECT function I could control the light of each object? That is stinking awesome!!

Thanks for taking the time to write this up for people!

Yodaman

Signatures....peh. I never come up with anything good to say in them. Ah well.
TheComet
17
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 31st Dec 2007 17:43
Wow! Thanks for writing this up, Latch!

TheComet

Oooooops!!! I accidentally formated drive c.
TheComet
17
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 2nd Jan 2008 19:48
@Latch

This is almost a record! 416 people have looked at this in 24 hours! Brilliant!

Oooooops!!! I accidentally formated drive c.
Latch
18
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 2nd Jan 2008 20:45
@Yoda + @TheComet
I'm glad you find it useful.

@Comet
Quote: "This is almost a record! 416 people have looked at this in 24 hours! Brilliant!"


uhhm if that's 24 hours + October 31, 2007

Enjoy your day.
Yodaman Jer
User Banned
Posted: 10th Jan 2008 21:27 Edited at: 10th Jan 2008 21:57
Quote: "@Comet
Quote: "This is almost a record! 416 people have looked at this in 24 hours! Brilliant!"

uhhm if that's 24 hours + October 31, 2007 "


Whoops...



Sorry, TGC, that message just applied to me all too well . . .
Libervurto
18
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 22nd Jan 2008 04:06
@Latch
I forgot to thank you for this
Now I like cubes again!

Latch
18
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 25th Apr 2008 01:44
I just noticed something. If you use Dark Ghosting (negative alphablending) with DBC v 1.20, the effect depends on the material settings. I found this out by running the DBC tank demo. I could see the squareness of the plain the smoke is textured on where as in v1.13 I could not.

If one wants to use Dark Ghosting (GHOST OBJECT ON <obj>,1) then they should increase ambient lighting for the object until the desired shade is achieved (for complete inversion that generally means SET OBJECT AMBIENT <obj> rgb(255,255,255) ).

You can also control the shade using SET OBJECT EMISSIVE. The rgb values do not have to be set to white for this to work, but rather a combination of ambient and emissive together to get the desired effect.

Here is an example using just SET OBJECT AMBIENT. Click a mouse button to toggle the default ambient setting to rgb(255,255,255).



Enjoy your day.

Login to post a reply

Server time is: 2024-11-21 10:26:43
Your offset time is: 2024-11-21 10:26:43