Added more advanced sun light calculation

develop
Japa 2013-06-25 16:33:01 +05:30 committed by Warmist
parent dceec6c6c7
commit 0551661db2
4 changed files with 95 additions and 14 deletions

@ -144,9 +144,7 @@ bool lightingEngineViewscreen::lightUpCell(lightCell& power,int dx,int dy,int tx
if (dsq>0 && !wallhack)
{
power.r=power.r*(pow(v.r,dt));
power.g=power.g*(pow(v.g,dt));
power.b=power.b*(pow(v.b,dt));
power*=v.power(dt);
}
if(ls.radius>0 && dsq>0)
{
@ -294,10 +292,15 @@ matLightDef* lightingEngineViewscreen::getMaterial(int matType,int matIndex)
else
return NULL;
}
void lightingEngineViewscreen::applyMaterial(int tileId,const matLightDef& mat,float size)
void lightingEngineViewscreen::applyMaterial(int tileId,const matLightDef& mat,float size, float thickness)
{
if(mat.isTransparent)
{
if(thickness > 0.999 && thickness < 1.001)
ocupancy[tileId]*=mat.transparency;
else
ocupancy[tileId]*=(mat.transparency.power(thickness));
}
else
ocupancy[tileId]=lightCell(0,0,0);
if(mat.isEmiting)
@ -345,19 +348,19 @@ lightCell lightingEngineViewscreen::propogateSun(MapExtras::Block* b, int x,int
else if(basic_shape==df::tiletype_shape_basic::Floor || basic_shape==df::tiletype_shape_basic::Ramp || shape==df::tiletype_shape::STAIR_UP)
{
if(!lastLevel)
ret*=lightDef->transparency; //TODO modify because floors have less material
ret*=lightDef->transparency.power(1.0f/7.0f);
}
else if(shape==df::tiletype_shape::STAIR_DOWN || shape==df::tiletype_shape::STAIR_UPDOWN)
{
ret*=matStairCase;
}
if(d.bits.liquid_type == df::enums::tile_liquid::Water && d.bits.flow_size)
if(d.bits.liquid_type == df::enums::tile_liquid::Water && d.bits.flow_size > 0)
{
ret *=matWater.transparency;// (lightCell(1,1,1) - (lightCell(1,1,1) - matWater)*((float)d.bits.flow_size/7.0f));
ret *=matWater.transparency.power((float)d.bits.flow_size/7.0f);
}
else if(d.bits.liquid_type == df::enums::tile_liquid::Magma && d.bits.flow_size > 3)
else if(d.bits.liquid_type == df::enums::tile_liquid::Magma && d.bits.flow_size > 0)
{
ret *=matLava.transparency;
ret *=matLava.transparency.power((float)d.bits.flow_size/7.0f);
}
return ret;
}
@ -432,7 +435,7 @@ void lightingEngineViewscreen::doSun(const lightSource& sky,MapExtras::MapCache&
void lightingEngineViewscreen::doOcupancyAndLights()
{
// TODO better curve (+red dawn ?)
float daycol = abs((*df::global::cur_year_tick % 1200) - 600.0) / 400.0;
float daycol = 1;//abs((*df::global::cur_year_tick % 1200) - 600.0) / 400.0;
lightCell sky_col(daycol, daycol, daycol);
lightSource sky(sky_col, 15);
@ -502,9 +505,9 @@ void lightingEngineViewscreen::doOcupancyAndLights()
else
applyMaterial(tile,*lightDef);
}
else if(!d.bits.liquid_type && d.bits.flow_size>3 )
else if(!d.bits.liquid_type && d.bits.flow_size>0 )
{
applyMaterial(tile,matWater);
applyMaterial(tile,matWater, 1, (float)d.bits.flow_size/7.0f);
}
if(d.bits.liquid_type && d.bits.flow_size>0)
{

@ -148,7 +148,7 @@ private:
matLightDef* getMaterial(int matType,int matIndex);
//apply material to cell
void applyMaterial(int tileId,const matLightDef& mat,float size=1);
void applyMaterial(int tileId,const matLightDef& mat,float size=1, float thickness = 1);
//try to find and apply material, if failed return false, and if def!=null then apply def.
bool applyMaterial(int tileId,int matType,int matIndex,float size=1,const matLightDef* def=NULL);
size_t inline getIndex(int x,int y)

@ -13,6 +13,7 @@
#include "df/zoom_commands.h"
#include "df/texture_handler.h"
#include "df/graphic.h"
#include <math.h>
using df::renderer;
using df::init;
@ -230,6 +231,14 @@ struct lightCell
{
return r*other.r+g*other.g+b*other.b;
}
lightCell power(const float exp) const
{
return lightCell(pow(r, exp), pow(g, exp), pow(b, exp));
}
lightCell power(const int exp) const
{
return lightCell(pow(r, exp), pow(g, exp), pow(b, exp));
}
};
struct renderer_test : public renderer_wrap {
private:

@ -0,0 +1,69 @@
--scroll down to the end for configuration
ret={...}
ret=ret[1]
ret.materials={}
ret.buildings={}
ret.special={}
for k,v in pairs(ret) do
_ENV[k]=v
end
-- add material by id (index,mat pair or token string or a type number), flags is a table of strings
-- supported flags:
-- flicker
-- sizeModifiesPower
-- sizeModifiesRange
function addMaterial(id,transparency,emitance,radius,flags)
local matinfo
if type(id)=="string" then
matinfo=dfhack.matinfo.find(id)
elseif type(id)=="table" then
matinfo=dfhack.matinfo.decode(id[1],id[2])
else
matinfo=dfhack.matinfo.decode(id,0)
end
if matinfo==nil then
error("Material not found")
end
materials[matinfo.type]=materials[matinfo.type] or {}
materials[matinfo.type][matinfo.index]=makeMaterialDef(transparency,emitance,radius,flags)
end
function addBuilding(id,transparency,emitance,radius,flags)
--stuff
end
function makeMaterialDef(transparency,emitance,radius,flags)
local flg
if flags then
flg={}
for k,v in ipairs(flags) do
flg[v]=true
end
end
return {tr=transparency,em=emitance,rad=radius,flags=flg}
end
------------------------------------------------------------------------
---------------- Configuration Starts Here -------------------------
------------------------------------------------------------------------
--special things
special.LAVA=makeMaterialDef({0.8,0.2,0.2},{0.8,0.2,0.2},5)
special.WATER=makeMaterialDef({0.5,0.5,0.8})
special.FROZEN_LIQUID=makeMaterialDef({0.2,0.7,0.9}) -- ice
special.AMBIENT=makeMaterialDef({0.85,0.85,0.85}) --ambient fog
special.CURSOR=makeMaterialDef({1,1,1},{0.96,0.84,0.03},11, {"flicker"})
--TODO dragonfire
--TODO daylight
--materials
-- glasses
addMaterial("GLASS_GREEN",{0.1,0.9,0.5})
addMaterial("GLASS_CLEAR",{0.5,0.95,0.9})
addMaterial("GLASS_CRYSTAL",{0.75,0.95,0.95})
-- Plants
addMaterial("PLANT:TOWER_CAP",nil,{0.65,0.65,0.65},6)
addMaterial("PLANT:MUSHROOM_CUP_DIMPLE",nil,{0.03,0.03,0.5},3)
addMaterial("PLANT:CAVE MOSS",nil,{0.1,0.1,0.4},2)
addMaterial("PLANT:MUSHROOM_HELMET_PLUMP",nil,{0.2,0.1,0.6},2)
-- inorganics
addMaterial("INORGANIC:ADAMANTINE",{0.1,0.3,0.3},{0.1,0.3,0.3},4)
-- TODO gems
--buildings