1. Post #1
    Gold Member

    June 2007
    4,281 Posts

    What are these mysterious entities, you ask? Well, these things are LightSpheres: they forge a magical field of light around them, using lots of beautiful light sources which orbit the core of the LightSphere. These rotating orbs will form all kinds of different patterns when time progresses. Every LightSphere has a different pattern. You can change the color of the LightSpheres with the Color tool. I shall give you some pictures.


    Eager to try it out? Wait no longer and download it here:


    Installing is as easy as it gets. Drop the LightSphere folder in your addons folder... and you're done!

    Changelog:

    V1.1: Optimizations (thanks to various lua coders)

    Known issues:
    - The spheres eat FPS. Spawning more than 5 LightSpheres at a time will make your FPS drop to 20 and lower. Any coders who might help me with optimizing?
    - They look pretty boring without bloom on, so TURN THAT SHIT ON! (and lower Darken Amount to 0.14)

    Rate, comment, whatever
    (also, if you use this for a pose or a machinima or something, please notify me! I'm curious )

    Video by Hydrochlorider:
    Reply With Quote Edit / Delete Reply Netherlands Show Events Artistic x 47Dumb x 2Agree x 1Late x 1Optimistic x 1 (list)

  2. Post #2
    Taught by John Lua
    MakeR's Avatar
    May 2007
    2,680 Posts
    Nice, I like it.
    Reply With Quote Edit / Delete Reply United Kingdom Show Events Agree Agree x 2 (list)

  3. Post #3
    decyg's Avatar
    September 2009
    865 Posts
    Bloody beautiful.
    Reply With Quote Edit / Delete Reply United Kingdom Show Events Agree Agree x 1 (list)

  4. Post #4
    Hugh Mann's Avatar
    April 2010
    90 Posts
    This is incredibly sexy :gizz:
    Reply With Quote Edit / Delete Reply United Kingdom Show Events Funny Funny x 2Agree Agree x 2Dumb Dumb x 1 (list)

  5. Post #5
    open.gl
    Overv's Avatar
    February 2007
    6,848 Posts
    Very nice, I'll go see if I can optimize it.
    Reply With Quote Edit / Delete Reply Netherlands Show Events Friendly Friendly x 1 (list)

  6. Post #6
    Gold Member
    Mikesword221's Avatar
    April 2009
    3,578 Posts
    :aaa:

  7. Post #7
    MCZorba's Avatar
    November 2007
    82 Posts
    These are hot! Not sure what they can be used for, but nice job anyhow.

  8. Post #8
    Gold Member
    ~ZOMG's Avatar
    December 2009
    9,154 Posts
    Really nice work, dude.

    This looks awesome.

  9. Post #9

    May 2010
    2 Posts
    Pretty nice addon and it's also beautiful with the colors.

  10. Post #10
    Kude's Avatar
    April 2008
    791 Posts
    -snip-

    Looks nice! I think I'll DL it.

  11. Post #11
    Dennab
    February 2010
    7,163 Posts
    This is pure intersecks

  12. Post #12
    CapsAdmin's Avatar
    August 2005
    4,149 Posts
    I think the reason this lags is because of math.NormalizeAngle.

    Might also be sprites, you can try to use particles instead.

  13. Post #13
    Holy sh-:gizz:
    Thats awesome.

  14. Post #14
    open.gl
    Overv's Avatar
    February 2007
    6,848 Posts
    I think the reason this lags is because of math.NormalizeAngle.

    Might also be sprites, you can try to use particles instead.
    Yeah, it's definitely the rendering. I've done some benchmarking and the stuff in the loop takes such a small amount of time, os.clock() usually can't even measure it.

  15. Post #15
    Gold Member
    Wizey!'s Avatar
    October 2008
    2,007 Posts
    Looks brilliant.

    Cant wait to dazzle up gm_flatgrass with them :3:

  16. Post #16
    CapsAdmin's Avatar
    August 2005
    4,149 Posts
    Yeah, it's definitely the rendering. I've done some benchmarking and the stuff in the loop takes such a small amount of time, os.clock() usually can't even measure it.
    But math.NormalizeAngle is pretty heavy.

    I tried using particles with this, and a for i=500 loop the math.normalize angle kills my gmod and it won't stop lagging either when it's done. I have to rejoin.

  17. Post #17
    Gold Member

    June 2007
    4,281 Posts
    I'm going to bed now, thanks for the positive reactions! I thought nobody would find a use for it but I was wrong
    I'll look at the optimizing stuff tomorrow.

  18. Post #18
    open.gl
    Overv's Avatar
    February 2007
    6,848 Posts
    Look at that... FPS.



    As CapsAdmin pointed out, the math.NormalizeAngle function is the bottleneck, because it's horribly written. Replace line 36 in cl_init.lua with this and you will experience an FPS increase of roughly 50%:

    local Forward = Angle( Ang * Seed1, Ang * Seed2, 0 ):Forward()
    Reply With Quote Edit / Delete Reply Netherlands Show Events Useful Useful x 1 (list)

  19. Post #19
    kolipoki7's Avatar
    December 2009
    287 Posts
    god. they are beutiful :D yet misterious

    also it looks nice for a machinimas

  20. Post #20
    adamfiru's Avatar
    November 2009
    167 Posts
    I did this


    not too great but meh
    Reply With Quote Edit / Delete Reply United States Show Events Artistic Artistic x 4Funny Funny x 1Dumb Dumb x 1 (list)

  21. Post #21
    Gold Member
    Gbps's Avatar
    December 2008
    3,433 Posts
    10 lines of code makes this? Amazing
    Reply With Quote Edit / Delete Reply United States Show Events Bad Reading Bad Reading x 1 (list)

  22. Post #22
    I can resist everything except temptation
    norzone's Avatar
    January 2008
    3,528 Posts
    Holy shi-

    The FPS drop is worth it.
    Reply With Quote Edit / Delete Reply Norway Show Events Dumb Dumb x 1 (list)

  23. Post #23
    yakahughes's Avatar
    April 2008
    1,313 Posts
    FREAKING WIN. This is absolutely awesome.

    Edited:

    The logo thing is sweet too. Very very nice work Dlaor, I don't even mind that you put your name on the logo.
    Reply With Quote Edit / Delete Reply United States Show Events Dumb Dumb x 1 (list)

  24. Post #24
    foxcock
    Bletotum's Avatar
    June 2008
    5,903 Posts
    Most of the time the spheres are unintelligible patterns of chaos, but it's worth the wait when they gain more structure.

  25. Post #25
    I love Lemon Punch
    Sakarias88's Avatar
    January 2006
    1,179 Posts
    Looks great!
    So pretty.

  26. Post #26
    King of the Oil Refinery
    Tobba's Avatar
    December 2008
    6,763 Posts
    Gonna try to optimize this a little, should be pretty easy

    Edited:

    tried to optimize it, cl_init:
    include( "shared.lua" )
    
    ENT.RenderGroup = RENDERGROUP_TRANSLUCENT
    
    local NormalizeAngle = math.NormalizeAngle
    local curTime = CurTime
    local dynamicLight = DynamicLight
    local SetMaterial = render.SetMaterial
    local DrawSprite = render.DrawSprite
    
    local GlowMat = Material( "sprites/light_glow02_add" )
    
    function ENT:Draw()
    
    	self:DrawShadow( false )
    	
    	local R, G, B, A = self:GetColor()
    	R = R / 255
    	G = G / 255
    	B = B / 255
    	A = A / 255
    	
    	SetMaterial( GlowMat )
    	local Seed1 = self:GetDTFloat( 0 )
    	local Seed2 = self:GetDTFloat( 1 )
    
    	for i = 1, 180 do
    		local Ang = ( self:EntIndex() + 1337 + curTime() ) * i //Yeah, random math makes awesome shit!
    		local Size = ( 155 - i ) / 6 
    		local Forward = Angle( NormalizeAngle( Ang * Seed1 ), NormalizeAngle( Ang * Seed2 ), 0 ):Forward()
    		local Pos = self:GetPos() + Forward * i * 0.09
    		local Gray = i / 150 * 255
    		Gray = Color( Gray * R, Gray * G, Gray * B, Gray * A )
    		DrawSprite( Pos, Size, Size, Gray )
    	end
    
    end
    
    function ENT:Think()
    	local R, G, B, A = self:GetColor()
    	R = R / 255
    	G = G / 255
    	B = B / 255
    	A = A / 255
    	local DLight = dynamicLight( self:EntIndex() )
    	if ( DLight ) then
    		DLight.Pos = self:GetPos()
    		DLight.r = R * 255
    		DLight.g = G * 255
    		DLight.b = B * 255
    		DLight.Brightness = A
    		DLight.Size = 128
    		DLight.Decay = 512
    		DLight.DieTime = curTime() + 1
    	end
    end

  27. Post #27
    Strong Member
    thelinx's Avatar
    January 2007
    2,175 Posts
    function ENT:Draw()
    	self:DrawShadow( false )
    Just curious, does this need to be set every time the entity draws?

  28. Post #28
    King of the Oil Refinery
    Tobba's Avatar
    December 2008
    6,763 Posts
    Not sure, but im pretty sure it dosent hit the performance much

  29. Post #29
    CapsAdmin's Avatar
    August 2005
    4,149 Posts
    It's not enough. math.NormalizeAngle is just bad and it doesn't matter if you localize it. Look at the source of it, it's pretty bad.

  30. Post #30
    Strong Member
    thelinx's Avatar
    January 2007
    2,175 Posts
    Redefine it?

  31. Post #31
    King of the Oil Refinery
    Tobba's Avatar
    December 2008
    6,763 Posts
    function math.NormalizeAngle( a )
    
    	while (a < 0) do
    		a = a + 360
    	end
    	
    	while (a >= 360) do
    		a = a - 360
    	end
    	
    	if ( a > 180 ) then
    		return a - 360
    	end
    
    	return a
    	
    end

    Indeed its shitty
    Reply With Quote Edit / Delete Reply Sweden Show Events Bad Spelling Bad Spelling x 1 (list)

  32. Post #32
    Strong Member
    thelinx's Avatar
    January 2007
    2,175 Posts
    -i probably misunderstood-snip-
    Reply With Quote Edit / Delete Reply Sweden Show Events Bad Spelling Bad Spelling x 1 (list)

  33. Post #33
    Taught by John Lua
    MakeR's Avatar
    May 2007
    2,680 Posts
    function math.NormalizeAngle( a )
    
    	while (a < 0) do
    		a = a + 360
    	end
    	
    	while (a >= 360) do
    		a = a - 360
    	end
    	
    	if ( a > 180 ) then
    		return a - 360
    	end
    
    	return a
    	
    end

    Indeed its shitty
    That is pretty shitty. Here is a better version that you can use to replace the old one.

    function math.NormalizeAngle(a)
        a = a%360
        if a > 180 then
            a = a - 360
        end
        return a
    end

  34. Post #34
    King of the Oil Refinery
    Tobba's Avatar
    December 2008
    6,763 Posts
    function math.NormalizeAngle(a) return ((a+180)%360)-180 end

    works too

  35. Post #35
    Taught by John Lua
    MakeR's Avatar
    May 2007
    2,680 Posts
    function math.NormalizeAngle(a) return ((a+180)%360)-180 end

    works too
    Actually, it doesn't. well... it works with all cases apart from one, If you pass it 180, it returns -180. My one doesn't.
    Reply With Quote Edit / Delete Reply United Kingdom Show Events Bad Spelling Bad Spelling x 1 (list)

  36. Post #36
    King of the Oil Refinery
    Tobba's Avatar
    December 2008
    6,763 Posts
    debug.sethook()
    
    local function A(a)
        a = a%360
        if a > 180 then
            a = a - 360
        end
        return a
    end
    
    local time = SysTime()
    
    for i=1, 1000000 do A(1000) end
    
    print(SysTime()-time)
    
    local function B(a)
    	return ((a+180)%360)-180
    end
    
    local time = SysTime()
    
    for i=1, 1000000 do B(1000) end
    
    print(SysTime()-time)

    0.159912109375
    0.143798828125

    Not sure if mine always outputs the right value though

    Edited:

    awww yeah

    Edited:

    debug.sethook()
    
    local function A(a)
        a = a%360
        if a > 180 then
            a = a - 360
        end
        return a
    end
    
    local time = SysTime()
    
    for i=1, 1000000 do A(1000) end
    
    print(SysTime()-time)
    
    local B = math.NormalizeAngle
    
    local time = SysTime()
    
    for i=1, 1000000 do B(1000) end
    
    print(SysTime()-time)


    0.15869140625
    0.2099609375

    Garrys is much slower

    Edited:

    More optimized (using MakeR's function and another thing)
    include( "shared.lua" )
    
    ENT.RenderGroup = RENDERGROUP_TRANSLUCENT
    
    local NormalizeAngle = function(a)
        a = a%360
        if a > 180 then
            a = a - 360
        end
        return a
    end
    
    local curTime = CurTime
    local dynamicLight = DynamicLight
    local SetMaterial = render.SetMaterial
    local DrawSprite = render.DrawSprite
    local angle = Angle
    local color = Color
    
    local GlowMat = Material( "sprites/light_glow02_add" )
    
    function ENT:Draw()
    
    	self:DrawShadow( false )
    	
    	local R, G, B, A = self:GetColor()
    	R = R / 255
    	G = G / 255
    	B = B / 255
    	A = A / 255
    	
    	SetMaterial( GlowMat )
    	local Seed1 = self:GetDTFloat( 0 )
    	local Seed2 = self:GetDTFloat( 1 )
    	local curtime = curTime()
    
    	for i = 1, 180 do
    		local Ang = ( self:EntIndex() + 1337 + curtime ) * i //Yeah, random math makes awesome shit!
    		local Size = ( 155 - i ) / 6 
    		local Forward = angle( NormalizeAngle( Ang * Seed1 ), NormalizeAngle( Ang * Seed2 ), 0 ):Forward()
    		local Pos = self:GetPos() + Forward * i * 0.09
    		local Gray = i / 150 * 255
    		Gray = color( Gray * R, Gray * G, Gray * B, Gray * A )
    		DrawSprite( Pos, Size, Size, Gray )
    	end
    
    end
    
    function ENT:Think()
    	local R, G, B, A = self:GetColor()
    	R = R / 255
    	G = G / 255
    	B = B / 255
    	A = A / 255
    	local DLight = dynamicLight( self:EntIndex() )
    	if ( DLight ) then
    		DLight.Pos = self:GetPos()
    		DLight.r = R * 255
    		DLight.g = G * 255
    		DLight.b = B * 255
    		DLight.Brightness = A
    		DLight.Size = 128
    		DLight.Decay = 512
    		DLight.DieTime = curTime() + 1
    	end
    end

    Edited:

    edited for even more optimization

  37. Post #37
    Taught by John Lua
    MakeR's Avatar
    May 2007
    2,680 Posts
    Even more optimised, although it will make little difference.

    include( "shared.lua" )
    
    ENT.RenderGroup = RENDERGROUP_TRANSLUCENT
    
    local NormalizeAngle = function(a)
        a = a%360
        if a > 180 then
            a = a - 360
        end
        return a
    end
    
    local curTime = CurTime
    local dynamicLight = DynamicLight
    local SetMaterial = render.SetMaterial
    local DrawSprite = render.DrawSprite
    local angle = Angle
    local color = Color
    
    local GlowMat = Material( "sprites/light_glow02_add" )
    
    function ENT:Draw()
    
    	self:DrawShadow( false )
    	
    	local R, G, B, A = self:GetColor()
    	R = R / 255
    	G = G / 255
    	B = B / 255
    	A = A / 255
    	
    	SetMaterial( GlowMat )
    	local Seed1 = self:GetDTFloat( 0 )
    	local Seed2 = self:GetDTFloat( 1 )
    	local curtime = curTime()
    	local pos = self:GetPos()
    	local id = self:EntIndex()
    	
    	for i = 1, 180 do
    		local Ang = ( id + 1337 + curtime ) * i
    		local Size = ( 155 - i ) / 6 
    		local Forward = angle( NormalizeAngle( Ang * Seed1 ), NormalizeAngle( Ang * Seed2 ), 0 ):Forward()
    		local Pos = pos + Forward * i * 0.09
    		local Gray = i / 150 * 255
    		Gray = color( Gray * R, Gray * G, Gray * B, Gray * A )
    		DrawSprite( Pos, Size, Size, Gray )
    	end
    
    end
    
    function ENT:Think()
    	local R, G, B, A = self:GetColor()
    	R = R / 255
    	G = G / 255
    	B = B / 255
    	A = A / 255
    	local DLight = dynamicLight( self:EntIndex() )
    	if ( DLight ) then
    		DLight.Pos = self:GetPos()
    		DLight.r = R * 255
    		DLight.g = G * 255
    		DLight.b = B * 255
    		DLight.Brightness = A
    		DLight.Size = 128
    		DLight.Decay = 512
    		DLight.DieTime = curTime() + 1
    	end
    end

    It doesn't call EntIndex or GetPos 180 times a frame now.
    Reply With Quote Edit / Delete Reply United Kingdom Show Events Optimistic Optimistic x 2 (list)

  38. Post #38
    Strong Member
    thelinx's Avatar
    January 2007
    2,175 Posts
    local NormalizeAngle = function(a)
    why
    Reply With Quote Edit / Delete Reply Sweden Show Events Bad Spelling Bad Spelling x 1 (list)

  39. Post #39
    King of the Oil Refinery
    Tobba's Avatar
    December 2008
    6,763 Posts
    That is probbably as optimized as it can get

    Edited:

    Original is slow

  40. Post #40
    Strong Member
    thelinx's Avatar
    January 2007
    2,175 Posts
    I mean why not
    local function NormalizeAngle(a)
    Reply With Quote Edit / Delete Reply Sweden Show Events Bad Spelling Bad Spelling x 1 (list)