Announcement

Collapse
No announcement yet.

Can I import vertex colors from a custom leaf mesh?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Can I import vertex colors from a custom leaf mesh?

    I have some leaf assets that I've tested in UE4 with movement driven by custom vertex colors. They function as desired, but when I try to use these leaf assets in SpeedTree, it resets all their color values to flat white. Is there a way to preserve the vertex color information on a mesh when importing to SpeedTree? Thanks.

  • #2
    Hello,

    You can set up vertex colors in the tree. This can be done procedurally, but leaves also have the option to use the color from the mesh. The mesh cutout editor also allows you to paint vertex colors directly on the meshes you create, so you don't have to rely upon an external app.

    http://docs8.speedtree.com/modeler/d...=vertex_colors

    HOWEVER, the SpeedTree importer in UE4 does not load those vertex colors. The vertex color in the UE4 mesh is set to (ao,ao,ao,blend), and this is what is available when you use a vertex color node in the material. When you tell the importer to set up branch blends, you will see this is the case. If you are building UE4 yourself, you could change the SpeedTreeImportFactory to use the real vertex colors instead since they are included in the file, but this may have wide-reaching effects on material setup.

    Hope this helps

    Comment


    • #3
      Thanks Greg! That's a shame about the UE4 importer, but I think this is worth a try at least.

      You've said that leaves have the option to use the vertex colors from the mesh, but when I enable Render > Vertex Color > Color, it just shows them as either flat white, or blue by default if I enable "Vertex Colors" under Compute Flags in the generator. Below are my vertex colors in Maya, versus what they appear as in SpeedTree. Is there a checkbox somewhere to use vertex colors from the mesh that I'm missing?

      Click image for larger version  Name:	Capture5.PNG Views:	1 Size:	196.9 KB ID:	7202Click image for larger version  Name:	Capture6.PNG Views:	1 Size:	493.6 KB ID:	7204

      As for the SpeedTreeImportFactory.cpp file, would this require a significant code change? Or just a simple line swap somewhere? Some specifics on this adjustment would be appreciated, since I'm just a 3D Artist without much C++ knowledge, and I can't seem to find an actual example of this.

      Thanks again!

      Comment


      • #4
        Hello,

        After you enable vertex colors on the tree generator, go to the leaf generator and you will have a new vertex color property group.

        In there, you can control the procedural red, green, and blue, but there is also a "mesh asset" group that lets you interpolate or add the mesh vertex color to the procedural color. Set it to interpolate and set the contribution to 1, and you'll get the mesh asset colors.

        Comment


        • #5
          Ahhh, so there is! Awesome, that's very helpful. I can see them now.

          There was a second part to my previous question, in case you missed it at the bottom there. Would it be possible to get an example of the code required to change the SpeedTreeImportFactory.cpp file to include these colors? I assume it would be a modification of the following segment:

          // vertex color for AO and blending
          UMaterialExpressionVertexColor* VertexColor = NULL;
          if (GeomType != STG_Billboard)
          {
          VertexColor = NewObject<UMaterialExpressionVertexColor>(UnrealMa terial);
          UnrealMaterial->Expressions.Add(VertexColor);
          UnrealMaterial->AmbientOcclusion.Expression = VertexColor;
          UnrealMaterial->AmbientOcclusion.Mask = VertexColor->GetOutputs()[0].Mask;
          UnrealMaterial->AmbientOcclusion.MaskR = 1;
          UnrealMaterial->AmbientOcclusion.MaskG = 0;
          UnrealMaterial->AmbientOcclusion.MaskB = 0;
          UnrealMaterial->AmbientOcclusion.MaskA = 0;
          }

          Thanks again!

          Comment


          • #6
            Sorry, I did indeed miss that question.

            The first place you'll need to edit is in FactoryCreateBinary8. You'll want to change this section:

            Code:
            // ao and branch blend in vertex color
            if (DrawCall.m_eWindGeometryType != SpeedTree8::Billboard)
            {
                uint8 AO = Vertex.m_fAmbientOcclusion * 255.0f;
                RawMesh.WedgeColors.Add(FColor(AO, AO, AO, Vertex.m_fBlendWeight * 255));
            }


            to this:

            Code:
            // color and branch blend in vertex color
            if (DrawCall.m_eWindGeometryType != SpeedTree8::Billboard)
            {
                RawMesh.WedgeColors.Add(FColor(Vertex.m_vColor.x * 255, Vertex.m_vColor.y * 255, Vertex.m_vColor.z * 255, Vertex.m_fBlendWeight * 255));
            }


            Then, in that section you indicated in CreateSpeedTreeMaterial8 (make sure you are editing CreateSpeedTreeMaterial8 and not CreateSpeedTreeMaterial7) you'll want to leave the creation of the node for branch blends later on, but remove the part about hooking it to AO (which doesn't get used a lot anyway). Like this:

            Code:
            UMaterialExpressionVertexColor* VertexColor = NULL;
            if (GeomType != STG_Billboard)
            {
                VertexColor = NewObject<UMaterialExpressionVertexColor>(UnrealMaterial);
                UnrealMaterial->Expressions.Add(VertexColor);
            }


            Hopefully that'll get it all working

            Comment


            • #7
              Thanks so much for this Greg! We got it all working, though the change in the first segment was a little different in our file. Perhaps we're looking at different versions.

              For us, it was the same line but the naming was a little different, so we ended up changing this:
              Code:
              // ao and branch blend in vertex color
              if (DrawCall.m_eWindGeometryType != SpeedTree8::Billboard)
              {
                   uint8 AO = Vertex.m_fAmbientOcclusion * 255.0f;
                   VertexInstanceColors[VertexInstanceID] = FVector4(FLinearColor(FColor(AO, AO, AO, Vertex.m_fBlendWeight * 255)));
              }

              to this:
              Code:
              // color and branch blend in vertex color
              if (DrawCall.m_eWindGeometryType != SpeedTree8::Billboard)
              {
                   VertexInstanceColors[VertexInstanceID] = FVector4(FLinearColor(FColor(Vertex.m_vColor.x * 255, Vertex.m_vColor.y * 255, Vertex.m_vColor.z * 255, Vertex.m_fBlendWeight * 255)));
              }

              Regardless, it works great for what we're trying to achieve now, so that's awesome. We would've been clueless without you. Thanks again!

              Comment

              Working...
              X