OpenGL: clean up smoke & fire shaders

TODO: swap gl_Vertex for vec3 pos, update smoke setup code
This commit is contained in:
Mike Erwin 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;
out vec4 fragColor;
#define texture1D texture
#define texture3D texture
uniform sampler3D flame_texture;
uniform sampler1D spectrum_texture;
void main()
{
float flame = texture3D(flame_texture, coords).r;
vec4 emission = texture1D(spectrum_texture, flame);
float flame = texture(flame_texture, coords).r;
vec4 emission = texture(spectrum_texture, flame);
vec4 color;
color.rgb = emission.a * emission.rgb;
color.a = emission.a;
fragColor = color;
fragColor.rgb = emission.a * emission.rgb;
fragColor.a = emission.a;
}

View File

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

View File

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