Skip to content
Snippets Groups Projects
Commit 9d1012e4 authored by DarkGod's avatar DarkGod
Browse files

Improved water display (with a shader)

parent 35c76ef9
No related branches found
No related tags found
No related merge requests found
......@@ -29,6 +29,12 @@ _M.progs = {}
loadNoDelay = true
local allows = {
}
function core.shader.allow(kind)
end
--- Make a shader
function _M:init(name, args)
self.args = args or {}
......
......@@ -125,6 +125,7 @@ newEntity{
display = '~', color=colors.AQUAMARINE, back_color=colors.DARK_BLUE,
always_remember = true,
special_minimap = colors.BLUE,
shader = "water",
}
-----------------------------------------
......@@ -169,6 +170,7 @@ newEntity{
end,
combatAttack = function(self) return rng.range(self.mindam, self.maxdam) end,
nice_tiler = { method="replace", base={"POISON_DEEP_WATER", 100, 1, 6}},
shader = "water",
}
for i = 1, 6 do newEntity{ base="POISON_DEEP_WATER", define_as = "POISON_DEEP_WATER"..i, image = "terrain/poisoned_water_0"..i..".png" } end
......
// Simple Water shader. (c) Victor Korsun, bitekas@gmail.com; 2012.
//
// Attribution-ShareAlike CC License.
#ifdef GL_ES
precision highp float;
#endif
vec3 iResolution = vec3(64.0,64.0,0.0);// viewport resolution (in pixels)
uniform float tick;
uniform sampler3D noisevol;
uniform sampler2D tex;
uniform vec2 mapCoord;
uniform vec4 displayColor;
uniform vec4 color1;
uniform vec4 color2;
const float PI = 3.1415926535897932;
// play with these parameters to custimize the effect
// ===================================================
//speed
const float speed = 0.2;
const float speed_x = 0.3;
const float speed_y = 0.3;
// refraction
const float emboss = 0.50;
const float intensity = 2.4;
const int steps = 10;
const float frequency = 12.0;
const int angle = 7; // better when a prime
// reflection
const float delta = 60.;
const float intence = 700.;
const float reflectionCutOff = 0.012;
const float reflectionIntence = 200000.;
// ===================================================
float time = tick / 10000.0;
float col(vec2 coord)
{
float delta_theta = 2.0 * PI / float(angle);
float col = 0.0;
float theta = 0.0;
for (int i = 0; i < steps; i++)
{
vec2 adjc = coord;
theta = delta_theta*float(i);
adjc.x += cos(theta)*time*speed + time * speed_x;
adjc.y -= sin(theta)*time*speed - time * speed_y;
col = col + cos( (adjc.x*cos(theta) - adjc.y*sin(theta))*frequency)*intensity;
}
return cos(col);
}
//---------- main
void main(void)
{
float fTime0_X = tick / 100000.0;
vec2 coord = mapCoord+gl_TexCoord[0].xy;
float noisy = texture3D(noisevol,vec3(coord,fTime0_X)).r;
float noisy2 = texture3D(noisevol,vec3(coord/5.0,fTime0_X)).r;
float noisy3 = texture3D(noisevol,vec3(coord/7.0,fTime0_X)).r;
float noise = (noisy+noisy2+noisy3)/3.0;
float bump = 1.0-abs((2.0 * noise)-1.0);
bump *= bump - 0.3;
gl_FragColor = mix(color1, color2, bump) * displayColor;
gl_FragColor.a = 0.4;
vec2 p = (gl_FragCoord.xy + mapCoord) / iResolution.xy, c1 = p, c2 = p;
float cc1 = col(c1);
c2.x += iResolution.x/delta;
float dx = emboss*(cc1-col(c2))/delta;
c2.x = p.x;
c2.y += iResolution.y/delta;
float dy = emboss*(cc1-col(c2))/delta;
c1.x += dx*2.;
c1.y = -(c1.y+dy*2.);
float alpha = 1.+dot(dx,dy)*intence;
float ddx = dx - reflectionCutOff;
float ddy = dy - reflectionCutOff;
if (ddx > 0. && ddy > 0.)
alpha = pow(alpha, ddx*ddy*reflectionIntence);
vec4 col = texture2D(tex,c1)*(alpha);
gl_FragColor = col;
}
......@@ -21,9 +21,7 @@ return {
frag = "water",
vert = nil,
args = {
noisevol = { texture = 1 },
color1 = {0,0,1,1},
color2 = {0,0.6,0.8,1},
tex = { texture = 0 },
},
clone = false,
}
......@@ -35,6 +35,7 @@ newEntity{
block_sight = true,
dig = "SHALLOW_WATER",
nice_tiler = { method="replace", base={"BOGTREE", 100, 1, 20}},
shader = "water",
}
for i = 1, 20 do newEntity{ base="BOGTREE", define_as = "BOGTREE"..i, image = "terrain/poisoned_water_01.png", add_displays = class:makeTrees("terrain/swamptree", 3, 3)} end
......
......@@ -53,6 +53,7 @@ newEntity{
block_sight = true,
dig = "BOGWATER",
nice_tiler = { method="replace", base={"BOGTREE", 100, 1, 20}},
shader = "water",
}
for i = 1, 20 do newEntity{ base="BOGTREE", define_as = "BOGTREE"..i, image = "terrain/water_grass_5_1.png", add_displays = class:makeTrees("terrain/tree_alpha", 13, 9)} end
......
......@@ -174,6 +174,7 @@ newEntity{
always_remember = true,
can_encounter="water", equilibrium_level=-10,
special_minimap = colors.BLUE,
shader = "water",
}
newEntity{ base = "WATER_BASE", define_as = "WATER_BASE_DEEP", can_pass = {pass_water=1}, does_block_move = true }
......
......@@ -1308,7 +1308,7 @@ void do_quad(lua_State *L, const map_object *m, const map_object *dm, const map_
glColorPointer(4, GL_FLOAT, 0, colors);
}
lua_pop(L, 1);
if (m->shader) useShader(m->shader, i, j, map->tile_w, map->tile_h, r, g, b, a);
if (m->shader) useShader(m->shader, dx, dy, map->tile_w, map->tile_h, r, g, b, a);
}
}
......@@ -1387,7 +1387,7 @@ void display_map_quad(lua_State *L, GLuint *cur_tex, int *vert_idx, int *col_idx
********************************************************/
a = (a > 1) ? 1 : ((a < 0) ? 0 : a);
int z;
if (m->shader) useShader(m->shader, i, j, map->tile_w, map->tile_h, r, g, b, a);
if (m->shader) useShader(m->shader, dx, dy, map->tile_w, map->tile_h, r, g, b, a);
for (z = (!shaders_active) ? 0 : (m->nb_textures - 1); z > 0; z--)
{
if (multitexture_active && shaders_active) tglActiveTexture(GL_TEXTURE0+z);
......
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