~ Changed Pipelines
(Default2DPipeline: Has Lights, Post-ProcessingEffects, etc.) (Basic2DPipeline: Simple Color and Texture stuff, thats it)
This commit is contained in:
parent
1ed03fec3f
commit
5d4b360b05
23 changed files with 243 additions and 59 deletions
|
|
@ -1,5 +1,7 @@
|
|||
using System.Collections.Generic;
|
||||
using OpenTK;
|
||||
using OpenTK.Graphics;
|
||||
using SM.Base;
|
||||
using SM.Base.Types;
|
||||
using SM.OGL.Shaders;
|
||||
|
||||
|
|
@ -7,6 +9,7 @@ namespace SM2D.Light
|
|||
{
|
||||
public abstract class LightObject
|
||||
{
|
||||
private Vector2 _posNorm => Vector2.Divide(Position, (SMRenderer.CurrentWindow as GLWindow2D).WorldScale);
|
||||
internal abstract int Type { get; }
|
||||
|
||||
public CVector2 Position = new CVector2(0);
|
||||
|
|
|
|||
|
|
@ -8,12 +8,16 @@ namespace SM2D.Light
|
|||
internal override int Type { get; } = 0;
|
||||
|
||||
public float Power = 5;
|
||||
public float InnerCircle = 1;
|
||||
public float OuterCircle = 1;
|
||||
|
||||
internal override void SetUniforms(Dictionary<string, Uniform> uniforms)
|
||||
{
|
||||
base.SetUniforms(uniforms);
|
||||
|
||||
uniforms["Power"].SetUniform1(Power);
|
||||
uniforms["Inner"].SetUniform1(1 / InnerCircle);
|
||||
uniforms["Outer"].SetUniform1(1 / OuterCircle);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,9 +1,11 @@
|
|||
using System.Reflection;
|
||||
using SM.Base;
|
||||
using SM.Base.PostProcess;
|
||||
using SM.Base.Scene;
|
||||
using SM.OGL.Framebuffer;
|
||||
using SM.OGL.Shaders;
|
||||
using SM.Utility;
|
||||
using SM2D.Scene;
|
||||
|
||||
namespace SM2D.Light
|
||||
{
|
||||
|
|
@ -12,14 +14,25 @@ namespace SM2D.Light
|
|||
private PostProcessShader _shader = new PostProcessShader(AssemblyUtility.ReadAssemblyFile("SM2D.Light.light.frag"));
|
||||
private LightSceneExtension sceneExtension;
|
||||
|
||||
public override void Draw(Framebuffer main)
|
||||
public override void Init(Framebuffer main)
|
||||
{
|
||||
base.Draw(main);
|
||||
|
||||
base.Init(main);
|
||||
main.Append("occluder", 1);
|
||||
}
|
||||
|
||||
public override void Draw(Framebuffer main, Framebuffer target)
|
||||
{
|
||||
base.Draw(main, target);
|
||||
|
||||
_shader.Draw(main.ColorAttachments["color"], collection =>
|
||||
{
|
||||
collection["FragSize"].SetUniform2((SMRenderer.CurrentWindow as GLWindow2D).WorldScale);
|
||||
|
||||
collection["Ambient"].SetUniform4(sceneExtension.Ambient);
|
||||
collection["LightCount"].SetUniform1(sceneExtension.Lights.Count);
|
||||
collection["OccluderMap"].SetTexture(main.ColorAttachments["occluder"]);
|
||||
collection["ShadowSensitivty"].SetUniform1(1f);
|
||||
|
||||
UniformArray array = collection.GetArray("Lights");
|
||||
|
||||
for (int i = 0; i < sceneExtension.Lights.Count; i++)
|
||||
|
|
|
|||
|
|
@ -8,15 +8,22 @@ struct Light {
|
|||
|
||||
// pointStuff;
|
||||
float Power;
|
||||
float Inner;
|
||||
float Outer;
|
||||
};
|
||||
|
||||
in vec2 vTexture;
|
||||
in vec2 FragPos;
|
||||
|
||||
uniform vec2 FragSize;
|
||||
|
||||
uniform vec4 Ambient = vec4(1);
|
||||
uniform Light[24] Lights;
|
||||
uniform int LightCount;
|
||||
|
||||
uniform float ShadowSensitivty;
|
||||
uniform sampler2D OccluderMap;
|
||||
|
||||
layout(location = 0) out vec4 color;
|
||||
|
||||
vec4 GetRenderColor();
|
||||
|
|
@ -24,10 +31,27 @@ vec4 GetRenderColor();
|
|||
vec3 calcPointLight(Light light) {
|
||||
vec2 diff = light.Position - FragPos;
|
||||
|
||||
float dif = light.Power / length(diff);
|
||||
float intensity = 4 * PI * dif * (dif * dif);
|
||||
float dif = 20 / length(diff);
|
||||
float intensity = light.Power * (dif) * (dif * dif);
|
||||
|
||||
return vec3(intensity);
|
||||
return vec3(light.Color * intensity);
|
||||
}
|
||||
|
||||
float occluded(Light light) {
|
||||
float occluder = 1 - length(texture(OccluderMap, vTexture).rgb);
|
||||
|
||||
if (occluder != 0) {
|
||||
vec2 diff = light.Position - FragPos;
|
||||
vec2 dir = normalize(diff);
|
||||
|
||||
float steps = length(diff) / ShadowSensitivty;
|
||||
|
||||
vec2 curPos = FragPos;
|
||||
for(int i = 0; i < steps; i++) {
|
||||
curPos += dir * i * ShadowSensitivty;
|
||||
}
|
||||
}
|
||||
return occluder;
|
||||
}
|
||||
|
||||
vec3 calcLight() {
|
||||
|
|
@ -36,11 +60,13 @@ vec3 calcLight() {
|
|||
for(int i = 0; i < LightCount; i++) {
|
||||
Light light = Lights[i];
|
||||
|
||||
vec3 lightColor;
|
||||
switch(light.Type) {
|
||||
case 0:
|
||||
addedLight += calcPointLight(light);
|
||||
lightColor += calcPointLight(light);
|
||||
break;
|
||||
}
|
||||
addedLight += lightColor * occluded(light);
|
||||
}
|
||||
|
||||
return addedLight;
|
||||
|
|
@ -51,5 +77,5 @@ void main() {
|
|||
|
||||
color = render * Ambient;
|
||||
|
||||
color += vec4(calcLight() * render.xyz, 1);
|
||||
color += vec4(calcLight(), 1);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue