Skip to content
Snippets Groups Projects
Commit 5e276f7e authored by dg's avatar dg
Browse files

blah shaders of hell

git-svn-id: http://svn.net-core.org/repos/t-engine4@745 51575b47-30f0-44d4-a5cc-537603b46e54
parent be3a30d3
No related branches found
No related tags found
No related merge requests found
......@@ -413,6 +413,7 @@ end
-- @return true if the talent was learnt, nil and an error message otherwise
function _M:learnTalentType(tt, v)
if v == nil then v = true end
if self.talents_types[tt] then return end
self.talents_types[tt] = v
self.talents_types_mastery[tt] = self.talents_types_mastery[tt] or 1
self.changed = true
......
varying vec2 texCoord;
//uniform int tick;
//uniform sampler3D noisevol;
uniform sampler2D noise2d;
/*
uniform float tick;
uniform float alpha;
uniform sampler3D noisevol;
void main(void)
{
// float fTime0_X = (float)tick;
// vec4 noisy = texture3D(noisevol,vec3(gl_TexCoord[0].xy,fTime0_X));
// vec3 bump = 2.0 * noisy.xyz - 1.1;
// gl_FragColor.xyz = (1.0-bump.xyz)*vec3(0.3,0.3,1.0)+(bump.xyz)*vec3(0.0,0.0,0.0);
// vec4 noisy = texture2D(noise2d,gl_TexCoord[0].xy);
// vec4 bump = 2.0 * noisy - 1.1;
// gl_FragColor.xyz = (1.0-bump.xyz)*vec3(0.3,0.3,1.0)+(bump.xyz)*vec3(0.0,0.0,0.0);
// gl_FragColor = bump;
// vec4 n = texture2D(noise2d, texCoord.xy);
// n.x = 1;
// gl_FragColor = n;
gl_FragColor = texture2D(noise2d, texCoord.xy);
gl_FragColor.r = 1;
gl_FragColor.a = 1.0;
// int i = (tick / 30) % 255;
// float t = (float)i;
// t = t / 255;
// gl_FragColor = vec4(red, 0, t, 1);
// gl_FragColor.xy = gl_TexCoord[0].xy;
float fTime0_X = tick / 10000;
vec4 noisy = texture3D(noisevol,vec3(gl_TexCoord[0].xy,fTime0_X));
vec3 bump = 2.0 * noisy.xyz - 1.1;
gl_FragColor.xyz = (1.0-bump.xyz)*vec3(0.3,0.3,1.0)+(bump.xyz)*vec3(0.0,0.0,0.0);
gl_FragColor.a = 1;
}
*/
uniform float tick;
uniform sampler3D noisevol;
uniform ivec2 mapCoord;
void main(void)
{
float fTime0_X = tick / 10000;
vec4 noisy = texture3D(noisevol,vec3(gl_TexCoord[0].xy*0.3,fTime0_X));
vec4 noisy2 = texture3D(noisevol,vec3((mapCoord/50.0),fTime0_X));
vec3 bump = 2.0 * (noisy.xyz+noisy2.xyz)/2.0 - 1.1;
gl_FragColor.xyz = (1.0-bump.xyz)*vec3(0.3,0.3,1.0)+(bump.xyz)*vec3(0.0,0.0,0.0);
gl_FragColor.a = 1;
}
......@@ -23,9 +23,10 @@ tex = core.display.loadImage("/data/gfx/terrain/tree.png"):glTexture()
return {
frag = "water",
vert = "default",
vert = nil,
args = {
noise2d = { texture = tex },
-- noise2d = { texture = tex },
noisevol = { texture = tex, is3d=true },
},
clone = false,
}
......@@ -366,7 +366,7 @@ int initGL()
// glShadeModel( GL_SMOOTH );
/* Set the background black */
glClearColor( 0.0f, 0.0f, 1.0f, 1.0f );
glClearColor( 0.0f, 0.0f, 0.0f, 1.0f );
/* Depth buffer setup */
// glClearDepth( 1.0f );
......@@ -599,6 +599,8 @@ int main(int argc, char *argv[])
SDL_AddTimer(30, redraw_timer, NULL);
doit();
SDL_Event event;
while (!exit_engine)
{
......
......@@ -29,7 +29,7 @@
#include "tSDL.h"
//#include "shaders.h"
extern void useShader(GLuint p, int x, int y);
extern void useShader(GLuint p, int x, int y, float a);
// Minimap defines
#define MM_FLOOR 1
......@@ -340,6 +340,52 @@ static int map_set_scroll(lua_State *L)
return 0;
}
GLuint pfftex;
#include "libtcod.h"
#define BYTES_PER_TEXEL 3
#define LAYER(r) (w * h * r * BYTES_PER_TEXEL)
// 2->1 dimension mapping function
#define TEXEL2(s, t) (BYTES_PER_TEXEL * (s * w + t))
// 3->1 dimension mapping function
#define TEXEL3(s, t, r) (TEXEL2(s, t) + LAYER(r))
void doit()
{
TCOD_noise_t *noise = TCOD_noise_new(3, TCOD_NOISE_DEFAULT_HURST, TCOD_NOISE_DEFAULT_LACUNARITY);
int w = 128, h = 128, d=128, zoom = 4;
int x=0, y=0, z=0;
GLubyte *map = malloc(w * h * d * 3 * sizeof(GLubyte));
float p[3];
int i, j, k;
for (i = 0; i < w; i++)
{
for (j = 0; j < h; j++)
{
for (k = 0; k < d; k++)
{
p[0] = zoom * ((float)(i+x)) / w;
p[1] = zoom * ((float)(j+y)) / h;
p[2] = zoom * ((float)(k+z)) / d;
float v = ((TCOD_noise_simplex(noise, p) + 1) / 2) * 255;
map[TEXEL3(i, j, k)] = (GLubyte)v;
map[TEXEL3(i, j, k)+1] = (GLubyte)v;
map[TEXEL3(i, j, k)+2] = (GLubyte)v;
}
}
}
glGenTextures(1, &pfftex);
glBindTexture(GL_TEXTURE_3D, pfftex);
glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_R, GL_REPEAT);
glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexImage3D(GL_TEXTURE_3D, 0, GL_RGB8, w, h, d, 0, GL_RGB, GL_UNSIGNED_BYTE, map);
free(map);
}
static int map_to_screen(lua_State *L)
{
map_type *map = (map_type*)auxiliar_checkclass(L, "core{map}", 1);
......@@ -371,8 +417,11 @@ static int map_to_screen(lua_State *L)
glColor4f((map->shown_r + m->tint_r)/2, (map->shown_g + m->tint_g)/2, (map->shown_b + m->tint_b)/2, a);
else
glColor4f(map->shown_r, map->shown_g, map->shown_b, a);
if (m->shader) useShader(m->shader, i, j);
glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_3D, pfftex);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, map->grids_terrain[i][j].texture);
if (m->shader) useShader(m->shader, i, j, a);
glBegin(GL_QUADS);
glTexCoord2f(0,0); glVertex3f(0 +dx, 0 +dy,-99);
glTexCoord2f(1,0); glVertex3f(map->tile_w +dx, 0 +dy,-99);
......@@ -388,7 +437,7 @@ static int map_to_screen(lua_State *L)
glColor4f((map->shown_r + m->tint_r)/2, (map->shown_g + m->tint_g)/2, (map->shown_b + m->tint_b)/2, a);
else
glColor4f(map->shown_r, map->shown_g, map->shown_b, a);
if (m->shader) useShader(m->shader, i, j);
if (m->shader) useShader(m->shader, i, j, a);
glBindTexture(GL_TEXTURE_2D, map->grids_trap[i][j].texture);
glBegin(GL_QUADS);
glTexCoord2f(0,0); glVertex3f(0 +dx, 0 +dy,-99);
......@@ -405,7 +454,7 @@ static int map_to_screen(lua_State *L)
glColor4f((map->shown_r + m->tint_r)/2, (map->shown_g + m->tint_g)/2, (map->shown_b + m->tint_b)/2, a);
else
glColor4f(map->shown_r, map->shown_g, map->shown_b, a);
if (m->shader) useShader(m->shader, i, j);
if (m->shader) useShader(m->shader, i, j, a);
glBindTexture(GL_TEXTURE_2D, map->grids_object[i][j].texture);
glBegin(GL_QUADS);
glTexCoord2f(0,0); glVertex3f(0 +dx, 0 +dy,-99);
......@@ -422,7 +471,7 @@ static int map_to_screen(lua_State *L)
glColor4f((map->shown_r + m->tint_r)/2, (map->shown_g + m->tint_g)/2, (map->shown_b + m->tint_b)/2, a);
else
glColor4f(map->shown_r, map->shown_g, map->shown_b, a);
if (m->shader) useShader(m->shader, i, j);
if (m->shader) useShader(m->shader, i, j, a);
glBindTexture(GL_TEXTURE_2D, map->grids_actor[i][j].texture);
glBegin(GL_QUADS);
glTexCoord2f(0,0); glVertex3f(0 +dx, 0 +dy,-99);
......@@ -442,7 +491,7 @@ static int map_to_screen(lua_State *L)
glColor4f((map->shown_r + m->tint_r)/2, (map->shown_g + m->tint_g)/2, (map->shown_b + m->tint_b)/2, a);
else
glColor4f(map->shown_r, map->shown_g, map->shown_b, a);
if (m->shader) useShader(m->shader, i, j);
if (m->shader) useShader(m->shader, i, j, a);
glBindTexture(GL_TEXTURE_2D, map->grids_actor[i][j].texture);
glBegin(GL_QUADS);
glTexCoord2f(0,0); glVertex3f(0 +dx, 0 +dy,-99);
......@@ -459,7 +508,7 @@ static int map_to_screen(lua_State *L)
glColor4f((map->shown_r + m->tint_r)/2, (map->shown_g + m->tint_g)/2, (map->shown_b + m->tint_b)/2, a);
else
glColor4f(map->shown_r, map->shown_g, map->shown_b, a);
if (m->shader) useShader(m->shader, i, j);
if (m->shader) useShader(m->shader, i, j, a);
glBindTexture(GL_TEXTURE_2D, map->grids_object[i][j].texture);
glBegin(GL_QUADS);
glTexCoord2f(0,0); glVertex3f(0 +dx, 0 +dy,-99);
......@@ -476,7 +525,7 @@ static int map_to_screen(lua_State *L)
glColor4f((map->shown_r + m->tint_r)/2, (map->shown_g + m->tint_g)/2, (map->shown_b + m->tint_b)/2, a);
else
glColor4f(map->shown_r, map->shown_g, map->shown_b, a);
if (m->shader) useShader(m->shader, i, j);
if (m->shader) useShader(m->shader, i, j, a);
glBindTexture(GL_TEXTURE_2D, map->grids_trap[i][j].texture);
glBegin(GL_QUADS);
glTexCoord2f(0,0); glVertex3f(0 +dx, 0 +dy,-99);
......@@ -493,7 +542,7 @@ static int map_to_screen(lua_State *L)
glColor4f((map->shown_r + m->tint_r)/2, (map->shown_g + m->tint_g)/2, (map->shown_b + m->tint_b)/2, a);
else
glColor4f(map->shown_r, map->shown_g, map->shown_b, a);
if (m->shader) useShader(m->shader, i, j);
if (m->shader) useShader(m->shader, i, j, a);
glBindTexture(GL_TEXTURE_2D, map->grids_terrain[i][j].texture);
glBegin(GL_QUADS);
glTexCoord2f(0,0); glVertex3f(0 +dx, 0 +dy,-99);
......@@ -514,7 +563,7 @@ static int map_to_screen(lua_State *L)
glColor4f((map->obscure_r + m->tint_r)/2, (map->obscure_g + m->tint_g)/2, (map->obscure_b + m->tint_b)/2, map->obscure_a);
else
glColor4f(map->obscure_r, map->obscure_g, map->obscure_b, map->obscure_a);
if (m->shader) useShader(m->shader, i, j);
if (m->shader) useShader(m->shader, i, j, a);
glBindTexture(GL_TEXTURE_2D, map->grids_terrain[i][j].texture);
glBegin(GL_QUADS);
glTexCoord2f(0,0); glVertex3f(0 +dx, 0 +dy,-99);
......
......@@ -32,16 +32,15 @@
bool shaders_active = TRUE;
void useShader(GLuint p, int x, int y)
void useShader(GLuint p, int x, int y, float a)
{
CHECKGL(glUseProgramObjectARB(p));
GLint i = SDL_GetTicks();
CHECKGL(glUniform1ivARB(glGetUniformLocationARB(p, "tick"), 1, &i));
GLfloat t = SDL_GetTicks();
CHECKGL(glUniform1fvARB(glGetUniformLocationARB(p, "tick"), 1, &t));
t = a; CHECKGL(glUniform1fvARB(glGetUniformLocationARB(p, "alpha"), 1, &t));
i = x;
CHECKGL(glUniform1ivARB(glGetUniformLocationARB(p, "mapx"), 1, &i));
i = y;
CHECKGL(glUniform1ivARB(glGetUniformLocationARB(p, "mapy"), 1, &i));
GLint c[2] = {x, y};
CHECKGL(glUniform2ivARB(glGetUniformLocationARB(p, "mapCoord"), 2, c));
CHECKGLSLVALID(p);
}
......@@ -176,11 +175,11 @@ static int program_set_uniform_texture(lua_State *L)
GLint i = 1;
CHECKGL(glUseProgramObjectARB(*p));
CHECKGL(glActiveTexture(GL_TEXTURE1));
CHECKGL(glBindTexture(is3d ? GL_TEXTURE_3D : GL_TEXTURE_2D, *t));
// CHECKGL(glActiveTexture(GL_TEXTURE1));
// CHECKGL(glBindTexture(is3d ? GL_TEXTURE_3D : GL_TEXTURE_2D, *t));
CHECKGL(glUniform1ivARB(glGetUniformLocationARB(*p, var), 1, &i));
CHECKGL(glUseProgramObjectARB(0));
CHECKGL(glActiveTexture(GL_TEXTURE0));
// CHECKGL(glActiveTexture(GL_TEXTURE0));
return 0;
}
......
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