Skip to content

Commit

Permalink
removed implicit resource binding + replaced editor shaders with native
Browse files Browse the repository at this point in the history
  • Loading branch information
mrDIMAS committed Feb 20, 2025
1 parent 873ad7d commit ebf90eb
Show file tree
Hide file tree
Showing 15 changed files with 288 additions and 464 deletions.
100 changes: 100 additions & 0 deletions editor/resources/shaders/highlight.shader
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
(
name: "Highlight",
resources: [
(
name: "frameTexture",
kind: Texture(kind: Sampler2D, fallback: White),
binding: 0
),
(
name: "properties",
kind: PropertyGroup([
(name: "worldViewProjection", kind: Matrix4()),
(name: "color", kind: Vector4()),
]),
binding: 0
),
],
passes: [
(
name: "Primary",

draw_parameters: DrawParameters(
cull_face: None,
color_write: ColorMask(
red: true,
green: true,
blue: true,
alpha: true,
),
depth_write: false,
stencil_test: None,
depth_test: None,
blend: Some(BlendParameters(
func: BlendFunc(
sfactor: SrcAlpha,
dfactor: OneMinusSrcAlpha,
alpha_sfactor: SrcAlpha,
alpha_dfactor: OneMinusSrcAlpha,
),
equation: BlendEquation(
rgb: Add,
alpha: Add
)
)),
stencil_op: StencilOp(
fail: Keep,
zfail: Keep,
zpass: Keep,
write_mask: 0xFFFF_FFFF,
),
scissor_box: None
),

vertex_shader:
r#"
layout(location = 0) in vec3 vertexPosition;
layout(location = 1) in vec2 vertexTexCoord;

out vec2 texCoord;

void main()
{
texCoord = vertexTexCoord;
gl_Position = properties.worldViewProjection * vec4(vertexPosition, 1.0);
}
"#,

fragment_shader:
r#"
layout (location = 0) out vec4 outColor;

in vec2 texCoord;

void main() {
ivec2 size = textureSize(frameTexture, 0);

float w = 1.0 / float(size.x);
float h = 1.0 / float(size.y);

float n[9];
n[0] = texture(frameTexture, texCoord + vec2(-w, -h)).a;
n[1] = texture(frameTexture, texCoord + vec2(0.0, -h)).a;
n[2] = texture(frameTexture, texCoord + vec2(w, -h)).a;
n[3] = texture(frameTexture, texCoord + vec2( -w, 0.0)).a;
n[4] = texture(frameTexture, texCoord).a;
n[5] = texture(frameTexture, texCoord + vec2(w, 0.0)).a;
n[6] = texture(frameTexture, texCoord + vec2(-w, h)).a;
n[7] = texture(frameTexture, texCoord + vec2(0.0, h)).a;
n[8] = texture(frameTexture, texCoord + vec2(w, h)).a;

float sobel_edge_h = n[2] + (2.0 * n[5]) + n[8] - (n[0] + (2.0 * n[3]) + n[6]);
float sobel_edge_v = n[0] + (2.0 * n[1]) + n[2] - (n[6] + (2.0 * n[7]) + n[8]);
float sobel = sqrt((sobel_edge_h * sobel_edge_h) + (sobel_edge_v * sobel_edge_v));

outColor = vec4(properties.color.rgb, properties.color.a * sobel);
}
"#,
)
]
)
87 changes: 87 additions & 0 deletions editor/resources/shaders/overlay.shader
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
(
name: "Overlay",
resources: [
(
name: "diffuseTexture",
kind: Texture(kind: Sampler2D, fallback: White),
binding: 0
),
(
name: "properties",
kind: PropertyGroup([
(name: "viewProjectionMatrix", kind: Matrix4()),
(name: "worldMatrix", kind: Matrix4()),
(name: "cameraSideVector", kind: Vector3()),
(name: "cameraUpVector", kind: Vector3()),
(name: "size", kind: Float()),
]),
binding: 0
),
],
passes: [
(
name: "Primary",

draw_parameters: DrawParameters(
cull_face: None,
color_write: ColorMask(
red: true,
green: true,
blue: true,
alpha: true,
),
depth_write: false,
stencil_test: None,
depth_test: None,
blend: Some(BlendParameters(
func: BlendFunc(
sfactor: SrcAlpha,
dfactor: OneMinusSrcAlpha,
alpha_sfactor: SrcAlpha,
alpha_dfactor: OneMinusSrcAlpha,
),
equation: BlendEquation(
rgb: Add,
alpha: Add
)
)),
stencil_op: StencilOp(
fail: Keep,
zfail: Keep,
zpass: Keep,
write_mask: 0xFFFF_FFFF,
),
scissor_box: None
),

vertex_shader:
r#"
layout (location = 0) in vec3 vertexPosition;
layout (location = 1) in vec2 vertexTexCoord;

out vec2 texCoord;

void main()
{
texCoord = vertexTexCoord;
vec2 vertexOffset = vertexTexCoord * 2.0 - 1.0;
vec4 worldPosition = properties.worldMatrix * vec4(vertexPosition, 1.0);
vec3 offset = (vertexOffset.x * properties.cameraSideVector + vertexOffset.y * properties.cameraUpVector) * properties.size;
gl_Position = properties.viewProjectionMatrix * (worldPosition + vec4(offset.x, offset.y, offset.z, 0.0));
}
"#,

fragment_shader:
r#"
out vec4 FragColor;

in vec2 texCoord;

void main()
{
FragColor = texture(diffuseTexture, texCoord);
}
"#,
)
]
)
10 changes: 0 additions & 10 deletions editor/resources/shaders/overlay_fs.glsl

This file was deleted.

21 changes: 0 additions & 21 deletions editor/resources/shaders/overlay_vs.glsl

This file was deleted.

Loading

0 comments on commit ebf90eb

Please sign in to comment.