* fixed more bugs in face clipping, clip_line wasnt working when the line was horiz/vertical. unning exactly on the clipping rectangle bounds.
* testing if a point was inside a triangle didnt work if the point was touching the triangles edge, added IsectPT2Df_limit(...) for this rather then using 3 point/line intersection checks.
...Cant find anymore bugs in face clipping now :)
* Fixed another face clipping bug (some artifacts still when using screen aligned faces)
* Removed Soften and Warp buttons on the panit panel since they are not used for projection painting
* added do_versions to initialize bleed and normal values
* fix from last commit, threaded memarena wasnt used currectly in one case. (crashing blender)
* add a remove doubles and point on line test to face poly clipping function (fixes some cases where buckets are aligned with faces)
The new class VideoTexture.ImageMirror() is available to perform
automatic mirror rendering.
Constructor:
VideoTexture.ImageMirror(scene,observer,mirror,material)
scene: reference to the scene that will be rendered.
Both observer and mirror must be part of that scene.
observer: reference to a game object used as view point for
mirror rendering: the scene will be rendered through
the mirror as if the active camera was at the observer
location. Usually the observer is the active camera
but you can use any game obejct.
mirror: reference to the mesh object holding the mirror.
material: material ID of the mirror texture as returned by
VideoTexture.materialID(). The mirror is formed by
the polygons mapped to that material.
There are no specific methods or attributes. ImageMirror inherits
all methods and attributes from ImageRender. You must refresh the
parent VideoTexture.Texture object regularly to update the mirror
rendering.
Guidelines on how to create a working mirror:
- Use a texture that is specific to the mirror so that the mirror
rendering only appears on the mirror.
- The mirror must be planar; the algorithm works well only for planar
or quasi planar mirror. For spherical mirror, you will get better
results with ImageRender and a camera at the center of the mirror.
ImageMirror automatically computes the mirror orientation and
position. The mirror doesn't need to be rectangular, it can be
circular or take any form provided it is planar.
- The mirror up direction must be along the Z axis in local mesh
coordinates. If the mirror is not vertical, ImageMirror will
compute the up direction as being the projection of the Z axis
on the mirror plane.
- UV mapping must be set right to get correct mirror rendering:
- make a planar projection of the mirror polygons (Unwrap or projection from view)
- eventually rotate the projection so that UV up direction corresponds to the mesh Z axis
- scale the projection so that the extreme points touch the border of the texture
- flip the UV projection horizontally (scale -1 on X axis). This is needed
because the mirror texture is rendered from the back of the mirror and
thus is reversed from the view point of the observer. Horizontal flip
in the UV map restores the correct orientation.
Besides these simple rules, the mirror rendering is completely automatic.
In particular, you don't need to allocate a camera for the rendering,
ImageMirror creates dynamically a camera for that. The reflection is correct
even on large angles. The mirror can be a dynamic and moving object, the
algorithm always computes the correct camera position based on observer
relative position. You don't have to worry about mirror position in the scene:
the algorithm automatically computes the camera frustum so that any object
behind the mirror is not rendered.
Warnings:
- observer and mirror are references to game objects. ImageMirror keeps
a pointer to them but does not increment the reference count. You must ensure
that these game objects are not deleted as long as you refresh() the ImageMirror
object. You must release the ImageMirror object before you delete the game
objects. To release the ImageMirror object (normally stored in GameLogic),
just assign it to None.
- Mirror rendering is automatically skipped when the observer is behind the mirror
but it is not disabled when the mirror is out of sight of the observer.
You should only refresh the mirror when you know that the observer is likely to see it.
For example, no need to refresh a car inner mirror when the player is not in the car.
Example:
contr = GameLogic.getCurrentController()
# object holding the mirror
mirror = contr.getOwner()
scene = GameLogic.getCurrentScene()
# observer will be the active camere
camera = scene.getObjectList()['OBCamera']
matID = VideoTexture.materialID(mirror, 'IMmirror.png')
GameLogic.mirror = VideoTexture.Texture(mirror, matID)
GameLogic.mirror.source = VideoTexture.ImageMirror(scene,camera,mirror,matID)
# to render the mirror, just call GameLogic.mirror.refresh(True) on each frame.
You can download a demo game (with a video file) here:
http://home.scarlet.be/~tsi46445/blender/VideoTextureDemo.zip
For those who have already downloaded the demo, you can just update the blend file:
http://home.scarlet.be/~tsi46445/blender/MirrorTextureDemo.blend
* use 80deg rather then 90 for the "Normal" painting option, since painting faces that are very close to 90d to the view gives some artifacts.
* Brecht modified the Barycentric weights function to use a signed area. so BarycentricWeightsSimplePersp2f and BarycentricWeightsSimple2f these funcs are not needed anymore.
2 bugs with seams fixed
* triangle faces seams were not being filled correctly - causing visible seams
* the pretend 3D location for seam pixels was too close to the face edge - causing some pixels to be occluded by the adjacent face.
* style fits with blenders more
* use rctf and rcti and rctf types rather then float[4]
* some loops were confusing, use for loops rather then while or do/while
similar to os.path.relpath but uses blendfile path rather then the current working directory.
Also use python exceptions rather then providing our own ones.
The new class VideoTexture.ImageRender() is available to perform
render to texture in the GE.
Constructor:
VideoTexture.ImageRender(scene,cam)
cam : camera object that will be used for the render.
It must be an inactive camera.
scene: reference to the scene that will be rendered.
The camera must be part of that scene.
Returns an object that can be used as a source of a VideoTexture.Texture object
Methods: none
Attributes:
background:
4-tuple representing the background color of the rendering
as RGBA color components, each component being an integer
between 0 and 255.
Default value = [0,0,255,255] (=saturated blue)
Note: athough the alpha component can be specified, it is not
supported at the moment, the alpha channel of the rendered
texture will always be 255. You can however introduce an
alpha channel by appending a FilterBlueScreen() filter, it
will set the alpha to 0 (transparent) on all pixels that were
not rendered.
capsize:
2-tuple representing the size of the render area as [x,y] number of pixels.
Default value = largest rectangle with power of 2 dimensions that fits in the canvas
You may want to reduce the render area to increase performance. For example,
a render area of [256,128] is probably sufficient to implement a car inner mirror.
For best performance, use power of 2 dimensions and don't set any filter: this
allows direct transfer between the GPU frame buffer and texture memory
without going through the host.
alpha:
Boolean indicating if the render alpha channel should be copied to the texture.
Default value: False
Experimental, do not use.
whole:
Boolean indicating if the entire canvas should be used for the rendering.
Default value: False
Note: There is no reason to set this attribute to True: the rendering will
in any case be scaled down to the largest rectangle with power of 2
dimensions before transfering to the texture.
Attributes inherited from the ImageBase class:
image : image binary data, read-only
size : [x,y] size of the texture, read-only
scale : set to True for fast scale down in case the render area dimensions are not power of 2
flip : set to True for vertical flip.
filter: set a post-processing filter on the render.
Notes:
* Aspect Ratio
For consistent results in Blender and Blenderplayer, the same aspect ratio used
by Blender to draw the camera viewport (Scene(F10)->Format tab->Size X/Size Y)
is also used during the rendering. You can control the portion of the scene that
will be rendered by "looking through the camera": the zone inside the outer dotted
rectangle will be rendered to the texture.
In order to reproduce the scene without X/Y distortion, you must apply the texture
on an object or portion of object that has the same aspect ratio.
* Order of rendering
The rendereing is performed when you call the refresh() method of the parent
Texture object. This happens outside the normal frame rendering and will have no
effect on it.
However, if you want to use ImageViewport and ImageRender at the same time, be
sure to refresh the viewport texture before the render texture because the latter
will destroy the frame buffer that is used by the former to update the texture.
* Scene status
The meshes are not updated during the render to texture: the rendered texture
is one frame late to the rendered frame with regards to mesh deformation.
* Example:
cont = GameLogic.getCurrentController()
# object that receives the texture
obj = contr.getOwner()
scene = GameLogic.getCurrentScene()
# camera used for the render
tvcam = scene.getObjectList()['OBtvcam']
# assume obj has some faces UV assigned to tv.png
matID = VideoTexture.materialID(obj, 'IMtv.png')
GameLogic.tv = VideoTexture.Texture(obj, matID)
GameLogic.tv.source = VideoTexture.ImageRender(scene,tvcam)
GameLogic.tv.source.capsize = [256,256]
# to render the texture, just call GameLogic.tv.refresh(True) on each frame.
You can download a demo game (with a video file) here:
http://home.scarlet.be/~tsi46445/blender/VideoTextureDemo.zip
For those who have already downloaded the demo, you can just update the blend file:
http://home.scarlet.be/~tsi46445/blender/VideoTextureDemo.blend
outliner. Clicking on one activates it and takes you to the object buttons - it's a
lot better to see what's going on than a little < 1 Part 5 > that gives very little
indication.
* less calls to BKE_image_get_ibuf when switching between images
* remove thread debug prints
* use own pixel blending funcs (IMB_blend_color isnt needed in some cases), slightly faster without this.
to compile blender with gcc on IRIX, IRIX_USE_GCC needs to be set to true in
user-def.mk.
Other changes related to irix:
* compile solid from extern/
* don't build plugins (yet) with "make release" when using gcc (the shell
script used assumes MIPSpro is installed)
* use statvfs instead of statfs on irix, like done on solaris
* use external libs from $(LCGDIR) instead of /usr/freeware
* use glew header files from $(LCGDIR)/glew instead of the ones installed on
the system (this applies to other platforms as well)
* ffmpeg support currently is disabled on irix
* float buffer support for all painting operation and undo.
* only run brush_sample_tex() for textures brushes.
* redraw the brush outline even when nothing is painted.
Reset transform restriction flags when switching to other transformations while running.
Also don't draw constraint if no constraint flag is on (old annoyance).
The reason for this was with transforming screenspace points outside the face into UV space and when the bucket bounds was enough outside the face.
For faces viewed side on, this transformation would be applied incorrectly (a bit like trying to apply a projection matrix to a point behind the view), the buckets UV space coords would be incorrect and the wrong pixels would be initialized for that face.
solution is to clip the screenspace face with the bucket before getting the UVs. This should also be a bit faster since the clipped polyline will have a smaller bounding box.
* faces that were ignored were also not taken into acount when checking UV seams - causng bleed not to work properly in some cases.
* commented early pixel filling loop exit that fails in some cases.
void bicubic_interpolation(struct ImBuf *in, struct ImBuf *out, float u, float v, int xout, int yout);
void neareast_interpolation(struct ImBuf *in, struct ImBuf *out, float u, float v, int xout, int yout);
void bilinear_interpolation(struct ImBuf *in, struct ImBuf *out, float u, float v, int xout, int yout);
Added...
void bicubic_interpolation_color(struct ImBuf *in, unsigned char *col, float *col_float, float u, float v);
void neareast_interpolation_color(struct ImBuf *in, unsigned char *col, float *col_float, float u, float v);
void bilinear_interpolation_color(struct ImBuf *in, unsigned char *col, float *col_float, float u, float v);
This is needed so for projection painting but generally useful if you want to get the interpolated color of a pixel in an image without having a destination imbuf.
While editing these I noticed the functons are a bit dodgy, they assume the input ImBuf has matching float/chr buffer to the output.
Tested overall speedup is about 5x when scaling 4096x4096 -> 4000x4000 in the sequencer.
There were some artifacts in the resulting image but double checked and the old code gives the same problems.
Added back old code with #if 0's since its a bit more readable.
General optimizations
* Precompute 1/x when dividing by x multiple times.
* Use float constants like 0.0f instead of 0.0, avoids conversions from float to doubles and back.
ProjectPixel
* make pixel (and similar pointers elsewhere) a union with a float and unsigned int pointer to reduce the number of casts a little. generally there are a lot of casts going on in the code, makes it hard to read.
project_paint_begin()
* the perspective case checks with (*projScreenCo)[3] > 0.001) for faces behind the view. - Changed to use the clip start from get_view3d_viewplane
* removed arbitrary check for brush size to disable threads.
imapaint_paint_sub_stroke_project()
* Make clone tool use IMB_blend_color to reduce the code and support blend modes.
imapaint_paint_sub_stroke_project_mt()
* Make threaded and non threaded mode use same function (just dont start threads when its set to 1)
* removed PIL_sleep_ms, was not needed and slowed down threading (my bad!, was copied from bake code).
* use a faster method of getting a pixels screenspace location.
* check if its possible to break out of pixel to bucket/face intersection early - ~7% overall speedup (ignoring redraw time).
* removed scanline intersection function (added back incase they were needed but it looks like there not)
* speedup for painting with only 1 image (use a loop without context switching checks)
* more commenting + cleanup
* bucket resolution is now set from the brush size so there is around 9 buckets under the brush - (previously was fixed to 128x128).
* brush sizes below 40 disable multithreading, since threads only speeds up cases where each bucket has enough pixels in it for each core to spend some time.
* make smear use bicubic pixel lookups so a low Spacing value works as expected.
* smear tool was darkening pixels a tiny bit.
* fix for simple mistake causing ProjectPaintImage arrays not to be thread safe.
* added clone button to the paint editbuttons (was only in the image window before)
* ctrl+clicking to set the 3d cursor also sets its depth to the face its over (much more useful when cloning and rotating the view)
* support for painting and cloning for tiled textures (for UV's outside 0-1)
* more consistant veriable names, merged image arrays into a ProjectPaintImage type to be less confusing.
Grease Pencil crashed after duplicating a screen-area, and deleting a layer from the original screen-area. The duplication code was not reassigning some pointers.
Fix the roll mess in transform. Since roll is based on an automatically calculated up axis, transforming bones would mess up bone orientation. This code automatically adjusts the roll value to keep bone orientation as consistant as possible. That works all around in transform for all transformations.
Doesn't work with x-axis mirror though as that doesn't use transform elements (fixing it would be nice for later)
Most interesting is that it works with the mirror tool (obviously), so you don't have to fix all the rolls after mirroring one side of an armature.
It could be made an option if someone presents a good enough point for that, but I can't see why you'd want the previous mess instead.
NB: this also ports a utility fonction from etch-a-ton to set bone roll from an up axis.
* BLI_linklist_index() - to get an items index in a LinkList
* BLI_memarena_use_malloc() - BLI_memarena_use_calloc alredy existed but there was no way to switch back to malloc.
also added texnodes to cmake
Robin (Frrr) Allen did a decent job on this, so we can also welcome him
as a member in the svn committers team to maintain it!
I do the first commit with some minor fixes:
- get Makefiles work
- fix rounding issue with tiles on unit faces
- removed UI includes from tex node
A nice doc in wiki is here:
http://wiki.blender.org/index.php/User:Frr/TexnodeManual
On the todo for Robin is:
- When using one or more Texture-input nodes, you cannot edit them by activating
(as works now for Material nodes).
- The new "output node" option fails on the default case, when only one
output node is active. It then shows often a blank menu. Will get fixed asap.
- When using a NodeTree-Texture as input node, the menu for 'active output'
should not show. NodeTree should ignore other nodetrees to keep things sane
for now.
- On a future todo is proper usage of "Dxt" and "Dyt" texture vectors for
superior antialising of checkers/bricks.
General note; I know people are dying to get a full integrated shader system
with nodes. In theory we could merge this with Material Nodetrees... but I
rather wait for a solid and very well thought out design proposal for this,
also including design ideas for unifying with a shader language (GPU, CPU).
For the time being this is a nice extension of current textures. :)
This commit adds an exception for rotations (standard rotation and tracball) to still work on children of transformed objects and bones in an expected fashion. That is, you can select a chain of finger bones and rotate to flex them all at once.
Notes:
[1] This could be expended to other transformations if needed.
[2] Center of transformation is determined using the same principle as hinge bones (transformed children aren't taken into account)
SeamBleed in perspective mode mostly working (some small artifacts but generally looks ok)
Added BarycentricWeightsPersp2f and BarycentricWeightsSimplePersp2f for getting weights from verts with perspective matrix applied.
* initializing a bucket only initializes pixels from that bucket (was initializing all pixels in intersecting faces before which made large faces slow to paint onto)
* removed scanline functions, they are not as useful when initializing small areas.
* UV seam checking also sets the seam flag on the adjacent face to avoid double lookups.
TODO - uv seam bleed doesn't work in perspective mode.
Modified to work in linux too, on my system subprocess.Popen(appstring) only works when appstring is a list.
Blenders __import__ didnt support keywords like pythons causing the subprocess module to fail for me.
added keywords to blenders c/api import to match pythons.
You can specify a image name (starting with 'IM') instead of a material
name in VideoTexture.materialID() and return the material ID matching
this texture.
The advantage of this method is that is works with blender material
and UV texture. In case of UV texture, it grabs the internal material
corresponding to the faces that are assigned to this texture. In case
of blender material, it grabs the material that has an image texture
matching the name as first texture channel.
In both cases, the texture id used in VideoTexture.Texture() should be 0.
Ex:
matID = VideoTexture.materialID(obj,'IMvideo.png')
GameLogic.video = VideoTexture.Texture(obj, matID, 0)
The problem is that the audio_fill_seq function try to load the hd file
if the sequence don't have it, but it join the two string (directory path +
file path) without the / (Linux... \ Windows), so the result is a wrong path.
I change the the strncpy and strncat function for a BLI_join_dirfile (like
the reload_sequence_new_file) and all work fine now.
Also note that the "them go" that Luca report is (or what happen here) the
ctrl+z function, and now both case work fine here.
(interesting.. date from Feb 05.. 2006 ;)
The FFmpeg library allows to load image files. Although it is possible
to load images using the VideoFFmpeg class, it is not very efficient.
The new class VideoTexture.ImageFFmpeg is dedicated to image management.
Constructor:
-----------
VideoTexture.ImageFFmpeg('image_file_name')
Opens the file but does not load the texture yet.
The file name can also be a network address. It can also be a video
file name; in that case only the first image is loaded.
Methods:
-------
refresh(True)
Loads the image to texture.
You just need to call it once, the file is automatically closed after
that and calling refresh() again will have no effect.
reload('new_file_name')
Reloads the image (if new_file_name is omitted) or loads a new image.
The file is opened but the texture is not updated yet, you need
to call refresh() once to load the texture.
Attributes:
----------
status
returns the image status:
2 : file opened, texture not loaded
3 : file closed, texture loaded
image
returns the image data as a string of RGBA pixel
size
returns the image size [x,y]
scale
get/set the scale flag.
If the scale flag is False, the image is rescale to texture format
using gluScaleImage() function, slow but good quality.
If the scale flag is True, the image is rescaled using a fast but
less accurate algorithm.
flip
get/set Y-flip flag.
Set to True by default as FFmpeg always provides the image upside down
filter
get/set filter(s) on the image.
Example:
somehow scripts line endings change is messing things up, these changes wont be included
error is:
svn: File 'release/scripts/scripttemplate_metaball_create.py' has inconsistent newlines
svn: Inconsistent line ending style
svn: Error reading spooled REPORT request response
todo...
* pixel interpolation.
* clone option can currently only be set from the image paint panel.
* only initialize clone pixels under the mouse.
* overlap between source/target while painting could cause problems. need to look into this.
also fixed some cashes in painting normally.
1 issue was caused by detecting 2d horizontal line intersections for lines that had points equal to the horizontal Y value - solved by detecting point on line cases.
Another was because the 2D bounding box for painting could have faces edges running along it - solved by adding a small margin to the bounding box.
* add support for building redcode on win32/msvc, but disabled for now, as there are linking problems
- I cleaned the redcode sconscript - the copying of headers within the source tree is not a clean solution
This needs to be fixed later on. For now, lets use redcode from extern/ until a better way is found.
Python dict error: when trying to access a Bone via a key, and the key
was not found, a wrong error message got printed. Fix provided by
reporter Gregor Riepl. Thanks!
When entering a wrong expression (or garbish) in a Nkey panel button,
the cursor jumps to the place where the button was clicked. On failure
the button could return a B_NOP, not a 0
* When making a proxy, the lib linked IPO driver was also changed to
point to the proxy object, and after undo this local proxy object
was replaced so the pointer became invalid. In fact it is not needed
at all to change this because the IPO code maps the pointer to the
local proxy object already.
* Undoing the make proxy operation would crash because the proxy_from
pointer in the library linked object would still point to the removed
object. Now it clears all these pointers before undo, because on each
undo memory file read they will be set again anyway.
Bah... fix for envmaps just before 2.48 release gave good looking envmaps
only when there was no sky involved...
The alpha in environment maps should be reset to 255... something that was
never done before, but also didn't show errors until other fixes in image
rendering were done.
* The second opengl texture coordinate (gl_TexCoord[1]) are now filled
in as well, and will give canvas coordinates from 0.0 to 1.0. The
first texture coordinates still give the coordinates in the texture
that is being used, which may not match the canvas exactly, so both
coordinates are needed.
* Also optimization to allow using smaller texture sizes with multiple
smaller viewports.
* Print the detailed GLSL shader errors (once), for easier debugging.