Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Feature Request Post-Deformation Normal Recalculation and Skinned Mesh Renderer

Discussion in 'Graphics Dev Blitz Day 2023 - Q&A' started by icauroboros, May 25, 2023.

  1. icauroboros


    Apr 30, 2021
    Since demo team already develop a compute shader approach based on triangle adjacency data for Enemies, Is there any change to expect this feature any soon ?

    Also I'm currently writing my own library with some different approaches (Cpu, ComputeShader) for this purpose, but there some challenges that I face

    1 - Srp batcher not batching materials with structured buffers even materials use common buffers and all datas equivalent.

    2 - There is no some kind of GetAllBlendShapeWeights(out nativearray<float>) method on SMR.

    3 - There is no hasBlendShapesChangedThisFrame value on SMR.

    4 - On cpu approach, I need something SMR.GetMorphedVertices or SMR.BakeMeshWithZeroPose to get only blend shaped vertex position. Or is there better approach ?

    5 - Mesh.GetBlendShapeFrameVertices too heavy for my case because I need only positions.

    6 - Do I really need custom materials (also I dont want to write to mesh) to pass my custom normals to SMR?
    is there a way to inject after morphing and before skinning ?

    7 - I'm also planning to create my own compute shader skinner to Stay away that Black-box called SMR :D
    it will batches all shapes, vertex Normal from Adjacency and bone skinning to one Dispatch, then one dispatch for triangle normals, total 2 dispatch for everything. Is there any way to access Skinning.compute source to take references ? :D

    I appreciate any help
    Last edited: May 25, 2023
    Yoraiz0r likes this.
  2. Jebtor


    Unity Technologies

    Apr 18, 2018
    Hey! I wanted to make sure I took the time to write a good reply - apologies for the delay.

    We have a product ticket open to add normal recalculation post deformations. You can vote on this to let us know how important this feature is to you. We are aware there are gaps in the blend shape API. I would kindly ask you to submit product requests for this. Please add as much details as possible - why it is needed (use cases), how you expect the API to behave, what information it returns. For my understanding I have some questions:
    • 3. to clarify; this is to know if any of the blend shape weights have changed this frame?
    • 4. here you are interested in vertices that have been moved by any blend shape? Or are you interested in the delta's that make up a blend shape?
    • 5. You can pass in null for
      and they won't be retrieved. This is described in the documentation here. There is still quite a lot happening under the hood here but perhaps this can alleviate the problem a little bit.
    • 6. SMR will deform the normals and tangents if present. I suppose the custom materials are used to load your custom normals in the vertex shader? An alternative to consider could be a compute shader that writes the custom normals into SMR.GetVertexBuffer(). Thereby, overwriting the normals from SMR. I do think this could have a bigger impact on perf than your current approach.
    • I don't believe the one for SMR is easily accessible. The Entities Graphics package has a mesh deformation system too that does skinning and blend shapes. You should have easy access to the source code of packages :)
    Yoraiz0r likes this.
  3. icauroboros


    Apr 30, 2021
    Hey! thanks for the detailed answer.

    3 : About hasBlendShapeChanged this frame, yes I want to know if blend shapes changed to start my recalculation, currently my options getting all values and compare array or I could wrap SetBlendShape method and swap all animations keyframes, but I don't want to do that since its for public library.
    4 : I need all vertices (or mesh) itself from SMR after BlendShapes but before Bone Skinning to recalculate normals then pass to my material.
    My current approach is like
    • instancing same model with zero pose
    • copy BlendShape values to smr
    • baking to a temp mesh
    • get vertices and recalculate normals
    • pass to custom vertex shader
    • Destroy cop model
    Probably I need to revert pose to zero pose get data then revert back in same frame instead of instancing same model ,but I don't know how to do this currently :D

    Thanks for your advices, I will test them,
    Also I did already vote on product board like 1 year ago but I can give much more detailed feedback now,
    so if I edit my feedback are you guys gonna reevaluate it or should I use "submit new feedback" card?
    Jebtor likes this.
  4. Anne_Daney


    Unity Technologies

    Aug 30, 2022
    Hi icauroboros,
    You can edit your feedback, we will reevaluate it.
    We are notified each time there is a change.

    If you can't edit it, you can also vote again on the same card with the more detailed feedback.
    Your vote will be counted only once since you already voted, but the feedback will be added to your previous one.
    Last edited: Jun 2, 2023
    icauroboros likes this.