简体   繁体   English

2D几何轮廓着色器

[英]2D geometry outline shader

I want to create a shader to outline 2D geometry. 我想创建一个着色器以概述2D几何。 I'm using OpenGL ES2.0. 我正在使用OpenGL ES2.0。 I don't want to use a convolution filter, as the outline is not dependent on the texture, and it is too slow (I tried rendering the textured geometry to another texture, and then drawing that with the convolution shader). 我不想使用卷积滤镜,因为轮廓不依赖于纹理,而且速度太慢(我尝试将带纹理的几何体渲染为另一种纹理,然后使用卷积着色器进行绘制)。 I've also tried doing 2 passes, the first being single colorded overscaled geometry to represent an oultine, and then normal drawing on top, but this results in different thicknesses or unaligned outlines. 我还尝试了2次遍历,首先是单色上标过比例的几何图形来表示一个输卵管,然后是顶部的法线绘制,但这会导致厚度不同或轮廓未对齐。 I've looking into how silhouette's in cel-shading are done but they are all calculated using normals and lights, which I don't use at all. 我正在研究cel阴影中的轮廓是如何完成的,但是它们都是使用法线和光计算的,我根本不使用它们。

I'm using Box2D for physics, and have "destructable" objects with multiple fixtures. 我将Box2D用于物理,并且具有带有多个固定装置的“可破坏”对象。 At any point an object can be broken down (fixtures deleted), and I want to the outline to follow the new outter counter. 任何时候都可以分解对象(删除固定装置),并且我希望轮廓线跟随新的计数器。 I'm doing the drawing with a vertex buffer that matches the vertices of the fixtures, preset texture coordinates, and indices to draw triangles. 我正在使用顶点缓冲区进行绘制,该顶点缓冲区与灯具的顶点,预设的纹理坐标以及用于绘制三角形的索引相匹配。 When a fixture is removed, it's associated indices in the index buffer are set to 0, so no triangles are drawn there anymore. 移除夹具后,它在索引缓冲区中的关联索引将设置为0,因此不再在此处绘制三角形。 The following image shows what this looks like for one object when it is fully intact. 下图显示了一个完整的对象的外观。 The red points are the vertex positions (texturing isn't shown), the black lines are the fixtures, and the blue lines show the seperation of how the triangles are drawn. 红点是顶点位置(未显示纹理),黑线是灯具,蓝线表示三角形的绘制方式。 The gray outline is what I would like the outline to look like in any case. 在任何情况下,灰色轮廓都是我希望轮廓看起来像的样子。

1个

This image shows the same object with a few fixtures removed. 此图显示了相同的对象,但移除了一些固定装置。

2

Is this possible to do this in a vertex shader (or in combination with other simple methods)? 是否可以在顶点着色器中(或与其他简单方法结合使用)做到这一点? Any help would be appreciated. 任何帮助,将不胜感激。

Thanks :) 谢谢 :)

Assuming you're able to do something about those awkward points that are slightly inset from the corners (eg, if you numbered the points in English-reading order, with the first being '1', point 6 would be one)... 假设您能够对那些从角落稍微插入的尴尬点做一些处理(例如,如果您按英语阅读顺序对这些点进行编号,第一个为“ 1”,则点6将为一个)...

If a point is interior then if you list all the polygon edges connected to it in clockwise order, each pair of edges in sequence will have a polygon in common. 如果一个点在内部,则如果您按顺时针顺序列出与其连接的所有多边形边,则按顺序排列的每一对边将有一个共同的多边形。 If any two edges don't have a polygon in common then it's an exterior point. 如果任意两个边没有共同的多边形,则为外部点。

Starting from any exterior point you can then get the whole outline by first walking in any direction and subsequently along any edge that connects to an exterior point you haven't visited yet (or, alternatively, that isn't the edge you walked along just now). 从任何外部点开始,然后通过首先沿任意方向行走,然后沿与尚未访问的外部点相连的任何边缘(或者,这不是您仅沿其走过的边缘)来获得整个轮廓现在)。

Starting from an existing outline and removing some parts, you can obviously start from either exterior point that used to connect to another but no longer does and just walk from there until you get to the other. 从现有轮廓开始并删除一些零件,您显然可以从以前用于连接到另一个但不再连接的任何一个外部点开始,然后从那里步行直到到达另一个。

You can't handle this stuff in a shader under ES because you don't get connectivity information. 您无法在ES下的着色器中处理这些内容,因为您没有获得连接信息。


I think the best you could do in a shader is to expand the geometry by pushing vertices outward along their surface normals. 我认为在着色器中最好的方法是通过沿顶点的法线向外推动顶点来扩展其几何形状。 Supposing that your data structure is a list of rectangles, each described by, say, a centre, a width and a height, you could achieve the same thing by drawing each with the same centre but with a small amount added to the width and height. 假设您的数据结构是一个矩形列表,每个矩形都由一个中心,一个宽度和一个高度描述,则可以通过绘制具有相同中心的每个矩形,但在宽度和高度上添加少量来实现相同的目的。

To be completely general you'd need to store normals at vertices, but also to update them as geometry is removed. 要完全概括,您需要将法线存储在顶点上,而且还需要在移除几何图形时对其进行更新。 So there'd be some pushing of new information from the CPU but it'd be relatively limited. 因此,会有一些来自CPU的新信息推送,但是相对来说是有限的。

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

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