Jump to content

shadmar

Members
  • Posts

    3,618
  • Joined

  • Last visited

Posts posted by shadmar

  1. 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
  2. var corners : Vector3[] = new Vector3[ 4 ];

     

    to Lua How ?

    Vector3 is Vec3 in Lua but what about the square brackets and colon ?

     

    I believe corners is declared as a array of 4 vec3 values.

    I think you only need to do this in lua:

    corners = { }

    • Upvote 1
  3. I am getting interested in learning how to make my own shaders, is there any good tutorials out there?

     

    That would depend on what you already know about them, however since all engine has it's own way of doing shading I'd say generic tutorials aren't directly applicable in Leadwerks (or any other engine for that matter, they all have different input, output, uniform naming to the shader). So my answer to this is always, learn by doing, modify extisting shaders (what I did). Model fragment shaders are the simplest ones to mod, and since Leadwerks is a deferred engine, you don't have to worry about lightning. :)

    • Upvote 3
×
×
  • Create New...