News:

SMF - Just Installed!

Main Menu

How to emit light (light effect)

Started by minDark, December 02, 2013, 02:19:19 PM

Previous topic - Next topic

minDark

I need to replicate the behavior of Beacon Light. I tried to modify EmissiveColor property but that is not what i want. I want to actually emit light from a lamp.

EasyPLC_Master

You can use the system light objects properties.
For example for the box with index 0 of a UserDefinedComponent an example could be:
(remember to apply a green texture before)



bool green;

public void Init()
{
box[0].DiffuseColor = new Vector3(0, 0.7f, 0);
}

public void Main(GameTime gameTime)
{

  if(IO.GetOutput("Green"))     
{
    if (!green)
    {
box[0].SpecularPower = 0;
box[0].EmissiveColor = new Vector3(0,1,0);
box[0].SpecularColor = new Vector3(0,1,0);

    }
    green= true;
}
else
{
if(green)
{
box[0].SpecularPower = 100;
box[0].EmissiveColor = new Vector3(0,0,0);
box[0].SpecularColor = new Vector3(0,0,0);
}
green= false;
}
}

public void Draw(GameTime gameTime)
{

}

public void Finish()
{

}



For more sophisticated light you can add a billboard component to simulate the light brightness.

minDark

Thanks, but i already done that, is not what i want. Can you give an example on how to use the billboard?? I don't have experience with XNA programming.

EasyPLC_Master

Here is:

bool green;
Billboard billb;

public void Init()
{
box[0].DiffuseColor = new Vector3(0, 0.7f, 0);
billb = new Billboard(MachSim);
billb.Scale = new Vector3(1.0f, 1.0f, 1.0f);
billb.Alpha = 100;
billb.Position = box[0].Position;
billb.Texture = Editor.GetTexture(@"Transparents\Light.png");
billb.Visible = false;
MachSim.Components.Add(billb);
}

public void Main(GameTime gameTime)
{

  if(IO.GetOutput("Green"))     
{
    if (!green)
    {
box[0].SpecularPower = 0;
box[0].EmissiveColor = new Vector3(0,1,0);
box[0].SpecularColor = new Vector3(0,1,0);
billb.Visible = true;
    }
    green= true;
}
else
{
if(green)
{
box[0].SpecularPower = 100;
box[0].EmissiveColor = new Vector3(0,0,0);
box[0].SpecularColor = new Vector3(0,0,0);
billb.Visible = false;
}
green= false;
}
}

public void Draw(GameTime gameTime)
{

}

public void Finish()
{
MachSim.Components.Remove(billb);
}

minDark

It's better than previous example. I tried to change the texture with another .png but still cannot replicate the same effect as your Beacon Light from Components. Your beacon seems more realistic. Thanks a lot anyway!!!