mirror of
https://github.com/aharabada/glitchy-engine-beef.git
synced 2026-09-05 13:01:52 +00:00
Support materials in 2D Quad Renderer!
- Lost Circle rendering along the way - Cleaned up 2D shaders
This commit is contained in:
@@ -0,0 +1,74 @@
|
||||
#pragma EngineBuffer[ Name = "SceneConstants"; Binding = "Scene" ]
|
||||
/**
|
||||
* Contains constants that apply to the current scene.
|
||||
*/
|
||||
cbuffer SceneConstants : register(b0)
|
||||
{
|
||||
/**
|
||||
* View projection matrix of the active camera.
|
||||
*/
|
||||
float4x4 ViewProjection;
|
||||
}
|
||||
|
||||
/**
|
||||
* Contains the data provided by the engine for a 2D vertex shader.
|
||||
*/
|
||||
struct VS_Input
|
||||
{
|
||||
// Geometry
|
||||
|
||||
/**
|
||||
* Vertex position
|
||||
*/
|
||||
float2 Position : POSITION;
|
||||
/**
|
||||
* Vertex texture coordinate
|
||||
*/
|
||||
float2 Texcoord : TEXCOORD0;
|
||||
|
||||
// Instance data
|
||||
/**
|
||||
* model to world transform matrix of the current quad.
|
||||
*/
|
||||
float4x4 Transform : TRANSFORM;
|
||||
/**
|
||||
* Color of the current quad.
|
||||
*/
|
||||
float4 Color : COLOR;
|
||||
/**
|
||||
* model to world transform matrix of the current quad.
|
||||
*/
|
||||
float4 UVTransform : TEXCOORD1;
|
||||
#ifdef EDITOR
|
||||
/**
|
||||
* The ECS ID of the entity associated with the current quad.
|
||||
*/
|
||||
uint EntityId : ENTITYID;
|
||||
#endif
|
||||
};
|
||||
|
||||
/**
|
||||
* Contains the output data of the vertex shader that will be passed into the pixel shader.
|
||||
*/
|
||||
typedef struct PS_Input
|
||||
{
|
||||
/**
|
||||
* The screen space position of the current vertex.
|
||||
*/
|
||||
float4 Position : SV_Position;
|
||||
/**
|
||||
* The transformed texture coordinates of the current vertex.
|
||||
*/
|
||||
float2 Texcoord : TEXCOORD;
|
||||
/**
|
||||
* The color of the current vertex.
|
||||
*/
|
||||
float4 Color : COLOR;
|
||||
#ifdef EDITOR
|
||||
/**
|
||||
* The ECS ID of the entity associated with the current quad.
|
||||
* This should always just be passed through.
|
||||
*/
|
||||
nointerpolation uint EntityId : ENTITYID;
|
||||
#endif
|
||||
} VS_Output;
|
||||
@@ -0,0 +1,11 @@
|
||||
{
|
||||
AssetLoader = null,
|
||||
Config = null,
|
||||
Importer = "ShaderImporter",
|
||||
ImporterConfig = null,
|
||||
Processor = null,
|
||||
ProcessorConfig = null,
|
||||
Exporter = null,
|
||||
ExporterConfig = null,
|
||||
AssetHandle = 9184910549692735900
|
||||
}
|
||||
@@ -87,4 +87,15 @@ float GetBitangentHandedness(float tangentz)
|
||||
return (z & 1) > 0 ? 1.0 : -1.0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Transforms the given texture coordinates using the provided UV transform.
|
||||
* @param texcoords The texture coordinates to transform.
|
||||
* @param uvTransform the UV transform. X, Y: UV offset | Z, W: UV scaling.
|
||||
* @return The transformed uv coordinates.
|
||||
*/
|
||||
float2 TransformTexcoords(float2 texcoords, float4 uvTransform)
|
||||
{
|
||||
return uvTransform.xy + uvTransform.zw * texcoords;
|
||||
}
|
||||
|
||||
#endif // __SHADER_HELPERS_HLSL__
|
||||
@@ -1,61 +1,31 @@
|
||||
#define EDITOR
|
||||
|
||||
#include "GlitchyEngine2D.hlsl"
|
||||
#include "ShaderHelpers.hlsl"
|
||||
|
||||
Texture2D<float3> Texture : register(t0);
|
||||
SamplerState Sampler : register(s0);
|
||||
|
||||
cbuffer Constants
|
||||
cbuffer Material
|
||||
{
|
||||
float4x4 ViewProjection;
|
||||
float2 UnitRange;
|
||||
float screenPixelRange = 2;
|
||||
}
|
||||
|
||||
struct VS_Input
|
||||
VS_Output VS(VS_Input input)
|
||||
{
|
||||
float2 Position : POSITION;
|
||||
float2 Texcoord : TEXCOORD0;
|
||||
float4x4 Tranform : TRANSFORM;
|
||||
float4 Color : COLOR;
|
||||
float4 UVTransform : TEXCOORD1;
|
||||
};
|
||||
VS_Output output;
|
||||
|
||||
struct PS_Input
|
||||
{
|
||||
float4 Position : SV_Position;
|
||||
float2 TexCoord : TEXCOORD0;
|
||||
float4 Color : COLOR;
|
||||
};
|
||||
|
||||
PS_Input VS(VS_Input input)
|
||||
{
|
||||
PS_Input output;
|
||||
|
||||
output.Position = mul(ViewProjection, mul(input.Tranform, float4(input.Position, 0.0f, 1.0f)));
|
||||
output.TexCoord = input.UVTransform.xy + input.UVTransform.zw * input.Texcoord;
|
||||
output.Position = mul(ViewProjection, mul(input.Transform, float4(input.Position, 0.0f, 1.0f)));
|
||||
output.Texcoord = TransformTexcoords(input.Texcoord, input.UVTransform);
|
||||
output.Color = input.Color;
|
||||
|
||||
#ifdef EDITOR
|
||||
output.EntityId = input.EntityId;
|
||||
#endif
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
/*
|
||||
in vec2 texCoord;
|
||||
out vec4 color;
|
||||
uniform sampler2D msdf;
|
||||
uniform vec4 bgColor;
|
||||
uniform vec4 fgColor;
|
||||
|
||||
float median(float r, float g, float b) {
|
||||
return max(min(r, g), min(max(r, g), b));
|
||||
}
|
||||
|
||||
void main() {
|
||||
vec3 msd = texture(msdf, texCoord).rgb;
|
||||
float sd = median(msd.r, msd.g, msd.b);
|
||||
float screenPxDistance = screenPxRange()*(sd - 0.5);
|
||||
float opacity = clamp(screenPxDistance + 0.5, 0.0, 1.0);
|
||||
color = mix(bgColor, fgColor, opacity);
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
float median(float r, float g, float b)
|
||||
{
|
||||
return max(min(r, g), min(max(r, g), b));
|
||||
@@ -67,31 +37,32 @@ float ScreenPxRange(float2 texcoord)
|
||||
return max(0.5f * dot(UnitRange, screenTexSize), 1.0f);
|
||||
}
|
||||
|
||||
float4 PS(PS_Input input) : SV_Target0
|
||||
struct PS_Output
|
||||
{
|
||||
float3 msd = Texture.Sample(Sampler, input.TexCoord);
|
||||
float4 Color : SV_Target0;
|
||||
#ifdef EDITOR
|
||||
uint EntityId : SV_TARGET1;
|
||||
#endif
|
||||
};
|
||||
|
||||
PS_Output PS(PS_Input input)
|
||||
{
|
||||
PS_Output output;
|
||||
|
||||
float3 msd = Texture.Sample(Sampler, input.Texcoord);
|
||||
float sd = median(msd.r, msd.g, msd.b);
|
||||
float screenPxDistance = ScreenPxRange(input.TexCoord) * (sd - 0.5);
|
||||
float screenPxDistance = ScreenPxRange(input.Texcoord) * (sd - 0.5);
|
||||
float opacity = clamp(screenPxDistance + 0.5, 0.0, 1.0);
|
||||
|
||||
clip(opacity - 0.001f);
|
||||
|
||||
//return float4(input.Color.rgb, opacity * input.Color.a) * 0.0001f + float4(opacity.xxxx);
|
||||
return input.Color * opacity; // TODO: This is not quite right // float4(input.Color.rgb, input.Color.a * opacity);
|
||||
//return float4(input.Color.rgb, opacity * input.Color.a) * 0.0001f + float4(msd, 1.0f);
|
||||
output.Color = float4(input.Color.rgb, input.Color.a * opacity);
|
||||
|
||||
#ifdef EDITOR
|
||||
output.EntityId = input.EntityId;
|
||||
#endif
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
/*
|
||||
// 2D
|
||||
float4 PS(PS_Input input) : SV_Target0
|
||||
{
|
||||
float3 msd = Texture.Sample(Sampler, input.TexCoord).rgb;
|
||||
float sd = median(msd.r, msd.g, msd.b);
|
||||
float screenPxDistance = screenPixelRange*(sd - 0.5);
|
||||
float opacity = clamp(screenPxDistance + 0.5, 0.0, 1.0);
|
||||
|
||||
return float4(input.Color.rgb, opacity * input.Color.a);
|
||||
}
|
||||
*/
|
||||
|
||||
#pragma Effect[VS=VS; PS=PS]
|
||||
#pragma Effect[VS=VS; PS=PS]
|
||||
|
||||
@@ -1,41 +1,17 @@
|
||||
#define EDITOR
|
||||
|
||||
#include "GlitchyEngine2D.hlsl"
|
||||
#include "ShaderHelpers.hlsl"
|
||||
|
||||
Texture2D Texture : register(t0);
|
||||
SamplerState Sampler : register(s0);
|
||||
|
||||
cbuffer Constants : register(b0)
|
||||
VS_Output VS(VS_Input input)
|
||||
{
|
||||
float4x4 ViewProjection;
|
||||
};
|
||||
|
||||
struct VS_Input
|
||||
{
|
||||
float2 Position : POSITION;
|
||||
float2 Texcoord : TEXCOORD0;
|
||||
float4x4 Transform : TRANSFORM;
|
||||
float4 Color : COLOR;
|
||||
float4 UVTransform : TEXCOORD1;
|
||||
#ifdef EDITOR
|
||||
uint EntityId : ENTITYID;
|
||||
#endif
|
||||
};
|
||||
|
||||
struct PS_Input
|
||||
{
|
||||
float4 Position : SV_Position;
|
||||
float2 Texcoord : TEXCOORD;
|
||||
float4 Color : COLOR;
|
||||
#ifdef EDITOR
|
||||
nointerpolation uint EntityId : ENTITYID;
|
||||
#endif
|
||||
};
|
||||
|
||||
PS_Input VS(VS_Input input)
|
||||
{
|
||||
PS_Input output;
|
||||
VS_Output output;
|
||||
|
||||
output.Position = mul(ViewProjection, mul(input.Transform, float4(input.Position, 0.0f, 1.0f)));
|
||||
output.Texcoord = input.UVTransform.xy + input.UVTransform.zw * input.Texcoord;
|
||||
output.Texcoord = TransformTexcoords(input.Texcoord, input.UVTransform);
|
||||
output.Color = input.Color;
|
||||
|
||||
// Premultiply Alpha
|
||||
|
||||
@@ -514,7 +514,7 @@ namespace GlitchyEditor
|
||||
Matrix world = Billboard(transform.WorldTransform);
|
||||
|
||||
float alpha = CalculateAlpha(transform.WorldTransform.Translation);
|
||||
Renderer2D.DrawQuad(world, _editorIcons.Camera, ColorRGBA(alpha, alpha, alpha, alpha), .(0, 0, 1, 1), entity.Index);
|
||||
Renderer2D.DrawQuad(world, _editorIcons.Camera, null, ColorRGBA(alpha, alpha, alpha, alpha), .(0, 0, 1, 1), entity.Index);
|
||||
//Renderer2D.DrawQuad(world, _iconCamera, .White, .(0, 0, 1, 1), entity.Index);
|
||||
}
|
||||
|
||||
@@ -535,7 +535,7 @@ namespace GlitchyEditor
|
||||
Matrix world = Billboard(transform.WorldTransform);
|
||||
|
||||
float alpha = CalculateAlpha(transform.WorldTransform.Translation);
|
||||
Renderer2D.DrawQuad(world, _editorIcons.DirectionalLight, ColorRGBA(light.SceneLight.Color.R * alpha, light.SceneLight.Color.G * alpha, light.SceneLight.Color.B * alpha, alpha), .(0, 0, 1, 1), entity.Index);
|
||||
Renderer2D.DrawQuad(world, _editorIcons.DirectionalLight, null, ColorRGBA(light.SceneLight.Color.R * alpha, light.SceneLight.Color.G * alpha, light.SceneLight.Color.B * alpha, alpha), .(0, 0, 1, 1), entity.Index);
|
||||
}
|
||||
|
||||
for (var (entity, transform, collider) in _activeScene.GetEntities<TransformComponent, BoxCollider2DComponent>())
|
||||
|
||||
Reference in New Issue
Block a user