Jump to content

Lunarovich

Members
  • Posts

    166
  • Joined

  • Last visited

Posts posted by Lunarovich

  1. Ok, here it is, an absolutely minimal model shader... It will output a green geometry...

     

    Vertex shader:

     

    #version 400
    #define MAX_INSTANCES 256
    
    //Uniforms
    uniform instancematrices { mat4 matrix[MAX_INSTANCES];} entity;
    uniform mat4 projectioncameramatrix;
    
    //Attributes
    in vec3 vertex_position;
    
    void main()
    {
    mat4 entitymatrix = entity.matrix[gl_InstanceID];
    mat4 entitymatrix_ =entitymatrix;
    entitymatrix_[0][3]=0.0;
    entitymatrix_[1][3]=0.0;
    entitymatrix_[2][3]=0.0;
    entitymatrix_[3][3]=1.0;
    
    vec4 modelvertexposition = entitymatrix_ * vec4(vertex_position,1.0);
    
    gl_Position = projectioncameramatrix * modelvertexposition;
    }
    

     

    Fragment shader:

    #version 400
    
    // Outputs
    out vec4 fragData0;
    out vec4 fragData2;
    
    void main()
    {
    fragData0 = vec4(0.0, 1.0, 0.0, 0.0);
    fragData2 = vec4(0.0, 0.0, 0.0, 0.0);
    }
    

     

    For the explanation of attribs, uniforms and inputs/outputs see this link.

  2. Ok. Thanx. What I really want is to create some procedural textures. I'm starting to learn how to do it (Perlin noise and such things) and would like to be able to use this knowledge with LE. So, for now, I have, basically, found three possible approaches:

    1. Texture::SetPixels. But this function is not exposed to Lua.
    2. By using Buffer:Create, Buffer:SetCurrent, drawing to the buffer via Context:Plot and than get a texture via Buffer:GetColorTexture(0)
    3. Via shaders.

    In fact, I have had any success only by using the 2nd method thanks to your example found here. Now, I'd like to know if there is some LE specific way one should go about in order to make procedural textures.

     

    Anyway, a default shader is a jungle I cannot get through - no docs, no comments, no nothing! On the contrary, those GLSL tutorials are excellent and simple, and I don't see why it should be so complicated in LE to paint a triangle, with a VBO defined, in red via shaders (btw, I know how to do it by coloring vertices, but that's not something that I want, just for the record).

  3. Hello! As the title points out, I want to know how to color a simple triangle via my own shader. Basically, I want to achieve something like this:

     

    61VOQdE.png

     

    I'm trying to recreate, in LE, a tutorial 4 from this excellent resource. So, for the triangle itself, I do something like this:

     

        local model = Model:Create()
        model:SetColor(1.0,1.0,1.0)
    
        local surface = model:AddSurface()
        surface:AddVertex(-0.5,-0.5,0, 0,0,-1)
        surface:AddVertex(0.5,-0.5,0, 0,0,-1)
        surface:AddVertex(0.5,0.5,0, 0,0,-1)
        surface:AddTriangle(2,1,0)
        surface:Update()
        model:UpdateAABB(Entity.LocalAABB)
        model:UpdateAABB(Entity.GlobalAABB)
        return true
    

     

    With camera and light added (light is probably not needed) and properly positioned, I get a white triangle.

     

    I then proceed to create and add a material. Now comes the tricky part. My fragment shader looks like this:

     

    #version 400
    out vec4 FragColor;
    void main()
    {
    FragColor = vec4(1.0, 0.0, 0.0, 1.0);
    }
    

     

    However, I have no idea what to do with the vertex shader. If I do nothing with it, nothing gets displayed on the screen in return. Now, I've tried with something like this

     

    #version 400
    uniform mat4 projectionmatrix;
    uniform mat4 drawmatrix;
    uniform vec2 position[3];
    void main(void)
    {
    gl_Position = projectionmatrix * (drawmatrix * vec4(position[gl_VertexID], 0.0, 1.0));
    }
    

     

    but I cannot even get it working when the game starts, since I do not know how to send an array of floats via Lua. A side question: how does one sends an array of floats to a shader via Lua? Anyway, I see that there is no camera matrix transformation concatenated and I do not know how to do it. Any help would be appreciated.

     

    Thank you!

  4. The path parameter for Camera:AddPostEffect also accepts a Lua script which does the shader handling. I have no access to Leadwerks right now, but iirc the Bloom effect uses this approach (have a look at Shaders/PostProcess).

     

    Thanks! It occured to me to use also this approach. However, I wanted to see if there is a more direct approach. I'm asking all this because I have an idea of a gameplay based on various postprocessing parameter manipulations - different types of subjectivities manifested via different types of vision.

  5. You would have to make this into a uniform

     

    uniform int downgrade = 6;

     

    and can then set it via Shader:SetInt().

     

    I see the point. However, if you look at the API, you'll see that Camera:AddPostEffect accepts only string. That said, I cannot first load a shader and send a reference to the shader as a parameter to the camera. Rather, I send a string and never get the reference to the shader back from camera (at least in Lua and as far as I can see).

     

     

     

     

    That would probably be the way to control Shadmar's shaders? But can you control stock shaders (ones that come with LE) in the same way?

  6. Hello! I know how to attach post-processing effects to a camera via editor as well as programmatically. However, I do not know how to control post-processing shader parameters dynamically.

     

    For example, Shadmar's pixelate shader has this variable:

     

    const int downgrade = 6; //at original 1920x1080, 6 yields 320x180

     

    Now, how can I change downgrade value via Lua code?

     

    Thank you!

  7. I'm getting into textures right now (thinkering with Substance Designer and procedural textures). So if anyone has an interesting project for the tournament and needs textures for CSG (preferably abstract and SF), feel free to contact me...

  8. When I make an image in an external image editor (eg. Inkscape) and put it in the folder inside the project tree, it automatically gets converted to .tex as expected. I open it in the Texture editor and check Clamp checkboxes and do some other adjustments.

     

    Now, when I save an image over an original image file, texture gets updated. However, some settings are lost and some are preserved. Namely, Clamp checkboxes get unchecked.

     

    This is kind of annoying, since I'm adapting my textures often and have to go everytime to the Texture editor. What is more, it's an inconsistent behavior.

  9. Hmmm... Besides the water texture in Materials/Water folder, textures in Materials/Effects/Water and water shaders in Shaders/Water folder, I really don't see any prefab/entity/material that would be connected to water. And there is no tutorial how to make water. Could you give me, please, any lead?

  10. @shadmar Thank you! Will try to decipher it, since I'm noob in regards to shaders smile.png

     

    Anyway, can I (ab)use this opportunity to ask you what happens to your water prefab? I've downloaded it from here, but the water does not seem to move. Just sits there...

     

    EDIT The water does not seem to like postprocessor effects. When I turn them off, everything is as expected. Is there a way to have a water with postprocessor effects?

  11. @gamecreator Thank you! The mask will be very handy for my lib.

     

    However, neither of what you've said does not correspond to my needs. Firstly, clamping only stretches the last pixel of the texture to it's borders. Secondly, Shadmar made a masking shader and not a shader to draw a part of the image. Althoug, I can use it for those needs, it's complicated and costly workaround. There should be a much simpler way.

  12. I've adapted your shader to my needs. However, I do not see how to clip the image: image just wraps. I see that you use "zoom" in order to clip the rest of the image. However, I want a non scaled part of the image. Any ideas?

     

    Btw, I can't find Shadmar's shader that you're talking about. Could you please direct me where to find it?

  13. Hello! Would it be possible in LE to draw only a part of the image on the screen (via context). I mean, let's say I have a 256 x 256 texture with four 64 x 64 frames. Now, I would like to be able to draw, for example, a part of the image with following specs: x = 64, y = 0, w = 64, h = 64.

     

    I'm asking that because I'm building a basic 2d graphics lib and would like to implement animation in more elegant manner: right now, I'm just loading bunch of textures as frames, which is cumbersome and not quite efficient from renderer's point of view.

     

    Thank you.

  14. I've just read your example. It's such a shame that scaling does not work proprely in all cases. I've tested it with DrawImage/Text/Rectangle and it works as expected.

     

    Also, I've bumped into problems with SetTranslation cause I wanted to implement variable pivot for the rotation (put the rotation pivot in the center of the image, for example). Although I've done it already in HTML5 canvas, SetScale here does not work in the similar way...

  15. I have two questions regarding terrain:

     

    1) How can I access a terrain made in the editor from Lua script? Secondly, is there any way to create it programmatically / procedurally, ie. via scripting and not in the editor?

     

    2) I see that a terrain is shaded, which is fine. However, I notice that it does not cast shadows, which is very unrealistic. Is there a way to make it cast shadows.

     

    Thank you!

×
×
  • Create New...