Jump to content

GLSL Geometry Shader Help Needed


SpiderPig
 Share

Recommended Posts

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

The material itself has some functions to set shader-uniforms (sadly the function-name does not always reflect this, but e.g. these SetFloat, SetVec2, ... are for setting uniforms)

I don't really know about these types of buffers for shaders but if you can represent your buffer as a texture, you can do the following:

 

C:

m->GetSurface(0)->GetMaterial()->SetTexture("Materials/Developer/window.tex", 3);

This will bind the given texture to texture-slot 3 of m's material.

 

Fragment Shader:

uniform sampler2D texture3;
...
outcolor = texture(texture3, vTexCoords);

 

I haven't tried whether it is possible to access it from the geometry shader, though.

I just tried it in the geometry shader and it works there, as well.

Edited by Ma-Shell
Link to comment
Share on other sites

I have a problem with the geometry shader I'm working on. If someone could tell me why it works until I un-comment the line,

 

RunLOD(4);

 

That'd be great.

 

The shader, material and a grid model is attached. Thanks.

 

EDIT : Commenting out EmitVertex() solves the linking issue - but why?

 

EDIT : If I'd only looked at the Error log I had hidden to the edge of the screen I would have see this;

 

2: Line 0: Hardware limitation reached, can only emit 60 vertices of this size

 

Well that solves that. rolleyes.gif

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...