Dynamic Shader - in the Marketplace now!

Great!  Thanks Paul.  I’m also still investigating sprite sheets but the composite effects fill for Corona asks specifically for image files.  There might be a way around this. . .  I’ll keep you posted.

Image sheets:

Short answer:  Unfortunately, I don’t plan on supporting image sheets for the Dynamic Shader in the near future.

Long answer:  The graphics 2.0 composite.fill.effect parameters require a “type” (like “image”) and a location of the image files.  Since image sheets are one big file, I have to break up the sprites and normal maps on those sheets and re-save them as graphics files in the Document Directory before loading them into the shader which defeats the whole purpose of image sheets.  I’m experimenting with canvases but it looks like they will also bloat the Document Directory if I have to save then and then create a path.

I’ll keep experimenting but I’m moving this challenge to the back burner.

Thanks everyone!

Jonathan

No problem. I got the Dynamic Shader to work in my project just fine.

I noticed that on 1st Gen Apple products or older devices like the iPhone 5S that the Dynamic Shader dramatically slows down the game. Almost making it unplayable with a moving light source. But I did some experimenting… I made the light source not move .I stop the Shader right after the match 3 board is visible.

The Shader still SHADES the gem pieces even while the Dynamic Shader is stopped!

Some levels I have the light source turn off and on to make the game harder. So I noticed you have to turn the Shader ON when you move the light source then I instantly turn it OFF. This is part of the code:

Match3.ShaderLightSource.x = math.random(0, device)

dynamic_shader.start()
dynamic_shader.setLightRadius( math.random(2500, 3500) )

timer.performWithDelay( 1, function() dynamic_shader.stop() end)

But the stop has to happen a millisecond later. So now the game works super fast on the 1st gen apple devices and older iPhone 5S devices.

Does this sound right to you Jonathan? Does the Shader still Shade the objects when it is stopped as long as the light source doesn’t move or the radius of the light doesn’t change? Do you only have to turn the shader ON when you move the light or change the light radius?

Thanks for a wonderful plugin :slight_smile:

Jeff

Hey Jeff, 

I’m glad you are putting the Dynamic Shader to use.  The DS works by using composite images (one of your art and the other the normal map) so when you stop the DS the composite image (in this case the shaded image) “freezes” where it is.  With the DS stopped, the image will not be updated to reflect changes in positioning, rotation or lighting, however it will keep the shading effect from the moment the DS was stopped.  

To return to a non-shaded object you have to remove the object from the DS via removeObject( )

[lua]

shader.removeObject( object ) – remove object to the Dynamic Shader

[/lua]

You then have to use addObject( ) to return the object to the DS after adding the object.shadeInfo again.

[lua]

-----add shaderInfo table to object------

object.shaderInfo = { – create the object.shaderInfo table

name = “object”, – optional parameter - gives the object a name or the shader will assign one

map1 = “art/object.png”, – reference the image file

map2 = “art/object_n.png” – refernece the normal map file

}


shader.addObject( object ) – add object to the Dynamic Shader

[/lua]

I’ve been thinking of adding an “object pause” or something like

[lua]

object.shaderInfo.pause = true

[/lua]

which would preserve the object.shaderInfo table but otherwise remove the object from the DS until object.shaderInfo.pause = false.

Would something like that be useful?

As for the slowdown in older devices, were you using physics objects?  I’m thinking physics objects or old OpenGL processors could account for the slowdown.  It could also be that there is a lot of number crunching going on every frame, I was just surprised to hear that a 5s had slowdown trouble.  Keep on playing with the plugin and let me know how it goes, thanks Jeff!

Jonathan

Yeah you’re right. I didn’t realize my own work around I wasn’t actually moving any of my gems. LOL. I have a shader object for every gem at every position on the board. It appears like it’s moving. I show or hide the gem. When it drops I show the sprite image when it stops I hide the sprite object and show the shader object.
Yeah, it’s not the physics engine that slows down the iPhone 5s. But stopping the DS I made the game as fast as on the iPhone 6plus. I just can’t move the light back and forth.

**EDIT: The path was wrong, which caused the error - now it just says ‘no light source yet’ - working it.

Recently purchased the shader to use it as a light source on a Tiled map. The map doesn’t use a tilesheet but I’ve been unsuccessful.

Using the PonyTiled map loader, and the following code gives me an error.

 -- or load a tiled map local filename = system.pathForFile("scene/game/map/map1.json") local data = json.decodeFile(filename) map = ponytiled.new(data, "scene/game/map") map:centerObject("player") player = map:findObject("player") player:tofront() view:insert(map) dynamic\_shader.setDebugLevel( 2 ) player.shaderInfo = { map1 = "map/tiles/tile17.png", map2 = "map/tiles/tile17\_n.png", map3 = "map/tiles/tile18.png", map4 = "map/tiles/tile18\_n.png"} ------------------------------ dynamic\_shader.addObject(player) ----- Add a light source to the Dynamic Shader ----- local light = display.newCircle( 350, 200, 50 ) local colorTable = {1, 1, 1} light:setFillColor( colorTable ) dynamic\_shader.setLightColor( colorTable ) dynamic\_shader.addLight(light) ----- Start the Dynamic Shader ----- dynamic\_shader.start()

The error returned is 

Aug 01 08:11:52.878: WARNING: Failed to find image 'map/tiles/tile17.png' Aug 01 08:11:52.878: WARNING: Failed to find image 'map/tiles/tile17\_n.png' Aug 01 08:11:52.878: ERROR: Runtime error ?:0: attempt to index field 'fill' (a nil value) stack traceback: ?: in function 'addObject' /Users/grahamscott/Downloads/ponyblitz-master/scene/game.lua:53: in function '?' ?: in function 'dispatchEvent' ?: in function 'gotoScene' /Users/grahamscott/Downloads/ponyblitz-master/scene/menu.lua:22: in function 'listener' /Users/grahamscott/Downloads/ponyblitz-master/com/ponywolf/ponymenu.lua:153: in function '?' ?: in function \<?:182\>

Of interest, the tile17 images are in the same directory as the tile18 images, but 18 doesn’t give me an error!

(I get ‘not found’ on player too)

Any thoughts?

Hi Graham,

My hunch is that there is a problem loading the image from PonyTiled.

Try loading the player.shaderInfo table directly to see if that fixes the problem.  

[lua]

player.shaderInfo = {

     map1 = “direct link to tile17.png”,

     map2 = “direct link to tile17_n.png”}

[/lua]

If this fixes it, check your PonyTiled code.

*Note map3 and map4 will be ignored.  Dynamic Shader only looks at map1 and map2.

-Jonathan

I managed to figure it out. I moved the shader load to the tile load loop, and it’s working just fine now :slight_smile:

Shame I can’t have more than 1 light though, it looks pretty cool :P. -  some candles flickering would be a nice effect

Thanks for the prompt response. 

I’ll add a screenshot once I’ve tidied it a bit so that people can see what Dynamic Shader looks like on a Tiled map, it’s a nice effect.

I have a version 2.0 that I might release some day.  It has multiple lights, beams and flickers but has to be carefully managed as each element is computationally expensive.

I can’t wait to see the screen shots!

Here’s a couple of early screenshots. I played with some different layouts. I like the ‘full’ map, but the tiles show the lights as a but blocky (Likely my normals). 

The other was much simpler, but the lighting effect was more realistic.

Both of these were produced from a tiled map. I hope that a version 2 does make it one day :stuck_out_tongue: As you can imagine a couple of candles on a Tiled level would look wicked.

Definitely a few opportunities as it is anyway. It makes for a much improved atmosphere!

** Edit to show people HOW I added it to a tiled map, it isn’t rocket science, but it is when you don’t know how :stuck_out_tongue:

For those who wondered how, I used PonyTiled, and in the PonyTiled.lua module I added this code around 189 (in the ObjectGroup condition). Adding the light source can be done in your main routine.

if layer.name ~= "movables" and layer.name ~="power" then local shader1 = "scene/game/map/"..gid local shader2 = "scene/game/map/"..string.sub( gid, 1,13).."n"..string.sub( gid, 17) image.shaderInfo = { map1 = shader1, map2 = shader2} dynamic\_shader.addObject(image) end

To note: This will ONLY work when you are using tiles, NOT a timesheet.

My shader file names are a bit hokey, but that was because I misnamed them and was too lazy to rename all the tiles!

Be warned that this also gets added to EVERY tile in the layers I"m selecting, so if you have a huge map, I don’t know whether that will work processor wise. My simpler looking screen uses a LOT less map blocks, so caveat emptor.

Nice work Graham!  Keep us posted.

Hi,
we would like to bring some light effects into our RPG game.
We use the “Million Tile Engine - MTE” to load our maps and sprites.
Using the “Dynamic Shader” for that will not work I guess?
All the map tiles are made of tileset imagesheets.
Is there really no way to use that normal maps stuff for image sheets in corona?
And can’t we push the corona developers to make this possible?
Please dear corona devs :slight_smile:

best regards

Dima

Per my screen shots above, I am able to use it with Tiled using the images as embedded tiles, NOT tile sheets. I don’t recall if MTE lets you use images or only sheets. If you can go the image route, you can get it done.

It would be a huuge rework for me to make all the map tiles as single images instead of sprites of a tileset and I don’t know if its possible with MTE like this.
Also all the character sprites are sheets, it feels not right this way.
Rather I guess its a better way when Corona would support the sheet thing.

Hey Jonathan,
I was just about to write feedback to Corona regarding the problem that you mentioned on the first page.

Long answer:   The graphics 2.0 composite.fill.effect parameters require a “type” (like “image”) and a location of the image files.  Since image sheets are one big file, I have to break up the sprites and normal maps on those sheets and re-save them as graphics files in the Document Directory before loading them into the shader which defeats the whole purpose of image sheets.  I’m experimenting with canvases but it looks like they will also bloat the Document Directory if I have to save then and then create a path.

Then I found this here:
http://feedback.coronalabs.com/forums/188732-corona-feature-requests-feedback/suggestions/15340473-image-sheet-fills

Is this guy talking about the same issue?
If yes, the corona guys answered with a solution I think.

Can you take a look on that? :smiley:

Would love to purchase the Dynamic Shader module when the sheet thing would work.

Ah and the multiple lights think would be also veeery interesting for me.

Thank you

@Dimahh90 Unfortunately, that solution is for sprite fills and not composite fills.

Hey Jonathan,
thanks for the fast reply.
Ok, I will write the feedback and hope they can make it.

Hey :slight_smile:
so I wrote the feedback now.
http://feedback.coronalabs.com/forums/188732-corona-feature-requests-feedback/suggestions/31093474-support-for-image-sheets-in-composite-fill-effect

Let’s vote for it! :slight_smile:

You have my votes @Dimahh90

Added 3 more votes too.