Jump to content


  • Content Count

  • Joined

  • Last visited

Everything posted by Josh

  1. you will actually be able to do that with this.
  2. The Leadwerks 5 beta will soon be updated with particle emitters and an example particle system plugin. Previously, I showed some impressive results with physically interactive particles that collide with and exert forces on the environment. I decided to use the plugin system for controlling particle behavior, as this offers the best performance and can be run on the physics thread. A particle system plugin uses some predefined structures and functions to modify the behavior of particles when they are emitted or as they are updated. This allows for unlimited features to be added to the particle system, because anything you want can be added with a plugin. A system for sending settings to the plugin will be implemented in the future so you can adjust the plugin settings and see the results. The default particle settings and features will probably stay pretty barebones and I will just use the plugin system to add any advanced functionality since it is so flexible. void EmitParticle(ParticleModifier* mod, ParticleSystem* particlesystem, Particle* particle) { if (mod->emissionshape == EMISSION_SHAPE_BOX) { particle->position[0] = Random(-mod->area[0], mod->area[0]); particle->position[1] = Random(-mod->area[1], mod->area[1]); particle->position[2] = Random(-mod->area[2], mod->area[2]); } else if (mod->emissionshape == EMISSION_SHAPE_CYLINDER) { particle->position[0] = Random(-mod->area[0], mod->area[0]); particle->position[1] = Random(-mod->area[1], mod->area[1]); particle->position[2] = Random(-mod->area[2], mod->area[2]); auto l = sqrt(particle->position[0] * particle->position[0] + particle->position[1] * particle->position[1] + particle->position[2] * particle->position[2]); if (l > 0.0f) { particle->position[0] /= l; particle->position[1] /= l; particle->position[2] /= l; } } particle->position[0] += particlesystem->matrix[12]; particle->position[1] += particlesystem->matrix[13]; particle->position[2] += particlesystem->matrix[14]; } There are three other new Lua examples included. Coroutines.lua shows how a sequence of actions can be added to an entity before the game starts, and the actions will be executed in order: --Create model local model = CreateBox(world) --Add some behaviors to be executed in order model:AddCoroutine(MoveToPoint, Vec3(3,0,0), 2) model:AddCoroutine(MoveToPoint, Vec3(-3,0,0), 2) model:AddCoroutine(MoveToPoint, Vec3(0,0,0), 2) --Main loop while window:Closed() == false do world:Update() world:Render(framebuffer) end This is great for setting up cut scenes or other sequences of events. An example showing how to enable tessellation is also included. Tessellation is now a per-camera setting. camera:SetTessellation(10) The number you input is the size in pixels of the tessellated primitives. Use zero to disable tessellation. Tessellation is disabled by default on all cameras. Finally, an example showing how to use a texture loader plugin is included. All you have to do is load the plugin and after that textures can be loaded in VTF format: local vtfloader = LoadPlugin("Plugins/VTF.dll") local tex = LoadTexture("Materials/wall01.vtf")
  3. If you open up the FPSPlayer script you can see that the player itself will be passed into the Use() function: --Use the object, whatever it may be usableentity.script:Use(self) So you could add a value directly onto the player in your switch function: function Script:Use(player) player.disablemove = true if ShowedImage=="Yes" then ShowedImage="No" else ShowedImage="Yes" end end And then disable the player input in the FPSPlayer script if this value is set to true: if self.disablemove ~= true then if window:KeyDown(Key.W) then self.input[1]=self.input[1]+1 end if window:KeyDown(Key.S) then self.input[1]=self.input[1]-1 end if window:KeyDown(Key.D) then self.input[0]=self.input[0]+1 end if window:KeyDown(Key.A) then self.input[0]=self.input[0]-1 end end
  4. You would probably just want to add a variable to the player script like this: self.disableMovement = true And then add an if statement around the code that handles player input..
  5. Josh

    Particle Physics

    I made some changes to the design of the particle system. I am less concerned with the exact behavior of particles as they move around and move interested right now in building a system with good performance and deep physics interactions. Although I want particle behavior to be customizable, I don't think scripts are the right tool for the job. C++ plugins are better suited for this for two reasons. C++ is much faster, and particles are a system that will make heavy use of that. Lua scripts can't be run on separate threads. In Leadwerks Engine 4 we have basic particle collisions, but I wanted something more interactive in the new system. I move the particle update code into the physics thread. I implemented collision as well as the ability for particles to exert forces on other objects. Here's what happens when some slow-moving smoke particles interact with a scene: The lower platform rotates freely while the upper platform is motorized. When the particle velocity is increase they start to behave like a stream of water: Best of all, the speed is surprisingly fast. 4000 particles with collision update in just 2 milliseconds. The code scales well across cores so if you have a lot of CPU cores simulations with 100,000 particles are possible. Right now particles are processed in the physics thread, and get sent to the rendering thread for display, but right now the main thread actually never sees the individual particles. This is fast enough I think particles will default to full physics. Instead of just being a dumb visual effect we are going to have fully interactive fluids and gases. Flamethrowers can fill a room with fire and it will creep around corners to fill a space.
  6. Josh

    Beginning with Particles

    I see the "values" as being script-defined properties. I am offloading all the particle features and settings into Lua scripts so that there is no limit on the features particles can support..In LE4 we had fixed emission volumes, in the new engine you can add a script for a new emission shape of your own, or whatever you want. Does that make more sense now?
  7. I wanted to work on something a bit different, and this sure is different. I've got a framework of a new particle system worked out. What's really special about this system is the amount of interactivity the particles will allow. Particle-world collisions. Particle-particle collisions (repulsion) Particle-particle cohesion (fluids with surface tension) Instead of just being a visual effect, I want our new particles to be fully interactive with physics so that particles can exert forces on objects. This will allow you to simulate fluids, smoke, and other effects in a realistic manner, not just dumb collision of particles bounding off walls. It should even be possible to simulate hydrophobic and hydrophillic liquids if you mix two together with different cohesion values. Basically what I want is something like Nvidia Flow on the CPU and exerting forces on the world. So if you had water falling on a water wheel the wheel would move because of the forces, or a blast of wind could knock objects over without any special force fields or other fake effects. I also have a technique worked out that will allow lighting of clouds and other masses of gas, with back-scattering. Emitters can be instanced so if you have one really high-quality torch effect, for example, you can instance it and use it as much as you like without any additional computational cost per instance. Particle emitters can be controlled with a Lua script or C++ actor. Two new functions are available, UpdateParticle() and EmitParticle(). Here is a script that controls particle behavior over time: entity.particleVelocity = Vec3(0,0,1) entity.particleAcceleration = Vec3(0,-1,0) entity.inverseSquareFalloff = true entity.particleRadiusBegin = 0.1 entity.particleRadiusEnd = 0.2 entity.particleColorBegin = Vec4(1,1,1,1) entity.particleColorEnd = Vec4(1,1,1,0) entity.particleMass = 1 entity.particleSpin = 5 function entity:Start() self.particleColorBeginHSL = HSL(self.particleColorBegin.rgb) self.particleColorEndHSL = HSL(self.particleColorEnd.rgb) local emitter = Emitter(self) if emitter == nil then return end local n for n = 1, #emitter.particles do emitter.particles[n].mass = self.particleMass emitter.particles[n].falloff = (n-1) / (#emitter.particles - 1) end end function entity:EmitParticle(index) local emitter = Emitter(self) if emitter == nil then return end emitter.particles[index].position = self:GetPosition(true) emitter.particles[index].velocity = TransformVector(self.particleVelocity,self,nil) emitter.particles[index].radius = self.particleRadiusBegin emitter.particles[index].color = self.particleColorBegin end function entity:UpdateParticle(index) local emitter = Emitter(self) if emitter == nil then return end emitter.particles[index].velocity = emitter.particles[index].velocity + self.particleAcceleration / 60 local falloff = emitter.particles[index].falloff if self.inverseSquareFalloff then falloff = falloff * falloff end emitter.particles[index].color.rgb = RGB(self.particleColorBeginHSL * (1 - falloff) + self.particleColorEndHSL * falloff) emitter.particles[index].color.a = self.particleColorBegin.a * (1 - falloff) + self.particleColorEnd.a * falloff emitter.particles[index].radius = self.particleRadiusBegin * (1 - falloff) + self.particleRadiusEnd * falloff emitter.particles[index].rotation = emitter.particles[index].rotation + self.particleSpin / 60 end A different script could be used to make particles emit from vertices of a model, to make the model appear to be on fire, or other effects. This will allow infinite customization to create any behavior you want. Particle physics will be calculated on the physics thread so I expect them to be very fast.
  8. Josh

    Sprite Layers and the GUI

    Maybe it is being called somewhere else? I can’t tell without seeing the full program.
  9. Josh

    Sprite Layers and the GUI

    Just call GetEvent to retrieve the next event in the queue. If it is a mouse or hey event you can pass it straight to the GUI processEvent method.
  10. Josh

    Sprite Layers and the GUI

    gui->ProcessEvent() will send the event to the appropriate widget it effects. Those widgets may then emit an event for the widget action, which can be detected in the main event handling code like in your example above. So mouse and key events get send into the GUI and then may result in new events being generated. The reason it is done this way is it gives you precise control over the raw input, so you can do a 3D in-game GUI and control how the mouse events work.
  11. Josh

    Voxel Code

    In LE4 use Entity->Release(); In LE5 just set the variable to NULL. Frustum and occlusion culling are built-in. Surfaces can be cleared and re-built, but faces cannot be removed in LE4. In LE5 you can modify the vertex and indice arrays and then call Mesh->Finalize().
  12. Josh

    2D Drawing to Texture

    Here is what I came up with: void Camera::SetRealTime(const bool realtimemode) void Camera::Refresh() Refresh will cause a non-realtime camera to render once before it is disabled automatically, until the next refresh.
  13. Technically, 4,294,967,295 vertices is the max. But there will be a limit lower than that depending on your hardware. Very roughly I would aim for no more than 10,000-20,000 polys for any particular model.
  14. LE5 beta updated. Added 3D GUI example, missing newton double float lib.

  15. Josh

    3D GUI

    Putting all the pieces together, I was able to create a GUI with a sprite layer, attach it to a camera with a texture buffer render target, and render the GUI onto a texture applied to a 3D surface. Then I used the picked UV coords to convert to mouse coordinates and send user events to the GUI. Here is the result: This can be used for GUIs rendered onto surfaces in your game, or for a user interface that can be interacted with in VR. This example will be included in the next beta update.
  16. GUI is working in 3D space. Never did this before.

    1. gamecreator


      How much of these new features are a challenge you enjoy versus a frustrating necessity?

    2. Josh


      The features are pretty fun actually. I planned all this out to have this specific functionality work. Vulkan has been some of the most frustrating difficult stuff I have ever worked on (not as bad as Android / iOS stuff though) but the hard part of that is through I think.

  17. Josh

    Voxel Code

    If you keep developing this I would be interested in licensing the code to add a Minecraft-type game template to the new engine.
  18. A dynamic cast will return NULL if the conversion is not valid. (A static cast can potentially return an invalid object.) So you might want to also check if the result of the cast is NULL before continuing.
  19. Cast the Actor object to your custom actor object and the function will be available. See C++ dynamic casting.
  20. Both of those code examples do the exact same thing.
  21. Do you want a Lua or C++ function to be called?
  22. Josh

    Voxel Code

  23. Josh

    2D Drawing to Texture

    That is actually something I will have to figure out for the editor, too.
  24. Josh

    2D Drawing to Texture

    Hide the camera and it won’t render. There isn’t strict synchronization of the rendering and main threads so I am not sure how you would make sure it just rendered one single frame. Something to think about.
  25. New LE5 beta uploaded with render-to-texture.

  • Create New...