Skip to content
Snippets Groups Projects
Commit 946f0b9a authored by DarkGod's avatar DarkGod
Browse files

Improved starfields

parent 3230257e
No related branches found
No related tags found
No related merge requests found
Showing with 229 additions and 25 deletions
......@@ -63,6 +63,7 @@ function _M:init(t, no_default)
self:learnTalent(self.T_SHERTUL_FORTRESS_ORBIT, true)
self:addParticles(Particles.new("shertul_fortress_orbiters", 1, {}))
if core.shader.allow("distort") then self:addParticles(Particles.new("shertul_fortress_engine", 1, {})) end
end
function _M:tooltip(x, y, seen_by)
......
......@@ -448,7 +448,7 @@ function _M:createFBOs()
self.fbo = core.display.newFBO(Map.viewport.width, Map.viewport.height)
if self.fbo then
self.fbo_shader = Shader.new("main_fbo")
if not self.fbo_shader.shad then self.fbo = nil self.fbo_shader = nil else core.particles.defineFramebuffer(self.fbo) end
if not self.fbo_shader.shad then self.fbo = nil self.fbo_shader = nil end
self.fbo2 = core.display.newFBO(Map.viewport.width, Map.viewport.height)
end
......@@ -457,6 +457,9 @@ function _M:createFBOs()
self.full_fbo = core.display.newFBO(self.w, self.h)
if self.full_fbo then self.full_fbo_shader = Shader.new("full_fbo") if not self.full_fbo_shader.shad then self.full_fbo = nil self.full_fbo_shader = nil end end
if self.fbo and self.fbo2 then core.particles.defineFramebuffer(self.fbo)
else core.particles.defineFramebuffer(nil) end
-- self.mm_fbo = core.display.newFBO(200, 200)
-- if self.mm_fbo then self.mm_fbo_shader = Shader.new("mm_fbo") if not self.mm_fbo_shader.shad then self.mm_fbo = nil self.mm_fbo_shader = nil end end
end
......@@ -639,6 +642,9 @@ function _M:changeLevelReal(lev, zone, params)
local st = core.game.getTime()
local sti = 1
-- Flush particles remaining to draw
core.particles.flushLast()
-- Finish stuff registered for the previous level
self:onTickEndExecute()
......@@ -1318,14 +1324,7 @@ function _M:setupCommands()
print("===============")
end end,
[{"_g","ctrl"}] = function() if config.settings.cheat then
local particle = engine.Particles.new("shader_square", 1, {life=600}, {type="fireball"})
particle.x, particle.y = game.player.x, game.player.y
game.level.map:addParticleEmitter(particle)
do return end
game:changeLevel(1, "stellar-system-shandral")
do return end
local f, err = loadfile("/data/general/events/crystaline-forest.lua")
local f, err = loadfile("/data/general/events/fearscape-portal.lua")
print(f, err)
setfenv(f, setmetatable({level=self.level, zone=self.zone}, {__index=_G}))
print(pcall(f))
......
......@@ -85,8 +85,12 @@ local changer = function(id)
post_process = function(level)
local Map = require "engine.Map"
local Quadratic = require "engine.Quadratic"
level.background_particle1 = require("engine.Particles").new("starfield_static", 1, {width=Map.viewport.width, height=Map.viewport.height, nb=300, a_min=0.5, a_max = 0.8, size_min = 1, size_max = 3})
level.background_particle2 = require("engine.Particles").new("starfield_static", 1, {width=Map.viewport.width, height=Map.viewport.height, nb=300, a_min=0.5, a_max = 0.9, size_min = 4, size_max = 8})
if core.shader.allow("adv") then
level.starfield_shader = require("engine.Shader").new("starfield", {size={Map.viewport.width, Map.viewport.height}})
else
level.background_particle1 = require("engine.Particles").new("starfield_static", 1, {width=Map.viewport.width, height=Map.viewport.height, nb=300, a_min=0.5, a_max = 0.8, size_min = 1, size_max = 3})
level.background_particle2 = require("engine.Particles").new("starfield_static", 1, {width=Map.viewport.width, height=Map.viewport.height, nb=300, a_min=0.5, a_max = 0.9, size_min = 4, size_max = 8})
end
level.world_sphere = Quadratic.new()
game.zone.world_sphere_rot = (game.zone.world_sphere_rot or 0)
game.zone.cloud_sphere_rot = (game.zone.world_cloud_rot or 0)
......@@ -94,9 +98,15 @@ local changer = function(id)
background = function(level, x, y, nb_keyframes)
local Map = require "engine.Map"
level.background_particle1.ps:toScreen(x, y, true, 1)
local parx, pary = level.map.mx / (level.map.w - Map.viewport.mwidth), level.map.my / (level.map.h - Map.viewport.mheight)
level.background_particle2.ps:toScreen(x - parx * 40, y - pary * 40, true, 1)
if level.starfield_shader and level.starfield_shader.shad then
level.starfield_shader.shad:use(true)
core.display.drawQuad(x, y, Map.viewport.width, Map.viewport.height, 1, 1, 1, 1)
level.starfield_shader.shad:use(false)
elseif level.background_particle1 then
level.background_particle1.ps:toScreen(x, y, true, 1)
level.background_particle2.ps:toScreen(x - parx * 40, y - pary * 40, true, 1)
end
core.display.glDepthTest(true)
core.display.glMatrix(true)
......
-- ToME - Tales of Maj'Eyal
-- Copyright (C) 2009, 2010, 2011, 2012, 2013 Nicolas Casalini
--
-- This program is free software: you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation, either version 3 of the License, or
-- (at your option) any later version.
--
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License
-- along with this program. If not, see <http://www.gnu.org/licenses/>.
--
-- Nicolas Casalini "DarkGod"
-- darkgod@te4.org
local radius = radius or 1
dir = 90
use_shader = {type="distort", power=0.06, power_time=1000, blacken=30} alterscreen = true
base_size = 64
local life=50
return {
system_rotation = dir, system_rotationv = 0,
generator = function()
return {
trail = 0,
life = life or 32,
size = 145, sizev = 0, sizea = 0,
x = 0, xv = 0, xa = 0,
y = 0, yv = 0, ya = 0,
dir = 0, dirv = dirv, dira = 0,
vel = 0, velv = 0, vela = 0,
r = 1, rv = 0, ra = 0,
g = 1, gv = 0, ga = 0,
b = 1, bv = 0, ba = 0,
a = 1, av = 0, aa = 0,
}
end, },
function(self)
self.ps:emit(1)
end,
1, "particles_images/distort_wave_directional"
......@@ -67,4 +67,4 @@ function(self)
end
first = false
end,
1000
\ No newline at end of file
1000
uniform float tick;
// Star Nest by Kali
#define iterations 12
#define formuparam 0.530
#define volsteps 10
#define stepsize 0.100
#define zoom 2.000
#define tile 0.850
#define speedfact 0.0005
uniform float speed;
#define brightness 0.0015
#define darkmatter 0.600
#define distfading 0.660
#define saturation 0.800
uniform vec2 iResolution;
void main(void)
{
//get coords and direction
vec2 uv=gl_FragCoord.xy/iResolution.xy-.5;
uv.y*=iResolution.y/iResolution.x;
vec3 dir=vec3(uv*zoom,1.);
float time=tick/speed*speedfact+2.25;
//mouse rotation
float a1=.5/iResolution.x*2.;
float a2=.8/iResolution.y*2.;
mat2 rot1=mat2(cos(a1),sin(a1),-sin(a1),cos(a1));
mat2 rot2=mat2(cos(a2),sin(a2),-sin(a2),cos(a2));
dir.xz*=rot1;
dir.xy*=rot2;
vec3 from=vec3(1.,.5,0.5);
from+=vec3(time*2.,time,-2.);
from.xz*=rot1;
from.xy*=rot2;
//volumetric rendering
float s=0.1,fade=1.;
vec3 v=vec3(0.);
for (int r=0; r<volsteps; r++) {
vec3 p=from+s*dir*.5;
p = abs(vec3(tile)-mod(p,vec3(tile*2.))); // tiling fold
float pa,a=pa=0.;
for (int i=0; i<iterations; i++) {
p=abs(p)/dot(p,p)-formuparam; // the magic formula
a+=abs(length(p)-pa); // absolute sum of average change
pa=length(p);
}
float dm=max(0.,darkmatter-a*a*.001); //dark matter
a*=a*a; // add contrast
if (r>3) fade*=1.-dm; // dark matter, don't render near
//v+=vec3(dm,dm*.5,0.);
v+=fade;
v+=vec3(s,s*s,s*s*s*s)*a*brightness*fade; // coloring based on distance
fade*=distfading; // distance fading
s+=stepsize;
}
v=mix(vec3(length(v)),v,saturation); //color adjust
gl_FragColor = vec4(v*.01,1.);
}
\ No newline at end of file
-- ToME - Tales of Maj'Eyal
-- Copyright (C) 2009, 2010, 2011, 2012, 2013 Nicolas Casalini
--
-- This program is free software: you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation, either version 3 of the License, or
-- (at your option) any later version.
--
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License
-- along with this program. If not, see <http://www.gnu.org/licenses/>.
--
-- Nicolas Casalini "DarkGod"
-- darkgod@te4.org
return {
frag = "starfield",
vert = nil,
args = {
iResolution = size or {1024, 1024},
speed = speed or 1000,
},
clone = false,
}
......@@ -228,8 +228,12 @@ return {
post_process = function(level)
local Map = require "engine.Map"
local Quadratic = require "engine.Quadratic"
level.background_particle1 = require("engine.Particles").new("starfield_static", 1, {width=Map.viewport.width, height=Map.viewport.height, nb=300, a_min=0.5, a_max = 0.8, size_min = 1, size_max = 3})
level.background_particle2 = require("engine.Particles").new("starfield_static", 1, {width=Map.viewport.width, height=Map.viewport.height, nb=300, a_min=0.5, a_max = 0.9, size_min = 4, size_max = 8})
if core.shader.allow("adv") then
level.starfield_shader = require("engine.Shader").new("starfield", {size={Map.viewport.width, Map.viewport.height}})
else
level.background_particle1 = require("engine.Particles").new("starfield_static", 1, {width=Map.viewport.width, height=Map.viewport.height, nb=300, a_min=0.5, a_max = 0.8, size_min = 1, size_max = 3})
level.background_particle2 = require("engine.Particles").new("starfield_static", 1, {width=Map.viewport.width, height=Map.viewport.height, nb=300, a_min=0.5, a_max = 0.9, size_min = 4, size_max = 8})
end
level.world_sphere = Quadratic.new()
game.zone.world_sphere_rot = (game.zone.world_sphere_rot or 0)
game.zone.cloud_sphere_rot = (game.zone.world_cloud_rot or 0)
......@@ -237,9 +241,15 @@ return {
background = function(level, x, y, nb_keyframes)
local Map = require "engine.Map"
level.background_particle1.ps:toScreen(x, y, true, 1)
local parx, pary = level.map.mx / (level.map.w - Map.viewport.mwidth), level.map.my / (level.map.h - Map.viewport.mheight)
level.background_particle2.ps:toScreen(x - parx * 40, y - pary * 40, true, 1)
if level.starfield_shader and level.starfield_shader.shad then
level.starfield_shader.shad:use(true)
core.display.drawQuad(x, y, Map.viewport.width, Map.viewport.height, 1, 1, 1, 1)
level.starfield_shader.shad:use(false)
elseif level.background_particle1 then
level.background_particle1.ps:toScreen(x, y, true, 1)
level.background_particle2.ps:toScreen(x - parx * 40, y - pary * 40, true, 1)
end
core.display.glDepthTest(true)
core.display.glMatrix(true)
......
......@@ -52,7 +52,11 @@ return {
post_process = function(level)
if level.level == 1 then
local Map = require "engine.Map"
level.background_particle = require("engine.Particles").new("starfield", 1, {width=Map.viewport.width, height=Map.viewport.height})
if core.shader.allow("adv") then
level.starfield_shader = require("engine.Shader").new("starfield", {size={Map.viewport.width, Map.viewport.height}, speed=200})
else
level.background_particle = require("engine.Particles").new("starfield", 1, {width=Map.viewport.width, height=Map.viewport.height})
end
end
game.state:makeWeather(level, 6, {max_nb=1, chance=200, dir=120, speed={0.1, 0.9}, r=0.2, g=0.2, b=0.2, alpha={0.2, 0.4}, particle_name="weather/grey_cloud_%02d"})
......@@ -67,7 +71,13 @@ return {
if level.level ~= 1 then return end
local Map = require "engine.Map"
level.background_particle.ps:toScreen(x, y, true, 1)
if level.starfield_shader and level.starfield_shader.shad then
level.starfield_shader.shad:use(true)
core.display.drawQuad(x, y, Map.viewport.width, Map.viewport.height, 1, 1, 1, 1)
level.starfield_shader.shad:use(false)
elseif level.background_particle then
level.background_particle.ps:toScreen(x, y, true, 1)
end
end,
-- Handle drops
......
......@@ -44,8 +44,12 @@ return {
post_process = function(level)
local Map = require "engine.Map"
level.background_particle1 = require("engine.Particles").new("starfield_static", 1, {width=Map.viewport.width, height=Map.viewport.height, nb=300, a_min=0.5, a_max = 0.8, size_min = 1, size_max = 3})
level.background_particle2 = require("engine.Particles").new("starfield_static", 1, {width=Map.viewport.width, height=Map.viewport.height, nb=300, a_min=0.5, a_max = 0.9, size_min = 4, size_max = 8})
if core.shader.allow("adv") then
level.starfield_shader = require("engine.Shader").new("starfield", {size={Map.viewport.width, Map.viewport.height}})
else
level.background_particle1 = require("engine.Particles").new("starfield_static", 1, {width=Map.viewport.width, height=Map.viewport.height, nb=300, a_min=0.5, a_max = 0.8, size_min = 1, size_max = 3})
level.background_particle2 = require("engine.Particles").new("starfield_static", 1, {width=Map.viewport.width, height=Map.viewport.height, nb=300, a_min=0.5, a_max = 0.9, size_min = 4, size_max = 8})
end
end,
frames = 0,
......@@ -53,8 +57,14 @@ return {
level.data.frames = level.data.frames + nb_keyframes
local Map = require "engine.Map"
level.background_particle1.ps:toScreen(x, y, true, 1)
local parx, pary = level.map.mx / (level.map.w - Map.viewport.mwidth), level.map.my / (level.map.h - Map.viewport.mheight)
level.background_particle2.ps:toScreen(x - parx * 40, y - pary * 40, true, 1)
if level.starfield_shader and level.starfield_shader.shad then
level.starfield_shader.shad:use(true)
core.display.drawQuad(x, y, Map.viewport.width, Map.viewport.height, 1, 1, 1, 1)
level.starfield_shader.shad:use(false)
elseif level.background_particle1 then
level.background_particle1.ps:toScreen(x, y, true, 1)
local parx, pary = level.map.mx / (level.map.w - Map.viewport.mwidth), level.map.my / (level.map.h - Map.viewport.mheight)
level.background_particle2.ps:toScreen(x - parx * 40, y - pary * 40, true, 1)
end
end,
}
......@@ -83,8 +83,24 @@ static void getparticulefield(lua_State *L, const char *k, float *v)
lua_pop(L, 1);
}
static int particles_flush_last(lua_State *L)
{
while (pdls_head) {
particle_draw_last *pdl = pdls_head;
pdls_head = pdls_head->next;
free(pdl);
}
return 0;
}
static int particles_main_fbo(lua_State *L)
{
while (pdls_head) {
particle_draw_last *pdl = pdls_head;
pdls_head = pdls_head->next;
free(pdl);
}
if (lua_isnil(L, 1)) {
main_fbo = NULL;
return 0;
......@@ -137,6 +153,7 @@ static int particles_set_sub(lua_State *L)
particles_type *subps = (particles_type*)auxiliar_checkclass(L, "core{particles}", 2);
ps->sub = subps;
return 0;
}
......@@ -575,6 +592,7 @@ static const struct luaL_Reg particleslib[] =
{
{"newEmitter", particles_new},
{"defineFramebuffer", particles_main_fbo},
{"flushLast", particles_flush_last},
{"drawAlterings", particles_draw_last},
{NULL, NULL},
};
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment