[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [30893] branches/soc-2010-kwk: Bump Map Preview - Usage Simplification
Konrad Kleine
konrad at konradwilhelm.de
Fri Jul 30 11:55:01 CEST 2010
Revision: 30893
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=30893
Author: kwk
Date: 2010-07-30 11:55:01 +0200 (Fri, 30 Jul 2010)
Log Message:
-----------
Bump Map Preview - Usage Simplification
* Removed "Height to Normal" checkbox to simplify usage.
** Simply enable "Normal" under "Texture -> Influence -> Geometry" and have your bump map previewed in a GLSL 3D View.
* Changed color mapping: Dark colors map to heights while light colors map to lows.
** A lot of BlenderArtists.org forum users complained about Blender's bump mapping in a way that today everybody else maps colors exactly the other way around.
Issues:
* Still I cannot debug my code because at a certain point, my complete system hangs. I compiled my code on MacOS where it crashes but the system won't hang. Somehow the debug traceback is full "basic_string.h" file warnings in line 227 although the functions calls to the crash are: main -> WM_main -> wm_event_do_handlers -> wm_handler_operator_call -> paint_stroke_modal -> paint_stroke_done -> brush_painter_free. I will try to inspect my paint code and especially "paint_stroke_done". Hopefully I can close this bug soon and move on to the next task. Painting has to work before I can proceed.
Modified Paths:
--------------
branches/soc-2010-kwk/release/scripts/op/image.py
branches/soc-2010-kwk/release/scripts/ui/properties_texture.py
branches/soc-2010-kwk/source/blender/gpu/intern/gpu_material.c
branches/soc-2010-kwk/source/blender/gpu/intern/gpu_shader_material.glsl
branches/soc-2010-kwk/source/blender/gpu/intern/gpu_shader_material.glsl.c
branches/soc-2010-kwk/source/blender/makesdna/DNA_texture_types.h
branches/soc-2010-kwk/source/blender/makesrna/intern/rna_texture.c
Modified: branches/soc-2010-kwk/release/scripts/op/image.py
===================================================================
--- branches/soc-2010-kwk/release/scripts/op/image.py 2010-07-30 09:32:21 UTC (rev 30892)
+++ branches/soc-2010-kwk/release/scripts/op/image.py 2010-07-30 09:55:01 UTC (rev 30893)
@@ -188,9 +188,10 @@
def check_free_texture_slots(mat):
"""Returns True if there are texture slots free in mat; otherwise False is returned"""
- for slot in mat.texture_slots:
- if slot == None:
- return True
+ if mat != None:
+ for slot in mat.texture_slots:
+ if slot == None:
+ return True
return False
class MultiChannelAddChannel(bpy.types.Operator):
Modified: branches/soc-2010-kwk/release/scripts/ui/properties_texture.py
===================================================================
--- branches/soc-2010-kwk/release/scripts/ui/properties_texture.py 2010-07-30 09:32:21 UTC (rev 30892)
+++ branches/soc-2010-kwk/release/scripts/ui/properties_texture.py 2010-07-30 09:55:01 UTC (rev 30893)
@@ -670,9 +670,6 @@
col.prop(tex, "invert_alpha", text="Invert")
col.separator()
col.prop(tex, "flip_axis", text="Flip X/Y Axis")
- col.separator()
- col.label(text="Bump preview:")
- col.prop(tex, "gen_norm_from_height", text="Height to Normal")
if wide_ui:
col = split.column()
Modified: branches/soc-2010-kwk/source/blender/gpu/intern/gpu_material.c
===================================================================
--- branches/soc-2010-kwk/source/blender/gpu/intern/gpu_material.c 2010-07-30 09:32:21 UTC (rev 30892)
+++ branches/soc-2010-kwk/source/blender/gpu/intern/gpu_material.c 2010-07-30 09:55:01 UTC (rev 30893)
@@ -48,6 +48,7 @@
#include "BKE_colortools.h"
#include "BKE_DerivedMesh.h"
#include "BKE_global.h"
+#include "BKE_image.h"
#include "BKE_main.h"
#include "BKE_node.h"
#include "BKE_scene.h"
@@ -60,6 +61,9 @@
#include "GPU_extensions.h"
#include "GPU_material.h"
+#include "IMB_imbuf.h"
+#include "IMB_imbuf_types.h"
+
#include "gpu_codegen.h"
#include <string.h>
@@ -893,8 +897,10 @@
GPUNodeLink *texco_global, *texco_uv = NULL;
GPUNodeLink *newnor, *orn;
char *lastuvname = NULL;
- float one = 1.0f, norfac, ofs[3];
+ float one = 1.0f, norfac, ofs[3], texsize[2];
int tex_nr, rgbnor, talpha;
+ void *lock;
+ ImBuf *ibuf;
GPU_link(mat, "set_value", GPU_uniform(&one), &stencil);
@@ -946,7 +952,7 @@
/* in case of uv, this would just undo a multiplication in texco_uv */
if(mtex->texco != TEXCO_UV)
GPU_link(mat, "mtex_2d_mapping", texco, &texco);
-
+
if(mtex->size[0] != 1.0f || mtex->size[1] != 1.0f || mtex->size[2] != 1.0f)
GPU_link(mat, "mtex_mapping_size", texco, GPU_uniform(mtex->size), &texco);
@@ -959,13 +965,47 @@
talpha = 0;
rgbnor = 0;
- if(tex && tex->type == TEX_IMAGE && tex->ima) {
- if (tex->imaflag & TEX_GEN_NORMAL_FROM_HEIGHT) {
- GPU_link(mat, "mtex_image_h2n", texco, GPU_image(tex->ima, &tex->iuser), GPU_uniform(mtex->size), &tin, &trgb, &tnor);
+ if(tex && tex->type == TEX_IMAGE && tex->ima) {
+ /* BEGIN (kwk) Bump Map preview through conversion to normal map */
+ if(mtex->mapto & MAP_NORM && (tex->imaflag & TEX_NORMALMAP)==0) {
+ ibuf= BKE_image_acquire_ibuf(tex->ima, NULL, &lock);
+ if (ibuf) {
+ texsize[0] = ibuf->x;
+ texsize[1] = ibuf->y;
+ }
+ else
+ {
+ texsize[0] = 0;
+ texsize[1] = 0;
+ }
+ BKE_image_release_ibuf(tex->ima, lock);
+ GPU_link(mat, "mtex_height_to_normal", texco, GPU_image(tex->ima, &tex->iuser), GPU_uniform(texsize), &tin, &trgb, &tnor);
+
+ if(mtex->norfac < 0.0f)
+ GPU_link(mat, "mtex_negate_texnormal", tnor, &tnor);
+
+ if(mtex->normapspace == MTEX_NSPACE_TANGENT)
+ GPU_link(mat, "mtex_nspace_tangent", GPU_attribute(CD_TANGENT, ""), shi->vn, tnor, &newnor);
+ else
+ newnor = tnor;
+
+ norfac = MIN2(fabsf(mtex->norfac), 1.0);
+ if(norfac == 1.0f && !GPU_link_changed(stencil)) {
+ shi->vn = newnor;
+ }
+ else {
+ tnorfac = GPU_uniform(&norfac);
+
+ if(GPU_link_changed(stencil))
+ GPU_link(mat, "math_multiply", tnorfac, stencil, &tnorfac);
+
+ GPU_link(mat, "mtex_blend_normal", tnorfac, shi->vn, newnor, &shi->vn);
+ }
}
+ /* END (kwk) Bump Map preview through conversion to normal map */
else {
- GPU_link(mat, "mtex_image", texco, GPU_image(tex->ima, &tex->iuser), &tin, &trgb, &tnor);
- }
+ GPU_link(mat, "mtex_image", texco, GPU_image(tex->ima, &tex->iuser), &tin, &trgb, &tnor);
+ }
rgbnor= TEX_RGB;
if(tex->imaflag & TEX_USEALPHA)
Modified: branches/soc-2010-kwk/source/blender/gpu/intern/gpu_shader_material.glsl
===================================================================
--- branches/soc-2010-kwk/source/blender/gpu/intern/gpu_shader_material.glsl 2010-07-30 09:32:21 UTC (rev 30892)
+++ branches/soc-2010-kwk/source/blender/gpu/intern/gpu_shader_material.glsl 2010-07-30 09:55:01 UTC (rev 30893)
@@ -1069,7 +1069,7 @@
/*
Helper function for on the fly normal map generation from height map.
*/
-void mtex_image_h2n_rgb2float(vec4 color, out float outval)
+void mtex_h2n_rgb2float(vec4 color, out float outval)
{
float scale = 1.0;
outval = (color.r + color.g + color .b) / 3.0 * scale;
@@ -1082,17 +1082,17 @@
It is inspired by The GIMP normal map plugin. I took the explicit algorithm and
streamlined it to fit implicit GPU computation.
*/
-void mtex_image_h2n(vec3 texcoord, sampler2D image, vec3 texsize, out float value, out vec4 color, out vec3 normal)
+void mtex_height_to_normal(vec3 texcoord, sampler2D image, vec2 texsize, out float value, out vec4 color, out vec3 normal)
{
float down, up, right, left;
/*texsize.xy = textureSize2D(image, 0);*/
- mtex_image_h2n_rgb2float( texture2D(image, texcoord.st+vec2(0,1)/texsize.xy), down );
- mtex_image_h2n_rgb2float( texture2D(image, texcoord.st+vec2(0,-1)/texsize.xy), up );
- mtex_image_h2n_rgb2float( texture2D(image, texcoord.st+vec2(1,0)/texsize.xy), right );
- mtex_image_h2n_rgb2float( texture2D(image, texcoord.st+vec2(-1,0)/texsize.xy), left );
+ mtex_h2n_rgb2float( texture2D(image, texcoord.st+vec2(0,1)/texsize.xy), down );
+ mtex_h2n_rgb2float( texture2D(image, texcoord.st+vec2(0,-1)/texsize.xy), up );
+ mtex_h2n_rgb2float( texture2D(image, texcoord.st+vec2(1,0)/texsize.xy), right );
+ mtex_h2n_rgb2float( texture2D(image, texcoord.st+vec2(-1,0)/texsize.xy), left );
- normal = normalize(vec3(right - left, up - down, 1.0));
+ normal = normalize(vec3(left - right, down - up, 1.0));
color = texture2D(image, texcoord.xy);
value = 1.0;
}
Modified: branches/soc-2010-kwk/source/blender/gpu/intern/gpu_shader_material.glsl.c
===================================================================
--- branches/soc-2010-kwk/source/blender/gpu/intern/gpu_shader_material.glsl.c 2010-07-30 09:32:21 UTC (rev 30892)
+++ branches/soc-2010-kwk/source/blender/gpu/intern/gpu_shader_material.glsl.c 2010-07-30 09:55:01 UTC (rev 30893)
@@ -1,734 +1,734 @@
/* DataToC output of file <gpu_shader_material_glsl> */
-int datatoc_gpu_shader_material_glsl_size= 34682;
+int datatoc_gpu_shader_material_glsl_size= 34659;
char datatoc_gpu_shader_material_glsl[]= {
- 10,102,108,111, 97,116, 32,101,120,112, 95, 98,108,101,110,100,101,114, 40,102,108,111, 97,116, 32,102,
- 41, 10,123, 10, 9,114,101,116,117,114,110, 32,112,111,119, 40, 50, 46, 55, 49, 56, 50, 56, 49, 56, 50, 56, 52, 54, 44, 32,102,
- 41, 59, 10,125, 10, 10,118,111,105,100, 32,114,103, 98, 95,116,111, 95,104,115,118, 40,118,101, 99, 52, 32,114,103, 98, 44, 32,
-111,117,116, 32,118,101, 99, 52, 32,111,117,116, 99,111,108, 41, 10,123, 10, 9,102,108,111, 97,116, 32, 99,109, 97,120, 44, 32,
- 99,109,105,110, 44, 32,104, 44, 32,115, 44, 32,118, 44, 32, 99,100,101,108,116, 97, 59, 10, 9,118,101, 99, 51, 32, 99, 59, 10,
- 10, 9, 99,109, 97,120, 32, 61, 32,109, 97,120, 40,114,103, 98, 91, 48, 93, 44, 32,109, 97,120, 40,114,103, 98, 91, 49, 93, 44,
- 32,114,103, 98, 91, 50, 93, 41, 41, 59, 10, 9, 99,109,105,110, 32, 61, 32,109,105,110, 40,114,103, 98, 91, 48, 93, 44, 32,109,
-105,110, 40,114,103, 98, 91, 49, 93, 44, 32,114,103, 98, 91, 50, 93, 41, 41, 59, 10, 9, 99,100,101,108,116, 97, 32, 61, 32, 99,
-109, 97,120, 45, 99,109,105,110, 59, 10, 10, 9,118, 32, 61, 32, 99,109, 97,120, 59, 10, 9,105,102, 32, 40, 99,109, 97,120, 33,
- 61, 48, 46, 48, 41, 10, 9, 9,115, 32, 61, 32, 99,100,101,108,116, 97, 47, 99,109, 97,120, 59, 10, 9,101,108,115,101, 32,123,
- 10, 9, 9,115, 32, 61, 32, 48, 46, 48, 59, 10, 9, 9,104, 32, 61, 32, 48, 46, 48, 59, 10, 9,125, 10, 10, 9,105,102, 32, 40,
-115, 32, 61, 61, 32, 48, 46, 48, 41, 32,123, 10, 9, 9,104, 32, 61, 32, 48, 46, 48, 59, 10, 9,125, 10, 9,101,108,115,101, 32,
-123, 10, 9, 9, 99, 32, 61, 32, 40,118,101, 99, 51, 40, 99,109, 97,120, 44, 32, 99,109, 97,120, 44, 32, 99,109, 97,120, 41, 32,
- 45, 32,114,103, 98, 46,120,121,122, 41, 47, 99,100,101,108,116, 97, 59, 10, 10, 9, 9,105,102, 32, 40,114,103, 98, 46,120, 61,
- 61, 99,109, 97,120, 41, 32,104, 32, 61, 32, 99, 91, 50, 93, 32, 45, 32, 99, 91, 49, 93, 59, 10, 9, 9,101,108,115,101, 32,105,
-102, 32, 40,114,103, 98, 46,121, 61, 61, 99,109, 97,120, 41, 32,104, 32, 61, 32, 50, 46, 48, 32, 43, 32, 99, 91, 48, 93, 32, 45,
- 32, 32, 99, 91, 50, 93, 59, 10, 9, 9,101,108,115,101, 32,104, 32, 61, 32, 52, 46, 48, 32, 43, 32, 99, 91, 49, 93, 32, 45, 32,
- 99, 91, 48, 93, 59, 10, 10, 9, 9,104, 32, 47, 61, 32, 54, 46, 48, 59, 10, 10, 9, 9,105,102, 32, 40,104, 60, 48, 46, 48, 41,
- 10, 9, 9, 9,104, 32, 43, 61, 32, 49, 46, 48, 59, 10, 9,125, 10, 10, 9,111,117,116, 99,111,108, 32, 61, 32,118,101, 99, 52,
- 40,104, 44, 32,115, 44, 32,118, 44, 32,114,103, 98, 46,119, 41, 59, 10,125, 10, 10,118,111,105,100, 32,104,115,118, 95,116,111,
- 95,114,103, 98, 40,118,101, 99, 52, 32,104,115,118, 44, 32,111,117,116, 32,118,101, 99, 52, 32,111,117,116, 99,111,108, 41, 10,
-123, 10, 9,102,108,111, 97,116, 32,105, 44, 32,102, 44, 32,112, 44, 32,113, 44, 32,116, 44, 32,104, 44, 32,115, 44, 32,118, 59,
- 10, 9,118,101, 99, 51, 32,114,103, 98, 59, 10, 10, 9,104, 32, 61, 32,104,115,118, 91, 48, 93, 59, 10, 9,115, 32, 61, 32,104,
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list