[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [50282] trunk/blender/source/blender: Fix #32404: GLSL normal maps using float images were incorrectly getting

Brecht Van Lommel brechtvanlommel at pandora.be
Thu Aug 30 19:42:04 CEST 2012


Revision: 50282
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=50282
Author:   blendix
Date:     2012-08-30 17:42:04 +0000 (Thu, 30 Aug 2012)
Log Message:
-----------
Fix #32404: GLSL normal maps using float images were incorrectly getting
color managed.

Modified Paths:
--------------
    trunk/blender/source/blender/editors/space_view3d/drawmesh.c
    trunk/blender/source/blender/gpu/GPU_draw.h
    trunk/blender/source/blender/gpu/GPU_extensions.h
    trunk/blender/source/blender/gpu/GPU_material.h
    trunk/blender/source/blender/gpu/intern/gpu_codegen.c
    trunk/blender/source/blender/gpu/intern/gpu_codegen.h
    trunk/blender/source/blender/gpu/intern/gpu_draw.c
    trunk/blender/source/blender/gpu/intern/gpu_extensions.c
    trunk/blender/source/blender/gpu/intern/gpu_material.c
    trunk/blender/source/blender/nodes/shader/nodes/node_shader_tex_environment.c
    trunk/blender/source/blender/nodes/shader/nodes/node_shader_tex_image.c
    trunk/blender/source/blender/nodes/shader/nodes/node_shader_texture.c

Modified: trunk/blender/source/blender/editors/space_view3d/drawmesh.c
===================================================================
--- trunk/blender/source/blender/editors/space_view3d/drawmesh.c	2012-08-30 17:41:59 UTC (rev 50281)
+++ trunk/blender/source/blender/editors/space_view3d/drawmesh.c	2012-08-30 17:42:04 UTC (rev 50282)
@@ -871,7 +871,7 @@
 	if (ED_object_get_active_image(data->ob, mat_nr, &ima, &iuser, &node)) {
 		/* get openl texture */
 		int mipmap = 1;
-		int bindcode = (ima) ? GPU_verify_image(ima, iuser, 0, 0, mipmap) : 0;
+		int bindcode = (ima) ? GPU_verify_image(ima, iuser, 0, 0, mipmap, FALSE) : 0;
 		float zero[4] = {0.0f, 0.0f, 0.0f, 0.0f};
 
 		if (bindcode) {

Modified: trunk/blender/source/blender/gpu/GPU_draw.h
===================================================================
--- trunk/blender/source/blender/gpu/GPU_draw.h	2012-08-30 17:41:59 UTC (rev 50281)
+++ trunk/blender/source/blender/gpu/GPU_draw.h	2012-08-30 17:42:04 UTC (rev 50282)
@@ -122,7 +122,7 @@
 void GPU_paint_update_image(struct Image *ima, int x, int y, int w, int h, int mipmap);
 void GPU_update_images_framechange(void);
 int GPU_update_image_time(struct Image *ima, double time);
-int GPU_verify_image(struct Image *ima, struct ImageUser *iuser, int tftile, int compare, int mipmap);
+int GPU_verify_image(struct Image *ima, struct ImageUser *iuser, int tftile, int compare, int mipmap, int ncd);
 void GPU_create_gl_tex(unsigned int *bind, unsigned int *pix, float *frect, int rectw, int recth, int mipmap, int use_hight_bit_depth, struct Image *ima);
 void GPU_create_gl_tex_compressed(unsigned int *bind, unsigned int *pix, int x, int y, int mipmap, struct Image *ima, struct ImBuf *ibuf);
 int GPU_upload_dxt_texture(struct ImBuf *ibuf);

Modified: trunk/blender/source/blender/gpu/GPU_extensions.h
===================================================================
--- trunk/blender/source/blender/gpu/GPU_extensions.h	2012-08-30 17:41:59 UTC (rev 50281)
+++ trunk/blender/source/blender/gpu/GPU_extensions.h	2012-08-30 17:42:04 UTC (rev 50282)
@@ -111,7 +111,7 @@
 GPUTexture *GPU_texture_create_depth(int w, int h, char err_out[256]);
 GPUTexture *GPU_texture_create_vsm_shadow_map(int size, char err_out[256]);
 GPUTexture *GPU_texture_from_blender(struct Image *ima,
-	struct ImageUser *iuser, double time, int mipmap);
+	struct ImageUser *iuser, int ncd, double time, int mipmap);
 void GPU_texture_free(GPUTexture *tex);
 
 void GPU_texture_ref(GPUTexture *tex);

Modified: trunk/blender/source/blender/gpu/GPU_material.h
===================================================================
--- trunk/blender/source/blender/gpu/GPU_material.h	2012-08-30 17:41:59 UTC (rev 50281)
+++ trunk/blender/source/blender/gpu/GPU_material.h	2012-08-30 17:42:04 UTC (rev 50282)
@@ -107,7 +107,7 @@
 GPUNodeLink *GPU_attribute(int type, const char *name);
 GPUNodeLink *GPU_uniform(float *num);
 GPUNodeLink *GPU_dynamic_uniform(float *num, int dynamictype, void *data);
-GPUNodeLink *GPU_image(struct Image *ima, struct ImageUser *iuser);
+GPUNodeLink *GPU_image(struct Image *ima, struct ImageUser *iuser, int ncd);
 GPUNodeLink *GPU_texture(int size, float *pixels);
 GPUNodeLink *GPU_dynamic_texture(struct GPUTexture *tex, int dynamictype, void *data);
 GPUNodeLink *GPU_socket(GPUNodeStack *sock);

Modified: trunk/blender/source/blender/gpu/intern/gpu_codegen.c
===================================================================
--- trunk/blender/source/blender/gpu/intern/gpu_codegen.c	2012-08-30 17:41:59 UTC (rev 50281)
+++ trunk/blender/source/blender/gpu/intern/gpu_codegen.c	2012-08-30 17:42:04 UTC (rev 50282)
@@ -761,7 +761,7 @@
 	/* now bind the textures */
 	for (input=inputs->first; input; input=input->next) {
 		if (input->ima)
-			input->tex = GPU_texture_from_blender(input->ima, input->iuser, time, mipmap);
+			input->tex = GPU_texture_from_blender(input->ima, input->iuser, input->imagencd, time, mipmap);
 
 		if (input->tex && input->bindtex) {
 			GPU_texture_bind(input->tex, input->texid);
@@ -917,6 +917,7 @@
 
 		input->ima = link->ptr1;
 		input->iuser = link->ptr2;
+		input->imagencd = link->imagencd;
 		input->textarget = GL_TEXTURE_2D;
 		input->textype = GPU_TEX2D;
 		MEM_freeN(link);
@@ -1109,13 +1110,14 @@
 	return link;
 }
 
-GPUNodeLink *GPU_image(Image *ima, ImageUser *iuser)
+GPUNodeLink *GPU_image(Image *ima, ImageUser *iuser, int ncd)
 {
 	GPUNodeLink *link = GPU_node_link_create(0);
 
 	link->image= 1;
 	link->ptr1= ima;
 	link->ptr2= iuser;
+	link->imagencd= ncd;
 
 	return link;
 }

Modified: trunk/blender/source/blender/gpu/intern/gpu_codegen.h
===================================================================
--- trunk/blender/source/blender/gpu/intern/gpu_codegen.h	2012-08-30 17:41:59 UTC (rev 50281)
+++ trunk/blender/source/blender/gpu/intern/gpu_codegen.h	2012-08-30 17:42:04 UTC (rev 50282)
@@ -91,6 +91,7 @@
 	const char *attribname;
 
 	int image;
+	int imagencd;
 
 	int texture;
 	int texturesize;
@@ -137,6 +138,7 @@
 
 	struct Image *ima;		/* image */
 	struct ImageUser *iuser;/* image user */
+	int imagencd;			/* image does not contain color data */
 	float *dynamicvec;		/* vector data in case it is dynamic */
 	int dynamictype;		/* origin of the dynamic uniform (GPUDynamicType) */
 	void *dynamicdata;		/* data source of the dynamic uniform */

Modified: trunk/blender/source/blender/gpu/intern/gpu_draw.c
===================================================================
--- trunk/blender/source/blender/gpu/intern/gpu_draw.c	2012-08-30 17:41:59 UTC (rev 50281)
+++ trunk/blender/source/blender/gpu/intern/gpu_draw.c	2012-08-30 17:42:04 UTC (rev 50282)
@@ -422,7 +422,7 @@
 	}
 }
 
-int GPU_verify_image(Image *ima, ImageUser *iuser, int tftile, int compare, int mipmap)
+int GPU_verify_image(Image *ima, ImageUser *iuser, int tftile, int compare, int mipmap, int ncd)
 {
 	ImBuf *ibuf = NULL;
 	unsigned int *bind = NULL;
@@ -492,7 +492,7 @@
 		}
 
 		/* TODO unneeded when float images are correctly treated as linear always */
-		if (ibuf->profile == IB_PROFILE_LINEAR_RGB)
+		if (!ncd && ibuf->profile == IB_PROFILE_LINEAR_RGB)
 			do_color_management = TRUE;
 
 		if (ibuf->rect==NULL)
@@ -807,7 +807,7 @@
 	gpu_verify_alpha_blend(alphablend);
 	gpu_verify_reflection(ima);
 
-	if (GPU_verify_image(ima, NULL, tface->tile, 1, mipmap)) {
+	if (GPU_verify_image(ima, NULL, tface->tile, 1, mipmap, FALSE)) {
 		GTS.curtile= GTS.tile;
 		GTS.curima= GTS.ima;
 		GTS.curtilemode= GTS.tilemode;

Modified: trunk/blender/source/blender/gpu/intern/gpu_extensions.c
===================================================================
--- trunk/blender/source/blender/gpu/intern/gpu_extensions.c	2012-08-30 17:41:59 UTC (rev 50281)
+++ trunk/blender/source/blender/gpu/intern/gpu_extensions.c	2012-08-30 17:42:04 UTC (rev 50282)
@@ -522,7 +522,7 @@
 	return tex;
 }
 
-GPUTexture *GPU_texture_from_blender(Image *ima, ImageUser *iuser, double time, int mipmap)
+GPUTexture *GPU_texture_from_blender(Image *ima, ImageUser *iuser, int ncd, double time, int mipmap)
 {
 	GPUTexture *tex;
 	GLint w, h, border, lastbindcode, bindcode;
@@ -530,7 +530,7 @@
 	glGetIntegerv(GL_TEXTURE_BINDING_2D, &lastbindcode);
 
 	GPU_update_image_time(ima, time);
-	bindcode = GPU_verify_image(ima, iuser, 0, 0, mipmap);
+	bindcode = GPU_verify_image(ima, iuser, 0, 0, mipmap, ncd);
 
 	if (ima->gputexture) {
 		ima->gputexture->bindcode = bindcode;

Modified: trunk/blender/source/blender/gpu/intern/gpu_material.c
===================================================================
--- trunk/blender/source/blender/gpu/intern/gpu_material.c	2012-08-30 17:41:59 UTC (rev 50281)
+++ trunk/blender/source/blender/gpu/intern/gpu_material.c	2012-08-30 17:42:04 UTC (rev 50282)
@@ -645,7 +645,7 @@
 
 			GPU_link(mat, "shade_light_texture",
 				GPU_builtin(GPU_VIEW_POSITION),
-				GPU_image(mtex->tex->ima, &mtex->tex->iuser),
+				GPU_image(mtex->tex->ima, &mtex->tex->iuser, FALSE),
 				GPU_dynamic_uniform((float*)lamp->dynpersmat, GPU_DYNAMIC_LAMP_DYNPERSMAT, lamp->ob),
 				&tex_rgb);
 			texture_rgb_blend(mat, tex_rgb, *rgb, GPU_uniform(&one), GPU_uniform(&mtex->colfac), mtex->blendtype, rgb); 
@@ -1028,7 +1028,7 @@
 			talpha = 0;
 
 			if (tex && tex->type == TEX_IMAGE && tex->ima) {
-				GPU_link(mat, "mtex_image", texco, GPU_image(tex->ima, &tex->iuser), &tin, &trgb);
+				GPU_link(mat, "mtex_image", texco, GPU_image(tex->ima, &tex->iuser, FALSE), &tin, &trgb);
 				rgbnor= TEX_RGB;
 
 				if (tex->imaflag & TEX_USEALPHA)
@@ -1104,7 +1104,7 @@
 
 					if (tex->imaflag & TEX_NORMALMAP) {
 						/* normalmap image */
-						GPU_link(mat, "mtex_normal", texco, GPU_image(tex->ima, &tex->iuser), &tnor);
+						GPU_link(mat, "mtex_normal", texco, GPU_image(tex->ima, &tex->iuser, TRUE), &tnor);
 						
 						if (mtex->norfac < 0.0f)
 							GPU_link(mat, "mtex_negate_texnormal", tnor, &tnor);
@@ -1234,26 +1234,26 @@
 						
 						if (found_deriv_map) {
 							GPU_link(mat, "mtex_bump_deriv",
-							         texco, GPU_image(tex->ima, &tex->iuser), GPU_uniform(&ima_x), GPU_uniform(&ima_y), tnorfac,
+							         texco, GPU_image(tex->ima, &tex->iuser, TRUE), GPU_uniform(&ima_x), GPU_uniform(&ima_y), tnorfac,
 							         &dBs, &dBt );
 						}
 						else if ( mtex->texflag & MTEX_3TAP_BUMP)
 							GPU_link(mat, "mtex_bump_tap3",
-							         texco, GPU_image(tex->ima, &tex->iuser), tnorfac,
+							         texco, GPU_image(tex->ima, &tex->iuser, TRUE), tnorfac,
 							         &dBs, &dBt );
 						else if ( mtex->texflag & MTEX_5TAP_BUMP)
 							GPU_link(mat, "mtex_bump_tap5",
-							         texco, GPU_image(tex->ima, &tex->iuser), tnorfac,
+							         texco, GPU_image(tex->ima, &tex->iuser, TRUE), tnorfac,
 							         &dBs, &dBt );
 						else if ( mtex->texflag & MTEX_BICUBIC_BUMP ) {
 							if (GPU_bicubic_bump_support()) {
 								GPU_link(mat, "mtex_bump_bicubic",
-								         texco, GPU_image(tex->ima, &tex->iuser), tnorfac,
+								         texco, GPU_image(tex->ima, &tex->iuser, TRUE), tnorfac,
 								         &dBs, &dBt);
 							}
 							else {
 								GPU_link(mat, "mtex_bump_tap5",
-								         texco, GPU_image(tex->ima, &tex->iuser), tnorfac,
+								         texco, GPU_image(tex->ima, &tex->iuser, TRUE), tnorfac,
 								         &dBs, &dBt);
 							}
 						}
@@ -1263,7 +1263,7 @@
 							float imag_tspace_dimension_y = aspect*imag_tspace_dimension_x;

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list