Jump to content

SpiderPig

Members
  • Posts

    2,340
  • Joined

  • Last visited

Posts posted by SpiderPig

  1. Does anyone know how to set a Uniform Buffer Object from c++?

     

    The Geometry shader has the following Buffer Object;

    layout(std140) uniform DataBlock
    {
    float terrainHeight[1024];
    };
    

     

    https://www.khronos.org/opengl/wiki/Uniform_Buffer_Object

     

    Not sure how to get the program ID from a shader in Leadwerks. Or will I have to use OpenGL commands directly?I

     

    I figured out how to at least get the Data Blocks index;

     

    Shader* sh = material->GetShader();
    OpenGLShader* gl_sh = (OpenGLShader*)sh;
    unsigned int block_index = glGetUniformBlockIndex(gl_sh->program, "DataBlock");
    if (block_index != GL_INVALID_INDEX)
    {
    //bind it here
    }
    

     

    This command gets the size (in bytes) that is available for each buffer;

     

    int size;
    glGetIntegerv(GL_MAX_UNIFORM_BLOCK_SIZE, &size);
    

     

    In this case it was 65,536 bytes. I think there is a max number of buffers allowed too.

  2. I figured out how to do it now, thanks.

     

    It seems that gl_Position doesn't let the shader link when inside a loop that uses a uniform variable as a end condition.

     

    int current_level = 0;
    uniform int lod_level = 1;
    while(current_level < lod_level)
    {
    current_level++;
    gl_Position = pos;
    EmitVertex();
    }
    

     

    This isn't all the code, but commenting out gl_positon or changing the while loop to;

     

    while(current_level < 2)
    

     

    will then work.

  3. I'm currently trying to subdivide a triangle in the geometry shader. I put the material using the shader on a plane made from two triangles.

     

    However it seems that the coordinates in GLSL are different to that in Leadwerks? That the positive X axis in Leadwerks is actually the negative X axis in the shader. And the same for the Z axis. The Y axis seems fine.

     

    I want the shader to turn the plane of two triangles into a more detailed grid for a terrain. I know the shader works on each triangle, so I will have to divide each triangle itself into the appropriate triangles so that the end result in game looks like a uniform grid.

     

    I've thought of tessellation but I don't think it'll give me the results I'm looking for.

     

    Any help with this is appreciated. Thanks.

  4. Hi Josh,

     

    I would like to see more flexible commands surround the surface class. This will make real-time modification of large dynamic meshes much easier and hopefully faster, allowing for more control of what type of games that can be made.

     

     

    AddVertices(vec3** positions)

     

    RemoveSurface(int index)

    RemoveSurfaces(int* indexes)

     

    RemoveVertex(int index)

    RemoveVertices(int* indexes)

     

    RemoveTriangle(int index)

    RemoveTriangles(int* indexes)

     

    SetTriangleIndice(int index, in a, int b, int c)

     

     

    Creating a grid of only 256 x 256 vertices seems to take a lot longer than if programming it in a bare C++ OpenGL application using VBO's. Is there a reason for this?

     

     

    Thanks.

    • Upvote 1
  5. Thanks, that did the trick. For those who are interested here's the code I used.

     

    float cx = Math::Round(context->GetWidth() / 2);
    float cy = Math::Round(context->GetHeight() / 2);
    Vec3 mpos = window->GetMousePosition();
    window->SetMousePosition(cx, cy);
    mpos = mpos * looksmoothing + mousepos * (1 - looksmoothing);
    float dx = (mpos.x - cx) * lookspeed;
    float dy = (mpos.y - cy) * lookspeed;
    
    Vec3 prot = player->GetRotation();
    prot.y = dx;
    player->SetRotation(prot);
    
    Quat phy_rot = player->GetQuaternion(true);
    player_pivot->PhysicsSetRotation(phy_rot, 1.0);
    

     

    The physics shape is assigned to the pivot, and the model of the player is parented to the pivot.

    • Upvote 2
  6. Thanks Josh, an extra argument would be great.

     

    I tried the code but moving the mouse left and right just added to the players rotation so I changed the code from;

     

    prot.y += dx;
    

     

    to

     

    prot.y = dx;
    

     

    which did help. It gave me a rotation about the Y axis which followed the mouse. But when the player rotates 90 on the X axis and then I use this code in the update loop it goes haywire. Rotating in all manor of directions without stopping.

     

    My player is setup like this.

     

    Model* model = Model::Cylinder();
    model->SetShape(Shape::Cylinder());
    model->SetCollisionType(COLLISION::PLAYER);
    model->SetMass(10.0, 0, -1, 0, 1, 1, 1);//to make it more stable standing up
    model->SetPosition(Vec3(0, 5, 0));
    
    model->SetRotation(90, 0, 0);//this makes it go hay wire
    

     

    Basically I'm making my own character controller because the player is pulled toward different gravity directions through out the game. So I always want the player to rotate left and right with the mouse no matter what direction is down.

  7. I'm unsure how exactly to use Transform::Rotation in order to rotate my physics object about it's local Y axis. The code below works when the player is upright, but if it rotates 90 degrees on the X axis (lying down basically) it rotates about the global Y. How can I use this to transform to local?

     

    float cx = Math::Round(context->GetWidth() / 2);
    float cy = Math::Round(context->GetHeight() / 2);
    Vec3 mpos = window->GetMousePosition();
    window->SetMousePosition(cx, cy);
    mpos = mpos * looksmoothing + mousepos * (1 - looksmoothing);
    float dx = (mpos.x - cx) * lookspeed;
    float dy = (mpos.y - cy) * lookspeed;
    Vec3 prot = player->GetModel()->GetRotation(true);
    prot.y += dx;
    Vec3 v = Transform::Rotation(prot, NULL, player->GetModel());
    player->GetModel()->PhysicsSetRotation(v, 1.0);
    

     

    Thanks.

  8. I re-downloaded and found no material. But using the diffuse+normal+specular shader I found no issues on either models or with more than one in the scene. I've attached the material I used so you can compare it to the one you are using. I'm not sure what the "paper_m.tex" is used for?

     

    I'm not sure if you purposely need a large scale model, but they are quite large. I would suggest playing with your material settings to see if the problem disappears.

    Mat.zip

  9. Hi, I have made a large sphere shape which is set up as a trigger and I have attached a collision hook to a cube which I fire from the camera at the sphere. The hook is called upon collision but also seems to be called when the cube is inside the sphere. Even if it has been created in the sphere on start-up. Is there a way to only detect a collision with a face? Not the volume as well?

     

    I thought of just removing the hook upon first collision, but I'd like it there for collisions that may happen later.

     

    Any ideas?

  10. Thanks for the info. It sounds good for changing a mesh in real time, however its the physics shape that has to be changed in real time too. I'd like to see a faster method of PolyMesh (), but i may have to come up with a differnt way of generating the shapes in realtime.

  11. Hey guys,

     

    What I have is a large dynamic mesh, and Shape::PolyMesh() takes too long to be used in real-time. I want the shapes vertices to change along with the mesh's without using Shape::PolyMesh() all the time.

     

    Is it possible to manipulate the vertices of a shape without re-generating it? dry.png

×
×
  • Create New...