05.01.2021
+ Bloom effect + PixelInformation + Many Summaries + Add-methods for CVectors + Exposure-Field in GenericCamera for HDR. ~ ColorAttachments now can have PixelInformation ~ Transformed MeshAttributes to a own class ~ Fixed the non-applying of transformations at texts ~ Added more information to the context ~ Improved Pipeline-Process. ~ Changed how Uniform takes arrays - Light system
This commit is contained in:
parent
9b917ac181
commit
4c18127c88
52 changed files with 697 additions and 373 deletions
|
|
@ -4,6 +4,7 @@ using OpenTK;
|
|||
using OpenTK.Input;
|
||||
using SM.Base.Controls;
|
||||
using SM2D.Scene;
|
||||
using SM2D.Types;
|
||||
|
||||
#endregion
|
||||
|
||||
|
|
|
|||
|
|
@ -16,8 +16,6 @@ namespace SM2D.Drawing
|
|||
{
|
||||
public int ZIndex { get; set; }
|
||||
|
||||
public bool ShadowCaster = false;
|
||||
|
||||
public Texture Texture
|
||||
{
|
||||
get => (Texture) _material.Texture;
|
||||
|
|
@ -33,7 +31,6 @@ namespace SM2D.Drawing
|
|||
protected override void DrawContext(ref DrawContext context)
|
||||
{
|
||||
base.DrawContext(ref context);
|
||||
context.ShaderArguments["occluder"] = ShadowCaster;
|
||||
context.Shader.Draw(context);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,25 +0,0 @@
|
|||
using System.Collections.Generic;
|
||||
using OpenTK;
|
||||
using OpenTK.Graphics;
|
||||
using SM.Base;
|
||||
using SM.Base.Types;
|
||||
using SM.OGL.Shaders;
|
||||
|
||||
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);
|
||||
public Color4 Color = Color4.White;
|
||||
|
||||
internal virtual void SetUniforms(Dictionary<string, Uniform> uniforms)
|
||||
{
|
||||
uniforms["Type"].SetUniform1(Type);
|
||||
uniforms["Position"].SetUniform2(Position);
|
||||
uniforms["Color"].SetUniform4(Color);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,23 +0,0 @@
|
|||
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;
|
||||
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,49 +0,0 @@
|
|||
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
|
||||
{
|
||||
public class LightPostEffect : PostProcessEffect
|
||||
{
|
||||
private PostProcessShader _shader = new PostProcessShader(AssemblyUtility.ReadAssemblyFile("SM2D.Light.light.frag"));
|
||||
private LightSceneExtension sceneExtension;
|
||||
|
||||
public override void Init(Framebuffer main)
|
||||
{
|
||||
base.Init(main);
|
||||
main.Append("occluder", 1);
|
||||
}
|
||||
|
||||
public override void Draw(Framebuffer main, Framebuffer 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++)
|
||||
{
|
||||
sceneExtension.Lights[i].SetUniforms(array[i]);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public override void SceneChanged(GenericScene scene)
|
||||
{
|
||||
base.SceneChanged(scene);
|
||||
sceneExtension = scene.GetExtension<LightSceneExtension>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,12 +0,0 @@
|
|||
using System.Collections.Generic;
|
||||
using OpenTK.Graphics;
|
||||
|
||||
namespace SM2D.Light
|
||||
{
|
||||
public class LightSceneExtension
|
||||
{
|
||||
public Color4 Ambient = Color4.White;
|
||||
|
||||
public List<LightObject> Lights = new List<LightObject>();
|
||||
}
|
||||
}
|
||||
|
|
@ -1,81 +0,0 @@
|
|||
#version 330
|
||||
#define PI 3.14159265359
|
||||
|
||||
struct Light {
|
||||
int Type;
|
||||
vec2 Position;
|
||||
vec4 Color;
|
||||
|
||||
// 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();
|
||||
|
||||
vec3 calcPointLight(Light light) {
|
||||
vec2 diff = light.Position - FragPos;
|
||||
|
||||
float dif = 20 / length(diff);
|
||||
float intensity = light.Power * (dif) * (dif * dif);
|
||||
|
||||
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() {
|
||||
vec3 addedLight = vec3(0);
|
||||
|
||||
for(int i = 0; i < LightCount; i++) {
|
||||
Light light = Lights[i];
|
||||
|
||||
vec3 lightColor;
|
||||
switch(light.Type) {
|
||||
case 0:
|
||||
lightColor += calcPointLight(light);
|
||||
break;
|
||||
}
|
||||
addedLight += lightColor * occluded(light);
|
||||
}
|
||||
|
||||
return addedLight;
|
||||
}
|
||||
|
||||
void main() {
|
||||
vec4 render = GetRenderColor();
|
||||
|
||||
color = render * Ambient;
|
||||
|
||||
color += vec4(calcLight(), 1);
|
||||
}
|
||||
|
|
@ -12,16 +12,14 @@ namespace SM2D.Pipelines
|
|||
{
|
||||
public static Basic2DPipeline Pipeline = new Basic2DPipeline();
|
||||
|
||||
protected override MaterialShader _defaultShader { get; } = Basic2DShader.Shader;
|
||||
|
||||
private Basic2DPipeline()
|
||||
{
|
||||
Console.WriteLine();
|
||||
_defaultShader = Basic2DShader.Shader;
|
||||
}
|
||||
|
||||
protected override void Render(ref DrawContext context, Scene.Scene scene)
|
||||
protected override void RenderProcess(ref DrawContext context, Scene.Scene scene)
|
||||
{
|
||||
base.Render(ref context, scene);
|
||||
|
||||
Framebuffer.Screen.Activate(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
|
||||
if (scene != null) scene.Draw(context);
|
||||
|
|
|
|||
|
|
@ -6,7 +6,6 @@ using SM.Base;
|
|||
using SM.Base.Contexts;
|
||||
using SM.Base.Scene;
|
||||
using SM.OGL.Framebuffer;
|
||||
using SM2D.Light;
|
||||
using SM2D.Shader;
|
||||
|
||||
#endregion
|
||||
|
|
@ -17,11 +16,7 @@ namespace SM2D.Pipelines
|
|||
{
|
||||
public static Default2DPipeline Pipeline = new Default2DPipeline();
|
||||
|
||||
private Framebuffer _tempWindow;
|
||||
private Light.LightPostEffect _lightEffect;
|
||||
|
||||
protected override List<Framebuffer> _framebuffers { get; } = new List<Framebuffer>();
|
||||
|
||||
|
||||
private Default2DPipeline()
|
||||
{
|
||||
|
||||
|
|
@ -29,27 +24,19 @@ namespace SM2D.Pipelines
|
|||
|
||||
protected override void Initialization(GenericWindow window)
|
||||
{
|
||||
_tempWindow = CreateWindowFramebuffer();
|
||||
_lightEffect = new LightPostEffect();
|
||||
|
||||
_framebuffers.Add(_tempWindow);
|
||||
|
||||
_lightEffect.Init(_tempWindow);
|
||||
MainFramebuffer = CreateWindowFramebuffer();
|
||||
}
|
||||
|
||||
protected override void Render(ref DrawContext context, Scene.Scene scene)
|
||||
protected override void RenderProcess(ref DrawContext context, Scene.Scene scene)
|
||||
{
|
||||
base.Render(ref context, scene);
|
||||
|
||||
if (scene != null)
|
||||
{
|
||||
_tempWindow.Activate(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
|
||||
MainFramebuffer.Activate(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
|
||||
scene.DrawBackground(context);
|
||||
|
||||
scene.DrawMainObjects(context);
|
||||
|
||||
|
||||
Framebuffer.Screen.Activate();
|
||||
_lightEffect.Draw(_tempWindow, Framebuffer.Screen);
|
||||
|
||||
scene.DrawHUD(context);
|
||||
scene.DrawDebug(context);
|
||||
|
|
@ -59,7 +46,6 @@ namespace SM2D.Pipelines
|
|||
protected override void SceneChanged(Scene.Scene scene)
|
||||
{
|
||||
base.SceneChanged(scene);
|
||||
_lightEffect.SceneChanged(scene);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -45,10 +45,6 @@
|
|||
<Compile Include="Drawing\DrawParticles.cs" />
|
||||
<Compile Include="Drawing\DrawText.cs" />
|
||||
<Compile Include="GLWindow2D.cs" />
|
||||
<Compile Include="Light\LightObjects\LightObject.cs" />
|
||||
<Compile Include="Light\LightObjects\PointLight.cs" />
|
||||
<Compile Include="Light\LightPostEffect.cs" />
|
||||
<Compile Include="Light\LightSceneExtension.cs" />
|
||||
<Compile Include="Object\Polygon.cs" />
|
||||
<Compile Include="Object\PolygonVertex.cs" />
|
||||
<Compile Include="Pipelines\Adv2DPipeline.cs" />
|
||||
|
|
@ -81,9 +77,6 @@
|
|||
<Version>3.2.1</Version>
|
||||
</PackageReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Include="Light\light.frag" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Include="Shader\ShaderFiles\basic.glsl" />
|
||||
</ItemGroup>
|
||||
|
|
|
|||
|
|
@ -6,7 +6,6 @@ using SM.Base.Contexts;
|
|||
using SM.Base.Objects.Static;
|
||||
using SM.Base.Scene;
|
||||
using SM2D.Drawing;
|
||||
using SM2D.Light;
|
||||
|
||||
#endregion
|
||||
|
||||
|
|
@ -17,7 +16,6 @@ namespace SM2D.Scene
|
|||
private static DrawObject2D _axisHelper;
|
||||
|
||||
public float AxisHelperSize = 100;
|
||||
public LightSceneExtension LightInformations;
|
||||
static Scene()
|
||||
{
|
||||
_axisHelper = new DrawObject2D();
|
||||
|
|
@ -27,8 +25,6 @@ namespace SM2D.Scene
|
|||
public Scene()
|
||||
{
|
||||
_Background = new DrawBackground(Color4.Black);
|
||||
|
||||
SetExtension(LightInformations = new LightSceneExtension());
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -24,11 +24,9 @@ uniform bool UseTexture;
|
|||
uniform sampler2D Texture;
|
||||
|
||||
layout(location = 0) out vec4 color;
|
||||
layout(location = 1) out vec4 occluder;
|
||||
layout(location = 1) out vec4 bloom;
|
||||
|
||||
void fmain() {
|
||||
color = vColor * Tint;
|
||||
if (UseTexture) color *= texture(Texture, vTexture);
|
||||
|
||||
occluder = vec4(occlude,0,0,1);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue