简体   繁体   English

简单的平面曲面细分着色器

[英]Simple Flat Plane Tessellation Shader

Part 1:第1部分:

So I want to create a basic tessellation program that takes a plane of quads and transforms it into a more, well, detailed/tessellated plane of quads.所以我想创建一个基本的曲面细分程序,它采用一个四边形平面并将其转换为一个更详细/细分的四边形平面。 Such as the picture below.比如下图。 How much it gets tessellated would depend on user controls, passed in by a uniform (initially).它被细分的程度取决于用户控件,由统一(最初)传入。 However I am so new to tessellation shaders that I can't even figure out how to do this.但是,我对曲面细分着色器非常陌生,以至于我什至不知道如何执行此操作。

平面镶嵌

How is this typically done?这通常是如何完成的? Surely you shouldn't actually draw the plane of quads prior to the shader program, since from my understanding quads won't get tessellated this way, instead the get tessellated into a way like the below picture:当然,您不应该在着色器程序之前实际绘制四边形平面,因为根据我的理解,四边形不会以这种方式细分,而是细分为如下图所示的方式:

四曲面细分

I believe the answer could to be to draw a plane of points, and these points are then tessellated into more points, and these points are transformed into quads of the appropriate size in the geometry shader I think?我相信答案可能是绘制一个点平面,然后将这些点细分为更多点,然后这些点在我认为的几何着色器中转换为适当大小的四边形? Alternatively, instead of converting points into quads could I just draw quads between each four closest points (that would be much better)?或者,不是将点转换为四边形,我可以在每四个最近的点之间绘制四边形吗(那会好得多)? Examples very much appreciated!非常感谢示例!

NOTE: Using GLSL > 4.0 & C only (No C++/Python)注意:仅使用 GLSL > 4.0 & C(无 C++/Python)

Part 2:第2部分:

After I get part 1 working, how would I make it so that certain quads are more tessellated than others, such as this?:在我开始第 1 部分工作后,我将如何使某些四边形比其他四边形更加细分,例如这样?:

在此处输入图片说明

I want the parts closer to the camera to be more tessellated.我希望靠近相机的部分更加细分。

Part 3:第 3 部分:

If I were able to get that far, the next part would be to alter the z-axis of points to make the plane into an interesting environment.如果我能走那么远,下一部分将是改变点的 z 轴,使平面成为一个有趣的环境。 This would be done by reading in a 2Dsampler, I know how to do that and all.这将通过阅读 2Dsampler 来完成,我知道如何做到这一点。 However, if I am correct in Part 1 about using a plane of points then I need to do more than just alter the points that are converted into quads, because quads need to be sharing vertices essentially in order there to be no gaps between quads.但是,如果我在第 1 部分中关于使用点平面是正确的,那么我需要做的不仅仅是改变转换为四边形的点,因为四边形本质上需要共享顶点,以便四边形之间没有间隙。 How would that be done?那怎么办? Alternatively if we draw quads between points, with each point being the appriate height, then this wouldn't be a issue.或者,如果我们在点之间绘制四边形,每个点都是适当的高度,那么这不是问题。

Part 1第1部分

Yes you're correct: generate a 'patch' as a simple grid of points, specify the tesselation levels as uniforms into the TCS (tesselation control shader) and generate the vertex data in the TES (tesselation evaluation shader).是的,您是对的:将“补丁”生成为简单的点网格,将曲面细分级别指定为 TCS(曲面细分控制着色器)中的制服,并在 TES(曲面细分评估着色器)中生成顶点数据。

Sounds complicated?听起来很复杂? Here's a nice tutorial I based my work on: http://antongerdelan.net/opengl/tessellation.html这是我基于我的工作的一个很好的教程: http : //antongerdelan.net/opengl/tessellation.html

Part 2第2部分

What you are talking about here is LOD (or level of detail).你在这里谈论的是 LOD(或细节级别)。 You would need to tesselate and render the higher polygon-count bottom-left corner of your mesh as a separate object.您需要将网格的左下角多边形计数较高的部分细分并渲染为一个单独的对象。

Your suggested approach is correct: break the overall scene into 'chunks' and determine the LOD (ie the tesselation parameters) for each chunk separately, usually by some distance-to-camera algorithm.您建议的方法是正确的:将整个场景分成“块”并分别确定每个块的 LOD(即细分参数),通常是通过某种距离到相机的算法。

Part 3第 3 部分

Another excellent tutorial which does exactly what you are after I believe: http://codeflow.org/entries/2010/nov/07/opengl-4-tessellation/另一个出色的教程,我相信它完全符合您的要求: http : //codeflow.org/entries/2010/nov/07/opengl-4-tessellation/

I used this approach to get a very highly detailed but memory and frame efficient terrain.我使用这种方法来获得非常详细但内存和帧效率高的地形。

Hope this helps.希望这可以帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM