Announcement

Collapse
No announcement yet.

Generate Procedural Mesh

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

    Originally posted by electricsauce View Post
    What are you using as the inputs to ddx and ddy? Since I'm looking at fixing the lighting on my meshes anyways, I was noticing that flipping the green channel on my normal maps gives me the correct lighting on my generated meshes. I'm using this algorithm, to calculate my tangents.
    My apologies I forgot to SS that part, it uses the Absolute World Position as the input to both.


    Consider supporting me on patreon

    My Open source tools and plugins
    Advanced Sessions Plugin
    VR Expansion Plugin

    Comment


      Hi!! Sorry for my bad english ) (its not my native lang).

      I was edit the code and include smoothings groups support for triangles.



      Code:
      USTRUCT(BlueprintType)
      struct ProceduralMeshTriangle
      {
          GENERATED_USTRUCT_BODY()
      
              UPROPERTY(EditAnywhere, Category = Triangle)
              ProceduralMeshVertex Vertex0;
      
          UPROPERTY(EditAnywhere, Category = Triangle)
              ProceduralMeshVertex Vertex1;
      
          UPROPERTY(EditAnywhere, Category = Triangle)
              ProceduralMeshVertex Vertex2;
      
          UPROPERTY(EditAnywhere, Category = Triangle)
              int32 SmoothingsGroups;
      };
      and in to sceneproxy class

      Code:
            TArray<FVector> PositionEq;
              TArray<int32> SmoothingGroupEq;
      
              // Add each triangle to the vertex/index buffer
              for (int TriIdx = 0; TriIdx < Component->ProceduralMeshTris.Num(); TriIdx++)
              {
                  FProceduralMeshTriangle& Tri = Component->ProceduralMeshTris[TriIdx];
      
                  const FVector Edge01 = (Tri.Vertex1.Position - Tri.Vertex0.Position);
                  const FVector Edge02 = (Tri.Vertex2.Position - Tri.Vertex0.Position);
      
                  const FVector TangentX = Edge01.SafeNormal();
                  const FVector TangentZ = (Edge02 ^ Edge01).SafeNormal();
                  const FVector TangentY = (TangentX ^ TangentZ).SafeNormal();
      
                  int32 VIndex;
                  int32 SG;   //SmoothigGrup Buffer
      
                  SG = Tri.SmoothingsGroups;
      
                  FDynamicMeshVertex Vert0;
                  Vert0.Position = Tri.Vertex0.Position;
                  Vert0.Color = Tri.Vertex0.Color;
                  Vert0.SetTangents(TangentX, TangentY, TangentZ);
                  Vert0.TextureCoordinate.Set(Tri.Vertex0.U, Tri.Vertex0.V);
                  if (!PositionEq.Contains(Vert0.Position))
                  {
                      SmoothingGroupEq.Add(Tri.SmoothingsGroups);
                      PositionEq.Add(Vert0.Position);
                      VIndex = VertexBuffer.Vertices.Add(Vert0);
                      IndexBuffer.Indices.Add(VIndex);
                  } else 
                      {
                      if ((SmoothingGroupEq[PositionEq.Find(Vert0.Position)] == SG))
                          {
                              IndexBuffer.Indices.Add(PositionEq.Find(Vert0.Position));
                          } else    
                              {
                                  SmoothingGroupEq.Add(Tri.SmoothingsGroups);
                                  PositionEq.Add(Vert0.Position);
                                  VIndex = VertexBuffer.Vertices.Add(Vert0);
                                  IndexBuffer.Indices.Add(VIndex);
                              }
                      }
      
                  FDynamicMeshVertex Vert1;
                  Vert1.Position = Tri.Vertex1.Position;
                  Vert1.Color = Tri.Vertex1.Color;
                  Vert1.SetTangents(TangentX, TangentY, TangentZ);
                  Vert1.TextureCoordinate.Set(Tri.Vertex1.U, Tri.Vertex1.V);
                  if (!PositionEq.Contains(Vert1.Position))
                  {
                      SmoothingGroupEq.Add(Tri.SmoothingsGroups);
                      PositionEq.Add(Vert1.Position);
                      VIndex = VertexBuffer.Vertices.Add(Vert1);
                      IndexBuffer.Indices.Add(VIndex);
                  } else
                      {
                          if ((SmoothingGroupEq[PositionEq.Find(Vert1.Position)] == SG))
                          {
                          IndexBuffer.Indices.Add(PositionEq.Find(Vert1.Position));
                          } else
                              {
                              SmoothingGroupEq.Add(Tri.SmoothingsGroups);
                              PositionEq.Add(Vert1.Position);
                              VIndex = VertexBuffer.Vertices.Add(Vert1);
                              IndexBuffer.Indices.Add(VIndex);
                              }
                      }
                  FDynamicMeshVertex Vert2;
                  Vert2.Position = Tri.Vertex2.Position;
                  Vert2.Color = Tri.Vertex2.Color;
                  Vert2.SetTangents(TangentX, TangentY, TangentZ);
                  Vert2.TextureCoordinate.Set(Tri.Vertex2.U, Tri.Vertex2.V);
                  if (!PositionEq.Contains(Vert2.Position))
                  {
                      SmoothingGroupEq.Add(Tri.SmoothingsGroups);
                      PositionEq.Add(Vert2.Position);
                      VIndex = VertexBuffer.Vertices.Add(Vert2);
                      IndexBuffer.Indices.Add(VIndex);
                  } else
                      {
                          if ((SmoothingGroupEq[PositionEq.Find(Vert2.Position)] == SG))
                          {
                              IndexBuffer.Indices.Add(PositionEq.Find(Vert2.Position));
                          } else
                              {
                                  SmoothingGroupEq.Add(Tri.SmoothingsGroups);
                                  PositionEq.Add(Vert2.Position);
                                  VIndex = VertexBuffer.Vertices.Add(Vert2);
                                  IndexBuffer.Indices.Add(VIndex);
                              }
                      }
              }
      Last edited by artem8686; 02-25-2015, 10:25 AM.

      Comment


        And another news: I use procedural mesh in BP and make the procedural box, but whith tesselation. U can build box with x,y,z dimensions and t polygons in each side of box.
        https://drive.google.com/file/d/0ByX...ew?usp=sharing

        But this thing have some problems.
        1. This BP based on construction script and in viewport work fine. But when i press the play button my mesh disappear.
        2. This mesh contain vertex color. But vertex paint not work. I was founded in staticmeshcomponent.h struct Fpaintedvertex and thinking about including this code to the procedural mesh. But im a begginer...
        3. Next step what i want to make - add material id to the fproceduraltriangles.

        One week ago i was maked a BP wich build procedural house from static mesh clusters. This BP have input parameters: dimensions, number of floors, number of window and doors for each wall. And i can use vertex paint and diffrent materials. And it work fine. BUT. When i build a new house for example 5-9 floors and 10x15 meters dimensions - this BP contain 1000 static meshes. FPS down form 120 to 30. When I add a whole building of the same number of polygons from the 3d max - its ok whith FPS (120).

        Thats why i need procedural mesh - generate one mesh for one building or one floor.

        Comment


          Originally posted by TaurusI76 View Post
          I've had the exact same problem since the update from 4.6.1 to 4.7. I'd be super glad if somebody had a solution...
          Guys make sure that you actually implement
          Code:
          virtual void GetDynamicMeshElements(const TArray<const FSceneView*>& Views, const FSceneViewFamily& ViewFamily, uint32 VisibilityMap, FMeshElementCollector& Collector) const override
          and
          Code:
          virtual void DrawStaticElements(FStaticPrimitiveDrawInterface* PDI)
          The DrawDynamicElements() function has been on the way out for a couple of patches and they finally enforced it in this one and it doesn't get called at all (that is why it isn't rendering for you).

          This is actually the very first major update where I didn't have to change a single line of code to compile my project
          Last edited by mordentral; 02-25-2015, 01:47 PM.


          Consider supporting me on patreon

          My Open source tools and plugins
          Advanced Sessions Plugin
          VR Expansion Plugin

          Comment


            Originally posted by mordentral View Post


            Output of the cross goes to the normal input for the material, to use normal maps from textures you have to mask out the B channel for them and add the RG channels to the cross output. This of course is all being done on my end because I am triplaner texturing a landscape mesh, you might want to stick with calculated tangents since you seem to be generating static interior geometry and won't have as much raw data to pass back and forth to the GPU as I do.
            Thank you for posting this. But unfortunately it does not fix my lighting problems. Currently I have no idea what I could try and it looks really awkwared if ue4 changes the shading mode for higher distances and therefore getting a bright lighed landscape in the deep of the night .

            Comment


              Has anyone had any luck generating a procedural mesh as a static mesh? My procedural mesh actor is a child of AStaticMeshActor, and I've tried:
              Code:
              	GenerateCube(triangles, cubeSize, cubeSize, cubeSize, FVector(0.f, 0.f, 0.f), false, false, false);
              	mesh->SetProceduralMeshTriangles(triangles);
              	StaticMeshComponent->SetStaticMesh(Cast<UStaticMesh>(mesh));
              with no luck. Ideally I'd like to be able to bake lighting on the mesh which isn't possible as a procedural mesh. Is this even possible?

              Comment


                Originally posted by electricsauce View Post
                Has anyone had any luck generating a procedural mesh as a static mesh? My procedural mesh actor is a child of AStaticMeshActor, and I've tried:
                Code:
                	GenerateCube(triangles, cubeSize, cubeSize, cubeSize, FVector(0.f, 0.f, 0.f), false, false, false);
                	mesh->SetProceduralMeshTriangles(triangles);
                	StaticMeshComponent->SetStaticMesh(Cast<UStaticMesh>(mesh));
                with no luck. Ideally I'd like to be able to bake lighting on the mesh which isn't possible as a procedural mesh. Is this even possible?
                Yesterday i was tried too. But unreal crash whith this code. I'd like to be able to bake light and vertex paint. I see that the proceduralmeshcomponent and the staticmeshcomponent is a child of one class - meshcomponent. May be its possible to make proceduralmesh with the staticmesh opportunities. But i dont know how. Now i working with this idea. If u find how pleas send a message.

                Comment


                  I am doing some procedural terrain. The output of the algorithm (Dual Contouring) is a vertex list(position, normal), and a list of indices.

                  The output is also in Quads not triangles. I know I will have to triangulate these quads, but how do I create the tangent vectors? This terrain is smooth and the quads share verts (so I cannot create the tangents like the wiki does) it will just end up with a normal that favors the last triangle that uses that vert).

                  Do I create the tangents for every triangle that uses that vert then average them? It just feels like if I already have the normal I shouldn't have to go through all that (I could be wrong, it would not be the first time).

                  Comment


                    Originally posted by TaurusI76 View Post
                    I've had the exact same problem since the update from 4.6.1 to 4.7. I'd be super glad if somebody had a solution...
                    I found the solution to this. You are missing the "GetDynamicMeshElements" function inside the FGeneratedMeshSceneProxy. Take a look at the github project for the function.

                    Comment


                      Originally posted by JohnnyBeans78 View Post
                      I found the solution to this. You are missing the "GetDynamicMeshElements" function inside the FGeneratedMeshSceneProxy. Take a look at the github project for the function.
                      Could you please provide a link for this project? The one I've found doesn't have this code related to "GetDynamicMeshElements"

                      Comment


                        Originally posted by Dzhyrma View Post
                        Could you please provide a link for this project? The one I've found doesn't have this code related to "GetDynamicMeshElements"
                        https://github.com/SRombauts/UE4ProceduralMesh/

                        Comment


                          Originally posted by JohnnyBeans78 View Post
                          Maybe I'm too stupid for this. I use UE4.6.1 and after adding into the buildfile "RHI", "RenderCore", "ShaderCore", creating ProceduralTriangleActor and ProceduralMeshComponent I get errors in the following lines:

                          ProceduralMeshComponent.h:
                          line #include "ProceduralMeshComponent.generated.h" Error: cannot open source file "ProceduralMeshComponent.generated.h"
                          line FVector Position; Error: expected a ';'
                          line FProceduralMeshVertex Vertex0; Error: expected a ';'
                          line class UProceduralMeshComponent : public UMeshComponent, public IInterface_CollisionDataProvider{ GENERATED_UCLASS_BODY()... Error: expected an identifier

                          ProceduralMeshComponent.cpp:
                          lline UProceduralMeshComponent::UProceduralMeshComponent(const FObjectInitializer& PCIP): Super(PCIP) Error: no instance of overloaded funcion "UProceduralMeshComponent::UProceduralMeshComponent" matches the specified type

                          I'm sitting at this problem for about 2 weeks, can somebody help please?

                          I just became able to compile the code. The mistake was that I added the class ProceduralMeshComponent from within visual studio instead of the ue editor add code wizard
                          Last edited by YuZ; 03-04-2015, 06:55 AM.

                          Comment


                            Originally posted by JohnnyBeans78 View Post
                            I am doing some procedural terrain. The output of the algorithm (Dual Contouring) is a vertex list(position, normal), and a list of indices.

                            The output is also in Quads not triangles. I know I will have to triangulate these quads, but how do I create the tangent vectors? This terrain is smooth and the quads share verts (so I cannot create the tangents like the wiki does) it will just end up with a normal that favors the last triangle that uses that vert).

                            Do I create the tangents for every triangle that uses that vert then average them? It just feels like if I already have the normal I shouldn't have to go through all that (I could be wrong, it would not be the first time).
                            I am interested in this as well. I'm attempting to implement the same algorithm. So I guess there's no way to define meshes as quads?

                            Comment


                              I'm trying out mordentral's method of calculating tangents in the shader and I'm getting a weird lighting issue where the shadows are inverted from each other on the left and right sides. What could be causing this issue?

                              Comment


                                You have still marked the Tangent Space Normal in the checkbox on the left (in your material). You sould remove that maker if you are computing your normals within the shader.

                                Comment

                                Working...
                                X