Jump to content

Custom Geometry Shading


martyj
 Share

Recommended Posts

Is there any example? I can see how to compile my own shaders. How do I use them though?

 

The documentation on this is slim.

 

I found this.

 

 

Context::SetShader

 

 

How do I know what the variables are that are passed to the geometry shader from the tesselation evaluation shader?

 

I can see what I need to set as my output

Link to comment
Share on other sites

That example is a fragment shader.

 

Data in OpenGL passes through shaders in the following order:

 

Vertex -> Tessellation Control -> Tessellation Evaluation -> Geometry -> Fragment

 

The vertex shader manages vertex data,

the tessellation control, controls how much tessellation is applied.

The tessellation evaluation is what performs the tessellation

The geometry shader allows modification of the geometry before it is projected to the screen for fragmentation

The fragment shader deals with getting pixel colors on the screen.

Link to comment
Share on other sites

Here is a simple copy and offset geoemtry shader:

 

#version 400
#define MAX_INSTANCES 256

layout(triangles) in;
layout (triangle_strip, max_vertices=6) out;  //in a triangle are 3 verts, + 3 for the copy..

//all these are outs from the vertex shader:
in vec4 g_ex_color[];
in vec2 g_ex_texcoords0[];
in float g_ex_selectionstate[];
in vec3 g_ex_VertexCameraPosition[];
in vec3 g_ex_normal[];
in vec3 g_ex_tangent[];
in vec3 g_ex_binormal[];
in float g_clipdistance0[];
in vec4 g_modelvertexposition[];

//these goes into the fragment shader:
out vec4 ex_color;
out vec2 ex_texcoords0;
out float ex_selectionstate;
out vec3 ex_VertexCameraPosition;
out vec3 ex_normal;
out vec3 ex_tangent;
out vec3 ex_binormal;
out float clipdistance0;

uniform mat4 projectioncameramatrix;

void main()
{
 //Just pass everything as is.. draw the original:
 for(int i = 0; i < gl_in.length(); i++)
 {
   gl_Position = gl_in[i].gl_Position;
    ex_color=g_ex_color[i];
    ex_texcoords0=g_ex_texcoords0[i];
    ex_selectionstate=g_ex_selectionstate[i];
    ex_VertexCameraPosition=g_ex_VertexCameraPosition[i];
    ex_normal=g_ex_normal[i];
    ex_tangent=g_ex_tangent[i];
    ex_binormal=g_ex_binormal[i];
    clipdistance0=g_clipdistance0[i];
   // done with the vertex
 EmitVertex();
  }
  EndPrimitive();

 //And now, make a copy and offset it a bit :
 for(int i = 0; i < gl_in.length(); i++)
 {
   vec4 offset=vec4(3,3,3,0);
   gl_Position = projectioncameramatrix*(g_modelvertexposition[i]+offset);
    ex_color=g_ex_color[i];
    ex_texcoords0=g_ex_texcoords0[i];
    ex_selectionstate=g_ex_selectionstate[i];
    ex_VertexCameraPosition=g_ex_VertexCameraPosition[i];
    ex_normal=g_ex_normal[i];
    ex_tangent=g_ex_tangent[i];
    ex_binormal=g_ex_binormal[i];
    clipdistance0=g_clipdistance0[i];
   // done with the vertex
   EmitVertex();
 }
 EndPrimitive();
}

  • Upvote 1

HP Omen - 16GB - i7 - Nvidia GTX 1060 6GB

Link to comment
Share on other sites

Also geometry made by the gs won't cast shadows, and doesn't have an aabb of it's own, cant be picked or have any api back to you application since the geometry is all made after leadwerks has sendt everything to the render pipline.

HP Omen - 16GB - i7 - Nvidia GTX 1060 6GB

Link to comment
Share on other sites

Thx, shadmar, for this example. For this to run, you will nevertheless have to modify some parts of your vertex-shader, so that the "in"s and "out"s match.

 

Also geometry made by the gs won't cast shadows

That's not true. You just have to set the same shader in the Material-Settings in the Shaders-tab as the Shadow-shader, then it will have a shadow.

This is the advantage of shadow maps: The shadows are generated from the depth-buffers of the generated fragments, so that is after the fragment-shader (and since the fragment-shader is run for the newly generated gemoetry, as well, they can cast shadows as well).

  • Upvote 1
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...