Page 1 of 1
How to use the ZGE-Light component?
Posted: Wed Feb 16, 2022 2:43 pm
by ab2
The documentation is sparse
http://www.zgameeditor.org/index.php/ComponentRef/Light
and I did not find any zgeproj-file nor another tutorial or example
that is using the ZGE-Light component.
Can someone demonstrate the usage?
My attempts to add lights did not change the scene at all.
What would be needed?
Thanks for some advice.
Cheers
Andreas
Re: How to use the ZGE-Light component?
Posted: Wed Feb 16, 2022 3:10 pm
by Kjell
Hi Andreas,
ab2 wrote: ↑Wed Feb 16, 2022 2:43 pmCan someone demonstrate the usage?
Here's a simple demonstration of a white cube being lit by 3 differently colored point lights ( red, green and blue ).
Code: Select all
<?xml version="1.0" encoding="iso-8859-1" ?>
<ZApplication Name="App" Caption="ZGameEditor application" AmbientLightColor="0 0 0 1" FileVersion="2">
<OnLoaded>
<SpawnModel Model="Box"/>
</OnLoaded>
<OnUpdate>
<ZExpression>
<Expression>
<![CDATA[// Animate all 3 lights
float t = App.Time/8;
RedLight.Position.X = cos(t*3)*4;
RedLight.Position.Z = sin(t*3)*4;
GreenLight.Position.Y = cos(t*4)*4;
GreenLight.Position.Z = sin(t*4)*4;
BlueLight.Position.X = cos(t*5)*4;
BlueLight.Position.Y = sin(t*5)*4;]]>
</Expression>
</ZExpression>
</OnUpdate>
<OnRender>
<UseMaterial Material="NodeMaterial"/>
<Repeat Name="NodeRepeat" Count="3" WhileExp="//">
<OnIteration>
<ZExpression>
<Expression>
<![CDATA[// Render light "representation" nodes for demonstation purposes
switch(NodeRepeat.Iteration)
{
case 0:
NodeColor.Color = RedLight.Color;
NodeTransform.Translate = RedLight.Position;
break;
case 1:
NodeColor.Color = GreenLight.Color;
NodeTransform.Translate = GreenLight.Position;
break;
case 2:
NodeColor.Color = BlueLight.Color;
NodeTransform.Translate = BlueLight.Position;
break;
}]]>
</Expression>
</ZExpression>
<RenderSetColor Name="NodeColor" Color="0 0 1 1"/>
<RenderTransformGroup Name="NodeTransform">
<Children>
<RenderMesh Mesh="NodeMesh"/>
</Children>
</RenderTransformGroup>
</OnIteration>
</Repeat>
</OnRender>
<Lights>
<Light Name="RedLight" Color="1 0 0 1" Kind="1"/>
<Light Name="GreenLight" Color="0 1 0 1" Kind="1"/>
<Light Name="BlueLight" Color="0 0 1 1" Kind="1"/>
</Lights>
<Content>
<Model Name="Box" RotationVelocity="0.1 0.2 0">
<OnRender>
<UseMaterial Material="BoxMaterial"/>
<RenderMesh Mesh="BoxMesh"/>
</OnRender>
</Model>
<Mesh Name="BoxMesh">
<Producers>
<MeshBox/>
</Producers>
</Mesh>
<Material Name="BoxMaterial"/>
<Mesh Name="NodeMesh">
<Producers>
<MeshSphere Scale="0.25 0.25 0.25" ZSamples="3" RadialSamples="4"/>
</Producers>
</Mesh>
<Material Name="NodeMaterial" Shading="2" Light="0"/>
</Content>
</ZApplication>
K
Re: How to use the ZGE-Light component?
Posted: Fri Feb 18, 2022 11:34 am
by ab2
Thank you for your vivid demonstration.
So lights by itself are invisible objects and
the in the example attached nodes can be used
to visualize them.
Can a spot-light effect like in a theatre
with a sharp radial illumnination on an
object be achived?
Or do you know of a good demonstration / page
what light type (spot, point, directional) to use
for what effect on a scene or object and how it should look like?
Many thanks
A
Re: How to use the ZGE-Light component?
Posted: Fri Feb 18, 2022 12:11 pm
by Kjell
Hi Andreas,
ab2 wrote: ↑Fri Feb 18, 2022 11:34 amSo lights by itself are invisible objects and the in the example attached nodes can be used to visualize them.
Yea, i just added the "nodes" so it's easier to understand what's going on.
ab2 wrote: ↑Fri Feb 18, 2022 11:34 amCan a spot-light effect like in a theatre with a sharp radial illumnination on an object be achived?
Yes, but you probably want to use shaders for that. When you use the fixed-function pipeline light is calculated at vertex level, so you'd need high-poly meshes for the effect to look good. Here's a simple example of that using a single spotlight. You can control the "softness" of the spotlight by moving your mouse up/down, and you can toggle the shading style of the scene by pressing 1/2/3/4 on your keyboard ( for debugging purposes ).
Code: Select all
<?xml version="1.0" encoding="iso-8859-1" ?>
<ZApplication Name="App" Caption="ZGameEditor application" AmbientLightColor="0 0 0 1" CameraPosition="0 10 10" CameraRotation="0.125 0 0" MouseVisible="255" FileVersion="2">
<OnUpdate>
<ZExpression>
<Expression>
<![CDATA[// Control spot "softness"
SpotLight.SpotExponent = (1-App.MousePosition.Y)*22.5;
// Animate spot light
float a = sin(App.Time*2)/4;
SpotLight.SpotDirection.X = sin(a);
SpotLight.SpotDirection.Y = -cos(a);
SpotLight.Position.Y = 8+sin(App.Time/3)*4;]]>
</Expression>
</ZExpression>
<KeyPress Name="ShadingKey" Keys="1234">
<OnPressed>
<ZExpression>
<Expression>
<![CDATA[// Switch scene shading
SceneMaterial.Shading = ShadingKey.KeyIndex;]]>
</Expression>
</ZExpression>
</OnPressed>
</KeyPress>
</OnUpdate>
<OnRender>
<UseMaterial Material="SceneMaterial"/>
<RenderMesh Mesh="SceneMesh"/>
</OnRender>
<Lights>
<Light Name="SpotLight" Color="1 1 1 1" Kind="2" SpotDirection="0 0 0" SpotCutoff="22.5"/>
</Lights>
<Content>
<Mesh Name="SceneMesh">
<Producers>
<MeshBox Scale="4 4 1" XCount="15" YCount="15" Grid2DOnly="255"/>
<MeshTransform Position="0 -1 0" Rotation="-0.25 0 0"/>
<MeshBox XCount="3" YCount="3"/>
<MeshCombine/>
</Producers>
</Mesh>
<Material Name="SceneMaterial"/>
</Content>
</ZApplication>
K
Re: How to use the ZGE-Light component?
Posted: Fri Feb 18, 2022 5:02 pm
by ab2
Thanks. That is the tutorial style i really like an can handle
pretty good.
Sorry that I experiment with it .. probably with to few understanding ..
but why in this project gets the Light Color overwritten by the
Scene-Material Color?
Re: How to use the ZGE-Light component?
Posted: Fri Feb 18, 2022 5:21 pm
by Kjell
Hi Andreas,
ab2 wrote: ↑Fri Feb 18, 2022 5:02 pmSorry that I experiment with it .. probably with to few understanding .. but why in this project gets the Light Color overwritten by the Scene-Material Color?
It doesn't. When you for example change SceneMaterial.Color from white into yellow the scene ( box & floor ) appears yellow because at that point it's a yellow box & floor lit by a white light. But if you then for example change the SpotLight.Color from white into red, the yellow box & floor appears red.
The result is always a combination of the object's color and the color of the emitted light.
K
Re: How to use the ZGE-Light component?
Posted: Sat Feb 19, 2022 1:42 am
by ab2
Sorry without additional tries i choose first yellow for the spotlight and then
orange for the scene. That was a bad Example.