Drawing a grid plane #995
-
Hi all, is there some kind of support for doing this (a 2D planar grid really, shown in my 3d scene, which could be used as a 'floor' or a 'wall' etc) already in VSG? I tried creating the grid lines using the Builder's 'createCylinder' function (with a scale transform), which probably could also leverage instancing, but this does not really look 'right' to me. Am I missing something or is that yet to be done? One alternative I could think of would be to simply use a textured quad, but I'm wondering if there isn't a simple 'line drawing' functionality (which could be useful in other circumstances as well..) Thank you |
Beta Was this translation helpful? Give feedback.
Replies: 5 comments
-
A texture quad would be one way to do it, vsg::Builder can be used to do this quite conveniently. Or just create the the geometry yourself. I wouldn't do it with cylinders, but would be much more expensive than just uses a grid of lines. |
Beta Was this translation helpful? Give feedback.
-
If you fancy playing with fragment shaders, one approach you could take is render the ground plan as a quad and then in fragment shader compute whether to use the base colour or line colour based on texture coordinate. It should be possible to compute a fragment proximity to the line positions you want and set the blending between the two colours to give you anti-aliased lines or vary the line width dynamically so that as you get closer the line width doesn't change in scene space. With such a procedural approach you should be able to get really high quality results, but than can be achieved using lines or other geometry, or using texturing. |
Beta Was this translation helpful? Give feedback.
-
Ben Golus has written up work he's done of grid shader - this is the type of thing I was thinking of: |
Beta Was this translation helpful? Give feedback.
-
Thank you very much for your answers. I'm afraid that this is way beyond my (current, I hope) skill level but will certainly be useful for others! |
Beta Was this translation helpful? Give feedback.
-
A while ago, based on this article [https://asliceofrendering.com/scene%20helper/2020/01/05/InfiniteGrid/], I implemented a grid plane. While it functions correctly, there are still some issues that I currently don't have the time to address. I'm sharing my code here in the hope that it can help others
#include #include "vsg/all.h" class ExtendedRasterizationState : public vsg::Inherit<vsg::RasterizationState, ExtendedRasterizationState>
protected: int main(int argc, char** argv)
}
#version 450 #extension GL_EXT_debug_printf : enable layout(push_constant) uniform PushConstants { mat4 projectionMat; }psh; layout(set = 0, binding = 0) uniform PbrData{ layout(location = 0) out vec3 nearPoint; vec3 unprojectPoint(float x, float y, float z, mat4 viewProjectionInverse) { vec3 gridPlane[6] = vec3[]( void main() {
}
#version 450 layout(location = 0) in vec3 nearPoint; vec4 grid(vec3 pos) {
} float fadeFactor(vec3 pos) { void main() {
// |
Beta Was this translation helpful? Give feedback.
A texture quad would be one way to do it, vsg::Builder can be used to do this quite conveniently.
Or just create the the geometry yourself. I wouldn't do it with cylinders, but would be much more expensive than just uses a grid of lines.