mirror of
https://github.com/The-Powder-Toy/The-Powder-Toy.git
synced 2025-04-25 09:14:22 +02:00
Generate fire/plasma gradients at runtime, makes editing easier
This commit is contained in:
parent
66fd41673b
commit
8f91f948c1
@ -2,7 +2,6 @@
|
||||
#define GRAPHICS_H
|
||||
#include <SDL/SDL.h>
|
||||
#include "defines.h"
|
||||
#include "hmap.h"
|
||||
|
||||
#ifdef PIX16
|
||||
#define PIXELSIZE 2
|
||||
@ -61,6 +60,16 @@ extern unsigned int fire_alpha[CELL*3][CELL*3];
|
||||
extern pixel *fire_bg;
|
||||
extern pixel *pers_bg;
|
||||
|
||||
extern char * flm_data;
|
||||
extern int flm_data_points;;
|
||||
extern pixel flm_data_colours[];
|
||||
extern float flm_data_pos[];
|
||||
|
||||
extern char * plasma_data;
|
||||
extern int plasma_data_points;;
|
||||
extern pixel plasma_data_colours[];
|
||||
extern float plasma_data_pos[];
|
||||
|
||||
struct gcache_item
|
||||
{
|
||||
int isready;
|
||||
@ -76,6 +85,8 @@ int graphics_DEFAULT(GRAPHICS_FUNC_ARGS);
|
||||
|
||||
void prepare_graphicscache();
|
||||
|
||||
char * generate_gradient(pixel * colours, float * points, int pointcount, int size);
|
||||
|
||||
void draw_rgba_image(pixel *vid, unsigned char *data, int x, int y, float a);
|
||||
|
||||
void *ptif_pack(pixel *src, int w, int h, int *result_size);
|
||||
@ -208,6 +219,8 @@ void ogl_blit(int x, int y, int w, int h, pixel *src, int pitch, int scale);
|
||||
#endif
|
||||
|
||||
#ifdef INCLUDE_SHADERS
|
||||
#ifndef SHADERS_H
|
||||
#define SHADERS_H
|
||||
const char * fireFragment = "uniform sampler2D fireAlpha;\
|
||||
void main () {\
|
||||
vec4 texColor = texture2D(fireAlpha, gl_PointCoord);\
|
||||
@ -257,5 +270,5 @@ const char * airVertex = "void main(void)\
|
||||
gl_Position = ftransform();;\
|
||||
gl_FrontColor = gl_Color;\
|
||||
}";
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
File diff suppressed because one or more lines are too long
@ -2,7 +2,7 @@
|
||||
|
||||
int graphics_FIRE(GRAPHICS_FUNC_ARGS)
|
||||
{
|
||||
int caddress = restrict_flt(restrict_flt((float)((int)(cpart->life/2)), 0.0f, 200.0f)*3, 0.0f, (200.0f*3)-3);
|
||||
int caddress = restrict_flt(restrict_flt((float)cpart->life, 0.0f, 200.0f)*3, 0.0f, (200.0f*3)-3);
|
||||
*colr = (unsigned char)flm_data[caddress];
|
||||
*colg = (unsigned char)flm_data[caddress+1];
|
||||
*colb = (unsigned char)flm_data[caddress+2];
|
||||
|
@ -1,4 +1,6 @@
|
||||
#include <element.h>
|
||||
#include "hmap.h"
|
||||
|
||||
int graphics_QRTZ(GRAPHICS_FUNC_ARGS) //QRTZ and PQRT
|
||||
{
|
||||
int t = cpart->type, z = cpart->tmp - 5;//speckles!
|
||||
|
@ -1,4 +1,5 @@
|
||||
#include <element.h>
|
||||
#include "hmap.h"
|
||||
|
||||
int graphics_PLSM(GRAPHICS_FUNC_ARGS)
|
||||
{
|
||||
@ -12,7 +13,7 @@ int graphics_PLSM(GRAPHICS_FUNC_ARGS)
|
||||
*fireg = *colg;
|
||||
*fireb = *colb;
|
||||
|
||||
*pixel_mode = PMODE_NONE; //Clear default, don't draw pixel
|
||||
*pixel_mode = PMODE_GLOW; //Clear default, don't draw pixel
|
||||
*pixel_mode |= FIRE_ADD;
|
||||
//Returning 0 means dynamic, do not cache
|
||||
return 0;
|
||||
|
@ -21,7 +21,7 @@
|
||||
#define INCLUDE_FONTDATA
|
||||
#include <font.h>
|
||||
#include <misc.h>
|
||||
|
||||
#include "hmap.h"
|
||||
|
||||
unsigned cmode = CM_FIRE;
|
||||
SDL_Surface *sdl_scrn;
|
||||
@ -44,6 +44,63 @@ unsigned int fire_alpha[CELL*3][CELL*3];
|
||||
pixel *fire_bg;
|
||||
pixel *pers_bg;
|
||||
|
||||
char * flm_data;
|
||||
int flm_data_points = 4;
|
||||
pixel flm_data_colours[] = {PIXPACK(0xAF9F0F), PIXPACK(0xDFBF0F), PIXPACK(0x60300F), PIXPACK(0x000000)};
|
||||
float flm_data_pos[] = {1.0f, 0.9f, 0.5f, 0.0f};
|
||||
|
||||
char * plasma_data;
|
||||
int plasma_data_points = 5;
|
||||
pixel plasma_data_colours[] = {PIXPACK(0xAFFFFF), PIXPACK(0xAFFFFF), PIXPACK(0x301060), PIXPACK(0x301040), PIXPACK(0x000000)};
|
||||
float plasma_data_pos[] = {1.0f, 0.9f, 0.5f, 0.25, 0.0f};
|
||||
|
||||
char * generate_gradient(pixel * colours, float * points, int pointcount, int size)
|
||||
{
|
||||
int cp, i, j;
|
||||
pixel ptemp;
|
||||
char * newdata = malloc(size * 3);
|
||||
float poss, pose, temp;
|
||||
memset(newdata, 0, size*3);
|
||||
//Sort the Colours and Points
|
||||
for (i = (pointcount - 1); i > 0; i--)
|
||||
{
|
||||
for (j = 1; j <= i; j++)
|
||||
{
|
||||
if (points[j-1] > points[j])
|
||||
{
|
||||
temp = points[j-1];
|
||||
points[j-1] = points[j];
|
||||
points[j] = temp;
|
||||
|
||||
ptemp = colours[j-1];
|
||||
colours[j-1] = colours[j];
|
||||
colours[j] = ptemp;
|
||||
}
|
||||
}
|
||||
}
|
||||
i = 0;
|
||||
j = 1;
|
||||
poss = points[i];
|
||||
pose = points[j];
|
||||
for (cp = 0; cp < size; cp++)
|
||||
{
|
||||
float cpos = (float)cp / (float)size, ccpos, cccpos;
|
||||
if(cpos > pose && j+1 < pointcount)
|
||||
{
|
||||
poss = points[++i];
|
||||
pose = points[++j];
|
||||
}
|
||||
ccpos = cpos - poss;
|
||||
cccpos = ccpos / (pose - poss);
|
||||
if(cccpos > 1.0f)
|
||||
cccpos = 1.0f;
|
||||
newdata[(cp*3)] = PIXR(colours[i])*(1.0f-cccpos) + PIXR(colours[j])*(cccpos);
|
||||
newdata[(cp*3)+1] = PIXG(colours[i])*(1.0f-cccpos) + PIXG(colours[j])*(cccpos);
|
||||
newdata[(cp*3)+2] = PIXB(colours[i])*(1.0f-cccpos) + PIXB(colours[j])*(cccpos);
|
||||
}
|
||||
return newdata;
|
||||
}
|
||||
|
||||
void *ptif_pack(pixel *src, int w, int h, int *result_size){
|
||||
int i = 0, datalen = (w*h)*3, cx = 0, cy = 0;
|
||||
unsigned char *red_chan = calloc(1, w*h);
|
||||
@ -3481,8 +3538,8 @@ int sdl_open(void)
|
||||
glGenTextures(1, &partsFboTex);
|
||||
glBindTexture(GL_TEXTURE_2D, partsFboTex);
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, XRES, YRES, 0, GL_RGBA, GL_FLOAT, NULL);
|
||||
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
|
||||
|
||||
//FBO
|
||||
glGenFramebuffers(1, &partsFbo);
|
||||
|
@ -1741,6 +1741,8 @@ int main(int argc, char *argv[])
|
||||
|
||||
prepare_alpha(CELL, 1.0f);
|
||||
prepare_graphicscache();
|
||||
flm_data = generate_gradient(flm_data_colours, flm_data_pos, flm_data_points, 200);
|
||||
plasma_data = generate_gradient(plasma_data_colours, plasma_data_pos, plasma_data_points, 200);
|
||||
|
||||
if (cpu_check())
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user