Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKévin Dietrich <kevin.dietrich@mailoo.org>2016-01-10 09:36:23 +0300
committerKévin Dietrich <kevin.dietrich@mailoo.org>2016-01-10 09:36:23 +0300
commit0372b642705c5304f252f7691b188fc65dd51b59 (patch)
treee7f1d6fb1dff5889a93d7ec0c363a04e0364365a /source/blender/gpu/shaders
parentd330162ba6981a6c3691bcc8759215463d47f973 (diff)
OpenGL: port smoke drawing code to GLSL.
Beside the obvious ARB -> GLSL change, the texture slicing algorithm had to be rewritten. Although this new algorithm has the same behaviour as the old one (view aligned slicing), it works with an arbitrary number of slices (which could eventually be set by the user), which means we can preallocate the buffer. The previous algorithm would slice from the begining to the end of the volume's bbox, and draw the slices as it generates them. Also support for ARB program was removed. Patch by myself, with some minor fixes by Brecht. Reviewers: brecht, #opengl_gfx Differential Revision: https://developer.blender.org/D1694
Diffstat (limited to 'source/blender/gpu/shaders')
-rw-r--r--source/blender/gpu/shaders/gpu_program_smoke_color_frag.glsl32
-rw-r--r--source/blender/gpu/shaders/gpu_program_smoke_frag.glsl27
-rw-r--r--source/blender/gpu/shaders/gpu_shader_smoke_frag.glsl48
-rw-r--r--source/blender/gpu/shaders/gpu_shader_smoke_vert.glsl12
4 files changed, 60 insertions, 59 deletions
diff --git a/source/blender/gpu/shaders/gpu_program_smoke_color_frag.glsl b/source/blender/gpu/shaders/gpu_program_smoke_color_frag.glsl
deleted file mode 100644
index a94c823f408..00000000000
--- a/source/blender/gpu/shaders/gpu_program_smoke_color_frag.glsl
+++ /dev/null
@@ -1,32 +0,0 @@
-!!ARBfp1.0
-PARAM dx = program.local[0];
-PARAM darkness = program.local[1];
-PARAM render = program.local[2];
-PARAM f = {1.442695041, 1.442695041, 1.442695041, 1.442695041};
-TEMP temp, shadow, flame, spec, value;
-TEX temp, fragment.texcoord[0], texture[0], 3D;
-TEX shadow, fragment.texcoord[0], texture[1], 3D;
-TEX flame, fragment.texcoord[0], texture[2], 3D;
-TEX spec, flame.r, texture[3], 1D;
-# unpremultiply volume texture
-RCP value.r, temp.a;
-MUL temp.r, temp.r, value.r;
-MUL temp.g, temp.g, value.r;
-MUL temp.b, temp.b, value.r;
-# calculate shading factor from density
-MUL value.r, temp.a, darkness.a;
-MUL value.r, value.r, dx.r;
-MUL value.r, value.r, f.r;
-EX2 value.r, -value.r;
-# alpha
-SUB temp.a, 1.0, value.r;
-# shade colors
-MUL temp.r, temp.r, shadow.r;
-MUL temp.g, temp.g, shadow.r;
-MUL temp.b, temp.b, shadow.r;
-MUL temp.r, temp.r, value.r;
-MUL temp.g, temp.g, value.r;
-MUL temp.b, temp.b, value.r;
-# for now this just replace smoke shading if rendering fire
-CMP result.color, render.r, temp, spec;
-END
diff --git a/source/blender/gpu/shaders/gpu_program_smoke_frag.glsl b/source/blender/gpu/shaders/gpu_program_smoke_frag.glsl
deleted file mode 100644
index 04b171d24bd..00000000000
--- a/source/blender/gpu/shaders/gpu_program_smoke_frag.glsl
+++ /dev/null
@@ -1,27 +0,0 @@
-!!ARBfp1.0
-PARAM dx = program.local[0];
-PARAM darkness = program.local[1];
-PARAM render = program.local[2];
-PARAM f = {1.442695041, 1.442695041, 1.442695041, 0.01};
-TEMP temp, shadow, flame, spec, value;
-TEX temp, fragment.texcoord[0], texture[0], 3D;
-TEX shadow, fragment.texcoord[0], texture[1], 3D;
-TEX flame, fragment.texcoord[0], texture[2], 3D;
-TEX spec, flame.r, texture[3], 1D;
-# calculate shading factor from density
-MUL value.r, temp.a, darkness.a;
-MUL value.r, value.r, dx.r;
-MUL value.r, value.r, f.r;
-EX2 temp, -value.r;
-# alpha
-SUB temp.a, 1.0, temp.r;
-# shade colors
-MUL temp.r, temp.r, shadow.r;
-MUL temp.g, temp.g, shadow.r;
-MUL temp.b, temp.b, shadow.r;
-MUL temp.r, temp.r, darkness.r;
-MUL temp.g, temp.g, darkness.g;
-MUL temp.b, temp.b, darkness.b;
-# for now this just replace smoke shading if rendering fire
-CMP result.color, render.r, temp, spec;
-END
diff --git a/source/blender/gpu/shaders/gpu_shader_smoke_frag.glsl b/source/blender/gpu/shaders/gpu_shader_smoke_frag.glsl
new file mode 100644
index 00000000000..c467925725d
--- /dev/null
+++ b/source/blender/gpu/shaders/gpu_shader_smoke_frag.glsl
@@ -0,0 +1,48 @@
+
+varying vec3 coords;
+
+uniform vec4 active_color;
+uniform float cell_spacing;
+
+uniform sampler3D soot_texture;
+uniform sampler3D shadow_texture;
+
+#ifdef USE_FIRE
+uniform sampler3D flame_texture;
+uniform sampler1D spectrum_texture;
+#endif
+
+void main()
+{
+ vec4 soot = texture3D(soot_texture, coords);
+
+ /* unpremultiply volume texture */
+ float value = 1.0f / soot.a;
+ soot.xyz *= vec3(value);
+
+ /* calculate shading factor from soot */
+ value = soot.a * active_color.a;
+ value *= cell_spacing;
+ value *= 1.442695041;
+ soot = vec4(pow(2.0, -value));
+
+ /* alpha */
+ soot.a = 1.0 - soot.r;
+
+ /* shade colors */
+ vec3 shadow = texture3D(shadow_texture, coords).rrr;
+ soot.xyz *= shadow;
+ soot.xyz *= active_color.xyz;
+
+ /* premultiply alpha */
+ vec4 color = vec4(soot.a * soot.rgb, soot.a);
+
+#ifdef USE_FIRE
+ /* blend in fire */
+ float flame = texture3D(flame_texture, coords).r;
+ vec4 spec = texture1D(spectrum_texture, flame);
+ color = vec4(color.rgb + (1 - color.a) * spec.a * spec.rgb, color.a);
+#endif
+
+ gl_FragColor = color;
+}
diff --git a/source/blender/gpu/shaders/gpu_shader_smoke_vert.glsl b/source/blender/gpu/shaders/gpu_shader_smoke_vert.glsl
new file mode 100644
index 00000000000..daabf9b97a3
--- /dev/null
+++ b/source/blender/gpu/shaders/gpu_shader_smoke_vert.glsl
@@ -0,0 +1,12 @@
+
+varying vec3 coords;
+
+uniform vec3 min;
+uniform vec3 invsize;
+uniform vec3 ob_sizei;
+
+void main()
+{
+ gl_Position = gl_ModelViewProjectionMatrix * vec4(gl_Vertex.xyz * ob_sizei, 1.0);
+ coords = (gl_Vertex.xyz - min) * invsize;
+}