Ambiera Forum

Discussions, Help and Support.

Ambiera Forum > CopperLicht
Dynamic lights

pptech
Registered User
Quote
2012-03-21 17:30:43

Does anybody know if the shader code for the dynamic lights is correct? I'm having trouble predicting the results and although my GLSL is a bit shakey the shader code looks quite different to those I have seen before. Thanks.


niko
Moderator
Quote
2012-03-22 06:01:18

You mean the internal code CopperLicht uses? What do you mean with correct? It's the same as used in the Flash 3D target, and has about the same result as the fixed function pipeline in OpenGL and Direct3D.


pptech
Registered User
Quote
2012-03-22 10:29:37

I have a model that has been used in other systems so I'm sure it is correct. In the scene shown in this image
🔎︎

I have a single light source placed at 5, 5, 5 with the light colour set to 0.7, 0.7, 0.7. There is ambient light set at 0.5, 0.5, 0.5.

The model is placed at 0, 0, 0 and has been scaled from the model units of mm by 1/1000.

As you can see there is very little lighting effect but what there is appears to be coming from below the ground. Moving the light position has little or no effect.

I must be missing something regarding lighting then. Any tips?

Thanks


niko
Moderator
Quote
2012-03-22 12:34:44

Ah, now I see. I think what might be the problem here is that in the Flash and WebGL target (=CopperLicht) of CopperCube, lighting doesn't work very nicely with scaled models. This has been done for increasing the performance, and when you are only slightly scaling your model, you won't notice anything. When scaling it quite a bit however, you will see that the lighting on your model isn't correct anymore.
I think this is what you are discovering. If you don't scale your model in the CopperCube editor, then lighting should be ok. You can scale it using the low poly scaling tool, though (under "Polygon editing"), which will change the vertex coordinates and not the scale. Or you can rescale and reimport your model as well, as alternative workaround.
Hope this helps!


pptech
Registered User
Quote
2012-03-22 19:33:33

Thanks that certainly did help but now I have a slightly different problem. I have added two lights into the scene They have locations of 20,20,20 and -20,-20,-20 respectively. It seems like as I turn the brightness of one of these lights up or down it has an impact on the brightness of the other light. On surfaces that point away from the first light their surface light should come from the ambient light and the second light only but this doesn't appear to be the case.

Screen shots might help. In the image on the left I have my default light settings. In the image on the right I have turned the second light colour up. Notice how the wall behind has got brighter but the model and the floor has got darker.

🔎︎



niko
Moderator
Quote
2012-03-23 06:20:40

Hm, this depends on how your scene is set up exactly, difficult to say what the problem is there. That the floor is so dark might be because you are using realtime dynamic light, which is vertex based. If your floor only consists of 4 vertices, then there are only 4 light samples and the values get interpolated between them, resulting in probably a wrong looking light. Splitting up the floor into more polygons helps then.
But generally, I'm not sure what causes the effect you described. Maybe you could send me the .ccb file (See Support -> Contact, there is a mail adress) and I'll have a look at this.


pptech
Registered User
Quote
2012-03-26 16:19:05

Unfortunately the model hasn't come from a ccb file but rather a custom downloader.

I have seen a few lighting shaders and never come across anything like this line:

float angle = sin( dot(vec3(n.xyz), vertexToLight) )


My understanding was that the dot function would return the cos of the angle between the two vectors (if they are normalized) and you could directly use that value to modulate the light colour. Do you have a reference for the origin of your shader or is it your own?

Thanks


niko
Moderator
Quote
2012-03-26 19:27:22

Hm, the dot product is the cosine of two vectors, in this case the vector of the normal of the surface to the vector to the light. Calculating the sin of it should get the angle, right? But yes, it should also work without the sin().
Yes, it's my own shader. :)


pptech
Registered User
Quote
2012-03-27 12:05:32

I thought dot gave you a value between -1 and 1. If you want the angle wouldn't you use acos? But you wouldn't want the angle, a value between -1 and 1 is fine. Ignore the values < 0 to modulate the light..
float modulate = max(dot(n.xyz, vertexToLight), 0.0);
Don't quote me, I'm no expert but I've seen this sort of calculation lots of times before.


Create reply:


Posted by: (you are not logged in)


Enter the missing letter in: "I?ternational" (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