Search the Community
Showing results for tags 'line'.
-
Hi ! I've got a problem with drawing ObjectDynamic in lines with simple shader. My goal is to connect several points in world with solid lines. The good practice for this issue is ObjectDynamic class. It can de drawn in lines. I've create a new empty project and made a couple chages (remove material ball and switch sun scaterring mode to "moon"). ObjectDynamic is constructed in AppWorldLogic. There are only 3 points added to ObjectDynamic to make a triangle. Surface mode is set to MODE_LINES. AppWorldLogic.h #include <UnigineObjects.h> using namespace Unigine; class AppWorldLogic : public Unigine::WorldLogic { public: ... private: ObjectDynamicPtr pOD; }; AppWorldLogic.cpp int AppWorldLogic::init() { pOD = ObjectDynamic::create (); const ObjectDynamic::Attribute attributes[] = { { 0, ObjectDynamic::TYPE_FLOAT, 3 } }; pOD->setVertexFormat ( attributes, 1 ); pOD->setSurfaceMode ( ObjectDynamic::MODE_LINES, 0 ); pOD->addLineStrip ( 4 ); pOD->addVertexFloat ( 0, Math::vec3 ( -2.0, 2.0, 1.0 ).get (), 3 ); pOD->addVertexFloat ( 0, Math::vec3 ( 2.0, 2.0, 1.0 ).get (), 3 ); pOD->addVertexFloat ( 0, Math::vec3 ( 0.0, 2.0, 3.0 ).get (), 3 ); pOD->addVertexFloat ( 0, Math::vec3 ( -2.0, 2.0, 1.0 ).get (), 3 ); pOD->setMaterial ( "lines", "*" ); pOD->flushVertex (); return 1; } "lines" is a basic material with very simple shaders: lines.mat <?xml version="1.0" encoding="utf-8"?> <base_material name="lines" version="2.0" parameters_prefix="m" editable="0"> <supported node="object_dynamic"/> <shader pass="deferred" node="object_dynamic" vertex="lines.vert" fragment="lines.frag"/> </base_material> lines.vert #include <core/shaders/common/common.h> STRUCT(VERTEX_IN) INIT_ATTRIBUTE(float4,0,POSITION) END STRUCT(VERTEX_OUT) INIT_POSITION END MAIN_BEGIN(VERTEX_OUT,VERTEX_IN) float4 row_0 = s_transform[0]; float4 row_1 = s_transform[1]; float4 row_2 = s_transform[2]; float4 in_vertex = float4(IN_ATTRIBUTE(0).xyz,1.0f); float4 position = mul4(row_0,row_1,row_2,in_vertex); OUT_POSITION = getPosition(position); MAIN_END lines.fraq #include <core/shaders/common/fragment.h> STRUCT(FRAGMENT_IN) INIT_POSITION END MAIN_BEGIN(FRAGMENT_OUT,FRAGMENT_IN) OUT_COLOR.r = 1.0f; OUT_COLOR.g = 1.0f; OUT_COLOR.b = 0.0f; OUT_COLOR.a = 0.0f; MAIN_END It works. The triangle is visible. But I've got a problem. Right after start the triangle is partialy visible. It looks like the triangle is clipped by some plane. This "cut-off line" is moving if I change the camera elevation. But if I had once change camera elevation totaly down the triangle becomes completely visible. I can't understand there is my mistake. Additional questions: 1) How can I increase lines width? Can it be done from fragment shader? 2) Can lines be drawing using some antialiasing?
- 5 replies
-
- objectdynamic
- shader
-
(and 1 more)
Tagged with:
-
Hi, this is similar to my other thread. In that thread I was asking about how to draw lines faster, but that part of my questioning was ignored and then the topic was marked as solved so I decided to move this to a new thread. We are reading in lines from dwg files and displaying them. Unfortunately, this can mean up to thousands of lines, and drawing them using the Visualizer just doesn't seem to cut it, as drawing these lines slows down the framerate. I want to be able to draw with something that uses vertex buffers that caches the geometry and all I need to do is send it in a batch to the GPU. However, with the Visualizer, I have to make calls one by one, which is slow. From poking around, it seems that ObjectDynamic is the answer, as it has some line drawing methods. However, everything I've tried just doesn't seem to work with it. Could I get some help on how to use this class to draw lines? Here's an example of what we're doing. The text on the ground is all written with line primitives. Yes, I know, not the most efficient way to draw text, but these lines just come from a dwg file, and we want to just draw whatever is in that dwg file.