Jump to content

Rastar

Members
  • Posts

    421
  • Joined

  • Last visited

Posts posted by Rastar

  1. Well, you can't divide a triangle into an arbitrary number of triangles, because the tessellation factors are limited (iirc factors of 64 are guarantueed, more might be available). But usually that's sufficient. A good approach often is to calculate the tessellation factors based on the screen-space size of the triangle edge. That way the tessellation automatically changes based on the distance from the camera. Here is an example

     

    http://codeflow.org/entries/2010/nov/07/opengl-4-tessellation/

     

    The author's doing that for terrain tessellation, but the principle is the same.

    • Upvote 1
  2. Yes, that works. But I am trying to get the content of a render buffer

     

    Texture* tex = Texture::Create(width, height);
    Buffer* buffer = Buffer::Create(width, height, 1, 0);
    buffer->SetColorTexture(tex);
    buffer->Enable();
    buffer->Clear();
    world->Render();
    buffer->Disable();
    Context::SetCurrent(context);
    tex = buffer->GetColorTexture();
    const char* pixelBuf = new char[tex->GetMipmapSize(0)];
    tex->GetPixels(pixelBuf);
    

     

    A call to mat->SetTexture(tex) works, probably because the texture handle is being passed, but the above call to GetPixels() doesn't. As I said, I assume the texture isn't actually retrieved from the GPU to the main memory.

  3. Mmmmh, it's been a while since I did some programming in Leadwerks, and things seem to have changed slightly... If I see this right, for C++ projects the Main.lua script is executed in App::Start(), which contains the game loop. And when this is ended, the C++ execution continues in App::Start(), then App::Loop() (which basically does nothing). Also, since everything is done in Main.lua, the World, Context, Camera and Window member variables are all null.

     

    I can change this according to my needs, but I think for C++ projects there should be a template with a clean lifecycle implementation done in C++. When I choose a C++ project, I prefer to use Lua for encapsulated entity behavior, but use C++ for the heavy lifting in the background.

  4. When running an app from the IDE, the following line in App.Start() (I don't have an App.lua, so it's trying to execute Main.lua)

     

    //Invoke the start script
    if (!Interpreter::ExecuteFile(scriptpath))
    {
    

     

    will throw an error

     

    First-chance exception at 0x76C23E28 in MTLighting.debug.exe: Microsoft C++ exception: common::CNamedArgsUndefinedNameException at memory location 0x00CFE7A4.
    First-chance exception at 0x76C23E28 in MTLighting.debug.exe: Microsoft C++ exception: common::CNamedArgsUndefinedNameException at memory location 0x00CFE774.
    

     

    The execution jumps out here and continues when stopping the application (Esc) at

     

    //Call the App:Start() function
    Interpreter::GetGlobal("App");
    if (Interpreter::IsTable())
    

     

    in App.Start(), and then executes App.Loop() (which returns right away).

  5. At some point you will have to just grind your teeth and get through that kind of code. Lua is actually one of the nicer languages for beginners, so it could be even worse wink.png . But if your more the graphical/artistic kind of person, maybe a visual programming language like https://scratch.mit.edu is a better starting point for you to easier grasp fundamental elements like loops, conditional expressions etc.

  6. This is really a bit mask. You start with a value of 1 (2^0), which in binary is 00000001. If you add 2 (2^1), this means the second bit flag from the right will be set as well (00000011). So the actual number 3 doesn't have a special meaning, just which bits are true or false.

     

    Now, the value is stored as a number between 0.0 and 1.0 in fragData2. So you have to divide the value by 255 (equivalent to 11111111).

    • Upvote 1
  7. Leadwerks uses a little trick to render selected items differently (this is relevant for the editor). If you look e.g. into the fragment shader of default.shader

     

    if (ex_selectionstate>0.0) materialflags += 2;
    

     

    so if an entity is selected, the corresponding material flag will be set. Now, in the lighting shaders (e.g. Lighting/directionallight.shader) you'll find the lines

     

     //Blend with red if selected
     if ((2 & materialflags)!=0)
     {
      sampleoutput = (sampleoutput + vec4(1.0,0.0,0.0,0.0))/2.0;
     }
    

     

    so red will be added to the output color.

  8. First, you should write your color values to fragData0. Leadwerks uses a deferred renderer - that means you don't set the fragment color yourself, but rather write your data to several buffers in the shaders, and afterwards the engine does the lighting computations and actually sets the fragment color. Unfortunately, most OpenGL tutorials that you find use a forward renderer, and you can't simply apply them 1:1 to Leadwerks, but rather have to understand the general concepts and adapt them to this engine.

     

    Then, you don't need the position uniform in the vertex shader. You do create three vertices and add them to a triangle. When Leadwerks issues the draw call for your model, the vertex shader will be executed for every single vertex of your model, and its data like position and uv coordinates are automatically passed to the shader.

     

    I actually haven't thought through if your code is equivalent to this, but the usual lines for the coordinate transformation are

     

    vec4 modelvertexposition = entitymatrix_ * vec4(vertex_position,1.0);
    gl_Position = projectioncameramatrix * modelvertexposition;
    

     

    where the first line transform the vertex position from object space to world space, and the second line transform that to camera (eye) space and applies the perspective transformation.

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

     

    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).

    • Upvote 1
  10. After some time off I am picking up my PBR stuff for Leadwerks again. For the indirect specular lighitng I need special cubemaps that I would like to generate using the Leadwerks API. I would prefer to stay in Lua.

     

    I am doing it currently like this

    local cameraBuffer = Buffer:Create(self.resolution, self.resolution, 1, 0)
    local cubemap = Texture:CubeMap(self.resolution, self.resolution, Texture.RGB)
    
    cameraBuffer:Enable()
    for i = 1,6 do
    camera:SetRotation(self.cameraRotations[i])
    cameraBuffer:SetColorTexture(cubemap, 0, i-1)
    App.world:Render()
    end
    cameraBuffer:Disable()
    Context:SetCurrent(App.context)
    

     

    Now

    • Running this code gives me a "Asset map vaue is different" error, though the game continues normally. I don't know what this means?
    • What is the second parameter to Buffer:SetColorTexture()? The mipmap level?
    • I'm assuming that a cubemap is created by specifying the width and height of a single face (rather than width*6), is this correct?
    • As I see it, there currently is no way to save a texture to disk (or is there?). Would it be possible to add this to the (Lua) API?

  11. The texture editor has a "Generate Mipmaps" flag. I take it that when set, Leadwerks will calculate the mipmaps for a texture (and import only the first level when unchecked)? I actually need to import textures that already have mipmaps which should not be overwritten during import because that carry information other than plain mipmapping (e.g. specular cubemaps giving the irradiance for several levels of specular power).

     

    Is there a way to import those into Leadwerks?

  12. Yes, start small and grow big. Begin with a pass-through shader that does nothing but transform coordinates and output color. Experiment with that. You might find this thread

     

    http://www.leadwerks.com/werkspace/topic/8203-internal-shader-uniforms/page__hl__uniform

     

    useful as it lists the uniforms (constants passed into the shader) that you need. Also, be aware that Leadwerks has a deferred renderer - many examples you might find online are for a forward renderer. The big difference being that in a forward shader you do the lighting calculations right away, whereas in deferred rendering you first write certain values into a so-called G-buffer, and Leadwerks does the lighting calculations afterwards in a separate pass.

     

    The most important buffers you'll need in the beginning are fragData0 for the diffuse color and fragData1 for the normals.

     

    Also, don't hesitate to ask here what exactly you don't understand about the inner workings of the Leadwerks shaders!

  13. Ahh, OK. And those 7 ambients?

     

    By the way, it seems the camera (range, zoom) uniforms aren't passed to the ambient lighting shaders. While that is fine for "ordinary", view-independent ambient terms, I would like to calculate an ambient specular contribution. Would it be possible to at least hand those two to the ambient lighting shaders so I can calculate the view direction vector?

     

    Thanks again!

  14. For some reason I seem to be unable to Bind the normals buffer in a PostProcess Lua file. In

     

    function Script:Render(camera,context,buffer,depth,diffuse,normals,emission)
    

     

    I try to bind the normals to texture2 using

     

    normals:Bind(2)
    

     

    but the result is complete blackness. Are they actually passed in to that function? Do I have to do something special/different?

  15. Is there any way to pass additional uniforms to the lighting shaders (directionallight.shader, ...) ? (Provided I have modified the sources and added those uniforms). Which is equivalent to. Is there a way to get a reference to the loaded shaders? I guess when I call Shader::Load() for those shaders I get a separate instance that I then set uniforms on, not the one actually loaded by the render code?

×
×
  • Create New...