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

munge_points_to_quads() only copies a hardcoded list of vertex data columns #870

Closed
el-dee opened this issue Feb 17, 2020 · 2 comments
Closed
Assignees
Labels
bug
Milestone

Comments

@el-dee
Copy link
Contributor

@el-dee el-dee commented Feb 17, 2020

When using "software" point sprites, the method munge_points_to_quads(), which create the quads from the point geom, only copies a selected list of vertex data columns. If one requires extra data columns to be send to the shader, there are not copied.

Here is a small test program to demonstrate the problem, when copying the point colours using the "extra" column the points have a random uniform colour instead of a green to red gradient.

The correct behaviour can be observed by switching to hardware point sprites.

from panda3d.core import *
from math import pi, cos, sin

from direct.directbase import DirectStart

def shader():
    return Shader.make(Shader.SL_GLSL,
                       vertex="""
#version 410

uniform mat4 p3d_ProjectionMatrix;
uniform mat4 p3d_ModelViewMatrix;

in vec4 p3d_Vertex;
in vec4 p3d_Color;
in vec4 extra;
out vec4 color;

void main() {
    gl_Position = p3d_ProjectionMatrix * (p3d_ModelViewMatrix * p3d_Vertex);
    //Uncomment to see the correct colors.
    //color = p3d_Color;
    //Uncomment to see the wrong color
    color = extra;
}
""",
                       fragment="""
#version 410

in vec4 color;
out vec4 frag_color;

void main() {
    frag_color = color;
}
""")

def make_geom(points, colors, size):
    array = GeomVertexArrayFormat()
    array.add_column(InternalName.make('vertex'), 3, Geom.NTFloat32, Geom.CPoint)
    array.add_column(InternalName.make('color'), 4, Geom.NTFloat32, Geom.CColor)
    array.add_column(InternalName.make('size'), 1, Geom.NTFloat32, Geom.COther)
    array.add_column(InternalName.make('extra'), 4, Geom.NTFloat32, Geom.COther)
    format = GeomVertexFormat()
    format.addArray(array)
    format = GeomVertexFormat.registerFormat(format)
    vdata = GeomVertexData('vdata', format, Geom.UH_static)
    vwriter = GeomVertexWriter(vdata, 'vertex')
    colorwriter = GeomVertexWriter(vdata, 'color')
    sizewriter = GeomVertexWriter(vdata, 'size')
    extrawriter = GeomVertexWriter(vdata, 'extra')
    geompoints = GeomPoints(Geom.UH_static)
    for index, (point, color) in enumerate(zip(points, colors)):
        vwriter.add_data3(point)
        colorwriter.add_data4(color)
        sizewriter.add_data1(size)
        extrawriter.add_data4(color)
        geompoints.add_vertex(index)
    geom = Geom(vdata)
    geom.add_primitive(geompoints)
    return geom

size = 1000
points = []
colors = []
for i in range(size):
    theta = pi * i / size
    x = cos(theta)
    y = sin(theta)
    z = 0
    points.append(LPoint3(x, y, z))
    a = i / size
    colors.append(LColor(1 - a, a, 0, 1))

geom = make_geom(points, colors, 4)
gnode = GeomNode('gnode')
gnode.add_geom(geom)
np = NodePath(gnode)
np.set_shader(shader())

np.reparent_to(render)

base.cam.set_pos(0, -1, 0)
base.run()

Here is the link to the copy perform by munge_points_to_quads() :

GeomVertexReader vertex(source_data, InternalName::get_vertex(),
current_thread);
GeomVertexReader normal(source_data, InternalName::get_normal(),
current_thread);
GeomVertexReader color(source_data, InternalName::get_color(),
current_thread);
GeomVertexReader texcoord(source_data, InternalName::get_texcoord(),
current_thread);
GeomVertexReader rotate(source_data, InternalName::get_rotate(),
current_thread);
GeomVertexReader size(source_data, InternalName::get_size(),
current_thread);
GeomVertexReader aspect_ratio(source_data, InternalName::get_aspect_ratio(),
current_thread);

@rdb rdb added the bug label Feb 17, 2020
@rdb rdb added this to the 1.10.6 milestone Feb 17, 2020
@rdb rdb self-assigned this Feb 22, 2020
@rdb rdb closed this in 18bb8a5 Feb 23, 2020
@rdb

This comment has been minimized.

Copy link
Member

@rdb rdb commented Feb 23, 2020

I would be very grateful if you could spend some time testing my fix.

@el-dee

This comment has been minimized.

Copy link
Contributor Author

@el-dee el-dee commented Feb 24, 2020

I did a few tests and it looks good to me : point sprites behave like before, the additional data columns are properly copied and each sprite has the correct data in the input of the vertex shader :)

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

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.