fury icon indicating copy to clipboard operation
fury copied to clipboard

Tutorial on making a primitive using polygons and SDF

Open tvcastillod opened this issue 3 years ago • 6 comments

This tutorial is intended to show two ways of primitives creation with the use of polygons, and SDF. I used cylinders as an example since they have a simpler polygonal representation, so it allows us to see better the difference between using one or the other method.

tvcastillod avatar Jul 04 '22 22:07 tvcastillod

Hello @tvcastillod! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found:

There are currently no PEP 8 issues detected in this Pull Request. Cheers! :beers:

Comment last updated at 2022-08-14 02:08:41 UTC

pep8speaks avatar Jul 04 '22 22:07 pep8speaks

Hello @tvcastillod, Good work! It's good to see another shape join the SDF club! This implementation should be used as an option in actor.sdf. I played around with this tutorial and came up with some suggestions.

  • You don't have to explicitly set the light direction in the shader. You might instead assume that the light is coming out of the camera vec3 ld = normalize(ro.xyz - point); which I think is used by default in normal actors. Which would make it look like the original cylinder actor as below:

https://user-images.githubusercontent.com/63170874/177390003-633ceae0-bca3-4476-9c0c-e9d57c720018.mp4

https://user-images.githubusercontent.com/63170874/177390022-3ce7cefe-c017-4ce6-b188-8e9d14287080.mp4

Also would like to hear @guaje opinion on this point.

  • The color calculations are not taking advantage of the settings VTK already provides:
 uniform float ambientIntensity; // the material ambient
 uniform float diffuseIntensity; // the material diffuse
 uniform float opacityUniform; // the fragment opacity
 uniform vec3 ambientColorUniform; // ambient color
 uniform vec3 diffuseColorUniform; // diffuse color
 uniform float specularIntensity; // the material specular intensity
 uniform vec3 specularColorUniform; // intensity weighted color
 uniform float specularPowerUniform;

Default frag calculations:

 vec3 specularColor = specularIntensity * specularColorUniform;
 float specularPower = specularPowerUniform;
 vec3 ambientColor = ambientIntensity * vertexColorVSOutput.rgb;
 vec3 diffuseColor = diffuseIntensity * vertexColorVSOutput.rgb;
 float opacity = opacityUniform * vertexColorVSOutput.a;

 //VTK::Normal::Impl
 float df = max(0.0,normalVCVSOutput.z);
 float sf = pow(df, specularPower);
 vec3 diffuse = df * diffuseColor * lightColor0;
 vec3 specular = sf * specularColor * lightColor0;
 fragOutput0 = vec4(ambientColor + diffuse + specular, opacity);

m-agour avatar Jul 05 '22 18:07 m-agour

  • You don't have to explicitly set the light direction in the shader. You might instead assume that the light is coming out of the camera vec3 ld = normalize(ro.xyz - point); which I think is used by default in normal actors. Which would make it look like the original cylinder actor as below:

Good catch @m-agour! You're right, by default VTK uses a retroreflective light model. BTW, the video comparisons look great, at some point, it would be nice to use your FPS to really test the performance of SDF-based vs polygonal-based actors.

  • The color calculations are not taking advantage of the settings VTK already provides:

@tvcastillod to take advantage of the default Blinn-Phong illumination model please use fury/shaders/lighting/blinn_phong_model.frag as in #587.

guaje avatar Jul 07 '22 15:07 guaje

Codecov Report

Merging #620 (3630842) into master (63b87a8) will decrease coverage by 0.49%. The diff coverage is 0.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #620      +/-   ##
==========================================
- Coverage   51.84%   51.34%   -0.50%     
==========================================
  Files         105      108       +3     
  Lines       22337    23882    +1545     
  Branches     2460     2631     +171     
==========================================
+ Hits        11581    12263     +682     
- Misses      10381    11208     +827     
- Partials      375      411      +36     
Impacted Files Coverage Δ
fury/primitive.py 0.00% <0.00%> (ø)
fury/ui/elements.py 0.00% <0.00%> (ø)
fury/ui/tests/test_elements.py 0.00% <0.00%> (ø)
fury/ui/tests/test_elements_callback.py 0.00% <0.00%> (ø)
fury/window.py 0.00% <0.00%> (ø)
fury/fury/ui/tests/test_containers.py 64.76% <0.00%> (-28.96%) :arrow_down:
fury/fury/tests/test_window.py 71.42% <0.00%> (-22.31%) :arrow_down:
fury/fury/window.py 73.98% <0.00%> (-9.28%) :arrow_down:
fury/fury/shaders/base.py 84.84% <0.00%> (-8.09%) :arrow_down:
fury/fury/ui/containers.py 82.92% <0.00%> (-0.89%) :arrow_down:
... and 29 more

codecov[bot] avatar Jul 21 '22 04:07 codecov[bot]

LGTM!

@skoudoro, @m-agour, do you have any more comments or suggestions? Or should I go ahead and merge it?

guaje avatar Aug 08 '22 19:08 guaje

I will look into it this week. If no comment until Sunday, you can go ahead

skoudoro avatar Aug 08 '22 19:08 skoudoro

@tvcastillod good job! This tutorial will be a great addition. Merging.

guaje avatar Aug 18 '22 21:08 guaje