OpenGL: clean up smoke & fire shaders

TODO: swap gl_Vertex for vec3 pos, update smoke setup code
This commit is contained in:
2017-05-19 10:43:32 -04:00
parent f6ffe12ddb
commit fa47437426
3 changed files with 14 additions and 22 deletions

View File

@@ -1,20 +1,15 @@
in vec3 coords; in vec3 coords;
out vec4 fragColor; out vec4 fragColor;
#define texture1D texture
#define texture3D texture
uniform sampler3D flame_texture; uniform sampler3D flame_texture;
uniform sampler1D spectrum_texture; uniform sampler1D spectrum_texture;
void main() void main()
{ {
float flame = texture3D(flame_texture, coords).r; float flame = texture(flame_texture, coords).r;
vec4 emission = texture1D(spectrum_texture, flame); vec4 emission = texture(spectrum_texture, flame);
vec4 color; fragColor.rgb = emission.a * emission.rgb;
color.rgb = emission.a * emission.rgb; fragColor.a = emission.a;
color.a = emission.a;
fragColor = color;
} }

View File

@@ -1,8 +1,6 @@
in vec3 coords; in vec3 coords;
out vec4 fragColor; out vec4 fragColor;
#define texture1D texture
#define texture3D texture
uniform vec3 active_color; uniform vec3 active_color;
uniform float step_size; uniform float step_size;
@@ -19,7 +17,7 @@ uniform sampler3D color_band_texture;
void main() void main()
{ {
/* compute color and density from volume texture */ /* compute color and density from volume texture */
vec4 soot = texture3D(soot_texture, coords); vec4 soot = texture(soot_texture, coords);
#ifndef USE_COBA #ifndef USE_COBA
vec3 soot_color; vec3 soot_color;
@@ -27,7 +25,7 @@ void main()
soot_color = active_color * soot.rgb / soot.a; soot_color = active_color * soot.rgb / soot.a;
} }
else { else {
soot_color = vec3(0, 0, 0); soot_color = vec3(0);
} }
float soot_density = density_scale * soot.a; float soot_density = density_scale * soot.a;
@@ -36,16 +34,14 @@ void main()
float soot_alpha = 1.0 - soot_transmittance; float soot_alpha = 1.0 - soot_transmittance;
/* shade */ /* shade */
float shadow = texture3D(shadow_texture, coords).r; float shadow = texture(shadow_texture, coords).r;
soot_color *= soot_transmittance * shadow; soot_color *= soot_transmittance * shadow;
/* premultiply alpha */ /* premultiply alpha */
vec4 color = vec4(soot_alpha * soot_color, soot_alpha); fragColor = vec4(soot_alpha * soot_color, soot_alpha);
#else #else
float color_band = texture3D(color_band_texture, coords).r; float color_band = texture(color_band_texture, coords).r;
vec4 transfer_function = texture1D(transfer_texture, color_band); vec4 transfer_function = texture(transfer_texture, color_band);
vec4 color = transfer_function * density_scale; fragColor = transfer_function * density_scale;
#endif #endif
fragColor = color;
} }

View File

@@ -9,6 +9,7 @@ uniform vec3 ob_sizei;
void main() void main()
{ {
// TODO: swap gl_Vertex for vec3 pos, update smoke setup code
gl_Position = ModelViewProjectionMatrix * vec4(gl_Vertex.xyz * ob_sizei, 1.0); gl_Position = ModelViewProjectionMatrix * vec4(gl_Vertex.xyz * ob_sizei, 1.0);
coords = (gl_Vertex.xyz - min_location) * invsize; coords = (gl_Vertex.xyz - min_location) * invsize;
} }