-
Posts
421 -
Joined
-
Last visited
Content Type
Blogs
Forums
Store
Gallery
Videos
Posts posted by Rastar
-
-
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.
- 1
-
Parallels only supports OpenGL 2.1 (I think it's similar with other VMs), so Leadwerks won't run, no matter what GPU you have.
-
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.
-
When I try to get the pixels of a Buffer's color texture, I get an exception. The texture is fine and can e.g. be set to a texture slot, so I guess the data isn't actually retrieved from the GPU? Is there a way to do this?
-
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.
-
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).
-
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 . 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.
-
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).
- 1
-
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.
-
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.
- 1
-
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).
- 1
-
You would have to make this into a uniform
uniform int downgrade = 6;
and can then set it via Shader:SetInt().
- 1
-
Hi shadmar, thanks for the suggestion - will try over the weekend!
-
Is the bullet scaled in-editor to values < 1? If so, maybe Instance() starts with a scale of 1. Just a wild guess, don't have access to LE right now...
-
Bump. Anybody?
I've put a screenshot of my WIP in the gallery
http://www.leadwerks.com/werkspace/page/viewitem?fileid=462724265
but without indirect specular lighting from (special) cubemaps this won't be the real deal ;-)
-
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?
- Running this code gives me a "Asset map vaue is different" error, though the game continues normally. I don't know what this means?
-
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?
-
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!
-
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!
-
Ummmm, sorry for a silly question, but I can't see the forest for the trees right now... what are those combinations (8*2*3) again? And those 7 for the ambient?
-
Ahhh, texelFetch, that was the missing clue - thanks, shadmar!
-
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?
-
Cool, thanks!
-
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?
Improving Tesselation Resolution
in Game Artwork
Posted
Which reminds me: Ages ago I did a couple of blog posts here a bout tessellation
http://www.leadwerks.com/werkspace/blog/117/entry-1185-pass-the-tessellation-please-part-1/
http://www.leadwerks.com/werkspace/blog/117/entry-1195-pass-the-tessellation-please-part-2/
Maybe there's something helpful in there as well.