Adding support for simple illumination

178 views
Skip to first unread message

tronr...@gmail.com

unread,
Jul 23, 2018, 11:41:37 PM7/23/18
to Sketch Users
I am looking at ways to add simple illumination support for Sketch. The idea is that one could use global options to specify ambient/diffuse/specular light sources, and then use the color mixing capabilities of the xcolor package to mix the albedo (i.e. "true color" of a polygon) with the illumination color depending on the direction of the normal with respect to the light source. Since the normal to the polygon is already computed for culling purposes, these extensions should be relatively feasible. My questions are: 1) Where to look in the source code for adding global options?, and 2) Where to look for accessing the normal information and the output of the colors of the polygons?
Thank you in advance!

Gene Ressler

unread,
Jul 24, 2018, 12:39:39 PM7/24/18
to sketch...@googlegroups.com
Yes this would have been the next addition had I been able to continue development. As you can see from the group traffic, Sketch has been in maintenance mode for some time. 

Parsing the input ultimately produces a binary space partition data structure that's refined by splitting and then sorted by depth in the hidden surface algorithm. Polygons in this data structure include plane normals computed with Newell's algorithm. The result is rendered as 2d output polygons.  

You could apply a lighting model on the bsp data structure before or after refinement. Start by looking at bsp.c and bsp.h. 

This will work fine for objects with planar boundaries. Unfortunately, for shading faceted curved shapes, you really Gouraud-shaded general polygons. PsTricks and Tikz didn't provide them (as I recall, TikZ had triangles only, so triangular decomposition of >3-gons would have been required), and emitting custom postscript looked messy.

Global options are set up directly by the parser. In sketch.y, see the production global_decl

Good luck with it. If you finally end up with a usable patch, I'll be happy to consider updating the project.

Gene

On Mon, Jul 23, 2018 at 3:27 PM, <tronr...@gmail.com> wrote:
I am looking at ways to add simple illumination support for Sketch. The idea is that one could use global options to specify ambient/diffuse/specular light sources, and then use the color mixing capabilities of the xcolor package to mix the albedo (i.e. "true color" of a polygon) with the illumination color depending on the direction of the normal with respect to the light source. Since the normal to the polygon is already computed for culling purposes, these extensions should be relatively feasible. My questions are: 1) Where to look in the source code for adding global options?, and 2) Where to look for accessing the normal information and the output of the colors of the polygons?
Thank you in advance!

--
You received this message because you are subscribed to the Google Groups "Sketch Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sketch-users+unsubscribe@googlegroups.com.
To post to this group, send email to sketch...@googlegroups.com.
Visit this group at https://groups.google.com/group/sketch-users.
For more options, visit https://groups.google.com/d/optout.



--
Gene Ressler
Reply all
Reply to author
Forward
0 new messages