Godot: VERTEX_ID and mesh-less rendering

Created on 9 Jun 2018  路  9Comments  路  Source: godotengine/godot

A friend of mine explained me an interesting rendering technique recently:
In some cases, you can render particles, grass, water or terrain chunks without using any mesh, and generating the geometry procedurally in the vertex shader, without geometry shader.

For example:

position = vec2(gl_VertexId & 1 ? -1.0f : 1.0f, gl_VertexId & 2 ? -1.0f : 1.0f);

The idea is to expose the VERTEX_ID builtin from GLSL in the shading language, and add the ability to draw something without specifying a vertex array. Instead, just specifying how many vertices there are, but without data (oh my god! No vertices? Mind = blown).
I think it should work in the version of OpenGL Godot uses.

The advantages are:

  • No need to setup a mesh
  • Reduces memory usage
  • Removes cost of vertex memory access
  • More dynamic shape variety using procedural techniques

Now, I'm aware that probably nobody in Godot thinks about it, since it's a kind of optimization you can do in an advanced stage of a game's development, but it's an interesting technique to consider.

archived feature proposal rendering

Most helpful comment

Bump for vertex id ! Its useful in many cases.

All 9 comments

I've done this a few times in my own engine. Its a cool technique though with limited applications. Adding the vertex index to the shader should be easy, it should already be there as its a build in variable on the GLSL side so the parser just needs to know it exists.
Its just adding something new to tell the render engine just to do a drawcall without a populated vertex and index buffer that will need a bit of thought on how to do nicely.

Bump for vertex id ! Its useful in many cases.

Sadly we are entering to feature freeze phase. Pushed to 3.2

A more specific bump, I'm interested in using the vertex_id for scientific analysis purposes unrelated to mesh-less rendering, so please, if added, just support having access to the index in the shader.

The details:
I have a large scientific data file (multiple gigabytes) which is a time series for each vertex some value that I need to visualize. The number of vertices is in the millions, so having access to the vertex_id would be useful so I can do a lookup in some texture what the value is and render the mapped color in the shader.

As of right now, I need to store the vertex_id in the uv, which is a hack.

The VertexID would be really nice to have to make custom vertex attributes (via texture uniform) easier (and also a lot of other cool stuff possible).

If i would send a PR to expose gl_vertex_id would there be any chance it would be accepted before 4.0 ?

It should be easy to do and not much of code.
The only problem i see is the GLES2 doesn't seem to support it.
GLES3 and openGL since 1.4 do though.

@SleepProgger new features for GLES3 will not be merged. Especially if it is not compatible with GLES2. However, new features will be considered in the master branch if targeting the GLES2 and/or Vulkan backends.

Good to know, thanks.
So it looks like i have to wait for 4.0 or use a patched fork.

Feature and improvement proposals for the Godot Engine are now being discussed and reviewed in a dedicated Godot Improvement Proposals (GIP) (godotengine/godot-proposals) issue tracker. The GIP tracker has a detailed issue template designed so that proposals include all the relevant information to start a productive discussion and help the community assess the validity of the proposal for the engine.

The main (godotengine/godot) tracker is now solely dedicated to bug reports and Pull Requests, enabling contributors to have a better focus on bug fixing work. Therefore, we are now closing all older feature proposals on the main issue tracker.

If you are interested in this feature proposal, please open a new proposal on the GIP tracker following the given issue template (after checking that it doesn't exist already). Be sure to reference this closed issue if it includes any relevant discussion (which you are also encouraged to summarize in the new proposal). Thanks in advance!

@SleepProgger @bmillare @Zylann In case you want to manually add support for VERTEX_ID, these are the changes I had to make in 3.2.3-stable for spatial shaders. I wanted to use the vertex ID for creating procedural animations as in the GDC presentation "The Inner Workings of Fortnite's Shader-Based Procedural Animations" https://www.youtube.com/watch?v=7Fl3so0Z5Tc

In drivers/gles3/shader_compiler_gles3.cpp in the function ShaderCompilerGLES3::ShaderCompilerGLES3() :

actions[VS::SHADER_SPATIAL].renames["VERTEX_ID"] = "gl_VertexID";

and servers/visual/shader_types.cpp in the function ShaderTypes::ShaderTypes():

shader_modes[VS::SHADER_SPATIAL].functions["vertex"].built_ins["VERTEX_ID"] = constt(ShaderLanguage::TYPE_INT);

Then compile the source and it should work.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

SleepProgger picture SleepProgger  路  3Comments

n-pigeon picture n-pigeon  路  3Comments

Zylann picture Zylann  路  3Comments

EdwardAngeles picture EdwardAngeles  路  3Comments

Spooner picture Spooner  路  3Comments