SpiderPig Posted April 10, 2017 Share Posted April 10, 2017 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. Quote Link to comment Share on other sites More sharing options...
AggrorJorn Posted April 10, 2017 Share Posted April 10, 2017 not sure if this is related but the editor displays in centimeters, in coding you see in meters I believe. Quote Link to comment Share on other sites More sharing options...
SpiderPig Posted April 10, 2017 Author Share Posted April 10, 2017 Thanks. I just tried a few things and found I was wrong with the reversed axis's. I'm a little confused still on how to create a vertex in between two original vertices... Quote Link to comment Share on other sites More sharing options...
shadmar Posted April 10, 2017 Share Posted April 10, 2017 There is an tesselation shader shipped with leadwerks, diffuse+normal+specular+tessellation.shader Quote HP Omen - 16GB - i7 - Nvidia GTX 1060 6GB Link to comment Share on other sites More sharing options...
SpiderPig Posted April 10, 2017 Author Share Posted April 10, 2017 Thanks. I'll take a look. Quote Link to comment Share on other sites More sharing options...
SpiderPig Posted April 10, 2017 Author Share Posted April 10, 2017 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. Quote Link to comment Share on other sites More sharing options...
SpiderPig Posted April 10, 2017 Author Share Posted April 10, 2017 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. Quote Link to comment Share on other sites More sharing options...
Ma-Shell Posted April 11, 2017 Share Posted April 11, 2017 (edited) 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 April 11, 2017 by Ma-Shell Quote Link to comment Share on other sites More sharing options...
SpiderPig Posted April 11, 2017 Author Share Posted April 11, 2017 Thanks for the help. I think I'll have to do it that way. Buffer Objects aren't big enough for my needs. Quote Link to comment Share on other sites More sharing options...
SpiderPig Posted April 14, 2017 Author Share Posted April 14, 2017 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.