Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | Skyfish | |
Old Version | Published before Godot 3 was released. |
Hello I want to draw some 3D Starfield in Godot. I’m fairly new to Godot and Shaders.
I use an ImmediateGeometry with attached skript (just test Data):
extends ImmediateGeometry
func _ready():
self.begin(Mesh.PRIMITIVE_POINTS,null)
for i in range(0, 3000):
var x = rand_range(-1,1)
var y = rand_range(-1,1)
var z = rand_range(-0.2,0.2)
self.add_vertex(Vector3(x,y,z))
self.end()
I already managed to get the vertex shader to set the POINT_SIZE and COLOR in relation to the distance from camera.
uniform vec3 CameraPosition;
uniform float CameraZoom;
vec4 invcamx = INV_CAMERA_MATRIX.x;
vec4 invcamy = INV_CAMERA_MATRIX.y;
vec4 invcamz = INV_CAMERA_MATRIX.z;
vec4 invcamw = INV_CAMERA_MATRIX.w;
mat3 invcam = mat3(invcamx.xyz, invcamy.xyz, invcamz.xyz);
vec3 world_pos = (VERTEX - invcamw.xyz) * invcam;
float cameraDist = distance(CameraPosition.xyz,world_pos.xyz);
vec3 falloff = log(vec3(3-cameraDist,3-cameraDist,3-cameraDist));
COLOR = vec4(falloff.x, falloff.y , falloff.z,1);
POINT_SIZE = falloff.x * 32;
What I don’t get to work is the POINT_COORD in the Fragment shader. No Matter what I tried, I always get single colored point sprites instead of textured or multicolored ones when using POINT_COORD eg.:
DIFFUSE = vec3(POINT_COORD.x, POINT_COORD.y, 1);
I read that you need to gl.glEnable( 0x8861 ) in order to get gl_PointCoord to work like in this example:
http://badlogicgames.com/forum/viewtopic.php?t=658&p=3859
If you think POINT_COORD is not working, maybe you could submit a bug report with an example project showing it: Issues · godotengine/godot · GitHub
You could use world_pos
or VERTEX in the meantime?
Zylann | 2017-02-15 18:18
POINT_COORD works for me at least, both when using ImmediateGeometry and points generated with SurfaceTool. Godot version is 2.1.1.stable.official. The fragment shader I’m using is:
uniform texture point_texture;
DIFFUSE_ALPHA = tex(point_texture, POINT_COORD);
mollusca | 2017-02-15 22:37
Are you using this in a fragment shader or a vertex shader?
Zylann | 2017-02-15 23:00
Ok thanks for the confirmation that it should work. But exactly this does not work in my fragment shader. I come to believe its a hardware problem? I use a lenovo ultrabook with NVIDIA Quadro. I will try this on my desktop when I’m home again and tell you the result.
Skyfish | 2017-02-16 07:47
On my desktop NVIDIA GTX 760 it’s even worse: even POINT_SIZE isn’t working which did work on my laptop. Nothing but dots instead of squares.
Skyfish | 2017-02-16 18:26
I opened an issue like you suggested: Point Sprites: POINT_SIZE / POINT_COORD not working in shader · Issue #7824 · godotengine/godot · GitHub
Skyfish | 2017-02-16 19:05
Note that POINT_SIZE
is only accessible in vertex shaders, and POINT_COORD
only available in fragment shaders.
http://docs.godotengine.org/en/stable/reference/shading_language.html?highlight=POINT_SIZE
Zylann | 2017-02-16 19:45