Dynamic Shader - in the Marketplace now!

Great! :slight_smile:
Hope this will get some attention from the devs

----- Add a light source  to the Dynamic Shader  -----
local light = display.newCircle( 350, 200, 50 )

light:setFillColor( 1, 1, 1 )

local table = {1, 1, 1}

dynamic_shader.setLightColor( table )dynamic_shader.addLight(light)dynamic_shader.setLightRadius(1500)

@toril.swift - Hi , there a question to accompany the code?

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

Great! :slight_smile:
Hope this will get some attention from the devs