Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VERTEX_ID and mesh-less rendering #19473

Closed
Zylann opened this issue Jun 9, 2018 · 10 comments
Closed

VERTEX_ID and mesh-less rendering #19473

Zylann opened this issue Jun 9, 2018 · 10 comments

Comments

@Zylann
Copy link
Contributor

Zylann commented Jun 9, 2018

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.

@BastiaanOlij
Copy link
Contributor

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.

@m-irigoyen

This comment has been minimized.

@Chaosus
Copy link
Member

Chaosus commented Aug 29, 2018

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

@Chaosus Chaosus added this to the 3.2 milestone Aug 29, 2018
@bmillare
Copy link

bmillare commented May 21, 2019

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.

@akien-mga akien-mga modified the milestones: 3.2, 4.0 Nov 14, 2019
@SleepProgger
Copy link

SleepProgger commented Feb 8, 2020

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.

@clayjohn
Copy link
Member

clayjohn commented Feb 8, 2020

@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.

@SleepProgger
Copy link

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

@Calinou
Copy link
Member

Calinou commented May 26, 2020

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!

@johannmeyer
Copy link

@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.

@gormster
Copy link

gormster commented Sep 6, 2022

For the record, since this is the first Google result when searching "Godot vertex id" – VERTEX_ID is implemented as a shader variable in Godot 4.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests