Ambiera Forum

Discussions, Help and Support.

Ambiera Forum > CopperCube > Announcements and Showcase
Dynamic lighting for sky boxes

Robo
Guest
Quote
2019-11-19 06:53:34

I found a good way to dynamically change skybox lighting after quite a bit of trial and error.

You can now dynamically adjust Ambient & Emissive (glow) on textures like skyboxes etc. You have to convert an RGB value into HEX as below to run:

at every 50ms intervals or so run with variable ambient as 'amb' :


var node = ccbGetSceneNodeFromName("SkyBox");
if (amb > 50) {
amb = (amb - 1);

var rgbToHex = function (rgb) {
var hex = Number(rgb).toString(16);
if (hex.length < 2) {
hex = "0" + hex;
}
var color = (hex+hex+hex);
ccbSetSceneNodeMaterialProperty(node, 0, "Ambient", color);
ccbSetSceneNodeMaterialProperty(node, 1, "Ambient", color);
ccbSetSceneNodeMaterialProperty(node, 2, "Ambient", color);
ccbSetSceneNodeMaterialProperty(node, 3, "Ambient", color);
ccbSetSceneNodeMaterialProperty(node, 4, "Ambient", color);
ccbSetSceneNodeMaterialProperty(node, 5, "Ambient", color);
ccbSetCopperCubeVariable("skyAmb", amb);
return hex;
};
rgbToHex(amb);
}

This will darken a skybox and can also do the same by replacing "Ambient" with "Emissive".

I tried very hard but unable to adjust the alpha also this way...might not be possible....post an update anyone who figures that out.


Robo
Guest
Quote
2019-11-19 07:10:21

By the way, not only for lighting but change it to any color you want this way...I am going to use it for sunset/sunrise cloud darkening and maybe organge/yellow adjust as well to skybox...


carlosm
Registered User
Quote
2019-11-19 16:56:24

Do not understand!

Can I now dynamically change or the type of lighting?
what to say during the game?
is the amb variable defined as? before checking if it's bigger than 50?


Robo
Guest
Quote
2019-11-20 01:21:32

wrote:
Do not understand!

Can I now dynamically change or the type of lighting?
what to say during the game?
is the amb variable defined as? before checking if it's bigger than 50?



Yes, if you make a skybox with dynamic lighting (or select 'lighting' in irrLict properties) you can dynamically adjust its lighting using the code above. You could also use it for just changing the color only and use the default root scene node "AmbientLight" setting instead to do the lighting .

I have this code "var color = (hex+hex+hex);" which makes the lighting change intensity only as all 3 RGB numbers are the same. To get the color you want instead then add another 2 lines I think (havent tested yet) to run the function and get each hex output to then input into the Emissive/Ambient section as the new hex color.


Create reply:


Posted by: (you are not logged in)


Enter the missing letter in: "Internat?onal" (you are not logged in)


Text:

 

  

Possible Codes


Feature Code
Link [url] www.example.com [/url]
Bold [b]bold text[/b]
Image [img]http://www.example.com/image.jpg[/img]
Quote [quote]quoted text[/quote]
Code [code]source code[/code]

Emoticons


   






Copyright© Ambiera e.U. all rights reserved.
Privacy Policy | Terms and Conditions | Imprint | Contact