Search the Community
Showing results for tags 'objectdynamic'.
-
[SOLVED] Changing and replacing indices during runtime in ObjectDynamic
sebastian.vesenmayer posted a topic in C++ Programming
Hello together, I try to change the indices of an ObjectDynamic during runtime to discard some points in Unigine 2.11. I can call clearIndices() on this object and all geometry vanish. But when I change the index array and set it again. the changed data won't get uploaded and the geometry still looks the same. Any ideas? int AppWorldLogic::init() { // Write here code to be called on world initialization: initialize resources for your world scene during the world start. m_dynamicObject = Unigine::ObjectDynamic::create(); m_dynamicObject->setMaterialNodeType(Unigine::Node::TYPE::OBJECT_MESH_STATIC); m_dynamicObject->setWorldTransform(Unigine::Math::translate(Unigine::Math::Vec3(0.0, -4.0, 1.0))); m_dynamicObject->setMaterial("custom_forward_material","*"); const Unigine::ObjectDynamic::Attribute attributes[]={{ 0, Unigine::ObjectDynamic::TYPE_FLOAT, 3 }}; m_dynamicObject->setVertexFormat(attributes, 1); m_dynamicObject->setSurfaceMode(Unigine::ObjectDynamic::MODE::MODE_POINTS, 0); m_dynamicObject->setBoundBox(Unigine::BoundBox(Unigine::Math::vec3(-10000.f, -10000.f, -10000.f), Unigine::Math::vec3(10000.f, 10000.f, 10000.f))); Unigine::Math::vec3 position; for (int i = 0; i < 1000; ++i) { for (int j = 0; j < 100; ++j) { position = Unigine::Math::vec3(i, j, 1.f); m_dynamicObject->addVertexFloat(0, position, 3); } } m_indices = new int[100000]; for (int index = 0; index < 100000; ++index) { m_indices[index] = index; } m_dynamicObject->setIndicesArray(m_indices, 100000); return 1; } //////////////////////////////////////////////////////////////////////////////// // start of the main loop //////////////////////////////////////////////////////////////////////////////// int AppWorldLogic::update() { static int counter=1; if (counter % 120 == 0) { m_dynamicObject->clearIndices(); } else if(counter % 120 == 60) { for (int i = 0; i < 100000; ++i) { m_indices[i] = (rand() % 2 == 1) ? i : 0; } m_dynamicObject->setIndicesArray(m_indices, 100000); } counter++; return 1; } -
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:
-
We are using ObjectDynamic to render some lines, but when we use coloured lines, whenever the line is over the water or sky, the colour disappears. It seems to have to do with light scattering, when I tried it in the ObjectDynamic lines shader sample the tree turned black when I enabled scattering on one of the lights: I tried setting the material to post scattering, but this alone didn't help, when playing around with alpha blending settings it did fix the problem for some lines, but not all of them, as some other lines completely disappeared when enabling alpha blending. Does anyone know a proper way of rendering lines through ObjectDynamic that works with light scattering? Also is there some way to make the lines always on top (disable depth testing)?