ID:2178814
 
(See the best response by Lummox JR.)
Code:
var/const
LIGHTLEVELDARK = rgb(null,null,null,200)
LIGHTLEVELMEDDARK = rgb(null,null,null,150)
LIGHTLEVELMED = rgb(null,null,null,100)
LIGHTLEVELMEDBRIGHT = rgb(null,null,null,50)
LIGHTLEVELBRIGHT = rgb(null,null,null,0)

obj/lighting_plane
screen_loc = "1,1"
plane = 2
blend_mode = BLEND_MULTIPLY
appearance_flags = PLANE_MASTER | NO_CLIENT_COLOR
color = list(null,null,null,null,LIGHTLEVELDARK)
mouse_opacity = 0

image/spotlight
plane = 2
blend_mode = BLEND_ADD
icon = 'spotlight.dmi' // a 96x96 white circle
pixel_x = -32
pixel_y = -32


This results in a purely dark exterior and a sudden change to a completely bright within the circle. So I tried to make a gradient radial type solution and the closest I could get was...

Code:
var/const
LIGHTLEVELDARK = rgb(null,null,null,200)
LIGHTLEVELMEDDARK = rgb(null,null,null,150)
LIGHTLEVELMED = rgb(null,null,null,100)
LIGHTLEVELMEDBRIGHT = rgb(null,null,null,50)
LIGHTLEVELBRIGHT = rgb(null,null,null,0)

obj/lighting_plane
screen_loc = "1,1"
plane = 2
blend_mode = BLEND_MULTIPLY
appearance_flags = PLANE_MASTER | NO_CLIENT_COLOR
color = list(null,null,null,null,LIGHTLEVELDARK)
mouse_opacity = 0

image/spotlight
plane = 3 //<------INSTEAD OF 2
blend_mode = BLEND_MULTIPLY // <----INSTEAD OF BLEND_ADD
icon = 'spotlight.dmi' // a 96x96 pattern of white circles with diff alpha
pixel_x = -32
pixel_y = -32

Now keep in mind! On this one 'spotlight.dmi' is a 96x96 full solid white background with a series of circles getting closer to fully alpha as it gets closer to the middle ending with alpha 1 because 0 goes back to completely dark.

This provides an almost better effect and is the only way I have found to make the light gradually stronger as it gets closer to the player but This does not seem to be the way most lighting is done and still has a little bit of darkness left over in even the brightest of area in the middle my next attempt will be to add a second spotlight on plane 4 with a blend_mode = BLEND_ADD to totally clean out the middle. Any suggestions before I proudly barbarian code my way to a result?


Best response
Your color matrix is being built incorrectly.

First, the various light level consts are specifying all black with an alpha value; it's not actually alpha that you want to change on your lighting plane. Second, the lighting plane's matrix should be setting the alpha value to 0 across the board in the fourth argument.

For a lighting plane that has a 20% gray ambient light, you would use a color matrix like this:

color = list(null, null, null, "#0000", "#333f")

In this short-form matrix, each item represents a row: red, green, and blue are left alone. The alpha row is completely eliminated, because you don't want to preserve alpha. Then a constant of #333f (20% gray and full alpha) is added to the total.

The spotlight really should be on the same plane as your plane master for lighting, and should have BLEND_ADD. That was correct the first time. The problem you had was the incorrect matrix and the lack of a backdrop.
The appearance_flags var (atom) help file has the following
color = list(null,null,null,null,"#333f")

I am just now reading it closer along with your other post and I understand what you are saying. My second piece of code actually gets pretty close to the fading effect if you use multiple circle going from solid white outside to barely visible inside. Now let me try it the correct way. By the way below is the help file just to understand the help file isn't incorrect their is just a smoother way of doing it is what your saying right?

Thanks again!

appearance_flags var (atom)
obj/lighting_plane
screen_loc = "1,1"
plane = 2
blend_mode = BLEND_MULTIPLY
appearance_flags = PLANE_MASTER | NO_CLIENT_COLOR
// use 20% ambient lighting; be sure to add full alpha
color = list(null,null,null,null,"#333f")<--incorrect?
mouse_opacity = 0 // nothing on this plane is mouse-visible

image/spotlight
plane = 2
blend_mode = BLEND_ADD
icon = 'spotlight.dmi' // a 96x96 white circle
pixel_x = -32
pixel_y = -32

mob/Login()
..()
client.screen += new/obj/lighting_plane
overlays += /image/spotlight


This all works but it doesn't "fade" at all it is just a lit circle in the middle of the screen. Trying it your way after reading everything from your post here and on the other lighting tips post.
In response to Zamargo
Zamargo wrote:
The appearance_flags var (atom) help file has the following
color = list(null,null,null,null,"#333f")

Hrm. Did I not update that? I thought I had fixed that. The fourth argument should really be "#0000" to clear out any existing alpha.
I tried to understand your backdrop idea I really did, but I'm confused with most of it and I can't even get it to compile copy and pasted straight from your example. I will study it a bit and hopefully I will catch on.

proc/UpdateView(client/C)
var/vx,vy
var/obj/O = new
var/list/L = overlays.Copy()
O.appearance = L[1]
if(isnum(C.view)) vx = vy = (2*C.view) + 2//<--line45
else
L = splittext(C.view, "x")
vx = L[1] + 1
vy = L[2] + 1
O.transform = matrix(vx, 0, 0, 0, vy, 0)
overlays = list(O)


proc.dm:45:error: =: expected end of statement
proc.dm:45:error: missing left-hand argument to =.

I wish their was an easier way to make a backdrop I am totally confused with this UpdateView bit.
The "expected end of statement" error is an indicator you're using 510 and not 511; 511 supports chaining of assignment statements. All you have to do for 510 is change this line:

if(isnum(C.view)) vx = vy = (2*C.view) + 2

to this:

if(isnum(C.view))
vx = (2*C.view) + 2
vy = vx

The reason for the UpdateView() proc is to make sure the backdrop is scaled big enough. If you know the view will always be a certain size, you can just set the transform at compile-time and let it go.
PS: I may have had it working somewhere throughout the night I didn't realize I had to draw the fadeout by hand I thought it did it in code somewhere. AHHHHH! SHOOT ME

Okay got it not to error but it just shows a big white circle over my character now. Without MASTER_PLANE appearance flag in the lightning plane object it seems to do that every time.

When my mob logs in
//lighting
client.screen += src
var/obj/O = new
O.blend_mode = BLEND_OVERLAY // this is important so it doesn't inherit
O.icon = 'blackness.dmi' // a black icon using your regular world.icon_size
O.layer = BACKGROUND_LAYER
overlays += O
UpdateView(client)
client.screen += new/obj/lighting_plane
overlays += /image/spotlight


lighting
obj/lighting_plane
plane = 2 // or whatever plane you use for lighting
screen_loc = "CENTER"
blend_mode = BLEND_MULTIPLY
// this has an ambient light of 20% gray added to all lights
color = list(null, null, null, "#0000", "#333f")

image/spotlight
plane = 2
blend_mode = BLEND_ADD
icon = 'spotlight.dmi' // a 96x96 white circle
pixel_x = -32
pixel_y = -32



proc's
proc/UpdateView(client/C)
var/vx,vy
var/obj/O = new
var/list/L = usr.overlays.Copy()
O.appearance = L[1]
if(isnum(C.view))
vx = (2*C.view) + 2
vy = vx
else
L = splittext(C.view, "x")
vx = L[1] + 1
vy = L[2] + 1
O.transform = matrix(vx, 0, 0, 0, vy, 0)
usr.overlays = list(O)


I will fiddle with it tomorrow I am certain I am doing something wrong, but I am too tired to pinpoint it.
Why did you take PLANE_MASTER out of the appearance flags for the lighting plane object? That's critical.

That flag says: Gather everything else on this plane, render it to a temporary surface, and then render that result over the map using the plane master's blend_mode, color, etc.
I learned the odds & ends of the handling lighting via planes through Nadrew's library:

http://www.byond.com/developer/Nadrew/LightingTest

Give it a read through or drop it right into your project, it's optimized and has plenty of notes.
Lummox I think I am getting confused trying to merge a few different examples the reason I took it out is because in this post below where you explain backdrop in your lighting tips you have it taken out and I assumed that it was part of what made the backdrop work. Though I must say I tried putting back in plane master changing the order of everything changing everything from obj's to images, adding planes to objs, and every combination I could find that affects the visual I couldn't get to work yet. Going to try to get ahold of it gonna keep mesing around.

http://www.byond.com/forum/?post=2141928

IThanks flame guardian for all the extra examples. Thank you as well lummox yet again for trying to help me climb the ranks of a decent coder. So grateful for having such a nice community of folks here.
The backdrop itself does not have PLANE_MASTER; the backdrop is an overlay of the plane master.