mirror of
https://github.com/aharabada/glitchy-engine-beef.git
synced 2026-09-05 13:01:52 +00:00
Editor changes
- Updated Renderer2D shaders - Fixed scene viewport having resolution - Show Grid even if no entity is selected - Explicit conversion from ImGui.VecX <-> VectorX - Simplified EditorLayer
This commit is contained in:
@@ -0,0 +1,62 @@
|
||||
Texture2D Texture : register(t0);
|
||||
SamplerState Sampler : register(s0);
|
||||
|
||||
cbuffer Constants : register(b0)
|
||||
{
|
||||
float4x4 ViewProjection;
|
||||
};
|
||||
|
||||
struct VS_Input
|
||||
{
|
||||
float2 Position : POSITION;
|
||||
float2 Texcoord : TEXCOORD0;
|
||||
float4x4 Transform : TRANSFORM;
|
||||
float4 Color : COLOR;
|
||||
float4 UVTransform : TEXCOORD1;
|
||||
float InnerRadius : TEXCOORD2;
|
||||
};
|
||||
|
||||
struct PS_Input
|
||||
{
|
||||
float4 Position : SV_Position;
|
||||
float2 RawPos : TEXCOORD0;
|
||||
float2 Texcoord : TEXCOORD1;
|
||||
float4 Color : COLOR;
|
||||
float InnerRadius : TEXCOORD2;
|
||||
};
|
||||
|
||||
PS_Input VS(VS_Input input)
|
||||
{
|
||||
PS_Input 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.RawPos = input.Position;
|
||||
output.Color = input.Color;
|
||||
output.InnerRadius = input.InnerRadius;
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
float4 PS(PS_Input input) : SV_Target0
|
||||
{
|
||||
float2 uv = input.RawPos * 2;
|
||||
|
||||
float distance = 1.0f - length(uv);
|
||||
|
||||
// Smoothing edges based on derivative (not sure if RawPos is the best value for this)
|
||||
float f = fwidth(input.RawPos.x) + fwidth(input.RawPos.y);
|
||||
|
||||
float amount = smoothstep(0.0f, f, distance);
|
||||
amount *= smoothstep(input.InnerRadius + f, input.InnerRadius, distance);
|
||||
|
||||
// Discard invisible pixels
|
||||
clip(amount - 0.5f);
|
||||
|
||||
float4 color = Texture.Sample(Sampler, input.Texcoord) * input.Color;
|
||||
color.a *= amount;
|
||||
|
||||
return color;
|
||||
}
|
||||
|
||||
#effect[VS=VS, PS=PS]
|
||||
@@ -0,0 +1,93 @@
|
||||
Texture2D<float3> Texture : register(t0);
|
||||
SamplerState Sampler : register(s0);
|
||||
|
||||
cbuffer Constants
|
||||
{
|
||||
float4x4 ViewProjection;
|
||||
float2 UnitRange;
|
||||
float screenPixelRange = 2;
|
||||
}
|
||||
|
||||
struct VS_Input
|
||||
{
|
||||
float2 Position : POSITION;
|
||||
float2 Texcoord : TEXCOORD0;
|
||||
float4x4 Tranform : TRANSFORM;
|
||||
float4 Color : COLOR;
|
||||
float4 UVTransform : TEXCOORD1;
|
||||
};
|
||||
|
||||
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.Color = input.Color;
|
||||
|
||||
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));
|
||||
}
|
||||
|
||||
float ScreenPxRange(float2 texcoord)
|
||||
{
|
||||
float2 screenTexSize = 1.0f / fwidth(texcoord);
|
||||
return max(0.5f * dot(UnitRange, screenTexSize), 1.0f);
|
||||
}
|
||||
|
||||
float4 PS(PS_Input input) : SV_Target0
|
||||
{
|
||||
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 opacity = clamp(screenPxDistance + 0.5, 0.0, 1.0);
|
||||
|
||||
return float4(input.Color.rgb, opacity * input.Color.a);
|
||||
}
|
||||
|
||||
/*
|
||||
// 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);
|
||||
}
|
||||
*/
|
||||
|
||||
#effect[VS=VS, PS=PS]
|
||||
@@ -1,37 +0,0 @@
|
||||
Texture2D Texture : register(t0);
|
||||
SamplerState Sampler : register(s0);
|
||||
|
||||
struct VS_Input
|
||||
{
|
||||
float2 Position : POSITION;
|
||||
float4x4 Tranform : TRANSFORM;
|
||||
float4 Color : COLOR;
|
||||
float4 UVTransform : TEXCOORD;
|
||||
};
|
||||
|
||||
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(float4(input.Position, 0.0f, 1.0f), input.Tranform);
|
||||
output.TexCoord = input.UVTransform.xy + input.UVTransform.zw * input.Position;
|
||||
output.Color = input.Color;
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
float4 PS(PS_Input input) : SV_Target0
|
||||
{
|
||||
float4 color = input.Color * Texture.Sample(Sampler, input.TexCoord);
|
||||
|
||||
return color;
|
||||
}
|
||||
|
||||
#effect[VS=VS, PS=PS]
|
||||
@@ -0,0 +1,41 @@
|
||||
Texture2D Texture : register(t0);
|
||||
SamplerState Sampler : register(s0);
|
||||
|
||||
cbuffer Constants : register(b0)
|
||||
{
|
||||
float4x4 ViewProjection;
|
||||
};
|
||||
|
||||
struct VS_Input
|
||||
{
|
||||
float2 Position : POSITION;
|
||||
float2 Texcoord : TEXCOORD0;
|
||||
float4x4 Transform : TRANSFORM;
|
||||
float4 Color : COLOR;
|
||||
float4 UVTransform : TEXCOORD1;
|
||||
};
|
||||
|
||||
struct PS_Input
|
||||
{
|
||||
float4 Position : SV_Position;
|
||||
float2 Texcoord : TEXCOORD;
|
||||
float4 Color : COLOR;
|
||||
};
|
||||
|
||||
PS_Input VS(VS_Input input)
|
||||
{
|
||||
PS_Input 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.Color = input.Color;
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
float4 PS(PS_Input input) : SV_Target0
|
||||
{
|
||||
return Texture.Sample(Sampler, input.Texcoord) * input.Color;
|
||||
}
|
||||
|
||||
#effect[VS=VS, PS=PS]
|
||||
@@ -1,84 +0,0 @@
|
||||
cbuffer SceneConstants
|
||||
{
|
||||
float4x4 ViewProjection = float4x4(1, 0, 0, 0,
|
||||
0, 1, 0, 0,
|
||||
0, 0, 1, 0,
|
||||
0, 0, 0, 1);
|
||||
}
|
||||
|
||||
cbuffer ObjectConstants
|
||||
{
|
||||
float4x4 Transform;
|
||||
}
|
||||
|
||||
cbuffer Constants
|
||||
{
|
||||
float4 BaseColor;
|
||||
float3 LightDir;
|
||||
}
|
||||
|
||||
cbuffer SkinningMatrices
|
||||
{
|
||||
matrix SkinningMatrices[255];
|
||||
float3x3 InvTransSkinningMatrices[255];
|
||||
}
|
||||
|
||||
struct VS_IN
|
||||
{
|
||||
float3 Position : POSITION;
|
||||
float3 Normal : NORMAL;
|
||||
uint4 JointIndices : JOINTS_0;
|
||||
float4 JointWeights : WEIGHTS_0;
|
||||
};
|
||||
|
||||
struct PS_IN
|
||||
{
|
||||
float4 Position : SV_POSITION;
|
||||
float3 Normal : NORMAL;
|
||||
};
|
||||
|
||||
PS_IN VS(VS_IN input)
|
||||
{
|
||||
PS_IN output;
|
||||
|
||||
// Unanimated position in modelspace
|
||||
float4 positionRaw = float4(input.Position, 1);
|
||||
|
||||
// Calculate animated position in modelspace
|
||||
|
||||
float4 position =
|
||||
mul(SkinningMatrices[input.JointIndices.x], positionRaw) * input.JointWeights.x +
|
||||
mul(SkinningMatrices[input.JointIndices.y], positionRaw) * input.JointWeights.y +
|
||||
mul(SkinningMatrices[input.JointIndices.z], positionRaw) * input.JointWeights.z +
|
||||
mul(SkinningMatrices[input.JointIndices.w], positionRaw) * input.JointWeights.w;
|
||||
|
||||
float3 normal =
|
||||
mul(InvTransSkinningMatrices[input.JointIndices.x], input.Normal) * input.JointWeights.x +
|
||||
mul(InvTransSkinningMatrices[input.JointIndices.y], input.Normal) * input.JointWeights.y +
|
||||
mul(InvTransSkinningMatrices[input.JointIndices.z], input.Normal) * input.JointWeights.z +
|
||||
mul(InvTransSkinningMatrices[input.JointIndices.w], input.Normal) * input.JointWeights.w;
|
||||
|
||||
//position = saturate(position - 1000) + positionRaw;
|
||||
|
||||
//float4 position = mul(SkinningMatrices[input.JointIndices.x], positionRaw);
|
||||
|
||||
float4 worldPosition = mul(Transform, position);
|
||||
|
||||
output.Position = mul(ViewProjection, worldPosition);
|
||||
output.Normal = mul((float3x3)Transform, normal);
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
float4 PS(PS_IN input) : SV_TARGET
|
||||
{
|
||||
input.Normal = normalize(input.Normal);
|
||||
|
||||
float shading = dot(LightDir, input.Normal);
|
||||
//float shading = dot(LightDir, LightDir) + 1;
|
||||
shading = clamp(shading, 0.0f, 1.0f);
|
||||
|
||||
return BaseColor * shading;
|
||||
}
|
||||
|
||||
#effect[VS=VS,PS=PS]
|
||||
Reference in New Issue
Block a user