Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

Dynamic lighting camera system
Started by basiliogerman Oct 02 2019 09:50 PM

31 replies to this topic
[TOPIC CONTROLS]
Page 1 of 2 1 2
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

basiliogerman

[GLOBAL: userInfoPane.html]
basiliogerman
  • Contributor

  • 116 posts
  • Corona SDK

Some years ago i adventured myself into the universe of the custom shaders in corona and got some dynamic lighting system working with normal maps, but, after some weeks of inactivity (worked on my spare time) i lost the proof of concept code in a system format and never got to work on it again, (I did record it however)

 

Until a week ago, where I've made huge progress! I reworked how stuff would work, coded from scratch and made it compatible with normal grouping and many many other stuff, including a tracking camera with rotation tracking as well. (Yes, as in the camera view rotates too.)

 

This is still a work in progress and depending on how it turns out, i will consider on putting it as a plugin in the marketplace, but right now, how some things work might be changed in Corona in the future (Uniforms) so that leaves it a little bit uncertain. It basically works with the graphics.newTexture API. Anyway, here's the showcase (Old now)

 

 

You can find updates on it on the channel as well. Any feedback is appreciated

 

EDIT: Here is the latest video of the project

ANOTHER EDIT: Here are some up to date screenshots of the project:

 

Attached File  Screen Shot 2019-10-06 at 1.14.49 PM.jpg   258.34KB   0 downloads

Attached File  Screen Shot 2019-10-06 at 1.15.00 PM.jpg   310.38KB   0 downloads

 

YET ANOTHER EDIT:

Try it out as an HTML5 build here: http://zetosoft.com/dynacam/ Use the arrow keys to accelerate and rotate, tap on the ship to toggle ship light, tap on coins or shapes for other tests (Only on desktop, sorry)


  • Michael Flad and StarCrunch like this

[TOPIC: post.html]
#2

sporkfin

[GLOBAL: userInfoPane.html]
sporkfin
  • Contributor

  • 661 posts
  • Corona SDK

Cool, so you have both custom shaders and a vignette mask in that sample?

 

It looks great!  Please keep us posted as your projects evolve. 


  • basiliogerman likes this

[TOPIC: post.html]
#3

XeduR @Spyric

[GLOBAL: userInfoPane.html]
XeduR @Spyric
  • Corona Geek

  • 1,020 posts
  • Corona SDK

I agree, this looks fascinating. I have a few concepts in mind that could leverage something like this.

Like @sporkfin already said, keep us posted!


  • basiliogerman likes this

[TOPIC: post.html]
#4

basiliogerman

[GLOBAL: userInfoPane.html]
basiliogerman
  • Contributor

  • 116 posts
  • Corona SDK

Hi Sporkfin, XeduR! long time no see. Currently it's divided into 2 general shaders, one to calculate lights, and another to apply the lights. I use another shader to fix the normal map rotation, but no mask is used,

 

I just use the alpha value to mask it, the display object has an out of the box filter applied as well, filter.pixelate, with a transition changing it's value

 

Got sprites working, physics is next on the list to try out, but i will have to fix some stuff there, check out the video of progress



[TOPIC: post.html]
#5

Rob Miracle

[GLOBAL: userInfoPane.html]
Rob Miracle
  • Moderator

  • 26,392 posts
  • Enterprise

That's really cool!

 

Rob


  • schroederapps and basiliogerman like this

[TOPIC: post.html]
#6

basiliogerman

[GLOBAL: userInfoPane.html]
basiliogerman
  • Contributor

  • 116 posts
  • Corona SDK

Thanks @Rob Miracle!

 

Currently working on getting physics bodies working correctly, but it seems i will have to track each dynamic object individually to update the normal map's rotation.

 

The problem relies in that once physics owns the body, i can't intercept the transform change, not even in a metatable (As i do with normal display objects) or wrapping the translate or rotate functions. 

 

One solution would be to add a wrapper to physics.addBody so that i can get these dynamic bodies in a list and update their normal rotation in an enterFrame.

 

Right now i'm just browsing around the Corona repository to see how physics is handled.



[TOPIC: post.html]
#7

basiliogerman

[GLOBAL: userInfoPane.html]
basiliogerman
  • Contributor

  • 116 posts
  • Corona SDK

New update, got physics working!

 

Check it in action here!

 

Now i just need to tidy up the code, add all of the missing functions if this is ever going to be a plugin, and write some documentation, which is pretty straightforward.

 

The engine/camera adds new object types, lights, lightGroups, and lightObjects (Like a normal displayObject). Grouping works like normal Corona, light objects have an extra normal fill property, and it works as the other two, same type of fills and that. 

object.fill
object.stroke
object.normal
There are still a few issues so don't get too excited if your next project depends on something like this. I have not benchmarked it in a stress test yet as well but it seems to run fine so far.
 
 
EDIT: Meshes, Polygons, Lines, Sprites, Rects, RoundedRects, Circles, Snapshots, Containers, ImageRect, Image, Groups, Text, Embossed text, & all Physics bodies now work with the Dynamic camera. Next up are emitters
 
EDIT: Just finished updating the documentation, and a lot of polishing. Emitters can wait another day. 

  • Appletreeman and sporkfin like this

[TOPIC: post.html]
#8

basiliogerman

[GLOBAL: userInfoPane.html]
basiliogerman
  • Contributor

  • 116 posts
  • Corona SDK

Worked mostly on seeing how to export normals from blender to use in a 2D game, read this blog and used the project, except i had to modify the composite so that it does not invert the X.

 

Anyway, did not work too much on anything, but did notice that tap and touch listeners are gone as i am rendering everything using frame buffers. I think i have a solution anyway, but will end up testing it on another day. Emitters are still 0% done. The good news is that default displayObjects can also be inserted into the light group hierarchy, thus, default emitters can be placed without a problem right now (Without shading, which looks weird)

 

So, i added some stuff to stress the engine and it now has a name, check out the latest video here, its gold! lol It's around 130 normal tiles, 50 sprites each with its own light, and other stuff to test the engine (1 container, some images, a mesh, text, line, different shapes with fill properties, and other lights)

 

Other good news include that it works on HTML5 builds, although performance is not the best.

 

EDIT: For now, the project will remain as a private dependency until i implement it on an editor i've been working on and iron things out, some days at the most. Made with Corona as well:

 

Attached File  Screen Shot 2019-10-06 at 1.28.16 PM.jpg   310.26KB   0 downloads

 

For those interested in the editor, it works with physics, has layered (background & foreground) capability, custom item loader, scenery placement, will soon have a light mode, and other interesting stuff


  • StarCrunch likes this

[TOPIC: post.html]
#9

basiliogerman

[GLOBAL: userInfoPane.html]
basiliogerman
  • Contributor

  • 116 posts
  • Corona SDK

New stuff, touch and tap listeners are still a work in progress, i still have to compare what the real result from the event listener would be compared to what it is right now, maybe add some masks to hit mask the rect? I think i'll leave it as it is and add only circle and roundedRect paths as they are easy values to read.

 

Attached File  Screen Shot 2019-10-06 at 11.12.53 PM.jpg   207.63KB   0 downloads



[TOPIC: post.html]
#10

Appletreeman

[GLOBAL: userInfoPane.html]
Appletreeman
  • Contributor

  • 450 posts
  • Corona SDK

This looks absolutely amazing.  So is the plan to eventually have it on the marketplace as a plugin?

I've had an idea for a game in my head for a while now and this would push it to the next level.


  • basiliogerman likes this

[TOPIC: post.html]
#11

sporkfin

[GLOBAL: userInfoPane.html]
sporkfin
  • Contributor

  • 661 posts
  • Corona SDK

The multiple light sources work great together.  I love it!


  • basiliogerman likes this

[TOPIC: post.html]
#12

basiliogerman

[GLOBAL: userInfoPane.html]
basiliogerman
  • Contributor

  • 116 posts
  • Corona SDK

@Appletreeman Yes, that is the plan. I'm just making sure everything works as close as expected.

 

I'm currently integrating it into an existing project to see what works and iron things out

 

@sporkfin Yes! thought it would slow down after some lights, but i still have to benchmark this on real devices.

 

EDIT: Touch and tap listeners are working like intended, to an extent. Still need to listen for hierarchy changes somehow to update the touch object. Right now, it's a group copy mimicking the whole original group hierarchy/object that the listener was added to, in the end, white stuff is the touch area:

 

Attached File  Screen Shot 2019-10-07 at 6.41.21 PM..jpg   241.63KB   0 downloads

 

ANOTHER EDIT: Editor is up and running. Integrating it did help iron stuff out. Some things are still not finished and will continue working on it until the editor is ready (Must add light placement mode) 



[TOPIC: post.html]
#13

basiliogerman

[GLOBAL: userInfoPane.html]
basiliogerman
  • Contributor

  • 116 posts
  • Corona SDK

For the curious, i've uploaded the demo as an HTML5 build to http://zetosoft.com/dynacam/ Use the arrow keys to accelerate and rotate, click on the ship to toggle ship light, tap on coins or shapes for other tests

 

Getting pretty decent FPS!!!

 

Please let me know what you think! 



[TOPIC: post.html]
#14

Arteficio

[GLOBAL: userInfoPane.html]
Arteficio
  • Enthusiast

  • 83 posts
  • Corona SDK

I tried with iphone 6s, safari on ios 13.1 an it gave me an error in the fragment kernel

ERROR: 0:11: 'vec2' : declaration must include a precision qualifier for type
ERROR: 0:11: 'float' : declaration must include a precision qualifier for type
ERROR: 0:22: Invalid call of undeclared identifier 'webgl_88f75f8300000015'

Then the demo started but tapping on the ship did nothing
  • basiliogerman likes this

[TOPIC: post.html]
#15

basiliogerman

[GLOBAL: userInfoPane.html]
basiliogerman
  • Contributor

  • 116 posts
  • Corona SDK

Hmmm i have not tested on other browser other than chrome. I'll do some testing on Safari and fix anything that comes up.

You will need a keyboard to test movement out for now. No plans on making this an actual full game, the assets were borrowed from other of my projects.

 

EDIT: fixed both ERROR 0:11 (not reflected on build)

EDIT2: Error is fixed on build



[TOPIC: post.html]
#16

cyberparkstudios

[GLOBAL: userInfoPane.html]
cyberparkstudios
  • Contributor

  • 573 posts
  • Corona SDK

I looked at the HTML5 via my MacMini Safari ver 12.0 ... no errors, looks really good.  Nice work!


  • basiliogerman likes this

[TOPIC: post.html]
#17

Rob Miracle

[GLOBAL: userInfoPane.html]
Rob Miracle
  • Moderator

  • 26,392 posts
  • Enterprise

Very nice!


  • basiliogerman likes this

[TOPIC: post.html]
#18

sporkfin

[GLOBAL: userInfoPane.html]
sporkfin
  • Contributor

  • 661 posts
  • Corona SDK

I tried it on MacOS Safari 13.1 and Chrome Version 77.0.3865.90 and it worked and looked great!


  • basiliogerman likes this

[TOPIC: post.html]
#19

basiliogerman

[GLOBAL: userInfoPane.html]
basiliogerman
  • Contributor

  • 116 posts
  • Corona SDK

Glad you guys are liking it, more is to come!

 

Latest update: Got zoom working

And more zooming



[TOPIC: post.html]
#20

basiliogerman

[GLOBAL: userInfoPane.html]
basiliogerman
  • Contributor

  • 116 posts
  • Corona SDK

Updated HTML5 demo build. Added some sliders to modify ship light and camera zoom. Sliders represent:

Constant, Linear and Quadratic attenuation factors, Light scale, Light color Red, Green, Blue, and camera Zoom

 

Test the dynamic lights demo here



[TOPIC: post.html]
#21

Arteficio

[GLOBAL: userInfoPane.html]
Arteficio
  • Enthusiast

  • 83 posts
  • Corona SDK

The fragment error is solved and it works well now on my iphone (although with no movement possible but it does non matter, the shading is great!)
I’m really impressed!
  • basiliogerman likes this

[TOPIC: post.html]
#22

basiliogerman

[GLOBAL: userInfoPane.html]
basiliogerman
  • Contributor

  • 116 posts
  • Corona SDK

Engine has been fit into the editor, many adjustments and improvements were made to the camera library in the process. I still have to handle system events like suspend (texture memory handling), do some real device testing and some benchmarking as well.

 

Anyway, here's a screenshot of the editor using the most recent dynacam library:

 

Attached File  Screen Shot 2019-10-11 at 12.39.07 AM.jpg   264KB   0 downloads

 

Next task will be to add the engine to one of the games i'm making, to do real device Android & iOS testing.

 

EDIT: Engine working in-game. Super easy to convert. I will test builds another day. I'll be busy all next week doing other stuff so updates might be a bit scarce, but i do estimate that it will be done soon. About the marketplace plugin I will have to talk to someone at Corona first as it uses an undocumented feature.



[TOPIC: post.html]
#23

basiliogerman

[GLOBAL: userInfoPane.html]
basiliogerman
  • Contributor

  • 116 posts
  • Corona SDK

New update, Everything works. Emitters can be placed on a default object view and they look great. Have been testing on an iPhone X and it performs smooth;

 

Except for the crash that sends everything to hell on IOS. Randomly, sometimes not so randomly, always without stack trace. Just crashes directly to the app screen. After some time of research, logging, tons of debugging and a lot of builds, I've managed to identify the cause of the crash and will implement and test a definitive fix next week. 

 

For anyone interested on how the engine works and how it is being developed, it basically wraps all display object creation APIs to create two display objects instead of one, and finally rendered together in a canvas merging 3 frame buffers (Diffuse, Normal and Light). So basically the whole scene is constructed two times behind the scenes: All diffuse and normal objects are "entangled" or paired with each other. This means that all transformation changes made in the diffuse object are replicated to the normal object, and this is true also for function calls, like sprite:setSequence() will set the sequence for both objects. 

 

Touch, tap, and mouse listener objects have a third entangled/clone dynamic object hierarchy that lives in front of the canvas that forward these events, as objects being drawn in a canvas texture loose their ability to receive tap, touch and mouse events by normal means. 

 

Fill and effect proxy tables forward respective changes to both worlds as well. Normal objects always have a default effect that fixes normal vector map individually based on local camera rotation, (Which essentially is like a "content rotation") and setting a new effect to an object will stack the rotation fix shader on the normal version of the object, essentially having two effects in the normal object.

 

Ambient occlusion is pre baked in the editor, as realtime AO was developed and tested but there were significant frame drops, probably can be optimized more, but will leave the realtime part of it disabled for now. Ambient occlusion adds more depth to the world:

 

In editor:

Attached File  Screen Shot 2019-10-24 at 4.12.47 PM.jpg   197.99KB   0 downloads

 

In game (Ambient light was adjusted):

Attached File  Screen Shot 2019-10-24 at 4.45.17 PM.jpg   130.73KB   0 downloads

 

As you can read, the engine contains a lot of moving parts which i need to carefully review so that i can deliver a bug-free release. Can't wait to release it for others to try it out!

 


  • StarCrunch likes this

[TOPIC: post.html]
#24

Rob Miracle

[GLOBAL: userInfoPane.html]
Rob Miracle
  • Moderator

  • 26,392 posts
  • Enterprise

Slick!


  • basiliogerman likes this

[TOPIC: post.html]
#25

sporkfin

[GLOBAL: userInfoPane.html]
sporkfin
  • Contributor

  • 661 posts
  • Corona SDK

Beautiful, sign me up for beta testing!


  • basiliogerman likes this


[topic_controls]
Page 1 of 2 1 2
 
[/topic_controls]