Simple 2D Lighting

what about the quad scripts (.vp and .fp)? which content?

4 posts were split to a new topic: Water effect

How can I get this result:
combination

front sprite should not be transparent
he should be black
How can I do it?

One solution could be to draw the background to one render target, the player to a second and the lava to a third render target. You render the player and the lava render targets onto the background and either draw as is from the player target or with rgb set to 0.0 depending on lava or not. And finally you apply the lights.

2 Likes

add some flicker to the light,
not all objects of light (selectively)
how to do it?

I don’t really understand your question. Could you please elaborate?

If you mean something like flickering light from e.g. fire, there is no problem - you have a game object with a sprite that has a light material, right? Then animate GO’s scale up and down relatively quick :wink:

I mean this piece of code:

function update(self)
...
    -- draw lights
	render_to_rt(self, self.light_rt, function(self)
		clear(AMBIENT_LIGHT, nil, nil)
		-- add some flicker to the light
		local constants = render.constant_buffer()
		constants.time = vmath.vector4(math.random(90, 100) / 100)
		render_to_world(self, { self.light_pred }, constants)
	end)
end

Yes it adds some variation. Do you wish to disable it?

I would like to be able to disable it on some game objects.
for example, create new material light2.material, and it will not flicker
but I don’t know how I can correctly specify this new material in postprocess.render_script.
I would appreciate the help… thanks!

Looks like the simple lighting example no longer works, any ideas on what has changed to cause these errors?

ERROR:CRASH: CALL STACK:

# 0 pc   0x3e0a85bd SharedFileList _sigtramp+29
# 1 pc     0x10eba8 dmengine _ZN8dmRender4DrawEPNS_13RenderContextEPNS_9PredicateEPNS_19NamedConstantBufferE+392
# 2 pc     0x10e6e1 dmengine _ZN8dmRender14DrawRenderListEPNS_13RenderContextEPNS_9PredicateEPNS_19NamedConstantBufferE+2545
# 3 pc     0x1135dd dmengine _ZN8dmRender13ParseCommandsEPNS_13RenderContextEPNS_7CommandEj+733
# 4 pc     0x11807a dmengine _ZN8dmRender26UpdateRenderScriptInstanceEPNS_20RenderScriptInstanceEf+170
# 5 pc       0x4aff dmengine _ZN8dmEngine4StepEPNS_6EngineE+975
# 6 pc      0x7d946 dmengine _ZN10dmGraphicsL24OpenGLRunApplicationLoopEPvPFvS0_EPFiS0_E+38
# 7 pc       0x58f1 dmengine _ZN8dmEngine6LaunchEiPPcPFvPNS_6EngineEPvES6_S4_+177
# 8 pc       0x5d1f dmengine _Z11engine_mainiPPc+143
1 Like

Strange, I don’t know that we’ve changed anything that should make it crash. I’ll take look.

I tested the example simple_lights and it worked for me on my mac, using 1.2.170.

What project did you run? What platform are you on?

Here isa partial error log; (includes system info)

Process:               dmengine [8612]
Path:                  /Applications/Defold.app/Contents/MacOS/Defold
Identifier:            com.defold.editor
Version:               2.0 (2.0)
Code Type:             X86-64 (Native)
Parent Process:        java [8590]
Responsible:           Defold [8588]
User ID:               501
OS Version:            Mac OS X 10.15

System Integrity Protection: enabled

Crashed Thread:        0  engine_main  Dispatch queue: com.apple.main-thread

Exception Type:        EXC_BAD_ACCESS (SIGSEGV)
Exception Codes:       EXC_I386_GPFLT
Exception Note:        EXC_CORPSE_NOTIFY

Termination Signal:    Segmentation fault: 11
Termination Reason:    Namespace SIGNAL, Code 0xb
Terminating Process:   exc handler [8612]

Thread 0 Crashed:: engine_main  Dispatch queue: com.apple.main-thread
0   dmengine                      	0x000000010673db83 dmRender::Draw(dmRender::RenderContext*, dmRender::Predicate*, dmRender::NamedConstantBuffer*) + 355
1   dmengine                      	0x000000010673d6e1 dmRender::DrawRenderList(dmRender::RenderContext*, dmRender::Predicate*, dmRender::NamedConstantBuffer*) + 2545
2   dmengine                      	0x00000001067425dd dmRender::ParseCommands(dmRender::RenderContext*, dmRender::Command*, unsigned int) + 733
3   dmengine                      	0x000000010674707a dmRender::UpdateRenderScriptInstance(dmRender::RenderScriptInstance*, float) + 170
4   dmengine                      	0x0000000106633aff dmEngine::Step(dmEngine::Engine*) + 975
5   dmengine                      	0x00000001066ac946 dmGraphics::OpenGLRunApplicationLoop(void*, void (*)(void*), int (*)(void*)) + 38
6   dmengine                      	0x00000001066348f1 dmEngine::Launch(int, char**, void (*)(dmEngine::Engine*, void*), void (*)(dmEngine::Engine*, void*), void*) + 177
7   dmengine                      	0x0000000106634d1f engine_main(int, char**) + 143
8   dmengine                      	0x0000000106630674 start + 52

Model: MacBookPro16,1, BootROM 1517.0.0.115.1 (iBridge: 18.16.10310.5.15,0), 8 processors, 8-Core Intel Core i9, 2.3 GHz, 16 GB, SMC 
Graphics: kHW_IntelUHDGraphics630Item, Intel UHD Graphics 630, spdisplays_builtin
Graphics: kHW_AMDRadeonPro5500MItem, AMD Radeon Pro 5500M, spdisplays_pcie_device, 4 GB

I just tested, it works fine when I build it first, then run the build. It only fails when loading from debug.

What do you mean by this?

When I use “Debug->Start/Attach” it no workie.

If I “Project->Build” it workie.

1 Like

After some messing around, I’ve narrowed it down to this block of code that cause the issue;

-- add some flicker to the light
local constants = render.constant_buffer()
constants.time = vmath.vector4(math.random(90, 100) / 100)
render_to_world(self, { self.light_pred }, constants)

if I comment it out and do just;
render_to_world(self, { self.light_pred })

I don’t have any issues.