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_2D_nodelink_vert.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_2D_nodelink_vert.glsl')
-rw-r--r-- | source/blender/gpu/shaders/gpu_shader_2D_nodelink_vert.glsl | 54 |
1 files changed, 34 insertions, 20 deletions
diff --git a/source/blender/gpu/shaders/gpu_shader_2D_nodelink_vert.glsl b/source/blender/gpu/shaders/gpu_shader_2D_nodelink_vert.glsl index 8325568988c..3d3a042de65 100644 --- a/source/blender/gpu/shaders/gpu_shader_2D_nodelink_vert.glsl +++ b/source/blender/gpu/shaders/gpu_shader_2D_nodelink_vert.glsl @@ -4,13 +4,15 @@ #define MID_VERTEX 65 +#ifndef USE_GPU_SHADER_CREATE_INFO + /* u is position along the curve, defining the tangent space. * v is "signed" distance (compressed to [0..1] range) from the pos in expand direction */ in vec2 uv; in vec2 pos; /* verts position in the curve tangent space */ in vec2 expand; -#ifdef USE_INSTANCE +# ifdef USE_INSTANCE /* Instance attrs. */ in vec2 P0; in vec2 P1; @@ -27,21 +29,10 @@ in float dash_alpha; uniform vec4 colors[6]; -# define colStart (colid_doarrow[0] < 3 ? start_color : colors[colid_doarrow[0]]) -# define colEnd (colid_doarrow[1] < 3 ? end_color : colors[colid_doarrow[1]]) -# define colShadow colors[colid_doarrow[2]] -# define doArrow (colid_doarrow[3] != 0) -# define doMuted (domuted[0] != 0) - -#else +# else /* Single curve drawcall, use uniform. */ uniform vec2 bezierPts[4]; -# define P0 bezierPts[0] -# define P1 bezierPts[1] -# define P2 bezierPts[2] -# define P3 bezierPts[3] - uniform vec4 colors[3]; uniform bool doArrow; uniform bool doMuted; @@ -50,11 +41,7 @@ uniform float thickness; uniform float dash_factor; uniform float dash_alpha; -# define colShadow colors[0] -# define colStart colors[1] -# define colEnd colors[2] - -#endif +# endif uniform float expandSize; uniform float arrowSize; @@ -67,6 +54,33 @@ flat out float lineLength; flat out float dashFactor; flat out float dashAlpha; flat out int isMainLine; +#endif + +#ifdef USE_INSTANCE +# define colStart (colid_doarrow[0] < 3 ? start_color : node_link_data.colors[colid_doarrow[0]]) +# define colEnd (colid_doarrow[1] < 3 ? end_color : node_link_data.colors[colid_doarrow[1]]) +# define colShadow node_link_data.colors[colid_doarrow[2]] +# define doArrow (colid_doarrow[3] != 0) +# define doMuted (domuted[0] != 0) + +#else +# define P0 node_link_data.bezierPts[0] +# define P1 node_link_data.bezierPts[1] +# define P2 node_link_data.bezierPts[2] +# define P3 node_link_data.bezierPts[3] +# define cols node_link_data.colors +# define doArrow node_link_data.doArrow +# define doMuted node_link_data.doMuted +# define dim_factor node_link_data.dim_factor +# define thickness node_link_data.thickness +# define dash_factor node_link_data.dash_factor +# define dash_alpha node_link_data.dash_alpha + +# define colShadow node_link_data.colors[0] +# define colStart node_link_data.colors[1] +# define colEnd node_link_data.colors[2] + +#endif /* Define where along the noodle the gradient will starts and ends. * Use 0.25 instead of 0.35-0.65, because of a visual shift issue. */ @@ -101,7 +115,7 @@ void main(void) vec2 normal = tangent.yx * vec2(-1.0, 1.0); /* Position vertex on the curve tangent space */ - point += (pos.x * tangent + pos.y * normal) * arrowSize; + point += (pos.x * tangent + pos.y * normal) * node_link_data.arrowSize; gl_Position = ModelViewProjectionMatrix * vec4(point, 0.0, 1.0); @@ -139,7 +153,7 @@ void main(void) finalColor[3] *= dim_factor; /* Expand into a line */ - gl_Position.xy += exp_axis * expandSize * expand_dist * thickness; + gl_Position.xy += exp_axis * node_link_data.expandSize * expand_dist * thickness; /* If the link is not muted or is not a reroute arrow the points are squashed to the center of * the line. Magic numbers are defined in drawnode.c */ |