projectile coloring by shader

This commit is contained in:
laochailan 2011-04-26 16:55:18 +02:00
parent bdc0db9957
commit 72286b4529
19 changed files with 99 additions and 109 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.8 KiB

After

Width:  |  Height:  |  Size: 1.1 KiB

View file

@ -15,7 +15,10 @@
id="svg2"
version="1.1"
inkscape:version="0.48.1 r9760"
sodipodi:docname="ball.svg">
sodipodi:docname="ball_auto.svg"
inkscape:export-filename="/home/laochailan/src/taisei/gfx/proj/ball.png"
inkscape:export-xdpi="90"
inkscape:export-ydpi="90">
<defs
id="defs4">
<linearGradient
@ -99,7 +102,7 @@
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title />
<dc:title></dc:title>
</cc:Work>
</rdf:RDF>
</metadata>
@ -116,7 +119,7 @@
sodipodi:cy="10.034214"
sodipodi:rx="8.4631844"
sodipodi:ry="8.4631844"
d="m 18.782524,10.034214 a 8.4631844,8.4631844 0 1 1 -16.9263686,0 8.4631844,8.4631844 0 1 1 16.9263686,0 z"
d="m 18.782524,10.034214 c 0,4.674088 -3.789097,8.463184 -8.463184,8.463184 -4.6740879,0 -8.4631846,-3.789096 -8.4631846,-8.463184 0,-4.6740876 3.7890967,-8.4631843 8.4631846,-8.4631843 4.674087,0 8.463184,3.7890967 8.463184,8.4631843 z"
transform="matrix(1.2539305,0,0,1.2539304,-0.18915284,1027.0303)" />
<path
sodipodi:type="arc"
@ -126,7 +129,7 @@
sodipodi:cy="10.034214"
sodipodi:rx="8.4631844"
sodipodi:ry="8.4631844"
d="m 18.782524,10.034214 a 8.4631844,8.4631844 0 1 1 -16.9263686,0 8.4631844,8.4631844 0 1 1 16.9263686,0 z"
d="m 18.782524,10.034214 c 0,4.674088 -3.789097,8.463184 -8.463184,8.463184 -4.6740879,0 -8.4631846,-3.789096 -8.4631846,-8.463184 0,-4.6740876 3.7890967,-8.4631843 8.4631846,-8.4631843 4.674087,0 8.463184,3.7890967 8.463184,8.4631843 z"
transform="matrix(1.4733683,0,0,1.4733683,-2.4636846,1024.824)" />
</g>
</svg>

Before

Width:  |  Height:  |  Size: 4 KiB

After

Width:  |  Height:  |  Size: 4.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.5 KiB

After

Width:  |  Height:  |  Size: 1.4 KiB

View file

@ -14,8 +14,11 @@
height="40"
id="svg4388"
version="1.1"
inkscape:version="0.48.0 r9654"
sodipodi:docname="Neues Dokument 8">
inkscape:version="0.48.1 r9760"
sodipodi:docname="bigball_auto.svg"
inkscape:export-filename="/home/laochailan/src/taisei/gfx/proj/bigball.png"
inkscape:export-xdpi="90"
inkscape:export-ydpi="90">
<defs
id="defs4390">
<linearGradient
@ -59,9 +62,9 @@
inkscape:current-layer="layer1"
showgrid="false"
inkscape:window-width="1918"
inkscape:window-height="1061"
inkscape:window-x="0"
inkscape:window-y="17"
inkscape:window-height="1037"
inkscape:window-x="-75"
inkscape:window-y="178"
inkscape:window-maximized="0" />
<metadata
id="metadata4393">
@ -88,7 +91,7 @@
sodipodi:cy="14.190687"
sodipodi:rx="5.6319289"
sodipodi:ry="6.2084255"
d="m 24.345897,14.190687 a 5.6319289,6.2084255 0 1 1 -11.263858,0 5.6319289,6.2084255 0 1 1 11.263858,0 z"
d="m 24.345897,14.190687 c 0,3.428819 -2.5215,6.208426 -5.631929,6.208426 -3.110428,0 -5.631929,-2.779607 -5.631929,-6.208426 0,-3.428819 2.521501,-6.2084253 5.631929,-6.2084253 3.110429,0 5.631929,2.7796063 5.631929,6.2084253 z"
transform="matrix(3.5511812,0,0,3.2214287,-46.456692,986.64793)" />
</g>
</svg>

Before

Width:  |  Height:  |  Size: 2.8 KiB

After

Width:  |  Height:  |  Size: 3.1 KiB

View file

@ -1,11 +0,0 @@
#!/bin/sh
# ** Render projectiles from svg ** #
#
# requires imagemagick
for f in *_auto.svg; do
convert \( $f -channel G -separate \( $f -channel B -separate \) +append \) \
\( +clone -colorspace HSL -channel B \) \
-channel A -combine ${f%_auto.*}.png
done

Binary file not shown.

Before

Width:  |  Height:  |  Size: 827 B

After

Width:  |  Height:  |  Size: 507 B

View file

@ -14,8 +14,11 @@
height="20"
id="svg3824"
version="1.1"
inkscape:version="0.48.0 r9654"
sodipodi:docname="Neues Dokument 5">
inkscape:version="0.48.1 r9760"
sodipodi:docname="rice_auto.svg"
inkscape:export-filename="/home/laochailan/src/taisei/gfx/proj/rice.png"
inkscape:export-xdpi="90"
inkscape:export-ydpi="90">
<defs
id="defs3826">
<linearGradient
@ -59,9 +62,9 @@
inkscape:current-layer="layer1"
showgrid="false"
inkscape:window-width="1918"
inkscape:window-height="1061"
inkscape:window-x="0"
inkscape:window-y="17"
inkscape:window-height="1037"
inkscape:window-x="-167"
inkscape:window-y="0"
inkscape:window-maximized="0" />
<metadata
id="metadata3829">
@ -88,7 +91,7 @@
sodipodi:cy="9.7228384"
sodipodi:rx="4.6452327"
sodipodi:ry="9.7228384"
d="m 9.2682924,9.7228384 a 4.6452327,9.7228384 0 1 1 -9.29046533,0 4.6452327,9.7228384 0 1 1 9.29046533,0 z"
d="m 9.2682924,9.7228384 c 0,5.3697756 -2.0797415,9.7228386 -4.6452327,9.7228386 -2.5654911,0 -4.64523263,-4.353063 -4.64523263,-9.7228386 C -0.02217293,4.353063 2.0575686,0 4.6230597,0 7.1885509,0 9.2682924,4.353063 9.2682924,9.7228384 z"
transform="matrix(1.0763723,0,0,1.0285062,0.02386633,1032.3622)" />
</g>
</svg>

Before

Width:  |  Height:  |  Size: 2.8 KiB

After

Width:  |  Height:  |  Size: 3.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 934 B

After

Width:  |  Height:  |  Size: 904 B

View file

@ -10,7 +10,7 @@
xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
width="16"
width="8"
height="12"
id="svg2"
version="1.1"
@ -74,19 +74,6 @@
x2="2.3495057"
y2="3.0433807"
gradientUnits="userSpaceOnUse" />
<filter
inkscape:collect="always"
id="filter4412"
x="-0.17254388"
width="1.3450878"
y="-0.12395158"
height="1.2479032"
color-interpolation-filters="sRGB">
<feGaussianBlur
inkscape:collect="always"
stdDeviation="0.095963993"
id="feGaussianBlur4414" />
</filter>
<filter
inkscape:collect="always"
id="filter3777"
@ -156,7 +143,7 @@
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title></dc:title>
<dc:title />
</cc:Work>
</rdf:RDF>
</metadata>
@ -166,13 +153,13 @@
id="layer1"
transform="translate(0,-1040.3622)">
<path
style="color:#000000;fill:url(#linearGradient3839);fill-opacity:1;stroke:none;stroke-width:1;marker:none;visibility:visible;display:inline;overflow:visible;enable-background:accumulate;opacity:0.82677165"
style="opacity:0.8267717;color:#000000;fill:url(#linearGradient3839);fill-opacity:1;stroke:none;stroke-width:1;marker:none;visibility:visible;display:inline;overflow:visible;enable-background:accumulate"
d="m 0.36489949,1047.7169 c 0.35033055,-8.1615 6.16583381,-10.4109 7.27020101,0 -2.5409842,-7.9675 -4.9605546,-7.708 -7.27020101,0 z"
id="path2985"
inkscape:connector-curvature="0"
sodipodi:nodetypes="ccc" />
<path
style="opacity:0.56299213;color:#000000;fill:#659eff;fill-opacity:1;stroke:none;stroke-width:1;marker:none;visibility:visible;display:inline;overflow:visible;filter:url(#filter3783);enable-background:accumulate"
style="opacity:0.56299217;color:#000000;fill:#659eff;fill-opacity:1;stroke:none;stroke-width:1;marker:none;visibility:visible;display:inline;overflow:visible;filter:url(#filter3783);enable-background:accumulate"
d="m 0.15077605,1052.2779 c 0.0776544,-16.901 6.23081395,-23.0311 7.86488385,0 -2.7886226,-9.0012 -5.4199058,-9.1633 -7.86488385,0 z"
id="path3781"
inkscape:connector-curvature="0"
@ -185,7 +172,7 @@
inkscape:connector-curvature="0"
id="path3775"
d="m 0.39474728,1047.3341 c 0.37898665,-8.8342 6.67018232,-11.269 7.86488382,0 -2.5560342,-7.0818 -5.2264322,-7.2242 -7.86488382,0 z"
style="color:#000000;fill:url(#linearGradient3841);fill-opacity:1;stroke:none;stroke-width:1;marker:none;visibility:visible;display:inline;overflow:visible;filter:url(#filter3777);enable-background:accumulate;opacity:0.82677165"
style="opacity:0.8267717;color:#000000;fill:url(#linearGradient3841);fill-opacity:1;stroke:none;stroke-width:1;marker:none;visibility:visible;display:inline;overflow:visible;filter:url(#filter3777);enable-background:accumulate"
transform="matrix(0.92438759,0,0,0.92385898,0,80.127931)" />
</g>
</svg>

Before

Width:  |  Height:  |  Size: 6.4 KiB

After

Width:  |  Height:  |  Size: 6 KiB

View file

@ -1,6 +1,4 @@
void main(void)
{
void main(void) {
gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
gl_FrontColor = gl_Color;
gl_TexCoord[0] = gl_MultiTexCoord0;
@ -12,9 +10,9 @@ uniform sampler2D tex;
uniform vec2 blur_orig; // center
uniform vec2 fix_orig;
uniform float rad; // radius of zoom effect
uniform float ratio; // texture w/h
void main(void)
{
void main(void) {
vec2 pos = vec2(gl_TexCoord[0]);
pos -= blur_orig;
@ -27,7 +25,7 @@ void main(void)
gl_FragColor = texture2D(tex, pos + blur_orig);
pos1 = vec2(gl_TexCoord[0]) - fix_orig;
pos1.y *= 2.0;
pos1.y *= ratio;
if(length(pos1) < rad)
gl_FragColor *= pow(vec4(0.1,0.2,0.3,1),vec4(3.0*(rad - length(pos1))));

15
shader/bullet_color.sha Normal file
View file

@ -0,0 +1,15 @@
void main(void) {
gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
gl_FrontColor = gl_Color;
gl_TexCoord[0] = gl_MultiTexCoord0;
}
%% -- FRAG
uniform sampler2D tex;
uniform vec4 color;
void main(void) {
vec4 texel = texture2D(tex, vec2(gl_TexCoord[0]));
gl_FragColor = mix(color, vec4(1.0), texel.b)*texel.a;
}

View file

@ -9,7 +9,7 @@
#include "global.h"
#include "list.h"
Laser *create_laser(LaserType type, complex pos, complex pos0, int time, int deathtime, ColorA color, LaserRule rule, complex args, ...) {
Laser *create_laser(LaserType type, complex pos, complex pos0, int time, int deathtime, Color color, LaserRule rule, complex args, ...) {
Laser *l = create_element((void **)&global.lasers, sizeof(Laser));
l->type = type;

View file

@ -29,7 +29,7 @@ typedef struct Laser {
complex pos;
complex pos0; // if type == LaserLine, carg(pos0) is orientation and cabs(pos0) width
ColorA color;
Color color;
int birthtime;
int time; // line: startup time; curve: length
@ -39,7 +39,7 @@ typedef struct Laser {
complex args[4];
} Laser;
Laser *create_laser(LaserType type, complex pos, complex pos0, int time, int deathtime, ColorA color, LaserRule rule, complex args, ...);
Laser *create_laser(LaserType type, complex pos, complex pos0, int time, int deathtime, Color color, LaserRule rule, complex args, ...);
void draw_lasers();
void free_lasers();
void process_lasers();

View file

@ -90,14 +90,14 @@ void player_logic(Player* plr) {
process_enemies(&plr->slaves);
if(plr->fire && !(global.frames % 4)) {
create_projectile("youmu", plr->pos + 10 - I*20, ((Color){1,1,1}), linear, -20I)->type = PlrProj;
create_projectile("youmu", plr->pos - 10 - I*20, ((Color){1,1,1}), linear, -20I)->type = PlrProj;
create_projectile("youmu", plr->pos + 10 - I*20, NULL, linear, -20I)->type = PlrProj;
create_projectile("youmu", plr->pos - 10 - I*20, NULL, linear, -20I)->type = PlrProj;
if(plr->power >= 2) {
float a = 0.20;
if(plr->focus > 0) a = 0.06;
create_projectile("youmu", plr->pos - 10 - I*20, ((Color){1,1,1}), linear, I*-20*cexp(-I*a))->type = PlrProj;
create_projectile("youmu", plr->pos + 10 - I*20, ((Color){1,1,1}), linear, I*-20*cexp(I*a))->type = PlrProj;
create_projectile("youmu", plr->pos - 10 - I*20, NULL, linear, I*-20*cexp(-I*a))->type = PlrProj;
create_projectile("youmu", plr->pos + 10 - I*20, NULL, linear, I*-20*cexp(I*a))->type = PlrProj;
}
}

View file

@ -29,7 +29,7 @@ void youmu_opposite_logic(Enemy *e, int t) {
}
if(plr->fire && !(global.frames % 4))
create_projectile("youmu", e->pos + plr->pos, ((Color){1,1,1}), linear, -20*cexp(I*e->args[1]))->type = PlrProj;
create_projectile("youmu", e->pos + plr->pos, NULL, linear, -20*cexp(I*e->args[1]))->type = PlrProj;
e->pos0 = e->pos + plr->pos;
}

View file

@ -12,7 +12,21 @@
#include "global.h"
#include "list.h"
Projectile *create_projectile(char *name, complex pos, Color clr,
Color *rgba(float r, float g, float b, float a) {
Color *clr = malloc(sizeof(Color));
clr->r = r;
clr->g = g;
clr->b = b;
clr->a = a;
return clr;
}
inline Color *rgb(float r, float g, float b) {
return rgba(r, g, b, 1.0);
}
Projectile *create_projectile(char *name, complex pos, Color *clr,
ProjRule rule, complex args, ...) {
Projectile *p = create_element((void **)&global.projs, sizeof(Projectile));
@ -50,7 +64,7 @@ void free_projectiles() {
delete_all_elements((void **)&global.projs);
}
int test_collision(Projectile *p) {
int collision_projectile(Projectile *p) {
if(p->type == FairyProj) {
float angle = carg(global.plr.pos - p->pos);
int projr = sqrt(pow(p->tex->w/4*cos(angle),2)*8/10 + pow(p->tex->h/2*sin(angle)*8/10,2));
@ -63,7 +77,6 @@ int test_collision(Projectile *p) {
if(e->hp != ENEMY_IMMUNE && cabs(e->pos - p->pos) < 15) {
global.points += 100;
e->hp--;
play_sound("hit");
return 2;
}
e = e->next;
@ -71,55 +84,35 @@ int test_collision(Projectile *p) {
if(global.boss != NULL && cabs(global.boss->pos - p->pos) < 15) {
global.boss->dmg++;
play_sound("hit");
return 2;
}
}
return 0;
}
void draw_projectiles() {
glEnable(GL_TEXTURE_2D);
void draw_projectiles() {
Projectile *proj;
Texture *tex;
float wq, hq;
for(proj = global.projs; proj; proj = proj->next) {
tex = proj->tex;
glBindTexture(GL_TEXTURE_2D, tex->gltex);
GLuint shader = get_shader("bullet_color");
glUseProgramObjectARB(shader);
wq = ((float)tex->w/2.0)/tex->truew;
hq = ((float)tex->h)/tex->trueh;
for(proj = global.projs; proj; proj = proj->next) {
if(proj->clr == NULL)
glUseProgramObjectARB(0);
glUniform4fv(glGetUniformLocation(shader, "color"), 1, (GLfloat *)proj->clr);
glPushMatrix();
glTranslatef(creal(proj->pos), cimag(proj->pos), 0);
glRotatef(proj->angle*180/M_PI+90, 0, 0, 1);
glScalef(tex->w/4.0, tex->h/2.0,0);
glBegin(GL_QUADS);
glTexCoord2f(0,0); glVertex2f(-1, -1);
glTexCoord2f(0,hq); glVertex2f(-1, 1);
glTexCoord2f(wq,hq); glVertex2f(1, 1);
glTexCoord2f(wq,0); glVertex2f(1, -1);
glEnd();
glColor3fv((float *)&proj->clr);
glBegin(GL_QUADS);
glTexCoord2f(wq,0); glVertex2f(-1, -1);
glTexCoord2f(wq,hq); glVertex2f(-1, 1);
glTexCoord2f(2*wq,hq); glVertex2f(1, 1);
glTexCoord2f(2*wq,0); glVertex2f(1, -1);
glEnd();
draw_texture_p(0,0, proj->tex);
glPopMatrix();
glColor3f(1,1,1);
if(proj->clr == NULL)
glUseProgramObjectARB(shader);
}
glDisable(GL_TEXTURE_2D);
glUseProgramObjectARB(0);
}
void process_projectiles() {
@ -127,7 +120,7 @@ void process_projectiles() {
while(proj != NULL) {
proj->rule(&proj->pos, proj->pos0, &proj->angle, global.frames - proj->birthtime, proj->args);
int v = test_collision(proj);
int v = collision_projectile(proj);
if(v == 1 && (global.frames - abs(global.plr.recovery)) >= 0)
plr_death(&global.plr);

View file

@ -13,18 +13,12 @@
#include <stdarg.h>
#include <complex.h>
typedef struct {
float r;
float g;
float b;
} Color;
typedef struct {
float r;
float g;
float b;
float a;
} ColorA;
} Color;
struct Projectile;
typedef void (*ProjRule)(complex *pos, complex pos0, float *angle, int time, complex* args);
@ -45,20 +39,24 @@ typedef struct Projectile {
enum { PlrProj, FairyProj } type;
Color clr;
Color *clr;
complex args[4];
} Projectile;
void load_projectiles();
Projectile *create_projectile(char *name, complex pos, Color clr, ProjRule rule, complex args, ...);
Color *rgba(float r, float g, float b, float a);
inline Color *rgb(float r, float g, float b);
Projectile *create_projectile(char *name, complex pos, Color *clr, ProjRule rule, complex args, ...);
void delete_projectile(Projectile *proj);
void draw_projectile(Projectile *proj);
void draw_projectiles();
void free_projectiles();
int test_collision(Projectile *p);
int collision_projectile(Projectile *p);
void process_projectiles();
void linear(complex *pos, complex pos0, float *angle, int time, complex* args);

View file

@ -138,6 +138,7 @@ void apply_bg_shaders() {
glUniform2f(glGetUniformLocation(shader, "fix_orig"),
(creal(fpos)+VIEWPORT_X)/global.rtt.nw, (VIEWPORT_H - cimag(fpos) - VIEWPORT_Y/2)/global.rtt.nh);
glUniform1f(glGetUniformLocation(shader, "rad"), 0.3);
glUniform1f(glGetUniformLocation(shader, "ratio"), (float)global.rtt.nh/global.rtt.nw);
}
glPushMatrix();

View file

@ -20,7 +20,7 @@ void simpleEnemy(Enemy *e, int t) {
}
if(!((global.frames - e->birthtime) % 50))
create_projectile("rice", e->pos, ((Color){0,0,1}), linear,3 + 2I);
create_projectile("ball", e->pos, rgb(0,0,1), linear,3 + 2I);
e->moving = 1;
e->dir = creal(e->args[0]) < 0;
@ -128,7 +128,7 @@ void cirno_test(Boss *c, int time) {
int i;
if(!(time % 50))
for(i = 0; i < 6; i++)
create_laser(LaserCurve, c->pos, c->pos, 50, 200, ((ColorA){0.5,0.5,1,0.4}), lolsin, i);
create_laser(LaserCurve, c->pos, c->pos, 50, 200, ((Color){0.5,0.5,1,0.4}), lolsin, i);
}
Boss *create_cirno() {