diff options
author | Jeroen Bakker <jbakker> | 2022-01-17 16:32:03 +0300 |
---|---|---|
committer | Jeroen Bakker <jeroen@blender.org> | 2022-01-17 16:32:28 +0300 |
commit | 8fb2ff458ba579dba08bfdf57d043ad158b5db07 (patch) | |
tree | e6324c08c69de3e8ed34c1f85d0b2982fa1d38ed /source/blender/gpu/shaders/gpu_shader_gpencil_stroke_geom.glsl | |
parent | 08822801acf648d23791fa308ec8c1c26f86963e (diff) |
GPUShaderCreateInfo for interface abstraction
This is a first part of the Shader Create Info system could be.
A shader create info provides a way to define shader structure, resources
and interfaces. This makes for a quick way to provide backend agnostic
binding informations while also making shader variations easy to declare.
- Clear source input (only one file). Cleans up the GPU api since we can create a
shader from one descriptor
- Resources and interfaces are generated by the backend (much simpler than parsing).
- Bindings are explicit from position in the array.
- GPUShaderInterface becomes a trivial translation of enums and string copy.
- No external dependency to third party lib.
- Cleaner code, less fragmentation of resources in several libs.
- Easy to modify / extend at runtime.
- no parser involve, very easy to code.
- Does not hold any data, can be static and kept on disc.
- Could hold precompiled bytecode for static shaders.
This also includes a new global dependency system.
GLSL shaders can include other sources by using #pragma BLENDER_REQUIRE(...).
This patch already migrated several builtin shaders. Other shaders should be migrated
one at a time, and could be done inside master.
There is a new compile directive `WITH_GPU_SHADER_BUILDER` this is an optional
directive for linting shaders to increase turn around time.
What is remaining:
- pyGPU API {T94975}
- Migration of other shaders. This could be a community effort.
Reviewed By: jbakker
Maniphest Tasks: T94975
Differential Revision: https://developer.blender.org/D13360
Diffstat (limited to 'source/blender/gpu/shaders/gpu_shader_gpencil_stroke_geom.glsl')
-rw-r--r-- | source/blender/gpu/shaders/gpu_shader_gpencil_stroke_geom.glsl | 138 |
1 files changed, 78 insertions, 60 deletions
diff --git a/source/blender/gpu/shaders/gpu_shader_gpencil_stroke_geom.glsl b/source/blender/gpu/shaders/gpu_shader_gpencil_stroke_geom.glsl index b937323f62a..f076655b459 100644 --- a/source/blender/gpu/shaders/gpu_shader_gpencil_stroke_geom.glsl +++ b/source/blender/gpu/shaders/gpu_shader_gpencil_stroke_geom.glsl @@ -1,3 +1,4 @@ +#ifndef USE_GPU_SHADER_CREATE_INFO uniform mat4 ModelViewProjectionMatrix; uniform vec2 Viewport; uniform int xraymode; @@ -13,6 +14,7 @@ in float finalThickness[4]; out vec4 mColor; out vec2 mTexCoord; +#endif #define GP_XRAY_FRONT 0 #define GP_XRAY_3DSPACE 1 @@ -23,19 +25,19 @@ out vec2 mTexCoord; /* project 3d point to 2d on screen space */ vec2 toScreenSpace(vec4 vertex) { - return vec2(vertex.xy / vertex.w) * Viewport; + return vec2(vertex.xy / vertex.w) * gpencil_stroke_data.viewport; } /* get zdepth value */ float getZdepth(vec4 point) { - if (xraymode == GP_XRAY_FRONT) { + if (gpencil_stroke_data.xraymode == GP_XRAY_FRONT) { return 0.0; } - if (xraymode == GP_XRAY_3DSPACE) { + if (gpencil_stroke_data.xraymode == GP_XRAY_3DSPACE) { return (point.z / point.w); } - if (xraymode == GP_XRAY_BACK) { + if (gpencil_stroke_data.xraymode == GP_XRAY_BACK) { return 1.0; } @@ -75,7 +77,7 @@ void main(void) vec2 sp3 = toScreenSpace(P3); /* end of next segment */ /* culling outside viewport */ - vec2 area = Viewport * 4.0; + vec2 area = gpencil_stroke_data.viewport * 4.0; if (sp1.x < -area.x || sp1.x > area.x) { return; } @@ -112,8 +114,8 @@ void main(void) if (bn1 == 0) { bn1 = 1; } - float length_a = finalThickness[1] / an1; - float length_b = finalThickness[2] / bn1; + float length_a = geometry_in[1].finalThickness / an1; + float length_b = geometry_in[2].finalThickness / bn1; if (length_a <= 0.0) { length_a = 0.01; } @@ -124,41 +126,49 @@ void main(void) /* prevent excessively long miters at sharp corners */ if (dot(v0, v1) < -MiterLimit) { miter_a = n1; - length_a = finalThickness[1]; + length_a = geometry_in[1].finalThickness; /* close the gap */ if (dot(v0, n1) > 0) { - mTexCoord = vec2(0, 0); - mColor = finalColor[1]; - gl_Position = vec4((sp1 + finalThickness[1] * n0) / Viewport, getZdepth(P1), 1.0); + geometry_out.mTexCoord = vec2(0, 0); + geometry_out.mColor = geometry_in[1].finalColor; + gl_Position = vec4((sp1 + geometry_in[1].finalThickness * n0) / gpencil_stroke_data.viewport, + getZdepth(P1), + 1.0); EmitVertex(); - mTexCoord = vec2(0, 0); - mColor = finalColor[1]; - gl_Position = vec4((sp1 + finalThickness[1] * n1) / Viewport, getZdepth(P1), 1.0); + geometry_out.mTexCoord = vec2(0, 0); + geometry_out.mColor = geometry_in[1].finalColor; + gl_Position = vec4((sp1 + geometry_in[1].finalThickness * n1) / gpencil_stroke_data.viewport, + getZdepth(P1), + 1.0); EmitVertex(); - mTexCoord = vec2(0, 0.5); - mColor = finalColor[1]; - gl_Position = vec4(sp1 / Viewport, getZdepth(P1), 1.0); + geometry_out.mTexCoord = vec2(0, 0.5); + geometry_out.mColor = geometry_in[1].finalColor; + gl_Position = vec4(sp1 / gpencil_stroke_data.viewport, getZdepth(P1), 1.0); EmitVertex(); EndPrimitive(); } else { - mTexCoord = vec2(0, 1); - mColor = finalColor[1]; - gl_Position = vec4((sp1 - finalThickness[1] * n1) / Viewport, getZdepth(P1), 1.0); + geometry_out.mTexCoord = vec2(0, 1); + geometry_out.mColor = geometry_in[1].finalColor; + gl_Position = vec4((sp1 - geometry_in[1].finalThickness * n1) / gpencil_stroke_data.viewport, + getZdepth(P1), + 1.0); EmitVertex(); - mTexCoord = vec2(0, 1); - mColor = finalColor[1]; - gl_Position = vec4((sp1 - finalThickness[1] * n0) / Viewport, getZdepth(P1), 1.0); + geometry_out.mTexCoord = vec2(0, 1); + geometry_out.mColor = geometry_in[1].finalColor; + gl_Position = vec4((sp1 - geometry_in[1].finalThickness * n0) / gpencil_stroke_data.viewport, + getZdepth(P1), + 1.0); EmitVertex(); - mTexCoord = vec2(0, 0.5); - mColor = finalColor[1]; - gl_Position = vec4(sp1 / Viewport, getZdepth(P1), 1.0); + geometry_out.mTexCoord = vec2(0, 0.5); + geometry_out.mColor = geometry_in[1].finalColor; + gl_Position = vec4(sp1 / gpencil_stroke_data.viewport, getZdepth(P1), 1.0); EmitVertex(); EndPrimitive(); @@ -167,66 +177,74 @@ void main(void) if (dot(v1, v2) < -MiterLimit) { miter_b = n1; - length_b = finalThickness[2]; + length_b = geometry_in[2].finalThickness; } /* Generate the start end-cap (alpha < 0 used as end-cap flag). */ - float extend = (fill_stroke > 0) ? 2 : 1; - if ((caps_start != GPENCIL_FLATCAP) && is_equal(P0, P2)) { - mTexCoord = vec2(1, 0.5); - mColor = vec4(finalColor[1].rgb, finalColor[1].a * -1.0); + float extend = gpencil_stroke_data.fill_stroke ? 2 : 1; + if ((gpencil_stroke_data.caps_start != GPENCIL_FLATCAP) && is_equal(P0, P2)) { + geometry_out.mTexCoord = vec2(1, 0.5); + geometry_out.mColor = vec4(geometry_in[1].finalColor.rgb, geometry_in[1].finalColor.a * -1.0); vec2 svn1 = normalize(sp1 - sp2) * length_a * 4.0 * extend; - gl_Position = vec4((sp1 + svn1) / Viewport, getZdepth(P1), 1.0); + gl_Position = vec4((sp1 + svn1) / gpencil_stroke_data.viewport, getZdepth(P1), 1.0); EmitVertex(); - mTexCoord = vec2(0, 0); - mColor = vec4(finalColor[1].rgb, finalColor[1].a * -1.0); - gl_Position = vec4((sp1 - (length_a * 2.0) * miter_a) / Viewport, getZdepth(P1), 1.0); + geometry_out.mTexCoord = vec2(0, 0); + geometry_out.mColor = vec4(geometry_in[1].finalColor.rgb, geometry_in[1].finalColor.a * -1.0); + gl_Position = vec4( + (sp1 - (length_a * 2.0) * miter_a) / gpencil_stroke_data.viewport, getZdepth(P1), 1.0); EmitVertex(); - mTexCoord = vec2(0, 1); - mColor = vec4(finalColor[1].rgb, finalColor[1].a * -1.0); - gl_Position = vec4((sp1 + (length_a * 2.0) * miter_a) / Viewport, getZdepth(P1), 1.0); + geometry_out.mTexCoord = vec2(0, 1); + geometry_out.mColor = vec4(geometry_in[1].finalColor.rgb, geometry_in[1].finalColor.a * -1.0); + gl_Position = vec4( + (sp1 + (length_a * 2.0) * miter_a) / gpencil_stroke_data.viewport, getZdepth(P1), 1.0); EmitVertex(); } /* generate the triangle strip */ - mTexCoord = vec2(0, 0); - mColor = finalColor[1]; - gl_Position = vec4((sp1 + length_a * miter_a) / Viewport, getZdepth(P1), 1.0); + geometry_out.mTexCoord = vec2(0, 0); + geometry_out.mColor = geometry_in[1].finalColor; + gl_Position = vec4( + (sp1 + length_a * miter_a) / gpencil_stroke_data.viewport, getZdepth(P1), 1.0); EmitVertex(); - mTexCoord = vec2(0, 1); - mColor = finalColor[1]; - gl_Position = vec4((sp1 - length_a * miter_a) / Viewport, getZdepth(P1), 1.0); + geometry_out.mTexCoord = vec2(0, 1); + geometry_out.mColor = geometry_in[1].finalColor; + gl_Position = vec4( + (sp1 - length_a * miter_a) / gpencil_stroke_data.viewport, getZdepth(P1), 1.0); EmitVertex(); - mTexCoord = vec2(0, 0); - mColor = finalColor[2]; - gl_Position = vec4((sp2 + length_b * miter_b) / Viewport, getZdepth(P2), 1.0); + geometry_out.mTexCoord = vec2(0, 0); + geometry_out.mColor = geometry_in[2].finalColor; + gl_Position = vec4( + (sp2 + length_b * miter_b) / gpencil_stroke_data.viewport, getZdepth(P2), 1.0); EmitVertex(); - mTexCoord = vec2(0, 1); - mColor = finalColor[2]; - gl_Position = vec4((sp2 - length_b * miter_b) / Viewport, getZdepth(P2), 1.0); + geometry_out.mTexCoord = vec2(0, 1); + geometry_out.mColor = geometry_in[2].finalColor; + gl_Position = vec4( + (sp2 - length_b * miter_b) / gpencil_stroke_data.viewport, getZdepth(P2), 1.0); EmitVertex(); /* Generate the end end-cap (alpha < 0 used as end-cap flag). */ - if ((caps_end != GPENCIL_FLATCAP) && is_equal(P1, P3)) { - mTexCoord = vec2(0, 1); - mColor = vec4(finalColor[2].rgb, finalColor[2].a * -1.0); - gl_Position = vec4((sp2 + (length_b * 2.0) * miter_b) / Viewport, getZdepth(P2), 1.0); + if ((gpencil_stroke_data.caps_end != GPENCIL_FLATCAP) && is_equal(P1, P3)) { + geometry_out.mTexCoord = vec2(0, 1); + geometry_out.mColor = vec4(geometry_in[2].finalColor.rgb, geometry_in[2].finalColor.a * -1.0); + gl_Position = vec4( + (sp2 + (length_b * 2.0) * miter_b) / gpencil_stroke_data.viewport, getZdepth(P2), 1.0); EmitVertex(); - mTexCoord = vec2(0, 0); - mColor = vec4(finalColor[2].rgb, finalColor[2].a * -1.0); - gl_Position = vec4((sp2 - (length_b * 2.0) * miter_b) / Viewport, getZdepth(P2), 1.0); + geometry_out.mTexCoord = vec2(0, 0); + geometry_out.mColor = vec4(geometry_in[2].finalColor.rgb, geometry_in[2].finalColor.a * -1.0); + gl_Position = vec4( + (sp2 - (length_b * 2.0) * miter_b) / gpencil_stroke_data.viewport, getZdepth(P2), 1.0); EmitVertex(); - mTexCoord = vec2(1, 0.5); - mColor = vec4(finalColor[2].rgb, finalColor[2].a * -1.0); + geometry_out.mTexCoord = vec2(1, 0.5); + geometry_out.mColor = vec4(geometry_in[2].finalColor.rgb, geometry_in[2].finalColor.a * -1.0); vec2 svn2 = normalize(sp2 - sp1) * length_b * 4.0 * extend; - gl_Position = vec4((sp2 + svn2) / Viewport, getZdepth(P2), 1.0); + gl_Position = vec4((sp2 + svn2) / gpencil_stroke_data.viewport, getZdepth(P2), 1.0); EmitVertex(); } |