Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

Tessellation


havenphillip

140 views

If you liked vertex displacement, you're going to love tessellation. Tessellation is very similar, but incorporates the control and evaluation stages of the shader. The Leadwerks box brush creates a box that has two triangles per face. If you want to use some kind of vertex displacement on it you're going to have a bad time. With tessellation it's different because you are able to subdivide the faces with the shader, so you can use the shader to create more structurally complex models. The control stage in the shader does the subdivision, and the evaluation stage can be thought of as a post-control vertex stage - it just resets everything after tessellation has taken place. This "control" over the number of vertices makes the tessellation shader superior because you can take very simple models and subdivide them to exactly the number of vertices you need without going back and forth between Leadwerks and some modeling program.  You can set it to exactly the number you need.

You can see here this Leadwerks box in the material editor. It has two triangles per face. I subdivided it by 64. You can see how much detail you can with only two triangles:

1801348266_tessellatedbox.thumb.jpg.f73c7f5bb98cb6b59b517ad06d54eb5c.jpg

 

You can see that two triangles yields a lot. There is a limit, though. I'm fairly certain 64 is the maximum number of subdivisions you can do, and just like the vertex displacement the size of the object matters because the more space you have between vertices, the less crammed the details are. They get too spread out and the tessellation can't keep up with the smaller details. So if you need more than 64 will allow, you will have to subdivide your model a little bit more before you port it in to Leadwerks.

 

One thing I want to mention. I added this uncommented line in the vertex stage:

    vec4 modelvertexposition = entitymatrix_ * vec4(vertex_position - vertex_normal * 0.1,1.0);

 

Notice the above and below picture:

gap.thumb.jpg.3f23854ad72a6b6ddf9f1cfda1d223c5.jpg

 

Subtracting the vertex_normal from the vertex_position and multiplying it by some small number allows you to reduce this gap. That's just a little trick I picked up along the way. I still don't know how to close those seams. I think Josh tried to explain it to me once but I'm not a technical guy. I couldn't make sense of it. But just swap that line in instead of the standard modelvertexposition line and adjust the number. But don't go too far in because otherwise your plane will go beneath the surface of the mesh boundary and it will cast shadows on itself. You can disable Cast Shadows in the material editor and that will go away but obviously only do that if you don't want to cast shadows at all.

 

Here's the noobalyzed Leadwerks tessellation shader. It's a nice little Leadwerks gem:

tessphere.thumb.jpg.59cc3630f4012d7d03573563d7d27835.jpg

 

41_tessellation.zip

So think of your control stage as "controlling" the subdivisions, and the evaluation stage has the heightmap and the height strength and all the other things you would have put in the vertex stage in a vertex displacement shader.

 

You can add a time element to your heightmap in the evaluation stage to create a wind effect using textures:

sheet.thumb.jpg.f976a7e5fbb38c307ccac13cf5575dcf.jpg

 

42_sheet in the wind.zip

The sheet in the wind shader is a bit oddball because I haven't yet figured out how to make it two-sided. The problem is that with a two-sided object the height direction goes the opposite direction. So with this shader you get two sheets instead of one consistent sheet. Maybe it's a modeling problem. I don't know. You can set it to two-sided in the material editor but one of the sides won't react to the flashlight. That kind of thing irks me. It's not enough of a solution for me. But potentially this could be used for clothes or any other thing you want to blow in the wind. If and when I figure it out I'll let you know.

 

I put the heightmap normals information in the fragment shader from 37_normal from heightmap in both of these shaders. That's what gives the sheet any normals at all. You can sort of see it in the soft shadows in the sheet above. You'll see what I mean if you grab this shader and run it in your game.

 

Also, one important note:  I usually set my heightmaps to uncompressed in the texture editor. That makes a huge difference. Otherwise you get this weird sort of voxelized look. 

 

Happy shading!

 

Next: Geometry...

  • Like 3

0 Comments


Recommended Comments

There are no comments to display.

Guest
Add a comment...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...