PointLights work now
This commit is contained in:
parent
1551af28cc
commit
1ed03fec3f
3 changed files with 34 additions and 13 deletions
|
|
@ -1,7 +1,19 @@
|
||||||
namespace SM2D.Light
|
using System.Collections.Generic;
|
||||||
|
using SM.OGL.Shaders;
|
||||||
|
|
||||||
|
namespace SM2D.Light
|
||||||
{
|
{
|
||||||
public class PointLight : LightObject
|
public class PointLight : LightObject
|
||||||
{
|
{
|
||||||
internal override int Type { get; } = 0;
|
internal override int Type { get; } = 0;
|
||||||
|
|
||||||
|
public float Power = 5;
|
||||||
|
|
||||||
|
internal override void SetUniforms(Dictionary<string, Uniform> uniforms)
|
||||||
|
{
|
||||||
|
base.SetUniforms(uniforms);
|
||||||
|
|
||||||
|
uniforms["Power"].SetUniform1(Power);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -5,6 +5,9 @@ struct Light {
|
||||||
int Type;
|
int Type;
|
||||||
vec2 Position;
|
vec2 Position;
|
||||||
vec4 Color;
|
vec4 Color;
|
||||||
|
|
||||||
|
// pointStuff;
|
||||||
|
float Power;
|
||||||
};
|
};
|
||||||
|
|
||||||
in vec2 vTexture;
|
in vec2 vTexture;
|
||||||
|
|
@ -19,10 +22,12 @@ layout(location = 0) out vec4 color;
|
||||||
vec4 GetRenderColor();
|
vec4 GetRenderColor();
|
||||||
|
|
||||||
vec3 calcPointLight(Light light) {
|
vec3 calcPointLight(Light light) {
|
||||||
float dis = distance(FragPos, light.Position);
|
vec2 diff = light.Position - FragPos;
|
||||||
float intensity = 4 / 4 * PI * pow(dis, 2);
|
|
||||||
|
float dif = light.Power / length(diff);
|
||||||
return vec3(light.Color * intensity);
|
float intensity = 4 * PI * dif * (dif * dif);
|
||||||
|
|
||||||
|
return vec3(intensity);
|
||||||
}
|
}
|
||||||
|
|
||||||
vec3 calcLight() {
|
vec3 calcLight() {
|
||||||
|
|
@ -42,6 +47,9 @@ vec3 calcLight() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
color = GetRenderColor() * Ambient;
|
vec4 render = GetRenderColor();
|
||||||
color += vec4(calcLight(), 1);
|
|
||||||
|
color = render * Ambient;
|
||||||
|
|
||||||
|
color += vec4(calcLight() * render.xyz, 1);
|
||||||
}
|
}
|
||||||
|
|
@ -44,31 +44,32 @@ namespace SM_TEST
|
||||||
window.Run();
|
window.Run();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static DrawObject2D kasten;
|
private static PointLight light;
|
||||||
private static DrawParticles particles;
|
private static DrawParticles particles;
|
||||||
private static void WindowOnUpdateFrame(object sender, FrameEventArgs e)
|
private static void WindowOnUpdateFrame(object sender, FrameEventArgs e)
|
||||||
{
|
{
|
||||||
if (Keyboard.GetState()[Key.R])
|
if (Keyboard.GetState()[Key.R])
|
||||||
particles.Trigger();
|
particles.Trigger();
|
||||||
//particles.Paused = Keyboard.GetState()[Key.P];
|
//particles.Paused = Keyboard.GetState()[Key.P];
|
||||||
kasten.Transform.Position.Set( window.Mouse.InWorld());
|
light.Position.Set( window.Mouse.InWorld());
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void WindowOnLoad(object sender, EventArgs e)
|
private static void WindowOnLoad(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
scene.ShowAxisHelper = true;
|
scene.ShowAxisHelper = true;
|
||||||
|
|
||||||
kasten = new DrawObject2D();
|
DrawObject2D kasten = new DrawObject2D();
|
||||||
kasten.Texture = new Texture(new Bitmap("herosword.png"));
|
kasten.Texture = new Texture(new Bitmap("herosword.png"));
|
||||||
kasten.Transform.ApplyTextureSize(kasten.Texture, 500);
|
kasten.Transform.ApplyTextureSize(kasten.Texture, 500);
|
||||||
scene.Objects.Add(kasten);
|
scene.Objects.Add(kasten);
|
||||||
|
|
||||||
DrawText text = new DrawText(font, "Text");
|
DrawText text = new DrawText(font, "Text");
|
||||||
text.Transform.Position.Set(0, 500);
|
text.Transform.Position.Set(0, 500);
|
||||||
scene.HUD.Add(text);
|
scene.Objects.Add(text);
|
||||||
|
|
||||||
/*PointLight light = new PointLight();
|
light = new PointLight();
|
||||||
scene.LightInformations.Lights.Add(light);*/
|
light.Color = new Color4(0, 1,0,1);
|
||||||
|
scene.LightInformations.Lights.Add(light);
|
||||||
|
|
||||||
scene.LightInformations.Ambient = Color4.White;
|
scene.LightInformations.Ambient = Color4.White;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue