Add default uniform for actor 'uScale' 49/301549/2
authorEunki, Hong <eunkiki.hong@samsung.com>
Mon, 20 Nov 2023 02:40:41 +0000 (11:40 +0900)
committerEunki, Hong <eunkiki.hong@samsung.com>
Mon, 20 Nov 2023 04:25:16 +0000 (13:25 +0900)
Some shader codes like anti-alias need to be calculated
by pixel scaled.

But currently we don't have any way to get 'scaled' visual size
at shader side.

To support it, let we write scale value into shader.

Change-Id: Ie1d9e2e5429a3ed20fc3e9dde004b7546e3e2c32
Signed-off-by: Eunki, Hong <eunkiki.hong@samsung.com>
automated-tests/src/dali/dali-test-suite-utils/test-gl-abstraction.cpp
automated-tests/src/dali/dali-test-suite-utils/test-graphics-reflection.cpp
dali/internal/render/common/render-algorithms.cpp
dali/internal/render/common/render-item.cpp
dali/internal/render/common/render-item.h
dali/internal/render/renderers/render-renderer.cpp
dali/internal/render/renderers/render-renderer.h
dali/internal/render/shaders/program.cpp
dali/internal/render/shaders/program.h
dali/internal/update/manager/render-instruction-processor.cpp

index 38169a2..b861c66 100644 (file)
@@ -166,6 +166,7 @@ void TestGlAbstraction::Initialize()
     {"uMvpMatrix", GL_FLOAT_MAT4, 1},
     {"uNormalMatrix", GL_FLOAT_MAT4, 1},
     {"uProjection", GL_FLOAT_MAT4, 1},
+    {"uScale", GL_FLOAT_VEC3, 1},
     {"uSize", GL_FLOAT_VEC3, 1},
     {"uViewMatrix", GL_FLOAT_MAT4, 1},
     {"uLightCameraProjectionMatrix", GL_FLOAT_MAT4, 1},
index 7b3e6c8..3998fde 100644 (file)
@@ -54,6 +54,7 @@ static const std::vector<UniformData> UNIFORMS =
     UniformData("uMvpMatrix", Property::Type::MATRIX),
     UniformData("uNormalMatrix", Property::Type::MATRIX3),
     UniformData("uProjection", Property::Type::MATRIX),
+    UniformData("uScale", Property::Type::VECTOR3),
     UniformData("uSize", Property::Type::VECTOR3),
     UniformData("uViewMatrix", Property::Type::MATRIX),
     UniformData("uLightCameraProjectionMatrix", Property::Type::MATRIX),
index ad580cf..9c00289 100644 (file)
@@ -696,7 +696,7 @@ inline void RenderAlgorithms::ProcessRenderList(const RenderList&
         for(auto queue = 0u; queue < MAX_QUEUE; ++queue)
         {
           // Render the item. It will write into the command buffer everything it has to render
-          item.mRenderer->Render(secondaryCommandBuffer, bufferIndex, *item.mNode, item.mModelMatrix, item.mModelViewMatrix, viewMatrix, projectionMatrix, item.mSize, !item.mIsOpaque, instruction, queue);
+          item.mRenderer->Render(secondaryCommandBuffer, bufferIndex, *item.mNode, item.mModelMatrix, item.mModelViewMatrix, viewMatrix, projectionMatrix, item.mScale, item.mSize, !item.mIsOpaque, instruction, queue);
         }
       }
     }
index 0ba37c3..31c0678 100644 (file)
@@ -55,6 +55,7 @@ RenderItemKey RenderItem::NewKey()
 RenderItem::RenderItem()
 : mModelMatrix(false),
   mModelViewMatrix(false),
+  mScale(),
   mSize(),
   mRenderer{},
   mNode(nullptr),
index c13e98d..8142ea5 100644 (file)
@@ -120,6 +120,7 @@ struct RenderItem
 
   Matrix              mModelMatrix;
   Matrix              mModelViewMatrix;
+  Vector3             mScale;
   Vector3             mSize;
   Vector4             mUpdateArea; ///< Update area hint is provided for damaged area calculation. (x, y, width, height)
   Render::RendererKey mRenderer;
index e4aa1b9..4baebf9 100644 (file)
@@ -549,6 +549,7 @@ bool Renderer::Render(Graphics::CommandBuffer&                             comma
                       const Matrix&                                        modelViewMatrix,
                       const Matrix&                                        viewMatrix,
                       const Matrix&                                        projectionMatrix,
+                      const Vector3&                                       scale,
                       const Vector3&                                       size,
                       bool                                                 blend,
                       const Dali::Internal::SceneGraph::RenderInstruction& instruction,
@@ -651,8 +652,8 @@ bool Renderer::Render(Graphics::CommandBuffer&                             comma
 
     if(queueIndex == 0)
     {
-      std::size_t nodeIndex = BuildUniformIndexMap(bufferIndex, node, size, *program);
-      WriteUniformBuffer(bufferIndex, commandBuffer, program, instruction, node, modelMatrix, modelViewMatrix, viewMatrix, projectionMatrix, size, nodeIndex);
+      std::size_t nodeIndex = BuildUniformIndexMap(bufferIndex, node, *program);
+      WriteUniformBuffer(bufferIndex, commandBuffer, program, instruction, node, modelMatrix, modelViewMatrix, viewMatrix, projectionMatrix, scale, size, nodeIndex);
     }
     // @todo We should detect this case much earlier to prevent unnecessary work
     // Reuse latest bound vertex attributes location, or Bind buffers to attribute locations.
@@ -682,7 +683,7 @@ bool Renderer::Render(Graphics::CommandBuffer&                             comma
   return drawn;
 }
 
-std::size_t Renderer::BuildUniformIndexMap(BufferIndex bufferIndex, const SceneGraph::NodeDataProvider& node, const Vector3& size, Program& program)
+std::size_t Renderer::BuildUniformIndexMap(BufferIndex bufferIndex, const SceneGraph::NodeDataProvider& node, Program& program)
 {
   // Check if the map has changed
   DALI_ASSERT_DEBUG(mRenderDataProvider && "No Uniform map data provider available");
@@ -797,6 +798,7 @@ void Renderer::WriteUniformBuffer(
   const Matrix&                        modelViewMatrix,
   const Matrix&                        viewMatrix,
   const Matrix&                        projectionMatrix,
+  const Vector3&                       scale,
   const Vector3&                       size,
   std::size_t                          nodeIndex)
 {
@@ -856,6 +858,8 @@ void Renderer::WriteUniformBuffer(
       WriteDefaultUniformV2(normalUniformInfo, uboViews, normalMatrix);
     }
 
+    WriteDefaultUniformV2(program->GetDefaultUniform(Program::DefaultUniformIndex::SCALE), uboViews, scale);
+
     Vector4        finalColor;                               ///< Applied renderer's opacity color
     const Vector4& color = node.GetRenderColor(bufferIndex); ///< Actor's original color
     if(mPremultipliedAlphaEnabled)
@@ -867,7 +871,6 @@ void Renderer::WriteUniformBuffer(
     {
       finalColor = Vector4(color.r, color.g, color.b, color.a * mRenderDataProvider->GetOpacity(bufferIndex));
     }
-
     WriteDefaultUniformV2(program->GetDefaultUniform(Program::DefaultUniformIndex::COLOR), uboViews, finalColor);
     WriteDefaultUniformV2(program->GetDefaultUniform(Program::DefaultUniformIndex::ACTOR_COLOR), uboViews, color);
 
index 361840f..c8e9d3c 100644 (file)
@@ -400,6 +400,7 @@ public:
    * @param[in] modelViewMatrix The model-view matrix.
    * @param[in] viewMatrix The view matrix.
    * @param[in] projectionMatrix The projection matrix.
+   * @param[in] scale Scale factor of the render item
    * @param[in] size Size of the render item
    * @param[in] blend If true, blending is enabled
    * @param[in] instruction. for use case like reflection where CullFace needs to be adjusted
@@ -413,6 +414,7 @@ public:
               const Matrix&                                        modelViewMatrix,
               const Matrix&                                        viewMatrix,
               const Matrix&                                        projectionMatrix,
+              const Vector3&                                       scale,
               const Vector3&                                       size,
               bool                                                 blend,
               const Dali::Internal::SceneGraph::RenderInstruction& instruction,
@@ -542,12 +544,11 @@ private:
    * Builds a uniform map based on the index of the cached location in the Program.
    * @param[in] bufferIndex The index of the previous update buffer.
    * @param[in] node The node using the renderer
-   * @param[in] size The size of the renderer
    * @param[in] program The shader program on which to set the uniforms.
    *
    * @return the index of the node in change counters store / uniform maps store.
    */
-  std::size_t BuildUniformIndexMap(BufferIndex bufferIndex, const SceneGraph::NodeDataProvider& node, const Vector3& size, Program& program);
+  std::size_t BuildUniformIndexMap(BufferIndex bufferIndex, const SceneGraph::NodeDataProvider& node, Program& program);
 
   /**
    * Bind the textures and setup the samplers
@@ -580,6 +581,7 @@ private:
    * @param[in] modelViewMatrix The model-view matrix.
    * @param[in] viewMatrix The view matrix.
    * @param[in] projectionMatrix The projection matrix.
+   * @param[in] scale Scale factor of the render item
    * @param[in] size Size of the render item
    * @param[in] blend If true, blending is enabled
    * @param[in] instruction The render instruction
@@ -594,6 +596,7 @@ private:
                           const Matrix&                        modelViewMatrix,
                           const Matrix&                        viewMatrix,
                           const Matrix&                        projectionMatrix,
+                          const Vector3&                       scale,
                           const Vector3&                       size,
                           std::size_t                          nodeIndex);
 
index 02e1b18..b5aa1f8 100644 (file)
@@ -56,6 +56,7 @@ size_t DEFAULT_UNIFORM_HASHTABLE[NUMBER_OF_DEFAULT_UNIFORMS] =
     CalculateHash(std::string("uModelView")),
     CalculateHash(std::string("uNormalMatrix")),
     CalculateHash(std::string("uProjection")),
+    CalculateHash(std::string("uScale")),
     CalculateHash(std::string("uSize")),
     CalculateHash(std::string("uColor")),
     CalculateHash(std::string("uActorColor"))};
index f657159..c6e58b6 100644 (file)
@@ -68,6 +68,7 @@ public:
     MODEL_VIEW_MATRIX,
     NORMAL_MATRIX,
     PROJECTION_MATRIX,
+    SCALE,
     SIZE,
     COLOR,
     ACTOR_COLOR,
index 09fa6d5..21955c1 100644 (file)
@@ -203,6 +203,7 @@ inline void AddRendererToRenderList(BufferIndex               updateBufferIndex,
   bool    inside(true);
   Node*   node = renderable.mNode;
   Matrix  nodeWorldMatrix(false);
+  Vector3 nodeScale;
   Vector3 nodeSize;
   Vector4 nodeUpdateArea;
   bool    nodeUpdateAreaSet(false);
@@ -237,8 +238,9 @@ inline void AddRendererToRenderList(BufferIndex               updateBufferIndex,
       SetNodeUpdateArea(node, isLayer3d, nodeWorldMatrix, nodeSize, nodeUpdateArea);
       nodeUpdateAreaSet = true;
 
-      const Vector3& scale = nodeWorldMatrix.GetScale();
-      const Vector3& size  = Vector3(nodeUpdateArea.z, nodeUpdateArea.w, 0.0f) * scale;
+      nodeScale = nodeWorldMatrix.GetScale();
+
+      const Vector3& size = Vector3(nodeUpdateArea.z, nodeUpdateArea.w, 0.0f) * nodeScale;
 
       if(size.LengthSquared() > Math::MACHINE_EPSILON_1000)
       {
@@ -301,8 +303,10 @@ inline void AddRendererToRenderList(BufferIndex               updateBufferIndex,
       if(!nodeUpdateAreaSet)
       {
         SetNodeUpdateArea(node, isLayer3d, nodeWorldMatrix, nodeSize, nodeUpdateArea);
+        nodeScale = nodeWorldMatrix.GetScale();
       }
 
+      item.mScale       = nodeScale;
       item.mSize        = nodeSize;
       item.mUpdateArea  = nodeUpdateArea;
       item.mModelMatrix = nodeWorldMatrix;