[Bf-blender-cvs] [3ed6b4bf63f] tmp-gpu-shader-descriptor-2: gpu_shader_simple_lighting.

Jeroen Bakker noreply at git.blender.org
Wed Jan 12 11:28:26 CET 2022


Commit: 3ed6b4bf63f9ce0d218a75292df69bdcd6bdbf11
Author: Jeroen Bakker
Date:   Wed Jan 12 11:28:07 2022 +0100
Branches: tmp-gpu-shader-descriptor-2
https://developer.blender.org/rB3ed6b4bf63f9ce0d218a75292df69bdcd6bdbf11

gpu_shader_simple_lighting.

===================================================================

M	source/blender/editors/interface/interface_draw.c
M	source/blender/gpu/CMakeLists.txt
M	source/blender/gpu/GPU_shader_shared.h
M	source/blender/gpu/intern/gpu_shader_builtin.c
M	source/blender/gpu/intern/gpu_shader_create_info.hh
M	source/blender/gpu/opengl/gl_shader.cc
M	source/blender/gpu/shaders/gpu_shader_simple_lighting_frag.glsl
A	source/blender/gpu/shaders/infos/gpu_shader_simple_lighting_info.hh

===================================================================

diff --git a/source/blender/editors/interface/interface_draw.c b/source/blender/editors/interface/interface_draw.c
index 285c82b0fb3..f2fa375aa09 100644
--- a/source/blender/editors/interface/interface_draw.c
+++ b/source/blender/editors/interface/interface_draw.c
@@ -57,6 +57,7 @@
 #include "GPU_immediate.h"
 #include "GPU_immediate_util.h"
 #include "GPU_matrix.h"
+#include "GPU_shader_shared.h"
 #include "GPU_state.h"
 
 #include "UI_interface.h"
@@ -1384,10 +1385,16 @@ void ui_draw_but_UNITVEC(uiBut *but,
   GPU_matrix_scale_1f(size);
 
   GPUBatch *sphere = GPU_batch_preset_sphere(2);
+  struct SimpleLightingData simple_lighting_data;
+  copy_v4_fl4(simple_lighting_data.color, diffuse[0], diffuse[1], diffuse[2], 1.0f);
+  copy_v3_v3(simple_lighting_data.light, light);
+  GPUUniformBuf *ubo = GPU_uniformbuf_create_ex(
+      sizeof(struct SimpleLightingData), &simple_lighting_data, __func__);
+
   GPU_batch_program_set_builtin(sphere, GPU_SHADER_SIMPLE_LIGHTING);
-  GPU_batch_uniform_4f(sphere, "color", diffuse[0], diffuse[1], diffuse[2], 1.0f);
-  GPU_batch_uniform_3fv(sphere, "light", light);
+  GPU_batch_uniformbuf_bind(sphere, "simple_lighting_data", ubo);
   GPU_batch_draw(sphere);
+  GPU_uniformbuf_free(ubo);
 
   /* Restore. */
   GPU_face_culling(GPU_CULL_NONE);
diff --git a/source/blender/gpu/CMakeLists.txt b/source/blender/gpu/CMakeLists.txt
index 6db9bd882ea..03efc54635e 100644
--- a/source/blender/gpu/CMakeLists.txt
+++ b/source/blender/gpu/CMakeLists.txt
@@ -439,6 +439,7 @@ shaders/infos/gpu_shader_instance_varying_color_varying_size_info.hh
 shaders/infos/gpu_shader_3D_point_info.hh
 shaders/infos/gpu_shader_2D_nodelink_info.hh
 shaders/infos/gpu_shader_gpencil_stroke_info.hh
+shaders/infos/gpu_shader_simple_lighting_info.hh
 #shaders/infos/gpu_shader_todo_info.hh
 )
 
diff --git a/source/blender/gpu/GPU_shader_shared.h b/source/blender/gpu/GPU_shader_shared.h
index c84a99df990..576f88ddcca 100644
--- a/source/blender/gpu/GPU_shader_shared.h
+++ b/source/blender/gpu/GPU_shader_shared.h
@@ -5,6 +5,7 @@
 
 #ifdef __cplusplus
 using blender::float2;
+using blender::float3;
 using blender::float4;
 using blender::float4x4;
 #endif
@@ -26,7 +27,7 @@ struct NodeLinkInstanceData {
   float4 colors[6];
   float expandSize;
   float arrowSize;
-  float2 pad;
+  float2 _pad;
 };
 
 struct GPencilStrokeData {
@@ -39,10 +40,16 @@ struct GPencilStrokeData {
   int caps_end;
   bool1 keep_size;
   bool1 fill_stroke;
-  float2 pad;
+  float2 _pad;
 };
 
 struct GPUClipPlanes {
   float4x4 ModelMatrix;
   float4 world[6];
+};
+
+struct SimpleLightingData {
+  float4 color;
+  float3 light;
+  float _pad;
 };
\ No newline at end of file
diff --git a/source/blender/gpu/intern/gpu_shader_builtin.c b/source/blender/gpu/intern/gpu_shader_builtin.c
index a5a4e0309c2..26a0fff03b7 100644
--- a/source/blender/gpu/intern/gpu_shader_builtin.c
+++ b/source/blender/gpu/intern/gpu_shader_builtin.c
@@ -167,6 +167,7 @@ static const GPUShaderStages builtin_shader_stages[GPU_SHADER_BUILTIN_LEN] = {
     [GPU_SHADER_SIMPLE_LIGHTING] =
         {
             .name = "GPU_SHADER_SIMPLE_LIGHTING",
+            .create_info = "gpu_shader_simple_lighting",
             .vert = datatoc_gpu_shader_3D_normal_vert_glsl,
             .frag = datatoc_gpu_shader_simple_lighting_frag_glsl,
         },
diff --git a/source/blender/gpu/intern/gpu_shader_create_info.hh b/source/blender/gpu/intern/gpu_shader_create_info.hh
index da84916714f..731ffee35db 100644
--- a/source/blender/gpu/intern/gpu_shader_create_info.hh
+++ b/source/blender/gpu/intern/gpu_shader_create_info.hh
@@ -49,6 +49,7 @@ enum class Type {
   VEC2,
   VEC3,
   VEC4,
+  MAT3,
   MAT4,
   UINT,
   UVEC2,
diff --git a/source/blender/gpu/opengl/gl_shader.cc b/source/blender/gpu/opengl/gl_shader.cc
index e3d8d5f3b28..21389e447d4 100644
--- a/source/blender/gpu/opengl/gl_shader.cc
+++ b/source/blender/gpu/opengl/gl_shader.cc
@@ -100,6 +100,8 @@ static const char *to_string(const Type &type)
       return "vec3";
     case Type::VEC4:
       return "vec4";
+    case Type::MAT3:
+      return "mat3";
     case Type::MAT4:
       return "mat4";
     case Type::UINT:
diff --git a/source/blender/gpu/shaders/gpu_shader_simple_lighting_frag.glsl b/source/blender/gpu/shaders/gpu_shader_simple_lighting_frag.glsl
index 333789f82ca..6725bc82841 100644
--- a/source/blender/gpu/shaders/gpu_shader_simple_lighting_frag.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_simple_lighting_frag.glsl
@@ -14,6 +14,6 @@ out vec4 fragColor;
 
 void main()
 {
-  fragColor = color;
-  fragColor.xyz *= clamp(dot(normalize(normal), light), 0.0, 1.0);
+  fragColor = simple_lighting_data.color;
+  fragColor.xyz *= clamp(dot(normalize(normal), simple_lighting_data.light), 0.0, 1.0);
 }
diff --git a/source/blender/gpu/shaders/infos/gpu_shader_simple_lighting_info.hh b/source/blender/gpu/shaders/infos/gpu_shader_simple_lighting_info.hh
new file mode 100644
index 00000000000..109f5485355
--- /dev/null
+++ b/source/blender/gpu/shaders/infos/gpu_shader_simple_lighting_info.hh
@@ -0,0 +1,17 @@
+
+#include "gpu_shader_create_info.hh"
+
+GPU_SHADER_INTERFACE_INFO(smooth_normal_iface, "").smooth(Type::VEC3, "normal");
+
+GPU_SHADER_CREATE_INFO(gpu_shader_simple_lighting)
+    .vertex_in(0, Type::VEC3, "pos")
+    .vertex_in(1, Type::VEC3, "nor")
+    .vertex_out(smooth_normal_iface)
+    .fragment_out(0, Type::VEC4, "fragColor")
+    .uniform_buf(0, "SimpleLightingData", "simple_lighting_data", Frequency::PASS)
+    .push_constant(0, Type::MAT4, "ModelViewProjectionMatrix")
+    .push_constant(16, Type::MAT3, "NormalMatrix")
+    .typedef_source("GPU_shader_shared.h")
+    .vertex_source("gpu_shader_3D_normal_vert.glsl")
+    .fragment_source("gpu_shader_simple_lighting_frag.glsl")
+    .do_static_compilation(true);



More information about the Bf-blender-cvs mailing list