Skip to content

Commit e41abf5

Browse files
committed
Add function to create circular points.
1 parent 327bdc5 commit e41abf5

File tree

3 files changed

+28
-2
lines changed

3 files changed

+28
-2
lines changed

render_pipeline/rpcore/util/primitives.hpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,14 @@
77
namespace rpcore {
88

99
RENDER_PIPELINE_DECL NodePath create_points(const std::string& name, int count);
10+
11+
/**
12+
* Create circular points with radius.
13+
*
14+
* This creates circular points using 'effects/circular_point.yaml' effect.
15+
*/
16+
RENDER_PIPELINE_DECL NodePath create_circular_points(const std::string& name, int count, float radius);
17+
1018
RENDER_PIPELINE_DECL NodePath create_cube(const std::string& name);
1119
RENDER_PIPELINE_DECL NodePath create_sphere(const std::string& name, unsigned int latitude, unsigned int longitude);
1220

resources/effects/circular_points.yaml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,14 @@
33
vertex:
44
inout: |
55
uniform mat4 p3d_ModelViewMatrix;
6+
uniform mat4 p3d_ProjectionMatrix;
67
uniform float point_radius;
78
89
post_transform: |
9-
gl_PointSize = point_radius / -(p3d_ModelViewMatrix * p3d_Vertex).z;
10+
gl_PointSize = point_radius * WINDOW_WIDTH * p3d_ProjectionMatrix[0][0] / -(p3d_ModelViewMatrix * p3d_Vertex).z;
11+
12+
// override normal
13+
vOutput.normal = normalize((p3d_ModelMatrix * vec4(0, -1, 0, 0)).xyz);
1014
1115
1216
fragment:

src/rpcore/util/primitives.cpp

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
#include <geomPoints.h>
66
#include <geomNode.h>
77
#include <materialAttrib.h>
8+
#include <shaderAttrib.h>
89

10+
#include "render_pipeline/rpcore/render_pipeline.h"
911
#include "render_pipeline/rpcore/util/rpmaterial.hpp"
1012

1113
namespace rpcore {
@@ -24,7 +26,7 @@ static NodePath create_geom_node(const std::string& name, Geom* geom)
2426

2527
NodePath create_points(const std::string& name, int count)
2628
{
27-
// create vertices
29+
// create vertices
2830
PT(GeomVertexData) vdata = new GeomVertexData(name, GeomVertexFormat::get_v3(), Geom::UsageHint::UH_static);
2931
vdata->unclean_set_num_rows(count);
3032

@@ -46,6 +48,18 @@ NodePath create_points(const std::string& name, int count)
4648
return create_geom_node(name, geom);
4749
}
4850

51+
NodePath create_circular_points(const std::string& name, int count, float radius)
52+
{
53+
NodePath np = create_points(name, count);
54+
55+
np.set_shader_input("point_radius", radius);
56+
57+
rpcore::RenderPipeline::get_global_ptr()->set_effect(np, "effects/circular_points.yaml");
58+
np.set_attrib(DCAST(ShaderAttrib, np.get_attrib(ShaderAttrib::get_class_type()))->set_flag(ShaderAttrib::F_shader_point_size, true));
59+
60+
return np;
61+
}
62+
4963
NodePath create_cube(const std::string& name)
5064
{
5165
// create vertices

0 commit comments

Comments
 (0)