Merge fractalnoise into noisetextures.c, which will eventually add a few more fractal noise types. Current smoke is a blend of diamond-square and plasma noise.

Also make smoke less dense, in an attempt to fix Jin^eLD's problem with hwguy smoke.
This commit is contained in:
Ragnvald Maartmann-Moe IV 2001-04-04 05:39:44 +00:00
parent 2f2ba28bb7
commit f4632ccd8b
5 changed files with 59 additions and 141 deletions

View file

@ -1,34 +0,0 @@
/*
fractalnoise.h
LordHavocs fractial noise generator.
Copyright (C) 2000 Forest `LordHavoc` Hale.
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 2
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, write to:
Free Software Foundation, Inc.
59 Temple Place - Suite 330
Boston, MA 02111-1307, USA
$Id$
*/
#ifndef _FRACTALNOISE_H
#define _FRACTALNOISE_H
void fractalnoise(unsigned char *noise, int size);
#endif // _FRACTALNOISE_H

View file

@ -260,7 +260,7 @@ qw_client_x11_DEPENDENCIES= $(CLIENT_LIB_DEPS)
#
# ... Common stuff
#
ogl_SOURCES= fractalnoise.c gl_textures.c gl_draw.c gl_dyn_fires.c \
ogl_SOURCES= noisetextures.c gl_textures.c gl_draw.c gl_dyn_fires.c \
gl_dyn_part.c gl_dyn_textures.c gl_mesh.c gl_ngraph.c \
r_efrag.c gl_rlight.c gl_rmain.c gl_rmisc.c gl_rsurf.c \
gl_screen.c gl_skin.c gl_sky.c gl_sky_clip.c gl_view.c \

View file

@ -1,84 +0,0 @@
/*
fractalnoise.c
LordHavocs fractal noise generator.
Copyright (C) 2000 Forest `LordHavoc` Hale.
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 2
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, write to:
Free Software Foundation, Inc.
59 Temple Place - Suite 330
Boston, MA 02111-1307, USA
$Id$
*/
#include <stdlib.h>
void
fractalnoise (unsigned char *noise, int size)
{
int x, y, g, g2, amplitude, min, max, size1 = size - 1;
int *noisebuf;
#define n(x,y) noisebuf[((y)&size1)*size+((x)&size1)]
noisebuf = calloc (size * size, sizeof (int));
amplitude = 32767;
g2 = size;
n (0, 0) = 0;
for (; (g = g2 >> 1) >= 1; g2 >>= 1) {
// subdivide, diamond-square algorythm (really this has little to do
// with squares)
// diamond
for (y = 0; y < size; y += g2)
for (x = 0; x < size; x += g2)
n (x + g, y + g) =
(n (x, y) + n (x + g2, y) + n (x, y + g2) +
n (x + g2, y + g2)) >> 2;
// square
for (y = 0; y < size; y += g2)
for (x = 0; x < size; x += g2) {
n (x + g, y) =
(n (x, y) + n (x + g2, y) + n (x + g, y - g) +
n (x + g, y + g)) >> 2;
n (x, y + g) =
(n (x, y) + n (x, y + g2) + n (x - g, y + g) +
n (x + g, y + g)) >> 2;
}
// brownian motion theory
amplitude >>= 1;
for (y = 0; y < size; y += g)
for (x = 0; x < size; x += g)
n (x, y) += (rand () & amplitude);
}
// find range of noise values
min = max = 0;
for (y = 0; y < size; y++)
for (x = 0; x < size; x++) {
if (n (x, y) < min)
min = n (x, y);
if (n (x, y) > max)
max = n (x, y);
}
max -= min;
// normalize noise and copy to output
for (y = 0; y < size; y++)
for (x = 0; x < size; x++)
*noise++ = (n (x, y) - min) * 255 / max;
free (noisebuf);
#undef n
}

View file

@ -32,9 +32,11 @@
#include <stdlib.h>
#include "fractalnoise.h"
#include "glquake.h"
extern void noise_diamondsquare(unsigned char *noise, int size);
extern void noise_plasma(unsigned char *noise, int size);
static void GDT_InitDotParticleTexture (void);
static void GDT_InitSmokeParticleTexture (void);
@ -54,9 +56,9 @@ GDT_InitDotParticleTexture (void)
int x, y, dx2, dy, d;
byte data[16][16][2];
//
//
// particle texture
//
//
part_tex_dot = texture_extension_number++;
glBindTexture (GL_TEXTURE_2D, part_tex_dot);
@ -85,34 +87,28 @@ GDT_InitDotParticleTexture (void)
static void
GDT_InitSmokeParticleTexture (void)
{
int i, x, y, d;
int i, x, y, c;
float dx, dy2;
byte data[32][32][2], noise1[32][32], noise2[32][32];
byte d, data[32][32][2], noise1[32][32], noise2[32][32];
for (i = 0; i < 8; i++) {
fractalnoise (&noise1[0][0], 32);
fractalnoise (&noise2[0][0], 32);
noise_diamondsquare (&noise1[0][0], 32);
noise_plasma (&noise2[0][0], 32);
for (y = 0; y < 32; y++)
{
dy2 = y - 16;
dy2 *= dy2;
for (x = 0; x < 32; x++) {
dx = x - 16;
d = noise2[y][x] * 4 - 512;
c = 255 - (dx*dx + dy2);
if (c < 1)
c = 0;
d = (noise1[y][x] + noise2[y][x]) / 3;
if (d > 0) {
if (d > 255)
d = 255;
d = (d * (255 - (int) (dx * dx + dy2))) >> 8;
if (d <= 0) {
d = 0;
data[y][x][0] = 0;
} else
data[y][x][0] = (noise1[y][x] >> 1) + 128;
// if (d > 255)
// d = 255;
data[y][x][1] = (byte) d;
data[y][x][0] = 255;
data[y][x][1] = (d * c)/255;
} else {
data[y][x][0] = 0; //DESPAIR
data[y][x][0] = 255;
data[y][x][1] = 0;
}
}
@ -122,7 +118,6 @@ GDT_InitSmokeParticleTexture (void)
glTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexImage2D (GL_TEXTURE_2D, 0, 2, 32, 32, 0, GL_LUMINANCE_ALPHA,
GL_UNSIGNED_BYTE, data);
GL_UNSIGNED_BYTE, data);
}
}

View file

@ -84,6 +84,47 @@ typedef struct {
} glformat_t;
static glformat_t formats[] = {
/*
1-4 are standardly supported formats by GL, not exactly the
evil magic numbers they appear to be. Provided mostly as a
way to avoid ugly code for supporting a shortcut, partly for
consistency. --Despair
*/
/* EXT_paletted_textures
{"COLOR_INDEX1_EXT", COLOR_INDEX1_EXT}.
{"COLOR_INDEX2_EXT", COLOR_INDEX2_EXT},
{"COLOR_INDEX4_EXT", COLOR_INDEX4_EXT},
{"COLOR_INDEX8_EXT", COLOR_INDEX8_EXT},
{"COLOR_INDEX12_EXT", COLOR_INDEX12_EXT},
{"COLOR_INDEX16_EXT", COLOR_INDEX16_EXT},
*/
/* EXT_cymyka
{"CMYK_EXT", CMYK_EXT},
{"CMYKA_EXT", CMYKA_EXT},
*/
/* EXT_422_pixels
{"422_EXT", 422_EXT},
{"422_REV_EXT", 422_REV_EXT},
{"422_AVERAGE_EXT", 422_AVERAGE_EXT},
{"422_REV_AVERAGE_EXT", 422_REV_AVERAGE_EXT},
*/
/* EXT_abgr
{"ABGR_EXT", ABGR_EXT},
*/
/* EXT_bgra
{"BGR_EXT", BGR_EXT},
{"BGRA_EXT", BGRA_EXT},
*/
/* ARB_texture_compression
* only applicable for CompressedTexImage and CompressedTexSubimage
* which will complicate upload paths. *ponder*
{"COMPRESSED_ALPHA_ARB", COMPRESSED_ALPHA_ARB},
{"COMPRESSED_LUMINANCE_ARB", COMPRESSED_LUMINANCE_ARB},
{"COMPRESSED_LUMINANCE_ALPHA_ARB", COMPRESSED_LUMINANCE_ALPHA_ARB},
{"COMPRESSED_INTENSITY_ARB", COMPRESSED_INTENSITY_ARB},
{"COMPRESSED_RGB_ARB", COMPRESSED_RGB_ARB},
{"COMPRESSED_RGBA_ARB", COMPRESSED_RGBA_ARB},
*/
{"1", 1},
{"2", 2},
{"3", 3},