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
|
||||
{
|
||||
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;
|
||||
vec2 Position;
|
||||
vec4 Color;
|
||||
|
||||
// pointStuff;
|
||||
float Power;
|
||||
};
|
||||
|
||||
in vec2 vTexture;
|
||||
|
|
@ -19,10 +22,12 @@ layout(location = 0) out vec4 color;
|
|||
vec4 GetRenderColor();
|
||||
|
||||
vec3 calcPointLight(Light light) {
|
||||
float dis = distance(FragPos, light.Position);
|
||||
float intensity = 4 / 4 * PI * pow(dis, 2);
|
||||
vec2 diff = light.Position - FragPos;
|
||||
|
||||
return vec3(light.Color * intensity);
|
||||
float dif = light.Power / length(diff);
|
||||
float intensity = 4 * PI * dif * (dif * dif);
|
||||
|
||||
return vec3(intensity);
|
||||
}
|
||||
|
||||
vec3 calcLight() {
|
||||
|
|
@ -42,6 +47,9 @@ vec3 calcLight() {
|
|||
}
|
||||
|
||||
void main() {
|
||||
color = GetRenderColor() * Ambient;
|
||||
color += vec4(calcLight(), 1);
|
||||
vec4 render = GetRenderColor();
|
||||
|
||||
color = render * Ambient;
|
||||
|
||||
color += vec4(calcLight() * render.xyz, 1);
|
||||
}
|
||||
|
|
@ -44,31 +44,32 @@ namespace SM_TEST
|
|||
window.Run();
|
||||
}
|
||||
|
||||
private static DrawObject2D kasten;
|
||||
private static PointLight light;
|
||||
private static DrawParticles particles;
|
||||
private static void WindowOnUpdateFrame(object sender, FrameEventArgs e)
|
||||
{
|
||||
if (Keyboard.GetState()[Key.R])
|
||||
particles.Trigger();
|
||||
//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)
|
||||
{
|
||||
scene.ShowAxisHelper = true;
|
||||
|
||||
kasten = new DrawObject2D();
|
||||
DrawObject2D kasten = new DrawObject2D();
|
||||
kasten.Texture = new Texture(new Bitmap("herosword.png"));
|
||||
kasten.Transform.ApplyTextureSize(kasten.Texture, 500);
|
||||
scene.Objects.Add(kasten);
|
||||
|
||||
DrawText text = new DrawText(font, "Text");
|
||||
text.Transform.Position.Set(0, 500);
|
||||
scene.HUD.Add(text);
|
||||
scene.Objects.Add(text);
|
||||
|
||||
/*PointLight light = new PointLight();
|
||||
scene.LightInformations.Lights.Add(light);*/
|
||||
light = new PointLight();
|
||||
light.Color = new Color4(0, 1,0,1);
|
||||
scene.LightInformations.Lights.Add(light);
|
||||
|
||||
scene.LightInformations.Ambient = Color4.White;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue