[Bf-blender-npr] Feature/improvement idea for Freestyle

Tamito KAJIYAMA rd6t-kjym at asahi-net.or.jp
Tue Apr 8 04:22:56 CEST 2014


Hi Terry,

I reply to the following point now, and will respond later to the others.

 >> Changing the thickness of a crease line depending on the angle between
 >> the two faces on both sides of the line is technically possible. I just
 >> did a proof-of-concept implementation using the Python Scripting mode of
 >> Freestyle in Blender. See https://vimeo.com/91306354 for a quick test
 >> result. Implementing this crease angle dependent line thickness in the
 >> Parameter Editor mode needs further coding (that could be a short term
 >> goal).
 >
 > That was pretty neat, though! I may have to look into how you did 
that. That
 > would matter when it's the model that's changing rather than the camera.

Below you will find the style module I wrote to create the video clip.
Store this Python script in a file, and you can add it to the stack of
style modules in the Python Scripting mode of Freestyle in Blender.
Note that only crease lines will be drawn. It is a quick experimental
code so might turn out to be hard to apply to practical use.

------------------------------------------------------------

from freestyle.chainingiterators import *
from freestyle.predicates import *
from freestyle.shaders import *
from freestyle.types import Operators

import math

class CreaseAngleDependentThicknessShader(StrokeShader):
     def __init__(self, angle1, angle2, thickness1, thickness2):
         StrokeShader.__init__(self)
         self.__a1 = angle1
         self.__a2 = angle2
         self.__t1 = thickness1
         self.__t2 = thickness2

     def shade(self, stroke):
         delta_a = self.__a2 - self.__a1
         delta_t = self.__t2 - self.__t1
         fac = 1 / delta_a
         for v in stroke:
             fe = v.first_svertex.get_fedge(v.second_svertex)
             if not fe.is_smooth:
                 angle = 
math.degrees(math.acos(-fe.normal_left.dot(fe.normal_right)))
                 if angle < self.__a1:
                     t = self.__t1
                 elif angle > self.__a2:
                     t = self.__t2
                 else:
                     t = self.__t1 + delta_t * (angle - self.__a1) * fac
                 #print(angle, t)
                 v.attribute.thickness = (t/2, t/2)

upred = AndUP1D(QuantitativeInvisibilityUP1D(0), 
pyNatureUP1D(Nature.CREASE))
Operators.select(upred)
Operators.bidirectional_chain(ChainSilhouetteIterator(), NotUP1D(upred))
shaders_list = [
     SamplingShader(5.0),
     CreaseAngleDependentThicknessShader(70, 120, 5, 0),
     ConstantColorShader(0, 0, 0),
     ]
Operators.create(TrueUP1D(), shaders_list)

------------------------------------------------------------

Regards,

-- 
KAJIYAMA, Tamito <rd6t-kjym at asahi-net.or.jp>


On 08/04/2014 04:05, Terry Hancock wrote:
> TK,
>
>> I have seen many cases too where lines suddenly showing up and
>> disappearing are distracting, so I see the point of your post.
>>
>> Concerning crease lines, they are independent of the view point [...]
>
> Actually I knew that. Or should have remembered! (I've read the paper about
> the Freestyle algorithms). So that's not what I was seeing, of course.
>
>> Changing the thickness of a crease line depending on the angle between
>> the two faces on both sides of the line is technically possible. I just
>> did a proof-of-concept implementation using the Python Scripting mode of
>> Freestyle in Blender. See https://vimeo.com/91306354 for a quick test
>> result. Implementing this crease angle dependent line thickness in the
>> Parameter Editor mode needs further coding (that could be a short term
>> goal).
>
> That was pretty neat, though! I may have to look into how you did that. That
> would matter when it's the model that's changing rather than the camera.
>
>> Contours, on the other hand, are view dependent lines.
>
> Clearly that has to be the source of the problem I was talking about.
>
> It is the "suggestive contour" algorithm that I think offers a chance for
> improvement here.
>
> As I understand it, these are "almost contours", meaning that they do not
> quite undercut, but have a very steep angle relative to the line of sight.
>
> Freestyle currently must just have some cutoff point for this. (?)
>
> So then my request would amount to extracting the steepness -- "how close to a
> contour is it?" -- as a numerical value and making that available for
> modifiers.
>
> Typically, when a contour disappears, it should be a "suggestive contour" for
> a short time after. So if you have a modifier with a rapid fall-off in thickness
> and/or alpha, it would implement a softer disappearance.
>
>> Maintaining
>> inter-frame properties of lines (such as stability and gradually varying
>> thickness) is a problem called temporal coherence.
>
> Yep. That would get complicated.
>
> But I think the suggestive contour modifier idea would only depend on the
> instantaneous geometry of the current frame, so it doesn't fall into that
> category.
>
>> For now it is unlikely that the
>> temporal coherence problem is solved in Freestyle for Blender.
>
> Yeah, that's understandable, and even this contour issue is something I expect
> I'll just have to accept as a flaw for the present. Just thinking about ways to
> improve it. :-)
>
> Cheers,
> Terry


More information about the Bf-blender-npr mailing list