[Bf-committers] Fix for edge rendering when fields are enabled

Theodore Schundler bf-committers@blender.org
Thu, 22 Jul 2004 02:56:43 -0700


Hello. Based on the "introduction to the Blender source" I should post
this here. I haven't had a chance to test it outside my systems, but it
seems to have worked correctly for 500 frames so far. I'm pretty certain
that the changes are simple enough that it should work on any platform &
testing it with a variety my files & animations so far has yeilded good
results.

Basically if you enable edge rendering and do a field render, because
each frame is rendered at 1/2 the height, the edge effect is twice as
thick in Y as it is in X. And it's quite noticeable.

The edge rendering system uses changes in the z buffer value relative to
adjacent pixels to determine if it should draw an edge. In the standard
render pipe, the edge uses the same zbuffer as the rest of the scene, so
it isn't possible to properly determine what the edge should be - one
pixel above or below. But in the unified renderer, the edge system
builds its own zbuffer. So, I altered it so in the case of rendering
with fields, its own internal zbuffer is the full image height. So the
edges are rendered properly as if they are part of a full height frame
because the full zbuffer data is there.

Hopefully that made sense. To test it, make a solid, shadeless square in
front of the camera. Render it with edges. Turning OSA on helps edges a
lot. It will have a nice edge. Then turn on fields, and you'd see
clearly the difference in the size of the edges. Apply my path,
recompile, render the same image with fields on, and you get nice edges.
The improvement is more dramatic in more detailed scenes.

And finally, here's the patch against the current bf-blender:


Index: source/blender/render/intern/include/edgeRender.h
===================================================================
RCS file:
/cvsroot/bf-blender/blender/source/blender/render/intern/include/edgeRender.h,v
retrieving revision 1.5
diff -r1.5 edgeRender.h
57c57,58
< 	float b
---
> 	float b,
> 	int fields
Index: source/blender/render/intern/source/edgeRender.c
===================================================================
RCS file:
/cvsroot/bf-blender/blender/source/blender/render/intern/source/edgeRender.c,v
retrieving revision 1.6
diff -r1.6 edgeRender.c
104a105,106
> static int  useFields;       /* field Rendering mode enabled, so scale
things*/
>                              /*   to compute zbuffer for full height
image   */
126a129
> 
182c185,186
< 	float r, float g, float b
---
> 	float r, float g, float b,
>         int fields
186a191
> 	useFields  = fields;
220c225
< 	bufHeight  = imHeight + (2 * maskBorder);
---
> 	bufHeight  = imHeight * (useFields + 1) + (2 * maskBorder);
277c282
< 		(y < 0) || (y > (imHeight-1) ) ) {
---
>		(y < 0) || (y > (imHeight * (1 + useFields) - 1) ) ) {
487,489c492,494
< 		rz1+= 2;
< 		rz2+= 2;
< 		rz3+= 2;
---
> 		rz1+= 2 + bufWidth * useFields;
> 		rz2+= 2 + bufWidth * useFields;
> 		rz3+= 2 + bufWidth * useFields;
491,493c496,498
< 			matptr_low += 2;
< 			matptr_cent += 2;
< 			matptr_high += 2;
---
> 			matptr_low += 2 + bufWidth * useFields;
> 			matptr_cent += 2 + bufWidth * useFields;
> 			matptr_high += 2 + bufWidth * useFields;
549c554
<   	Zmuly= ((float) imHeight)/2.0;
---
>   	Zmuly= ((float) imHeight)/(2.0 - (float) useFields);
557c562
< 	Amaxy = imHeight;
---
> 	Amaxy = imHeight * (1 + useFields);
Index: source/blender/render/intern/source/vanillaRenderPipe.c
===================================================================
RCS file:
/cvsroot/bf-blender/blender/source/blender/render/intern/source/vanillaRenderPipe.c,v
retrieving revision 1.9
diff -r1.9 vanillaRenderPipe.c
245c245,246
< 			 R.r.edgeR, R.r.edgeG, R.r.edgeB);
---Hello. Based on the "introduction to the Blender source" I should
post this here. I haven't had a chance to test it outside my systems,
but it seems to have worked correctly for 500 frames so far. I'm pretty
certain that the changes are simple enough that it should work on any
platform & testing it with a variety my files & animations so far has
yeilded good results.

Basically if you enable edge rendering and do a field render, because
each frame is rendered at 1/2 the height, the edge effect is twice as
thick in Y as it is in X. And it's quite noticeable.

The edge rendering system uses changes in the z buffer value relative to
adjacent pixels to determine if it should draw an edge. In the standard
render pipe, the edge uses the same zbuffer as the rest of the scene, so
it isn't possible to properly determine what the edge should be - one
pixel above or below. But in the unified renderer, the edge system
builds its own zbuffer. So, I altered it so in the case of rendering
with fields, its own internal zbuffer is the full image height. So the
edges are rendered properly as if they are part of a full height frame
because the full zbuffer data is there.

Hopefully that made sense. To test it, make a solid, shadeless square in
front of the camera. Render it with edges. Turning OSA on helps edges a
lot. It will have a nice edge. Then turn on fields, and you'd see
clearly the difference in the size of the edges. Apply my path,
recompile, render the same image with fields on, and you get nice edges.
The improvement is more dramatic in more detailed scenes.

And finally, here's the patch against the current bf-blender:


Index: source/blender/render/intern/include/edgeRender.h
===================================================================
RCS file:
/cvsroot/bf-blender/blender/source/blender/render/intern/include/edgeRender.h,v
retrieving revision 1.5
diff -r1.5 edgeRender.h
57c57,58
< 	float b
---
> 	float b,
> 	int fields
Index: source/blender/render/intern/source/edgeRender.c
===================================================================
RCS file:
/cvsroot/bf-blender/blender/source/blender/render/intern/source/edgeRender.c,v
retrieving revision 1.6
diff -r1.6 edgeRender.c
104a105,106
> static int  useFields;       /* field Rendering mode enabled, so scale
things*/
>                              /*   to compute zbuffer for full height
image   */
126a129
> 
182c185,186
< 	float r, float g, float b
---
> 	float r, float g, float b,
>         int fields
186a191
> 	useFields  = fields;
220c225
< 	bufHeight  = imHeight + (2 * maskBorder);
---
> 	bufHeight  = imHeight * (useFields + 1) + (2 * maskBorder);
277c282
< 		(y < 0) || (y > (imHeight-1) ) ) {
---
>		(y < 0) || (y > (imHeight * (1 + useFields) - 1) ) ) {
487,489c492,494
< 		rz1+= 2;
< 		rz2+= 2;
< 		rz3+= 2;
---
> 		rz1+= 2 + bufWidth * useFields;
> 		rz2+= 2 + bufWidth * useFields;
> 		rz3+= 2 + bufWidth * useFields;
491,493c496,498
< 			matptr_low += 2;
< 			matptr_cent += 2;
< 			matptr_high += 2;
---
> 			matptr_low += 2 + bufWidth * useFields;
> 			matptr_cent += 2 + bufWidth * useFields;
> 			matptr_high += 2 + bufWidth * useFields;
549c554
<   	Zmuly= ((float) imHeight)/2.0;
---
>   	Zmuly= ((float) imHeight)/(2.0 - (float) useFields);
557c562
< 	Amaxy = imHeight;
---
> 	Amaxy = imHeight * (1 + useFields);
Index: source/blender/render/intern/source/vanillaRenderPipe.c
===================================================================
RCS file:
/cvsroot/bf-blender/blender/source/blender/render/intern/source/vanillaRenderPipe.c,v
retrieving revision 1.9
diff -r1.9 vanillaRenderPipe.c
245c245,246
< 			 R.r.edgeR, R.r.edgeG, R.r.edgeB);
---
> 			 R.r.edgeR, R.r.edgeG, R.r.edgeB,
> 			 (R.r.mode & R_FIELDS == R_FIELDS));

> 			 R.r.edgeR, R.r.edgeG, R.r.edgeB,
> 			 (R.r.mode & R_FIELDS == R_FIELDS));


This message scanned for viruses and SPAM by GWGuardian at SCU (MGW1)