I just wanted to make a quick post about a [URL="https://github.com/MysteryPancake/GMod-Rainbows"]GitHub thing I just set up[/URL]. It's a bunch of rainbow functions I made for you guys to use in whatever rainbow-related projects you might have lying around. Feel free to contribute your own rainbow-related functions if you have any, and have fun with them!
I wonder if you might further develop this through some optimization. For example, you could optionally render all of this only once into a texture and then only draw that texture in the requested screen space, so that the individual transitioning lines don't need recalculation.
I don't remember if you can render to a rendertarget once and it simply stick with the last seen render or if ceasing rendering to the RT means it goes blank. If it goes blank you could render to a .png file and then draw the png. Or just like, turn this into a function that generates smooth rainbow textures of the requested dimensions.
Well, optimization like that would be a very good idea, but I don't really know how to do that, I'll try that though, thanks for the idea!
[URL="https://github.com/MysteryPancake/GMod-Rainbows"]I added a few more functions to the thing[/URL], I'm quite happy that the DrawRainbowText one actually works. Maybe I'll try optimizing it soon, but rendering .png files and drawing them usually takes even longer than drawing a billion colored rects, so I don't really want to do it yet
[QUOTE=MPan1;50324385][URL="https://github.com/Mysterypancake1/GMod-Rainbows/blob/master/rainbow.lua"]I added a few more functions to the thing[/URL], I'm quite happy that the DrawRainbowText one actually works. Maybe I'll try optimizing it soon, but rendering .png files and drawing them usually takes even longer than drawing a billion colored rects, so I don't really want to do it yet[/QUOTE]
it doesn't take longer if you calculate the billion rects only once and thereafter only draw the generated png
Wow nice job! Thanks for sharing this :D
Why is everybody talking about generating pngs? You can already create materials, take a look at how I did rain.
[code]
function GM:RenderRain()
if RAIN_SETUP == false then
-- Create a new rain texture
local scaleDown = 1
local scaleUp = 1
for i = 0, RAIN_LAYERS do
local progress = (i / RAIN_LAYERS)
local inverse = 1 - progress
local RainRenderTarget = GetRenderTarget("CoopRainLayerN" .. tostring(i), ScrW(), ScrH(), false)
do -- Create rain texture
render.PushRenderTarget(RainRenderTarget)
--render.SuppressEngineLighting(true)
render.OverrideAlphaWriteEnable( true, true )
render.Clear(0, 0, 0, 0, true)
render.ClearDepth()
cam.Start2D()
local mat = Matrix()
mat:Translate(Vector(0,0,0))
mat:Scale( Vector(1, 1, 1) * scaleDown)
cam.PushModelMatrix(mat)
local alpha = ((progress * 70) * 0.4)
DbgPrint(alpha)
--for i = 0, (1024 * RAIN_DENSITY) do
for n = 0, ( (i + 1) * RAIN_DENSITY ) do
local x = math.random(0, ScrW() * scaleUp )
local y = math.random(0, ScrH() * scaleUp )
local z = 0
local pos = Vector(x, y, z)
--draw.DrawLine(pos, pos + Vector(1, 1, -2), Color(255, 255, 255), true)
if math.random(0, 10) == 0 then
--alpha = alpha + 60
end
local rainStep = 2
for p = 0, 10 do
local offset = (p * rainStep)
local mulitplier = 20 + alpha
surface.SetDrawColor(255, 255, 255, (1 - (p / 10)) * 20 )
surface.DrawLine( x, y + offset, x , y + offset + rainStep )
end
end
--if i % 2 == 0 then
-- Turns it black
--render.BlurRenderTarget(RainRenderTarget, 16, 16, 12)
--end
cam.PopModelMatrix()
--render.BlurRenderTarget(RainRenderTarget, 8, 8, 12)
cam.End2D()
render.OverrideAlphaWriteEnable( false )
--render.SuppressEngineLighting(false)
render.PopRenderTarget()
-- Blur the thing.
local params = {
--["$basetexture"] = "rain/coop_rain.vtf",
["$surfaceprop"] = "water",
["$surfaceprop2"] = "water",
["$translucent"] = 1,
["$bumpframe"] = 0,
["$alpha"] = 1,
Proxies =
{
TextureScroll =
{
texturescrollvar = "$basetexturetransform",
texturescrollrate = RAIN_SPEED, -- Rain mass?
texturescrollangle = (80 + math.random(1, 5)),
},
}
}
local mat = CreateMaterial("CoopRain__" .. CurTime(), "UnlitGeneric", params);
mat:SetTexture("$basetexture", RainRenderTarget)
table.insert(RAIN_TEXTURES, mat)
end
end
RAIN_SETUP = true
end
local ply = LocalPlayer()
render.UpdateScreenEffectTexture()
--render.SuppressEngineLighting(true)
for i, mat in pairs(RAIN_TEXTURES) do
local spacing = 32
local delta = 32
local offset = (delta * (i - 1))
-- Just return if it hasn't
--if ( spacing == self.spacing && offset == self.offset ) then return true end
local pos = ply:EyePos()
local ang = ply:EyeAngles()
ang.p = 0
local fwd = ang:Forward()
local back = -ang:Forward()
if ( ply:GetViewEntity() != ply ) then
pos = ply:GetViewEntity():GetPos()
fwd = ply:GetViewEntity():GetForward()
end
--render.UpdateRefractTexture()
//render.UpdateScreenEffectTexture()
render.SetMaterial( mat )
local shift = math.random(i * 10, 100)
--render.DrawSprite( pos, 1024 + (i * shift), 1024 + (i * shift), Color( 255, 255, 255 ) )
do -- Draw infront.
local pos1 = pos + ( fwd * spacing ) + ( fwd * offset )
pos1.x = alignCoord(pos1.x, spacing)
pos1.y = alignCoord(pos1.y, spacing)
pos1.z = alignCoord(pos1.z, spacing)
local up = pos1:Angle():Up()
local traceEnd = pos1 + (up * 1024)
local traceStart
local tr = util.TraceLine({
start = pos1,
endpos = pos1 + Vector(0, 0, 16384), -- TODO: Optimize me, we can estimate this number upfront by analysis later.
mask = MASK_SOLID_BRUSHONLY,
})
local renderQuad = false
if tr.Fraction < 1 then
if tr.HitSky then
renderQuad = true
end
end
if renderQuad then
--render.SetMaterial( mat )
fwd.x = math.Round(fwd.x)
fwd.y = math.Round(fwd.y)
fwd.z = 0
render.DrawQuadEasy(pos1, -fwd, ScrW(), ScrH(), Color(255, 255, 255), 20 )
end
--render.SetMaterial(MAT_WHITE)
--render.DrawQuadEasy(pos1, -fwd, 16, 16)
end
do -- Draw behind
--render.SetMaterial( mat )
-- We reduce the spacing here
local pos2 = pos + ( back * (spacing * 0.5) ) + ( back * offset )
pos2.x = alignCoord(pos2.x, spacing)
pos2.y = alignCoord(pos2.y, spacing)
fwd.x = math.Round(fwd.x)
fwd.y = math.Round(fwd.y)
fwd.z = 0
render.DrawQuadEasy(pos2, -back, ScrW(), ScrH(), Color(200, 200, 200), 20)
end
end
--render.SuppressEngineLighting(false)
end
[/code]
Its not perfect but it did the job.
[URL="https://github.com/MysteryPancake/GMod-Rainbows"]I added a new function to my rainbow-drawing thing.[/URL] It looks like this:
[IMG]http://i.imgur.com/J8JbKGL.png[/IMG]
It's incredibly slow to run, but was fun to find out the code that made it work. [URL="https://github.com/MysteryPancake/GMod-Rainbows/blob/master/README.md"]I also added pictures to my readme[/URL] so you can tell the functions apart (it'd be good if someone could help me with naming things, since I can't seem to do it very well myself).
[QUOTE=MPan1;50463586][URL="https://github.com/Mysterypancake1/GMod-Rainbows/blob/master/rainbow.lua#L144-L153"]I added a new function to my rainbow-drawing thing.[/URL] It looks like this:
[IMG]http://i.imgur.com/J8JbKGL.png[/IMG]
It's incredibly slow to run, but was fun to find out. [URL="https://github.com/Mysterypancake1/GMod-Rainbows/blob/master/README.md"]I also added pictures to my readme[/URL] so you can tell the functions apart (it'd be good if someone could help me with naming things, since I can't seem to do it very well myself).[/QUOTE]
You could just render them onto a render target and create a new material and render a Sprite/Quad with the given material, your function seem to be perfectly suitable to do that as they already use the surface library which is all 2d.
However I wouldn't change the code instead I would just utilize them as they are and they look perfectly fine.
Sorry, you need to Log In to post a reply to this thread.