More fun.

-Yosh
This commit is contained in:
Manish Singh 1998-06-11 06:04:59 +00:00
parent 67d371c5fe
commit 7fc4de2bf4
28 changed files with 4085 additions and 0 deletions

View file

@ -0,0 +1,6 @@
Makefile.in
Makefile
.deps
_libs
.libs
Lighting

View file

@ -0,0 +1,21 @@
Changes:
========
0.2.2: Fixed a bug in the preview code sometimes causing a SIGSEGV.
Thanks to Prabhanjan <prabham@india.s3.com> for reporting it.
0.2.1: Fixed a bug in the calculation of the normals. Thanks to
Simon Budig <Simon.Budig@unix-ag.org> for pointing this out.
0.2.0: Fixed crashes when rerunning after closing mapping images. Removed
GckNotebook and fixed gtk refcounting problems. Added non-interactive
(scripting) interface. First non-beta release.
0.1.1: Transparent background and RGBA support, various bug fixes and
minor speed ups. First beta version.
0.0.x: Many bug fixes. Moved it to "..filters/Light Effects/Lighting Effects"
0.0.1: First version for 0.99.x

View file

@ -0,0 +1,41 @@
## Process this file with automake to produce Makefile.in
pluginlibdir = $(gimpplugindir)/plug-ins
pluginlib_PROGRAMS = Lighting
Lighting_SOURCES = \
amb1.xpm amb2.xpm diffint1.xpm diffint2.xpm diffref1.xpm diffref2.xpm high1.xpm high2.xpm lighting_apply.c lighting_apply.h lighting_image.c lighting_image.h lighting_main.c lighting_main.h lighting_pixmaps.h lighting_preview.c lighting_preview.h lighting_shade.c lighting_shade.h lighting_ui.c lighting_ui.h specref1.xpm specref2.xpm
INCLUDES = \
-I$(top_srcdir) \
-I$(top_srcdir)/plug-ins/libgck \
-I$(includedir) \
$(X_CFLAGS)
LDADD = \
$(top_builddir)/libgimp/libgimpui.la \
$(top_builddir)/libgimp/libgimp.la \
$(top_builddir)/plug-ins/libgck/gck/libgck.la \
$(X_LIBS) \
-lc
DEPS = \
$(top_builddir)/libgimp/libgimpui.la \
$(top_builddir)/libgimp/libgimp.la \
$(top_builddir)/plug-ins/libgck/gck/libgck.la
Lighting_DEPENDENCIES = $(DEPS)
.PHONY: files
files:
@files=`ls $(DISTFILES) 2> /dev/null`; for p in $$files; do \
echo $$p; \
done
@for subdir in $(SUBDIRS); do \
files=`cd $$subdir; $(MAKE) files | grep -v "make\[[1-9]\]"`; \
for file in $$files; do \
echo $$subdir/$$file; \
done; \
done

39
plug-ins/Lighting/README Normal file
View file

@ -0,0 +1,39 @@
Lighting Effects 0.2.2 -- image filter plug-in for The GIMP program
===================================================================
Copyright (C) 1996-98 Tom Bech
Copyright (C) 1996-98 Federico Mena Quintero
You can reach the author(s) via E-mail:
tomb@gimp.org (Tom) or quartic@gimp.org (Federico).
The GIMP was developed by Peter Mattis and Spencer Kimball.
You can contact them at gimp@xcf.berkeley.edu.
There's more GIMP stuff on our home pages:
http://www.ii.uib.no/~tomb/gimp.html (Tom's page)
http://www.nuclecu.unam.mx/~federico/gimp/index.html (Quartic's page)
Legal stuff
===========
This program is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free Software
Foundation; either version 2 of the License, or (at your option) any later
version.
This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with
this program (see "COPYING" file); if not, write to the Free Software Foundation,
Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
In other words, you can't sue us for whatever happens while using this ;)
Have fun,
Tom

15
plug-ins/Lighting/TODO Normal file
View file

@ -0,0 +1,15 @@
The lighting plug-in "todo"-list:
=================================
* Supersampling/antialiasing
* Bilinear filtering of enviroment map
* Refraction back in?
* Support for any-sized non-gray bump-maps.
* Support for gray or alpha-channeled env-maps.
* Zooming and scrolling in preview window
* Autoconf/automake stuff
* Put spotlight back in
* Nicer interactive UI
* Presets
* Multiple light sources

View file

@ -0,0 +1,88 @@
/* XPM */
char * amb1_xpm[] = {
"32 32 53 1",
" c None",
". c #861786178617",
"X c #861782078617",
"o c #69A66DB669A6",
"O c #8E388E388E38",
"+ c #B6DAB2CAB6DA",
"@ c #BEFBBAEABEFB",
"# c #AEBAAEBAAEBA",
"$ c #9E799E799E79",
"% c #8E388A288E38",
"& c #618565956185",
"* c #30C234D330C2",
"= c #A699A699A699",
"- c #CF3CCF3CCF3C",
"; c #D75CD34CD75C",
": c #C71BC30BC71B",
"> c #DF7DDF7DDF7D",
", c #D75CD75CD75C",
"< c #CF3CCB2BCF3C",
"1 c #AEBAAAAAAEBA",
"2 c #965896589658",
"3 c #79E779E779E7",
"4 c #514455555144",
"5 c #18611C711861",
"6 c #E79DE38DE79D",
"7 c #E79DE79DE79D",
"8 c #DF7DDB6CDF7D",
"9 c #BEFBBEFBBEFB",
"0 c #9E799A699E79",
"q c #79E77DF779E7",
"w c #618561856185",
"e c #38E338E338E3",
"r c #000004100000",
"t c #EFBEEFBEEFBE",
"y c #FFFFFBEEFFFF",
"u c #410341034103",
"i c #08200C300820",
"p c #FFFFFFFFFFFF",
"a c #B6DAB6DAB6DA",
"s c #965892489658",
"d c #104014511040",
"f c #71C675D671C6",
"g c #596559655965",
"h c #104010401040",
"j c #000000000000",
"k c #514451445144",
"l c #30C230C230C2",
"z c #59655D755965",
"x c #410345144103",
"c c #208124922081",
"v c #49244D344924",
"b c #208120812081",
"n c #082008200820",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" .Xo ",
" O+@@#$%&* ",
" =-;;-:+$.&* ",
" =;>>>,<@12345 ",
" O->6778-9#0qwer ",
" +;>7tyt-910X&ui ",
" @;>7ypy-a=sqwud ",
" .@-,8ty6:#$Ofgehj ",
" X#:<---:+=2Xoklij ",
" o$+@99a#=2.fzxcrj ",
" %$1#1=$2.f&v*dj ",
" &.200sOXf&kebrj ",
" *&3qXqfozvecnjj ",
" *4w&wgkx*bnjj ",
" 5euuelcdrjj ",
" ridhirjjj ",
" jjj ",
" ",
" ",
" ",
" ",
" ",
" ",
" "};

View file

@ -0,0 +1,58 @@
/* XPM */
char * amb2_xpm[] = {
"32 32 23 1",
" c None",
". c #CF3CCF3CCF3C",
"X c #CF3CCB2BCF3C",
"o c #C71BC30BC71B",
"O c #D75CD75CD75C",
"+ c #DF7DDB6CDF7D",
"@ c #C71BC71BC71B",
"# c #AEBAAEBAAEBA",
"$ c #DF7DDF7DDF7D",
"% c #E79DE38DE79D",
"& c #D75CD34CD75C",
"* c #E79DE79DE79D",
"= c #AEBAAAAAAEBA",
"- c #EFBEEBADEFBE",
"; c #BEFBBEFBBEFB",
": c #A699A289A699",
"> c #F7DEF3CEF7DE",
", c #F7DEF7DEF7DE",
"< c #B6DAB2CAB6DA",
"1 c #FFFFFFFFFFFF",
"2 c #FFFFFBEEFFFF",
"3 c #B6DAB6DAB6DA",
"4 c #BEFBBAEABEFB",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ..X ",
" oO+++O.@# ",
" X$%%$$+O&X# ",
" X%%*%%$$+&.@= ",
" o$%**-*%$+O.@;: ",
" O%**>,,%$+O.Xo< ",
" +%%-,12*+O&.Xo3 ",
" .+$%*,2,%+O&.@;3< ",
" .+$$%%*%+O&.X@;3< ",
" XO+$$$++OO&.@o43< ",
" .O+++OO&&.Xo;3< ",
" @&&OO&&..X@;43# ",
" #X.....X@o;43<: ",
" #@@XX@@o;43<: ",
" =;oo;;433<: ",
" :<3333<#: ",
" <<< ",
" ",
" ",
" ",
" ",
" ",
" ",
" "};

View file

@ -0,0 +1,44 @@
/* XPM */
char * diffint1_xpm[] = {
"32 32 9 1",
" c None",
". c #514455555144",
"X c #514451445144",
"o c #49244D344924",
"O c #596559655965",
"+ c #492449244924",
"@ c #410345144103",
"# c #59655D755965",
"$ c #618561856185",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ..X ",
" o.OO...X+ ",
" XOOOOOO..X+ ",
" XOOOOOOO...X+ ",
" oOOOOOOOOO..Xo@ ",
" .OOO###OO...XX+ ",
" OOOO#$#OO...XXo ",
" .OOOO###OO...XXoo ",
" ..OOOOOOO...XXooo ",
" X.OOOOOO....XXooo ",
" ...O......XXooo ",
" X........XXXoo+ ",
" +X.....XXXXooo@ ",
" +XXXXXXXoooo@ ",
" +oXXXooooo@ ",
" @+ooooo+@ ",
" ooo ",
" ",
" ",
" ",
" ",
" ",
" ",
" "};

View file

@ -0,0 +1,80 @@
/* XPM */
char * diffint2_xpm[] = {
"32 32 45 1",
" c None",
". c #A699A699A699",
"X c #A699A289A699",
"o c #965896589658",
"O c #BEFBBEFBBEFB",
"+ c #CF3CCB2BCF3C",
"@ c #C71BC71BC71B",
"# c #C71BC30BC71B",
"$ c #B6DAB6DAB6DA",
"% c #8E388E388E38",
"& c #69A669A669A6",
"* c #D75CD75CD75C",
"= c #DF7DDB6CDF7D",
"- c #CF3CCF3CCF3C",
"; c #965892489658",
": c #DF7DDF7DDF7D",
"> c #E79DE38DE79D",
", c #D75CD34CD75C",
"< c #AEBAAEBAAEBA",
"1 c #9E799E799E79",
"2 c #861786178617",
"3 c #596559655965",
"4 c #E79DE79DE79D",
"5 c #B6DAB2CAB6DA",
"6 c #71C671C671C6",
"7 c #492449244924",
"8 c #F7DEF3CEF7DE",
"9 c #F7DEF7DEF7DE",
"0 c #71C675D671C6",
"q c #514455555144",
"w c #FFFFFFFFFFFF",
"e c #FFFFFBEEFFFF",
"r c #BEFBBAEABEFB",
"t c #EFBEEBADEFBE",
"y c #AEBAAAAAAEBA",
"u c #9E799A699E79",
"i c #8E388A288E38",
"p c #49244D344924",
"a c #861782078617",
"s c #69A66DB669A6",
"d c #79E779E779E7",
"f c #618565956185",
"g c #514451445144",
"h c #618561856185",
"j c #410345144103",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" .Xo ",
" .O+@#$.%& ",
" $*==*-#$.;& ",
" $=:>:=,+O<123 ",
" .*:444:*+O5X%67 ",
" O=>4898*+O5X%0q ",
" +=:49we=@r<1%03 ",
" .@*=:8et-#$yui03p ",
" X#-,**=-#r<Xoasqp ",
" o$#+++@#r5.uidfgp ",
" .$OOOr$<.1%as3p ",
" %.<55<yXu%a0hg7 ",
" &;1XX1uoia0fgpj ",
" &2%%%iadshgpj ",
" 36000sf3gpj ",
" 7q33qgp7j ",
" ppp ",
" ",
" ",
" ",
" ",
" ",
" ",
" "};

View file

@ -0,0 +1,46 @@
/* XPM */
char * diffref1_xpm[] = {
"32 32 11 1",
" c None",
". c #49244D344924",
"X c #410345144103",
"o c #492449244924",
"O c #514451445144",
"+ c #596559655965",
"@ c #79E779E779E7",
"# c #69A669A669A6",
"$ c #BEFBBAEABEFB",
"% c #8E388A288E38",
"& c #514455555144",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ... ",
" Xo.....oX ",
" X.........X ",
" X...........X ",
" X....OO.......X ",
" o...+@#O......o ",
" ...O@$%&....... ",
" ....O#%#O........ ",
" .....O&O......... ",
" ................. ",
" ............... ",
" o.............o ",
" X.............X ",
" X...........X ",
" X.........X ",
" Xo.....oX ",
" ... ",
" ",
" ",
" ",
" ",
" ",
" ",
" "};

View file

@ -0,0 +1,75 @@
/* XPM */
char * diffref2_xpm[] = {
"32 32 40 1",
" c None",
". c #D75CD34CD75C",
"X c #CF3CCF3CCF3C",
"o c #BEFBBAEABEFB",
"O c #F7DEF3CEF7DE",
"+ c #F7DEF7DEF7DE",
"@ c #FFFFFBEEFFFF",
"# c #EFBEEBADEFBE",
"$ c #D75CD75CD75C",
"% c #B6DAB2CAB6DA",
"& c #79E779E779E7",
"* c #E79DE79DE79D",
"= c #FFFFFFFFFFFF",
"- c #EFBEEFBEEFBE",
"; c #E79DE38DE79D",
": c #C71BC71BC71B",
"> c #A699A289A699",
", c #618565956185",
"< c #AEBAAEBAAEBA",
"1 c #861786178617",
"2 c #492449244924",
"3 c #8E388E388E38",
"4 c #596559655965",
"5 c #CF3CCB2BCF3C",
"6 c #618561856185",
"7 c #DF7DDB6CDF7D",
"8 c #C71BC30BC71B",
"9 c #AEBAAAAAAEBA",
"0 c #8E388A288E38",
"q c #49244D344924",
"w c #9E799E799E79",
"e c #79E77DF779E7",
"r c #965892489658",
"t c #71C671C671C6",
"y c #514451445144",
"u c #9E799A699E79",
"i c #861782078617",
"p c #69A66DB669A6",
"a c #514455555144",
"s c #410345144103",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" .Xo ",
" .O+@@#$%& ",
" *=====@-$%& ",
" *=======+;:>, ",
" .========+*X<12 ",
" O========+*X%34 ",
" +========O;5<36 ",
" .@=======@#78906q ",
" X@======@O;Xowe4q ",
" o#@====@O*$89rtyq ",
" $-+++O#;$:%ui6q ",
" %$;**;7X8%w0py2 ",
" &%:XX58o9u0taqs ",
" &><%<9wripaqs ",
" ,1330et6yqs ",
" 24664yq2s ",
" qqq ",
" ",
" ",
" ",
" ",
" ",
" ",
" "};

View file

@ -0,0 +1,75 @@
/* XPM */
char * high1_xpm[] = {
"32 32 40 1",
" c None",
". c #D75CD34CD75C",
"X c #CF3CCF3CCF3C",
"o c #BEFBBAEABEFB",
"O c #F7DEF3CEF7DE",
"+ c #F7DEF7DEF7DE",
"@ c #FFFFFBEEFFFF",
"# c #EFBEEBADEFBE",
"$ c #D75CD75CD75C",
"% c #B6DAB2CAB6DA",
"& c #79E779E779E7",
"* c #E79DE79DE79D",
"= c #FFFFFFFFFFFF",
"- c #EFBEEFBEEFBE",
"; c #E79DE38DE79D",
": c #C71BC71BC71B",
"> c #A699A289A699",
", c #618565956185",
"< c #AEBAAEBAAEBA",
"1 c #861786178617",
"2 c #492449244924",
"3 c #8E388E388E38",
"4 c #596559655965",
"5 c #CF3CCB2BCF3C",
"6 c #618561856185",
"7 c #DF7DDB6CDF7D",
"8 c #C71BC30BC71B",
"9 c #AEBAAAAAAEBA",
"0 c #8E388A288E38",
"q c #49244D344924",
"w c #9E799E799E79",
"e c #79E77DF779E7",
"r c #965892489658",
"t c #71C671C671C6",
"y c #514451445144",
"u c #9E799A699E79",
"i c #861782078617",
"p c #69A66DB669A6",
"a c #514455555144",
"s c #410345144103",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" .Xo ",
" .O+@@#$%& ",
" *=====@-$%& ",
" *=======+;:>, ",
" .========+*X<12 ",
" O========+*X%34 ",
" +========O;5<36 ",
" .@=======@#78906q ",
" X@======@O;Xowe4q ",
" o#@====@O*$89rtyq ",
" $-+++O#;$:%ui6q ",
" %$;**;7X8%w0py2 ",
" &%:XX58o9u0taqs ",
" &><%<9wripaqs ",
" ,1330et6yqs ",
" 24664yq2s ",
" qqq ",
" ",
" ",
" ",
" ",
" ",
" ",
" "};

View file

@ -0,0 +1,78 @@
/* XPM */
char * high2_xpm[] = {
"32 32 43 1",
" c None",
". c #A699A699A699",
"X c #A699A289A699",
"o c #965896589658",
"O c #BEFBBEFBBEFB",
"+ c #CF3CCB2BCF3C",
"@ c #C71BC71BC71B",
"# c #C71BC30BC71B",
"$ c #B6DAB6DAB6DA",
"% c #8E388E388E38",
"& c #69A669A669A6",
"* c #D75CD75CD75C",
"= c #DF7DDB6CDF7D",
"- c #CF3CCF3CCF3C",
"; c #965892489658",
": c #DF7DDF7DDF7D",
"> c #E79DE38DE79D",
", c #D75CD34CD75C",
"< c #AEBAAEBAAEBA",
"1 c #9E799E799E79",
"2 c #861786178617",
"3 c #596559655965",
"4 c #E79DE79DE79D",
"5 c #B6DAB2CAB6DA",
"6 c #71C671C671C6",
"7 c #492449244924",
"8 c #F7DEF7DEF7DE",
"9 c #71C675D671C6",
"0 c #514455555144",
"q c #FFFFFFFFFFFF",
"w c #BEFBBAEABEFB",
"e c #F7DEF3CEF7DE",
"r c #AEBAAAAAAEBA",
"t c #9E799A699E79",
"y c #8E388A288E38",
"u c #49244D344924",
"i c #861782078617",
"p c #69A66DB669A6",
"a c #79E779E779E7",
"s c #618565956185",
"d c #514451445144",
"f c #618561856185",
"g c #410345144103",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" .Xo ",
" .O+@#$.%& ",
" $*==*-#$.;& ",
" $=:>:=,+O<123 ",
" .*:>4>=*+O5X%67 ",
" O=>4>8:,+O5X%90 ",
" +=:>8qq-@w<1%93 ",
" .@*==:e=+#$rty93u ",
" X#-,*,*-#w<Xoip0u ",
" o$#+++@#w5.tyasdu ",
" .$OOOw$<.1%ip3u ",
" %.<55<rXt%i9fd7 ",
" &;1XX1toyi9sdug ",
" &2%%%yiapfdug ",
" 36999ps3dug ",
" 70330du7g ",
" uuu ",
" ",
" ",
" ",
" ",
" ",
" ",
" "};

View file

@ -0,0 +1,147 @@
/******************************************************/
/* Apply mapping and shading on the whole input image */
/******************************************************/
#include "lighting_shade.h"
/*************/
/* Main loop */
/*************/
get_ray_func ray_func;
void init_compute(void)
{
}
void render(gdouble x,gdouble y,GckRGB *col)
{
GckVector3 pos;
pos=int_to_pos(x,y);
*col=(*ray_func)(&pos);
}
void show_progress(gint min,gint max,gint curr)
{
gimp_progress_update((gdouble)curr/(gdouble)max);
}
void compute_image(void)
{
gint xcount,ycount;
GckRGB color;
glong progress_counter=0;
GckVector3 p;
gint32 new_image_id=-1,new_layer_id=-1,index;
guchar *row = NULL, obpp;
gint has_alpha;
init_compute();
if (mapvals.create_new_image==TRUE || (mapvals.transparent_background==TRUE
&& !gimp_drawable_has_alpha(input_drawable->id)))
{
/* Create a new image */
/* ================== */
new_image_id=gimp_image_new(width,height,RGB);
if (mapvals.transparent_background==TRUE)
{
/* Add a layer with an alpha channel */
/* ================================= */
new_layer_id=gimp_layer_new(new_image_id,"Background",
width,height,RGBA_IMAGE,100.0,NORMAL_MODE);
}
else
{
/* Create a "normal" layer */
/* ======================= */
new_layer_id=gimp_layer_new(new_image_id,"Background",
width,height,RGB_IMAGE,100.0,NORMAL_MODE);
}
gimp_image_add_layer(new_image_id,new_layer_id,0);
output_drawable=gimp_drawable_get(new_layer_id);
}
if (mapvals.bump_mapped==TRUE && mapvals.bumpmap_id!=-1)
{
gimp_pixel_rgn_init (&bump_region, gimp_drawable_get(mapvals.bumpmap_id),
0, 0, width, height, FALSE, FALSE);
precompute_init(width,height);
}
if (!mapvals.env_mapped || mapvals.envmap_id==-1)
ray_func = get_ray_color;
else
{
gimp_pixel_rgn_init (&env_region, gimp_drawable_get(mapvals.envmap_id),
0, 0, env_width, env_height, FALSE, FALSE);
ray_func = get_ray_color_ref;
}
gimp_pixel_rgn_init (&dest_region, output_drawable, 0,0, width,height, TRUE,TRUE);
obpp=gimp_drawable_bpp(output_drawable->id);
has_alpha=gimp_drawable_has_alpha(output_drawable->id);
row = (guchar *)malloc(sizeof(guchar)*(size_t)(obpp)*(size_t)(width));
gimp_progress_init("Lighting Effects");
/* if (mapvals.antialiasing==FALSE)
{ */
for (ycount=0;ycount<height;ycount++)
{
if (mapvals.bump_mapped==TRUE && mapvals.bumpmap_id!=-1)
precompute_normals(0,width,ycount);
index=0;
for (xcount=0;xcount<width;xcount++)
{
p=int_to_pos(xcount,ycount);
color=(*ray_func)(&p);
row[index++]=(guchar)(color.r*255.0);
row[index++]=(guchar)(color.g*255.0);
row[index++]=(guchar)(color.b*255.0);
if (has_alpha)
row[index++]=(guchar)(color.a*255.0);
if ((progress_counter++ % width)==0)
gimp_progress_update((gdouble)progress_counter/(gdouble)maxcounter);
}
gimp_pixel_rgn_set_row(&dest_region,row,0,ycount,width);
}
/* }
else
gck_adaptive_supersample_area(0,0,width-1,height-1,(gint)mapvals.max_depth,
mapvals.pixel_treshold,render,poke,show_progress); */
if (row!=NULL)
free(row);
/* Update image */
/* ============ */
gimp_drawable_flush(output_drawable);
gimp_drawable_merge_shadow(output_drawable->id, TRUE);
gimp_drawable_update(output_drawable->id, 0,0, width,height);
if (new_image_id!=-1)
{
gimp_display_new(new_image_id);
gimp_displays_flush();
gimp_drawable_detach(output_drawable);
}
}

View file

@ -0,0 +1,18 @@
#ifndef LIGHTINGAPPLYH
#define LIGHTINGAPPLYH
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <gdk/gdk.h>
#include <gtk/gtk.h>
#include <libgimp/gimp.h>
#include <gck/gck.h>
#include "lighting_main.h"
#include "lighting_image.h"
extern void init_compute (void);
extern void compute_image (void);
#endif

View file

@ -0,0 +1,342 @@
/*************************************/
/* GIMP image manipulation routines. */
/*************************************/
#include "lighting_image.h"
GDrawable *input_drawable,*output_drawable;
GPixelRgn source_region, dest_region;
GDrawable *bump_drawable = NULL;
GPixelRgn bump_region;
GDrawable *env_drawable = NULL;
GPixelRgn env_region;
guchar *preview_rgb_data = NULL;
GdkImage *image = NULL;
glong maxcounter;
gint imgtype,width,height,env_width,env_height,in_channels,out_channels;
GckRGB background;
gint border_x1,border_y1,border_x2,border_y2;
guchar sinemap[256],spheremap[256],logmap[256];
/******************/
/* Implementation */
/******************/
guchar peek_map(GPixelRgn *region,gint x,gint y)
{
guchar data;
gimp_pixel_rgn_get_pixel(region,&data,x,y);
return(data);
}
GckRGB peek(gint x,gint y)
{
guchar data[4];
GckRGB color;
gimp_pixel_rgn_get_pixel(&source_region,data,x,y);
color.r=(gdouble)(data[0])/255.0;
color.g=(gdouble)(data[1])/255.0;
color.b=(gdouble)(data[2])/255.0;
if (input_drawable->bpp==4)
{
if (in_channels==4)
color.a=(gdouble)(data[3])/255.0;
else
color.a=1.0;
}
else
color.a=1.0;
return(color);
}
GckRGB peek_env_map(gint x,gint y)
{
guchar data[4];
GckRGB color;
if (x<0)
x=0;
else if (x>=env_width)
x=env_width-1;
if (y<0)
y=0;
else if (y>=env_height)
y=env_height-1;
gimp_pixel_rgn_get_pixel(&env_region,data,x,y);
color.r=(gdouble)(data[0])/255.0;
color.g=(gdouble)(data[1])/255.0;
color.b=(gdouble)(data[2])/255.0;
color.a=1.0;
return(color);
}
void poke(gint x,gint y,GckRGB *color)
{
static guchar data[4];
if (x<0)
x=0;
else if (x>=width)
x=width-1;
if (y<0)
y=0;
else if (y>=height)
y=height-1;
data[0]=(guchar)(color->r*255.0);
data[1]=(guchar)(color->g*255.0);
data[2]=(guchar)(color->b*255.0);
data[3]=(guchar)(color->a*255.0);
gimp_pixel_rgn_set_pixel(&dest_region,data,x,y);
}
gint check_bounds(gint x,gint y)
{
if (x<border_x1 || y<border_y1 || x>=border_x2 || y>=border_y2)
return(FALSE);
else
return(TRUE);
}
GckVector3 int_to_pos(gint x,gint y)
{
GckVector3 pos;
if (width>=height)
{
pos.x=(gdouble)x/(gdouble)width;
pos.y=(gdouble)y/(gdouble)width;
pos.y+=0.5*(1.0-(gdouble)height/(gdouble)width);
}
else
{
pos.x=(gdouble)x/(gdouble)height;
pos.y=(gdouble)y/(gdouble)height;
pos.x+=0.5*(1.0-(gdouble)width/(gdouble)height);
}
pos.z=0.0;
return(pos);
}
GckVector3 int_to_posf(gdouble x,gdouble y)
{
GckVector3 pos;
if (width>=height)
{
pos.x=x/(gdouble)width;
pos.y=y/(gdouble)width;
pos.y+=0.5*(1.0-(gdouble)height/(gdouble)width);
}
else
{
pos.x=x/(gdouble)height;
pos.y=y/(gdouble)height;
pos.x+=0.5*(1.0-(gdouble)width/(gdouble)height);
}
pos.z=0.0;
return(pos);
}
void pos_to_int(gdouble x,gdouble y,gint *scr_x,gint *scr_y)
{
if (width>=height)
{
y-=0.5*(1.0-(gdouble)height/(gdouble)width);
*scr_x=(gint)((x*(gdouble)width)+0.5);
*scr_y=(gint)((y*(gdouble)width)+0.5);
}
else
{
x-=0.5*(1.0-(gdouble)width/(gdouble)height);
*scr_x=(gint)((x*(gdouble)height)+0.5);
*scr_y=(gint)((y*(gdouble)height)+0.5);
}
}
void pos_to_float(gdouble x,gdouble y,gdouble *xf,gdouble *yf)
{
if (width>=height)
{
y-=0.5*(1.0-(gdouble)height/(gdouble)width);
*xf=x*(gdouble)width;
*yf=y*(gdouble)width;
}
else
{
x-=0.5*(1.0-(gdouble)width/(gdouble)height);
*xf=x*(gdouble)height;
*yf=y*(gdouble)height;
}
}
/**********************************************/
/* Compute the image color at pos (u,v) using */
/* Quartics bilinear interpolation stuff. */
/**********************************************/
GckRGB get_image_color(gdouble u,gdouble v,gint *inside)
{
gint x1, y1, x2, y2;
GckRGB p[4];
x1=(gint)(u+0.5);
y1=(gint)(v+0.5);
if (check_bounds(x1,y1)==FALSE)
{
*inside=FALSE;
return(background);
}
x2 = (x1 + 1);
y2 = (y1 + 1);
if (check_bounds(x2,y2)==FALSE)
{
*inside=TRUE;
return(peek(x1,y1));
}
*inside=TRUE;
p[0] = peek(x1, y1);
p[1] = peek(x2, y1);
p[2] = peek(x1, y2);
p[3] = peek(x2, y2);
return(gck_bilinear_rgba(u, v, p));
}
gdouble get_map_value(GPixelRgn *region, gdouble u,gdouble v, gint *inside)
{
gint x1, y1, x2, y2;
gdouble p[4];
x1=(gint)(u+0.5);
y1=(gint)(v+0.5);
x2 = (x1 + 1);
y2 = (y1 + 1);
if (check_bounds(x2,y2)==FALSE)
{
*inside=TRUE;
return((gdouble)peek_map(region, x1,y1));
}
*inside=TRUE;
p[0] = (gdouble)peek_map(region, x1, y1);
p[1] = (gdouble)peek_map(region, x2, y1);
p[2] = (gdouble)peek_map(region, x1, y2);
p[3] = (gdouble)peek_map(region, x2, y2);
return(gck_bilinear(u, v, p));
}
void compute_maps(void)
{
gint x;
gdouble val,c,d;
/* Compute Sine, Log ans Spherical transfer function maps */
/* ====================================================== */
c=1.0/255.0;
d=1.15*255.0;
for (x=0;x<256;x++)
{
sinemap[x]=(guchar)(255.0*(0.5*(sin((M_PI*c*(gdouble)x)-0.5*M_PI)+1.0)));
spheremap[x]=(guchar)(255.0*(sqrt(sin(M_PI*(gdouble)x/512.0))));
val=(d*exp(-1.0/(8.0*c*((gdouble)x+5.0))));
if (val>255.0)
val=255.0;
logmap[x]=(guchar)val;
}
}
/****************************************/
/* Allocate memory for temporary images */
/****************************************/
gint image_setup(GDrawable *drawable,gint interactive)
{
glong numbytes;
compute_maps();
/* Get some useful info on the input drawable */
/* ========================================== */
input_drawable=drawable;
output_drawable=drawable;
gimp_drawable_mask_bounds (drawable->id, &border_x1, &border_y1, &border_x2, &border_y2);
width=input_drawable->width;
height=input_drawable->height;
gimp_pixel_rgn_init (&source_region, input_drawable, 0, 0, width, height, FALSE, FALSE);
maxcounter=(glong)width*(glong)height;
/* Assume at least RGB */
/* =================== */
in_channels=3;
if (gimp_drawable_has_alpha(input_drawable->id)==TRUE)
in_channels++;
if (interactive==TRUE)
{
/* Allocate memory for temp. images */
/* ================================ */
image=gdk_image_new(GDK_IMAGE_FASTEST,appwin->visinfo->visual,PREVIEW_WIDTH,PREVIEW_HEIGHT);
if (image==NULL)
return(FALSE);
numbytes=(glong)PREVIEW_WIDTH*(glong)PREVIEW_HEIGHT*3;
preview_rgb_data=(guchar *)malloc((size_t)numbytes);
if (preview_rgb_data==NULL)
return(FALSE);
memset(preview_rgb_data,0,numbytes);
/* Convert from raw RGB to GdkImage */
/* ================================ */
gck_rgb_to_gdkimage(appwin->visinfo,preview_rgb_data,image,PREVIEW_WIDTH,PREVIEW_HEIGHT);
}
return(TRUE);
}

View file

@ -0,0 +1,49 @@
#ifndef LIGHTINGIMAGEH
#define LIGHTINGIMAGEH
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <glib.h>
#include <gdk/gdk.h>
#include <gtk/gtk.h>
#include <gck/gck.h>
#include <libgimp/gimp.h>
#include "lighting_main.h"
extern GDrawable *input_drawable,*output_drawable;
extern GPixelRgn source_region, dest_region;
extern GDrawable *bump_drawable;
extern GPixelRgn bump_region;
extern GDrawable *env_drawable;
extern GPixelRgn env_region;
extern guchar *preview_rgb_data;
extern GdkImage *image;
extern glong maxcounter;
extern gint imgtype,width,height,env_width,env_height,in_channels,out_channels;
extern GckRGB background;
extern gint border_x1,border_y1,border_x2,border_y2;
extern guchar sinemap[256],spheremap[256],logmap[256];
guchar peek_map (GPixelRgn *region,gint x,gint y);
GckRGB peek (gint x,gint y);
GckRGB peek_env_map (gint x,gint y);
void poke (gint x,gint y,GckRGB *color);
gint check_bounds (gint x,gint y);
GckVector3 int_to_pos (gint x,gint y);
GckVector3 int_to_posf (gdouble x,gdouble y);
extern void pos_to_int (gdouble x,gdouble y,gint *scr_x,gint *scr_y);
extern void pos_to_float (gdouble x,gdouble y,gdouble *xf,gdouble *yf);
extern GckRGB get_image_color (gdouble u,gdouble v,gint *inside);
extern gdouble get_map_value (GPixelRgn *region, gdouble u,gdouble v, gint *inside);
extern gint image_setup (GDrawable *drawable,gint interactive);
#endif

View file

@ -0,0 +1,333 @@
/*********************************************************************************/
/* Lighting Effects 0.2.2 -- image filter plug-in for The Gimp program */
/* Copyright (C) 1996-98 Tom Bech */
/* Copyright (C) 1996-98 Federico Mena Quintero */
/*===============================================================================*/
/* E-mail: tomb@gimp.org (Tom) or quartic@gimp.org (Federico) */
/* You can contact the original The Gimp authors at gimp@xcf.berkeley.edu */
/*===============================================================================*/
/* This program is free software; you can redistribute it and/or modify it under */
/* the terms of the GNU General Public License as published by the Free Software */
/* Foundation; either version 2 of the License, or (at your option) any later */
/* version. */
/*===============================================================================*/
/* This program is distributed in the hope that it will be useful, but WITHOUT */
/* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS */
/* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.*/
/*===============================================================================*/
/* You should have received a copy of the GNU General Public License along with */
/* this program (read the "COPYING" file); if not, write to the Free Software */
/* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
/*===============================================================================*/
/* In other words, you can't sue us for whatever happens while using this ;) */
/*********************************************************************************/
#include "lighting_main.h"
/* Global variables */
/* ================ */
LightingValues mapvals;
/******************/
/* Implementation */
/******************/
void lighting_interactive (GDrawable *drawable);
void lighting_noninteractive (GDrawable *drawable);
/*************************************/
/* Set parameters to standard values */
/*************************************/
void set_default_settings(void)
{
gck_vector3_set(&mapvals.viewpoint, 0.5, 0.5, 0.25);
gck_vector3_set(&mapvals.planenormal, 0.0, 0.0, 1.0);
gck_vector3_set(&mapvals.lightsource.position, 1.0, 0.0, 1.0);
gck_vector3_set(&mapvals.lightsource.direction, -1.0, -1.0, 1.0);
gck_rgb_set(&mapvals.lightsource.color, 1.0, 1.0, 1.0);
mapvals.lightsource.intensity = 1.0;
mapvals.lightsource.type = POINT_LIGHT;
mapvals.material.ambient_int = 0.3;
mapvals.material.diffuse_int = 1.0;
mapvals.material.diffuse_ref = 0.4;
mapvals.material.specular_ref = 0.6;
mapvals.material.highlight = 27.0;
mapvals.pixel_treshold = 0.25;
mapvals.max_depth = 3.0;
mapvals.preview_zoom_factor = 1.0;
/* mapvals.bumptype=0; */
mapvals.bumpmaptype=0;
mapvals.bumpmin=0.0;
mapvals.bumpmax=0.1;
mapvals.antialiasing = FALSE;
mapvals.create_new_image = FALSE;
mapvals.transparent_background = FALSE;
mapvals.tooltips_enabled = FALSE;
mapvals.bump_mapped=FALSE;
mapvals.env_mapped=FALSE;
mapvals.ref_mapped=FALSE;
mapvals.previewquality=FALSE;
mapvals.bumpmap_id=-1;
mapvals.envmap_id=-1;
}
void check_drawables(void)
{
/* Check that envmap_id and bumpmap_id references legal images (are valid drawables) */
/* ================================================================================= */
if (mapvals.bumpmap_id!=-1 && gimp_drawable_image_id(mapvals.bumpmap_id)==-1)
{
mapvals.bump_mapped=FALSE;
mapvals.bumpmap_id=-1;
}
if (mapvals.envmap_id!=-1 && gimp_drawable_image_id(mapvals.envmap_id)==-1)
{
mapvals.env_mapped=FALSE;
mapvals.envmap_id=-1;
}
if (mapvals.bump_mapped)
{
/* Check if bump-map is grayscale and of the same size as the input drawable */
/* ========================================================================= */
if (!gimp_drawable_gray(mapvals.bumpmap_id) ||
gimp_drawable_width(mapvals.drawable_id)!=gimp_drawable_width(mapvals.bumpmap_id) ||
gimp_drawable_height(mapvals.drawable_id)!=gimp_drawable_height(mapvals.bumpmap_id))
{
/* If not then we silently disable bump mapping */
/* ============================================ */
mapvals.bump_mapped=FALSE;
mapvals.bumpmap_id=-1;
}
}
if (mapvals.env_mapped)
{
/* Check if env-map is grayscale or has alpha */
/* ========================================== */
if (gimp_drawable_gray(mapvals.envmap_id) ||
gimp_drawable_has_alpha(mapvals.envmap_id))
{
/* If it has then we silently disable env mapping */
/* ============================================== */
mapvals.bump_mapped=FALSE;
mapvals.bumpmap_id=-1;
}
}
}
MAIN();
static void query(void)
{
static GParamDef args[] =
{
{ PARAM_INT32, "run_mode", "Interactive (0), non-interactive (1)" },
{ PARAM_IMAGE, "image", "Input image" },
{ PARAM_DRAWABLE, "drawable", "Input drawable" },
{ PARAM_DRAWABLE, "bumpdrawable", "Bumpmap drawable (set to 0 if disabled)" },
{ PARAM_DRAWABLE, "envdrawable", "Environmentmap drawable (set to 0 if disabled)" },
{ PARAM_INT32, "dobumpmap", "Enable bumpmapping (TRUE/FALSE)" },
{ PARAM_INT32, "doenvmap", "Enable envmapping (TRUE/FALSE)" },
{ PARAM_INT32, "bumpmaptype", "Type of mapping (0=linear,1=log, 2=sinusoidal, 3=spherical)" },
{ PARAM_INT32, "lighttype", "Type of lightsource (0=point,1=directional,3=spot,4=none)" },
{ PARAM_COLOR, "lightcolor", "Lightsource color (r,g,b)" },
{ PARAM_FLOAT, "lightposition_x", "Lightsource position (x,y,z)" },
{ PARAM_FLOAT, "lightposition_y", "Lightsource position (x,y,z)" },
{ PARAM_FLOAT, "lightposition_z", "Lightsource position (x,y,z)" },
{ PARAM_FLOAT, "lightdirection_x", "Lightsource direction [x,y,z]" },
{ PARAM_FLOAT, "lightdirection_y", "Lightsource direction [x,y,z]" },
{ PARAM_FLOAT, "lightdirection_z", "Lightsource direction [x,y,z]" },
{ PARAM_FLOAT, "ambient_intensity", "Material ambient intensity (0..1)" },
{ PARAM_FLOAT, "diffuse_intensity", "Material diffuse intensity (0..1)" },
{ PARAM_FLOAT, "diffuse_reflectivity", "Material diffuse reflectivity (0..1)" },
{ PARAM_FLOAT, "specular_reflectivity", "Material specular reflectivity (0..1)" },
{ PARAM_FLOAT, "highlight", "Material highlight (0..->), note: it's expotential" },
{ PARAM_INT32, "antialiasing", "Apply antialiasing (TRUE/FALSE)" },
{ PARAM_INT32, "newimage", "Create a new image (TRUE/FALSE)" },
{ PARAM_INT32, "transparentbackground", "Make background transparent (TRUE/FALSE)" }
};
static GParamDef *return_vals = NULL;
static gint nargs = sizeof (args) / sizeof (args[0]);
static gint nreturn_vals = 0;
gimp_install_procedure ("plug_in_lighting",
"Apply various lighting effects to an image",
"No help yet",
"Tom Bech & Federico Mena Quintero",
"Tom Bech & Federico Mena Quintero",
"Version 0.2.0, March 15 1998",
"<Image>/Filters/Light Effects/Lighting Effects",
"RGB*",
PROC_PLUG_IN,
nargs, nreturn_vals,
args, return_vals);
}
static void run(gchar *name,
gint nparams,
GParam *param,
gint *nreturn_vals,
GParam **return_vals)
{
static GParam values[1];
GDrawable *drawable;
GRunModeType run_mode;
GStatusType status = STATUS_SUCCESS;
run_mode = param[0].data.d_int32;
*nreturn_vals = 1;
*return_vals = values;
values[0].type = PARAM_STATUS;
values[0].data.d_status = status;
/* Set default values */
/* ================== */
set_default_settings();
/* Possibly retrieve data */
/* ====================== */
gimp_get_data ("plug_in_lighting", &mapvals);
/* Get the specified drawable */
/* ========================== */
drawable = gimp_drawable_get (param[2].data.d_drawable);
mapvals.drawable_id=drawable->id;
check_drawables();
if (status == STATUS_SUCCESS)
{
/* Make sure that the drawable is RGBA or RGB color */
/* ================================================ */
if (gimp_drawable_color(drawable->id))
{
/* Set the tile cache size */
/* ======================= */
gimp_tile_cache_ntiles(TILE_CACHE_SIZE);
switch (run_mode)
{
case RUN_INTERACTIVE:
lighting_interactive(drawable);
gimp_set_data("plug_in_lighting", &mapvals, sizeof(LightingValues));
break;
case RUN_WITH_LAST_VALS:
image_setup(drawable,FALSE);
compute_image();
break;
case RUN_NONINTERACTIVE:
if (nparams != 24)
status = STATUS_CALLING_ERROR;
else if (status == STATUS_SUCCESS)
{
mapvals.bumpmap_id = param[3].data.d_drawable;
mapvals.envmap_id = param[4].data.d_drawable;
mapvals.bump_mapped = (gint)param[5].data.d_int32;
mapvals.env_mapped = (gint)param[6].data.d_int32;
mapvals.bumpmaptype = (gint)param[7].data.d_int32;
mapvals.lightsource.type = (LightType)param[8].data.d_int32;
mapvals.lightsource.color.r = param[9].data.d_color.red;
mapvals.lightsource.color.g = param[9].data.d_color.green;
mapvals.lightsource.color.b = param[9].data.d_color.blue;
mapvals.lightsource.position.x = param[10].data.d_float;
mapvals.lightsource.position.y = param[11].data.d_float;
mapvals.lightsource.position.z = param[12].data.d_float;
mapvals.lightsource.direction.x = param[13].data.d_float;
mapvals.lightsource.direction.y = param[14].data.d_float;
mapvals.lightsource.direction.z = param[15].data.d_float;
mapvals.material.ambient_int = param[16].data.d_float;
mapvals.material.diffuse_int = param[17].data.d_float;
mapvals.material.diffuse_ref = param[18].data.d_float;
mapvals.material.specular_ref = param[19].data.d_float;
mapvals.material.highlight = param[20].data.d_float;
mapvals.antialiasing = (gint)param[21].data.d_int32;
mapvals.create_new_image = (gint)param[22].data.d_int32;
mapvals.transparent_background = (gint)param[23].data.d_int32;
check_drawables();
image_setup(drawable, FALSE);
compute_image();
}
default:
break;
}
}
else
status = STATUS_EXECUTION_ERROR;
}
values[0].data.d_status = status;
gimp_drawable_detach (drawable);
}
GPlugInInfo PLUG_IN_INFO =
{
NULL, /* init_proc */
NULL, /* quit_proc */
query, /* query_proc */
run, /* run_proc */
};
void lighting_interactive(GDrawable *drawable)
{
gchar **argv;
gint argc;
argc = 1;
argv = g_new (gchar *, 1);
argv[0] = g_strdup ("lighting");
gdk_set_show_events(0);
gdk_set_use_xshm(gimp_use_xshm());
gtk_init (&argc, &argv);
gtk_rc_parse (gimp_gtkrc());
/* Create application window */
/* ========================= */
create_main_dialog();
/* Prepare images */
/* ============== */
image_setup(drawable,TRUE);
/* Gtk main event loop */
/* =================== */
gtk_main();
gdk_flush();
}
void lighting_noninteractive(GDrawable *drawable)
{
printf("Noninteractive not yet implemented! Sorry.\n");
}

View file

@ -0,0 +1,106 @@
#ifndef LIGHTINGMAINH
#define LIGHTINGMAINH
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <gdk/gdk.h>
#include <gtk/gtk.h>
#include <gck/gck.h>
#include <libgimp/gimp.h>
#include "lighting_ui.h"
#include "lighting_image.h"
#include "lighting_apply.h"
#include "lighting_preview.h"
/* Defines and stuff */
/* ================= */
#define TILE_CACHE_SIZE 16
/* Typedefs */
/* ======== */
typedef enum {
POINT_LIGHT,
DIRECTIONAL_LIGHT,
SPOT_LIGHT,
NO_LIGHT
} LightType;
enum {
IMAGE_BUMP,
WAVES_BUMP
};
typedef struct
{
gdouble ambient_int;
gdouble diffuse_int;
gdouble diffuse_ref;
gdouble specular_ref;
gdouble highlight;
GckRGB color;
} MaterialSettings;
typedef struct
{
LightType type;
GckVector3 position;
GckVector3 direction;
GckRGB color;
gdouble intensity;
} LightSettings;
typedef struct {
gint32 drawable_id;
gint32 bumpmap_id;
gint32 envmap_id;
/* Render variables */
/* ================ */
GckVector3 viewpoint;
GckVector3 planenormal;
LightSettings lightsource;
MaterialSettings material;
MaterialSettings ref_material;
gdouble pixel_treshold;
gdouble bumpmax,bumpmin;
/* gdouble wave_cx,wave_cy;
gdouble wave_lx,wave_ly;
gdouble wave_amp,wave_ph; */
gint max_depth;
gint bumpmaptype;
/* gint bumptype; */
/* Flags */
/* ===== */
gint antialiasing;
gint create_new_image;
gint transparent_background;
gint tooltips_enabled;
gint bump_mapped;
gint env_mapped;
gint ref_mapped;
gint bumpstretch;
gint previewquality;
/* Misc */
/* ==== */
gdouble preview_zoom_factor;
} LightingValues;
/* Externally visible variables */
/* ============================ */
extern LightingValues mapvals;
extern GckRGB background;
#endif

View file

@ -0,0 +1,26 @@
#ifndef LIGHTINGPIXMAPSH
#define LIGHTINGPIXMAPSH
#include "amb1.xpm"
#include "amb2.xpm"
#include "diffint1.xpm"
#include "diffint2.xpm"
#include "diffref1.xpm"
#include "diffref2.xpm"
#include "specref1.xpm"
#include "specref2.xpm"
#include "high1.xpm"
#include "high2.xpm"
extern char *amb1_xpm[];
extern char *amb2_xpm[];
extern char *diffint1_xpm[];
extern char *diffint2_xpm[];
extern char *diffref1_xpm[];
extern char *diffref2_xpm[];
extern char *specref1_xpm[];
extern char *specref2_xpm[];
extern char *high1_xpm[];
extern char *high2_xpm[];
#endif

View file

@ -0,0 +1,404 @@
/*************************************************/
/* Compute a preview image and preview wireframe */
/*************************************************/
#include "lighting_preview.h"
gint lightx,lighty;
BackBuffer backbuf={0,0,0,0,NULL};
gdouble *xpostab=NULL,*ypostab=NULL;
/* Protos */
/* ====== */
void draw_preview_image (gint recompute);
void update_light (gint xpos,gint ypos);
void draw_light_marker (gint xpos,gint ypos);
void clear_light_marker (void);
void compute_preview (gint startx,gint starty,gint w,gint h)
{
gint xcnt,ycnt,f1,f2;
gdouble imagex,imagey;
gint32 index=0;
GckRGB color,darkcheck,lightcheck,temp;
GckVector3 pos;
get_ray_func ray_func;
xpostab = (gdouble *)malloc(sizeof(gdouble)*w);
ypostab = (gdouble *)malloc(sizeof(gdouble)*h);
for (xcnt=0;xcnt<w;xcnt++)
xpostab[xcnt]=(gdouble)width*((gdouble)xcnt/(gdouble)w);
for (ycnt=0;ycnt<h;ycnt++)
ypostab[ycnt]=(gdouble)height*((gdouble)ycnt/(gdouble)h);
init_compute();
precompute_init(width,height);
gck_rgb_set(&lightcheck,0.75,0.75,0.75);
gck_rgb_set(&darkcheck, 0.50,0.50,0.50);
gck_rgb_set(&color,0.3,0.7,1.0);
if (mapvals.bump_mapped==TRUE && mapvals.bumpmap_id!=-1)
{
gimp_pixel_rgn_init (&bump_region, gimp_drawable_get(mapvals.bumpmap_id),
0, 0, width, height, FALSE, FALSE);
}
imagey=0;
if (mapvals.previewquality)
ray_func = get_ray_color;
else
ray_func = get_ray_color_no_bilinear;
if (mapvals.env_mapped==TRUE && mapvals.envmap_id!=-1)
{
env_width = gimp_drawable_width(mapvals.envmap_id);
env_height = gimp_drawable_height(mapvals.envmap_id);
gimp_pixel_rgn_init (&env_region, gimp_drawable_get(mapvals.envmap_id),
0, 0, env_width, env_height, FALSE, FALSE);
if (mapvals.previewquality)
ray_func = get_ray_color_ref;
else
ray_func = get_ray_color_no_bilinear_ref;
}
for (ycnt=0;ycnt<PREVIEW_HEIGHT;ycnt++)
{
for (xcnt=0;xcnt<PREVIEW_WIDTH;xcnt++)
{
if ((ycnt>=starty && ycnt<(starty+h)) &&
(xcnt>=startx && xcnt<(startx+w)))
{
imagex=xpostab[xcnt-startx];
imagey=ypostab[ycnt-starty];
pos=int_to_posf(imagex,imagey);
if (mapvals.bump_mapped==TRUE && mapvals.bumpmap_id!=-1 && xcnt==startx)
{
pos_to_float(pos.x,pos.y,&imagex,&imagey);
precompute_normals(0,width,(gint)(imagey+0.5));
}
color=(*ray_func)(&pos);
if (color.a<1.0)
{
f1=((xcnt % 32)<16);
f2=((ycnt % 32)<16);
f1=f1^f2;
if (f1)
{
if (color.a==0.0)
color=lightcheck;
else
{
gck_rgb_mul(&color,color.a);
temp=lightcheck;
gck_rgb_mul(&temp,1.0-color.a);
gck_rgb_add(&color,&temp);
}
}
else
{
if (color.a==0.0)
color=darkcheck;
else
{
gck_rgb_mul(&color,color.a);
temp=darkcheck;
gck_rgb_mul(&temp,1.0-color.a);
gck_rgb_add(&color,&temp);
}
}
}
preview_rgb_data[index++]=(guchar)(255.0*color.r);
preview_rgb_data[index++]=(guchar)(255.0*color.g);
preview_rgb_data[index++]=(guchar)(255.0*color.b);
imagex++;
}
else
{
preview_rgb_data[index++]=200;
preview_rgb_data[index++]=200;
preview_rgb_data[index++]=200;
}
}
}
gck_rgb_to_gdkimage(appwin->visinfo, preview_rgb_data, image, PREVIEW_WIDTH, PREVIEW_HEIGHT);
}
void blah()
{
/* First, compute the linear mapping (x,y,x+w,y+h) to (0,0,pw,ph) */
/* ============================================================== */
/* realw=(p2.x-p1.x);
realh=(p2.y-p1.y);
for (xcnt=0;xcnt<pw;xcnt++)
xpostab[xcnt]=p1.x+realw*((double)xcnt/(double)pw);
for (ycnt=0;ycnt<ph;ycnt++)
ypostab[ycnt]=p1.y+realh*((double)ycnt/(double)ph); */
/* Compute preview using the offset tables */
/* ======================================= */
/* if (mapvals.transparent_background==TRUE)
gck_rgba_set(&background,0.0,0.0,0.0,0.0);
else
{
gimp_palette_get_background(&r,&g,&b);
background.r=(gdouble)r/255.0;
background.g=(gdouble)g/255.0;
background.b=(gdouble)b/255.0;
background.a=1.0;
}
gck_rgb_set(&lightcheck,0.75,0.75,0.75);
gck_rgb_set(&darkcheck, 0.50,0.50,0.50);
gck_vector3_set(&p2,-1.0,-1.0,0.0);
for (ycnt=0;ycnt<ph;ycnt++)
{
for (xcnt=0;xcnt<pw;xcnt++)
{
p1.x=xpostab[xcnt];
p1.y=ypostab[ycnt]; */
/* If oldpos = newpos => same color, so skip shading */
/* ================================================= */
/* p2=p1;
color=get_ray_color(&p1);
if (color.a<1.0)
{
f1=((xcnt % 32)<16);
f2=((ycnt % 32)<16);
f1=f1^f2;
if (f1)
{
if (color.a==0.0)
color=lightcheck;
else
{
gck_rgb_mul(&color,color.a);
temp=lightcheck;
gck_rgb_mul(&temp,1.0-color.a);
gck_rgb_add(&color,&temp);
}
}
else
{
if (color.a==0.0)
color=darkcheck;
else
{
gck_rgb_mul(&color,color.a);
temp=darkcheck;
gck_rgb_mul(&temp,1.0-color.a);
gck_rgb_add(&color,&temp);
}
}
}
preview_rgb_data[index++]=(guchar)(color.r*255.0);
preview_rgb_data[index++]=(guchar)(color.g*255.0);
preview_rgb_data[index++]=(guchar)(color.b*255.0);
}
} */
/* Convert to visual type */
/* ====================== */
/* gck_rgb_to_gdkimage(appwin->visinfo,preview_rgb_data,image,pw,ph); */
}
/*************************************************/
/* Check if the given position is within the */
/* light marker. Return TRUE if so, FALSE if not */
/*************************************************/
gint check_light_hit(gint xpos,gint ypos)
{
/* gdouble dx,dy,r;
if (mapvals.lightsource.type==POINT_LIGHT)
{
dx=(gdouble)lightx-xpos;
dy=(gdouble)lighty-ypos;
r=sqrt(dx*dx+dy*dy)+0.5;
if ((gint)r>7)
return(FALSE);
else
return(TRUE);
}
*/
return(FALSE);
}
/****************************************/
/* Draw a marker to show light position */
/****************************************/
void draw_light_marker(gint xpos,gint ypos)
{
/* gck_gc_set_foreground(appwin->visinfo,gc,0,50,255);
gck_gc_set_background(appwin->visinfo,gc,0,0,0);
gdk_gc_set_function(gc,GDK_COPY);
if (mapvals.lightsource.type==POINT_LIGHT)
{
lightx=xpos;
lighty=ypos; */
/* Save background */
/* =============== */
/* backbuf.x=lightx-7;
backbuf.y=lighty-7;
backbuf.w=14;
backbuf.h=14; */
/* X doesn't like images that's outside a window, make sure */
/* we get the backbuffer image from within the boundaries */
/* ======================================================== */
/* if (backbuf.x<0)
backbuf.x=0;
else if ((backbuf.x+backbuf.w)>PREVIEW_WIDTH)
backbuf.w=(PREVIEW_WIDTH-backbuf.x);
if (backbuf.y<0)
backbuf.y=0;
else if ((backbuf.y+backbuf.h)>PREVIEW_HEIGHT)
backbuf.h=(PREVIEW_WIDTH-backbuf.y);
backbuf.image=gdk_image_get(previewarea->window,backbuf.x,backbuf.y,backbuf.w,backbuf.h);
gdk_draw_arc(previewarea->window,gc,TRUE,lightx-7,lighty-7,14,14,0,360*64);
} */
}
void clear_light_marker(void)
{
/* Restore background if it has been saved */
/* ======================================= */
/* if (backbuf.image!=NULL)
{
gck_gc_set_foreground(appwin->visinfo,gc,255,255,255);
gck_gc_set_background(appwin->visinfo,gc,0,0,0);
gdk_gc_set_function(gc,GDK_COPY);
gdk_draw_image(previewarea->window,gc,backbuf.image,0,0,backbuf.x,backbuf.y,
backbuf.w,backbuf.h);
gdk_image_destroy(backbuf.image);
backbuf.image=NULL;
} */
}
void draw_lights(void)
{
/* gdouble dxpos,dypos;
gint xpos,ypos;
clear_light_marker();
gck_3d_to_2d(startx,starty,pw,ph,&dxpos,&dypos,&mapvals.viewpoint,
&mapvals.lightsource.position);
xpos=(gint)(dxpos+0.5);
ypos=(gint)(dypos+0.5);
if (xpos>=0 && xpos<=PREVIEW_WIDTH && ypos>=0 && ypos<=PREVIEW_HEIGHT)
draw_light_marker(xpos,ypos); */
}
/*************************************************/
/* Update light position given new screen coords */
/*************************************************/
void update_light(gint xpos,gint ypos)
{
/* gint startx,starty,pw,ph;
pw=PREVIEW_WIDTH >> mapvals.preview_zoom_factor;
ph=PREVIEW_HEIGHT >> mapvals.preview_zoom_factor;
startx=(PREVIEW_WIDTH-pw)>>1;
starty=(PREVIEW_HEIGHT-ph)>>1;
gck_2d_to_3d(startx,starty,pw,ph,xpos,ypos,&mapvals.viewpoint,
&mapvals.lightsource.position);
draw_lights(startx,starty,pw,ph); */
}
void compute_preview_rectangle(gint *xp,gint *yp,gint *wid,gint *heig)
{
gdouble x,y,w,h;
if (width>=height)
{
w=(PREVIEW_WIDTH-50.0);
h=(gdouble)height*(w/(gdouble)width);
x=(PREVIEW_WIDTH-w)/2.0;
y=(PREVIEW_HEIGHT-h)/2.0;
}
else
{
h=(PREVIEW_HEIGHT-50.0);
w=(gdouble)width*(h/(gdouble)height);
x=(PREVIEW_WIDTH-w)/2.0;
y=(PREVIEW_HEIGHT-h)/2.0;
}
*xp=(gint)(x+0.5);
*yp=(gint)(y+0.5);
*wid=(gint)(w+0.5);
*heig=(gint)(h+0.5);
}
/******************************************************************/
/* Draw preview image. if DoCompute is TRUE then recompute image. */
/******************************************************************/
void draw_preview_image(gint recompute)
{
gint startx,starty,pw,ph;
gck_gc_set_foreground(appwin->visinfo,gc,255,255,255);
gck_gc_set_background(appwin->visinfo,gc,0,0,0);
gdk_gc_set_function(gc,GDK_COPY);
compute_preview_rectangle(&startx,&starty,&pw,&ph);
if (recompute==TRUE)
{
gck_cursor_set(previewarea->window,GDK_WATCH);
compute_preview(startx,starty,pw,ph);
gck_cursor_set(previewarea->window,GDK_HAND2);
clear_light_marker();
}
/* if (pw!=PREVIEW_WIDTH)
gdk_window_clear(previewarea->window); */
gdk_draw_image(previewarea->window,gc,image,0,0,0,0,PREVIEW_WIDTH,PREVIEW_HEIGHT);
/* draw_lights(); */
}

View file

@ -0,0 +1,41 @@
#ifndef LIGHTINGPREVIEWH
#define LIGHTINGPREVIEWH
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <gdk/gdk.h>
#include <gtk/gtk.h>
#include <gck/gck.h>
#include <libgimp/gimp.h>
#include "lighting_main.h"
#include "lighting_ui.h"
#include "lighting_image.h"
#include "lighting_apply.h"
#include "lighting_shade.h"
#define PREVIEW_WIDTH 300
#define PREVIEW_HEIGHT 300
typedef struct
{
gint x,y,w,h;
GdkImage *image;
} BackBuffer;
/* Externally visible variables */
/* ============================ */
extern gint lightx,lighty;
extern BackBuffer backbuf;
extern gdouble *xpostab,*ypostab;
/* Externally visible functions */
/* ============================ */
extern void draw_preview_image (gint recompute);
extern gint check_light_hit (gint xpos,gint ypos);
extern void update_light (gint xpos,gint ypos);
#endif

View file

@ -0,0 +1,634 @@
/*****************/
/* Shading stuff */
/*****************/
#include "lighting_shade.h"
GckVector3 *triangle_normals[2] = { NULL, NULL };
GckVector3 *vertex_normals[3] = { NULL, NULL, NULL };
gdouble *heights[3] = { NULL, NULL, NULL };
gdouble xstep,ystep;
guchar *bumprow=NULL;
gint pre_w=-1;
gint pre_h=-1;
/*****************/
/* Phong shading */
/*****************/
GckRGB phong_shade(GckVector3 *position,GckVector3 *viewpoint,
GckVector3 *normal,GckVector3 *lightposition,
GckRGB *diff_col,GckRGB *spec_col,
LightType light_type)
{
GckRGB ambient_color,diffuse_color,specular_color;
gdouble nl,rv,dist;
GckVector3 l,nn,v,n;
/* Compute ambient intensity */
/* ========================= */
n=*normal;
ambient_color=*diff_col;
gck_rgb_mul(&ambient_color,mapvals.material.ambient_int);
/* Compute (N*L) term of Phong's equation */
/* ====================================== */
if (light_type==POINT_LIGHT)
gck_vector3_sub(&l,lightposition,position);
else
l=*lightposition;
dist=gck_vector3_length(&l);
if (dist!=0.0)
gck_vector3_mul(&l,1.0/dist);
nl=2.0*gck_vector3_inner_product(&n,&l);
if (nl>=0.0)
{
/* Compute (R*V)^alpha term of Phong's equation */
/* ============================================ */
gck_vector3_sub(&v,viewpoint,position);
gck_vector3_normalize(&v);
gck_vector3_mul(&n,nl);
gck_vector3_sub(&nn,&n,&l);
rv=gck_vector3_inner_product(&nn,&v);
rv=pow(rv,mapvals.material.highlight);
/* Compute diffuse and specular intensity contribution */
/* =================================================== */
diffuse_color=*diff_col;
gck_rgb_mul(&diffuse_color,mapvals.material.diffuse_ref);
gck_rgb_mul(&diffuse_color,nl);
specular_color=*spec_col;
gck_rgb_mul(&specular_color,mapvals.material.specular_ref);
gck_rgb_mul(&specular_color,rv);
gck_rgb_add(&diffuse_color,&specular_color);
gck_rgb_mul(&diffuse_color,mapvals.material.diffuse_int);
gck_rgb_clamp(&diffuse_color);
gck_rgb_add(&ambient_color,&diffuse_color);
}
gck_rgb_clamp(&ambient_color);
return(ambient_color);
}
void get_normal(gdouble xf,gdouble yf,GckVector3 *normal)
{
GckVector3 v1,v2,n;
gint numvecs=0,x,y,f;
gdouble val,val1=-1.0,val2=-1.0,val3=-1.0,val4=-1.0, xstep,ystep;
x=(gint)(xf+0.5);
y=(gint)(yf+0.5);
xstep=1.0/(gdouble)width;
ystep=1.0/(gdouble)height;
val=mapvals.bumpmax*get_map_value(&bump_region, xf,yf, &f)/255.0;
if (check_bounds(x-1,y)) val1=mapvals.bumpmax*get_map_value(&bump_region, xf-1.0,yf, &f)/255.0 - val;
if (check_bounds(x,y-1)) val2=mapvals.bumpmax*get_map_value(&bump_region, xf,yf-1.0, &f)/255.0 - val;
if (check_bounds(x+1,y)) val3=mapvals.bumpmax*get_map_value(&bump_region, xf+1.0,yf, &f)/255.0 - val;
if (check_bounds(x,y+1)) val4=mapvals.bumpmax*get_map_value(&bump_region, xf,yf+1.0, &f)/255.0 - val;
gck_vector3_set(normal, 0.0,0.0,0.0);
if (val1!=-1.0 && val4!=-1.0)
{
v1.x=-xstep; v1.y=0.0; v1.z=val1;
v2.x=0.0; v2.y=ystep; v2.z=val4;
n=gck_vector3_cross_product(&v1,&v2);
gck_vector3_normalize(&n);
if (n.z<0.0)
n.z=-n.z;
gck_vector3_add(normal,normal,&n);
numvecs++;
}
if (val1!=-1.0 && val2!=-1.0)
{
v1.x=-xstep; v1.y=0.0; v1.z=val1;
v2.x=0.0; v2.y=-ystep; v2.z=val2;
n=gck_vector3_cross_product(&v1,&v2);
gck_vector3_normalize(&n);
if (n.z<0.0)
n.z=-n.z;
gck_vector3_add(normal,normal,&n);
numvecs++;
}
if (val2!=-1.0 && val3!=-1.0)
{
v1.x=0.0; v1.y=-ystep; v1.z=val2;
v2.x=xstep; v2.y=0.0; v2.z=val3;
n=gck_vector3_cross_product(&v1,&v2);
gck_vector3_normalize(&n);
if (n.z<0.0)
n.z=-n.z;
gck_vector3_add(normal,normal,&n);
numvecs++;
}
if (val3!=-1.0 && val4!=-1.0)
{
v1.x=xstep; v1.y=0.0; v1.z=val3;
v2.x=0.0; v2.y=ystep; v2.z=val4;
n=gck_vector3_cross_product(&v1,&v2);
gck_vector3_normalize(&n);
if (n.z<0.0)
n.z=-n.z;
gck_vector3_add(normal,normal,&n);
numvecs++;
}
gck_vector3_mul(normal,1.0/(gdouble)numvecs);
gck_vector3_normalize(normal);
}
void precompute_init(gint w,gint h)
{
gint n;
xstep=1.0/(gdouble)width;
ystep=1.0/(gdouble)height;
pre_w=w;
pre_h=h;
for (n=0;n<3;n++)
{
if (vertex_normals[n]!=NULL)
free(vertex_normals[n]);
if (heights[n]!=NULL)
free(heights[n]);
heights[n]=(gdouble *)malloc(sizeof(gdouble)*(size_t)w);
vertex_normals[n]=(GckVector3 *)malloc(sizeof(GckVector3)*(size_t)w);
}
for (n=0;n<2;n++)
if (triangle_normals[n]!=NULL)
free(triangle_normals[n]);
if (bumprow!=NULL)
{
free(bumprow);
bumprow=NULL;
}
bumprow=(guchar *)malloc(sizeof(guchar)*(size_t)w);
triangle_normals[0]=(GckVector3 *)malloc(sizeof(GckVector3)*(size_t)((w<<1)+2));
triangle_normals[1]=(GckVector3 *)malloc(sizeof(GckVector3)*(size_t)((w<<1)+2));
for (n=0;n<(w<<1)+1;n++)
{
gck_vector3_set(&triangle_normals[0][n],0.0,0.0,1.0);
gck_vector3_set(&triangle_normals[1][n],0.0,0.0,1.0);
}
for (n=0;n<w;n++)
{
gck_vector3_set(&vertex_normals[0][n],0.0,0.0,1.0);
gck_vector3_set(&vertex_normals[1][n],0.0,0.0,1.0);
gck_vector3_set(&vertex_normals[2][n],0.0,0.0,1.0);
heights[0][n]=0.0;
heights[1][n]=0.0;
heights[2][n]=0.0;
}
}
/********************************************/
/* Compute triangle and then vertex normals */
/********************************************/
void precompute_normals(gint x1,gint x2,gint y)
{
GckVector3 *tmpv,p1,p2,p3,normal;
gdouble *tmpd;
gint n,i,nv;
guchar *map=NULL;
/* First, compute the heights */
/* ========================== */
tmpv=triangle_normals[0];
triangle_normals[0]=triangle_normals[1];
triangle_normals[1]=tmpv;
tmpv=vertex_normals[0];
vertex_normals[0]=vertex_normals[1];
vertex_normals[1]=vertex_normals[2];
vertex_normals[2]=tmpv;
tmpd=heights[0];
heights[0]=heights[1];
heights[1]=heights[2];
heights[2]=tmpd;
/* printf("Get row (%d,%d,%d) to %p\n",x1,y,x2-x1,bumprow); */
gimp_pixel_rgn_get_row(&bump_region,bumprow,x1,y,x2-x1);
if (mapvals.bumpmaptype>0)
{
switch (mapvals.bumpmaptype)
{
case 1:
map=logmap;
break;
case 2:
map=sinemap;
break;
default:
map=spheremap;
break;
}
for (n=0;n<(x2-x1);n++)
heights[2][n]=(gdouble)mapvals.bumpmax*(gdouble)map[bumprow[n]]/255.0;
}
else for (n=0;n<(x2-x1);n++)
heights[2][n]=(gdouble)mapvals.bumpmax*(gdouble)bumprow[n]/255.0;
/* Compute triangle normals */
/* ======================== */
i=0;
for (n=0;n<(x2-x1-1);n++)
{
p1.x=0.0;
p1.y=ystep;
p1.z=heights[2][n]-heights[1][n];
p2.x=xstep;
p2.y=ystep;
p2.z=heights[2][n+1]-heights[1][n];
p3.x=xstep;
p3.y=0.0;
p3.z=heights[1][n+1]-heights[1][n];
triangle_normals[1][i]=gck_vector3_cross_product(&p2,&p1);
triangle_normals[1][i+1]=gck_vector3_cross_product(&p3,&p2);
gck_vector3_normalize(&triangle_normals[1][i]);
gck_vector3_normalize(&triangle_normals[1][i+1]);
i+=2;
}
/* Compute vertex normals */
/* ====================== */
i=0;
gck_vector3_set(&normal, 0.0,0.0,0.0);
for (n=0;n<(x2-x1-1);n++)
{
nv=0;
if (n>0)
{
if (y>0)
{
gck_vector3_add(&normal, &normal, &triangle_normals[0][i-1]);
gck_vector3_add(&normal, &normal, &triangle_normals[0][i-2]);
nv+=2;
}
if (y<pre_h)
{
gck_vector3_add(&normal, &normal, &triangle_normals[1][i-1]);
nv++;
}
}
if (n<pre_w)
{
if (y>0)
{
gck_vector3_add(&normal, &normal, &triangle_normals[0][i]);
gck_vector3_add(&normal, &normal, &triangle_normals[0][i+1]);
nv+=2;
}
if (y<pre_h)
{
gck_vector3_add(&normal, &normal, &triangle_normals[1][i]);
gck_vector3_add(&normal, &normal, &triangle_normals[1][i+1]);
nv+=2;
}
}
gck_vector3_mul(&normal, 1.0/(gdouble)nv);
gck_vector3_normalize(&normal);
vertex_normals[1][n]=normal;
i+=2;
}
}
/***********************************************************************/
/* Compute the reflected ray given the normalized normal and ins. vec. */
/***********************************************************************/
GckVector3 compute_reflected_ray(GckVector3 *normal,GckVector3 *view)
{
GckVector3 ref;
gdouble nl;
nl = 2.0*gck_vector3_inner_product(normal,view);
ref = *normal;
gck_vector3_mul(&ref,nl);
gck_vector3_sub(&ref,&ref,view);
return(ref);
}
/************************************************************************/
/* Given the NorthPole, Equator and a third vector (normal) compute */
/* the conversion from spherical coordinates to image space coordinates */
/************************************************************************/
void sphere_to_image(GckVector3 *normal,gdouble *u,gdouble *v)
{
static gdouble alpha,fac;
static GckVector3 cross_prod;
static GckVector3 firstaxis = { 1.0, 0.0, 0.0 };
static GckVector3 secondaxis = { 0.0, 1.0, 0.0 };
alpha=acos(-gck_vector3_inner_product(&secondaxis,normal));
*v=alpha/M_PI;
if (*v==0.0 || *v==1.0) *u=0.0;
else
{
fac=gck_vector3_inner_product(&firstaxis,normal)/sin(alpha);
/* Make sure that we map to -1.0..1.0 (take care of rounding errors) */
/* ================================================================= */
if (fac>1.0)
fac=1.0;
else if (fac<-1.0)
fac=-1.0;
*u=acos(fac)/(2.0*M_PI);
cross_prod=gck_vector3_cross_product(&secondaxis,&firstaxis);
if (gck_vector3_inner_product(&cross_prod,normal)<0.0)
*u=1.0-*u;
}
}
/*********************************************************************/
/* These routines computes the color of the surface at a given point */
/*********************************************************************/
GckRGB get_ray_color(GckVector3 *position)
{
GckRGB color;
gint x,f;
gdouble xf,yf;
GckVector3 normal,*p;
pos_to_float(position->x,position->y,&xf,&yf);
x = (gint)(xf+0.5);
if (mapvals.transparent_background && heights[1][x]==0)
color.a=0.0;
else
{
color=get_image_color(xf,yf,&f);
if (mapvals.lightsource.type==POINT_LIGHT)
p=&mapvals.lightsource.position;
else
p=&mapvals.lightsource.direction;
if (mapvals.bump_mapped==FALSE || mapvals.bumpmap_id==-1)
color=phong_shade(position,
&mapvals.viewpoint,
&mapvals.planenormal,
p,
&color,
&mapvals.lightsource.color,
mapvals.lightsource.type);
else
{
normal=vertex_normals[1][(gint)(xf+0.5)];
color=phong_shade(position,
&mapvals.viewpoint,
&normal,
p,
&color,
&mapvals.lightsource.color,
mapvals.lightsource.type);
}
}
return(color);
}
GckRGB get_ray_color_ref(GckVector3 *position)
{
GckRGB color,env_color;
gint x,f;
gdouble xf,yf;
GckVector3 normal,*p,v,r;
pos_to_float(position->x,position->y,&xf,&yf);
x = (gint)(xf+0.5);
if (mapvals.transparent_background && heights[1][x]==0)
color.a=0.0;
else
{
color=get_image_color(xf,yf,&f);
if (mapvals.lightsource.type==POINT_LIGHT)
p=&mapvals.lightsource.position;
else
p=&mapvals.lightsource.direction;
if (mapvals.bump_mapped==FALSE || mapvals.bumpmap_id==-1)
color=phong_shade(position,
&mapvals.viewpoint,
&mapvals.planenormal,
p,
&color,
&mapvals.lightsource.color,
mapvals.lightsource.type);
else
{
normal=vertex_normals[1][(gint)(xf+0.5)];
gck_vector3_sub(&v,&mapvals.viewpoint,position);
gck_vector3_normalize(&v);
r = compute_reflected_ray(&normal,&v);
/* Get color in the direction of r */
/* =============================== */
sphere_to_image(&r,&xf,&yf);
env_color = peek_env_map((gint)(env_width*xf+0.5),(gint)(env_height*yf+0.5));
color=phong_shade(position,
&mapvals.viewpoint,
&normal,
p,
&env_color,
&mapvals.lightsource.color,
mapvals.lightsource.type);
}
}
return(color);
}
GckRGB get_ray_color_no_bilinear(GckVector3 *position)
{
GckRGB color;
gint x;
gdouble xf,yf;
GckVector3 normal,*p;
pos_to_float(position->x,position->y,&xf,&yf);
x = (gint)(xf+0.5);
if (mapvals.transparent_background && heights[1][x]==0)
color.a=0.0;
else
{
color=peek(x,(gint)(yf+0.5));
if (mapvals.lightsource.type==POINT_LIGHT)
p=&mapvals.lightsource.position;
else
p=&mapvals.lightsource.direction;
if (mapvals.bump_mapped==FALSE || mapvals.bumpmap_id==-1)
color=phong_shade(position,
&mapvals.viewpoint,
&mapvals.planenormal,
p,
&color,
&mapvals.lightsource.color,
mapvals.lightsource.type);
else
{
normal=vertex_normals[1][x];
color=phong_shade(position,
&mapvals.viewpoint,
&normal,
p,
&color,
&mapvals.lightsource.color,
mapvals.lightsource.type);
}
}
return(color);
}
GckRGB get_ray_color_no_bilinear_ref(GckVector3 *position)
{
GckRGB color,env_color;
gint x;
gdouble xf,yf;
GckVector3 normal,*p,v,r;
pos_to_float(position->x,position->y,&xf,&yf);
x = (gint)(xf+0.5);
if (mapvals.transparent_background && heights[1][x]==0)
color.a=0.0;
else
{
color=peek((gint)(xf+0.5),(gint)(yf+0.5));
if (mapvals.lightsource.type==POINT_LIGHT)
p=&mapvals.lightsource.position;
else
p=&mapvals.lightsource.direction;
if (mapvals.bump_mapped==FALSE || mapvals.bumpmap_id==-1)
{
pos_to_float(position->x,position->y,&xf,&yf);
color=peek((gint)(xf+0.5),(gint)(yf+0.5));
gck_vector3_sub(&v,&mapvals.viewpoint,position);
gck_vector3_normalize(&v);
r = compute_reflected_ray(&mapvals.planenormal,&v);
/* Get color in the direction of r */
/* =============================== */
sphere_to_image(&r,&xf,&yf);
env_color = peek_env_map((gint)(env_width*xf+0.5),(gint)(env_height*yf+0.5));
color=phong_shade(position,
&mapvals.viewpoint,
&mapvals.planenormal,
p,
&env_color,
&mapvals.lightsource.color,
mapvals.lightsource.type);
}
else
{
normal=vertex_normals[1][(gint)(xf+0.5)];
pos_to_float(position->x,position->y,&xf,&yf);
color=peek((gint)(xf+0.5),(gint)(yf+0.5));
gck_vector3_sub(&v,&mapvals.viewpoint,position);
gck_vector3_normalize(&v);
r = compute_reflected_ray(&normal,&v);
/* Get color in the direction of r */
/* =============================== */
sphere_to_image(&r,&xf,&yf);
env_color = peek_env_map((gint)(env_width*xf+0.5),(gint)(env_height*yf+0.5));
color=phong_shade(position,
&mapvals.viewpoint,
&normal,
p,
&env_color,
&mapvals.lightsource.color,
mapvals.lightsource.type);
}
}
return(color);
}

View file

@ -0,0 +1,23 @@
#ifndef LIGHTINGSHADEH
#define LIGHTINGSHADEH
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <gdk/gdk.h>
#include <gck/gck.h>
#include "lighting_main.h"
#include "lighting_image.h"
typedef GckRGB (*get_ray_func) (GckVector3 *);
extern GckRGB get_ray_color (GckVector3 *position);
extern GckRGB get_ray_color_no_bilinear (GckVector3 *position);
extern GckRGB get_ray_color_ref (GckVector3 *position);
extern GckRGB get_ray_color_no_bilinear_ref (GckVector3 *position);
extern void precompute_init (gint w,gint h);
extern void precompute_normals (gint x1,gint x2,gint y);
#endif

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,31 @@
#ifndef LIGHTINGUIH
#define LIGHTINGUIH
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <gdk/gdk.h>
#include <gtk/gtk.h>
#include <gck/gck.h>
#include <libgimp/gimp.h>
#include <libgimp/gimpmenu.h>
#include "lighting_main.h"
#include "lighting_image.h"
#include "lighting_apply.h"
#include "lighting_preview.h"
/* Externally visible variables */
/* ============================ */
extern GckApplicationWindow *appwin;
extern GdkGC *gc;
extern GtkWidget *previewarea;
/* Externally visible functions */
/* ============================ */
extern void create_main_dialog (void);
#endif

View file

@ -0,0 +1,75 @@
/* XPM */
char * specref1_xpm[] = {
"32 32 40 1",
" c None",
". c #A699A699A699",
"X c #A699A289A699",
"o c #965896589658",
"O c #BEFBBEFBBEFB",
"+ c #CF3CCB2BCF3C",
"@ c #C71BC71BC71B",
"# c #C71BC30BC71B",
"$ c #B6DAB6DAB6DA",
"% c #8E388E388E38",
"& c #69A669A669A6",
"* c #D75CD75CD75C",
"= c #DF7DDB6CDF7D",
"- c #CF3CCF3CCF3C",
"; c #965892489658",
": c #DF7DDF7DDF7D",
"> c #E79DE38DE79D",
", c #D75CD34CD75C",
"< c #AEBAAEBAAEBA",
"1 c #9E799E799E79",
"2 c #861786178617",
"3 c #596559655965",
"4 c #E79DE79DE79D",
"5 c #B6DAB2CAB6DA",
"6 c #71C671C671C6",
"7 c #492449244924",
"8 c #71C675D671C6",
"9 c #514455555144",
"0 c #BEFBBAEABEFB",
"q c #AEBAAAAAAEBA",
"w c #9E799A699E79",
"e c #8E388A288E38",
"r c #49244D344924",
"t c #861782078617",
"y c #69A66DB669A6",
"u c #79E779E779E7",
"i c #618565956185",
"p c #514451445144",
"a c #618561856185",
"s c #410345144103",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" .Xo ",
" .O+@#$.%& ",
" $*==*-#$.;& ",
" $=:>:=,+O<123 ",
" .*:>4>=*+O5X%67 ",
" O=>4>>=,+O5X%89 ",
" +=:>>:*-@0<1%83 ",
" .@*===*,+#$qwe83r ",
" X#-,*,-+#0<Xoty9r ",
" o$#+++@#05.weuipr ",
" .$OOO0$<.1%ty3r ",
" %.<55<qXw%t8ap7 ",
" &;1XX1woet8iprs ",
" &2%%%etuyaprs ",
" 36888yi3prs ",
" 79339pr7s ",
" rrr ",
" ",
" ",
" ",
" ",
" ",
" ",
" "};

View file

@ -0,0 +1,79 @@
/* XPM */
char * specref2_xpm[] = {
"32 32 44 1",
" c None",
". c #A699A699A699",
"X c #A699A289A699",
"o c #965896589658",
"O c #BEFBBEFBBEFB",
"+ c #CF3CCB2BCF3C",
"@ c #C71BC71BC71B",
"# c #C71BC30BC71B",
"$ c #B6DAB6DAB6DA",
"% c #8E388E388E38",
"& c #69A669A669A6",
"* c #D75CD75CD75C",
"= c #DF7DDB6CDF7D",
"- c #CF3CCF3CCF3C",
"; c #965892489658",
": c #DF7DDF7DDF7D",
"> c #E79DE38DE79D",
", c #D75CD34CD75C",
"< c #AEBAAEBAAEBA",
"1 c #9E799E799E79",
"2 c #861786178617",
"3 c #596559655965",
"4 c #E79DE79DE79D",
"5 c #EFBEEFBEEFBE",
"6 c #B6DAB2CAB6DA",
"7 c #71C671C671C6",
"8 c #492449244924",
"9 c #FFFFFBEEFFFF",
"0 c #FFFFFFFFFFFF",
"q c #71C675D671C6",
"w c #514455555144",
"e c #EFBEEBADEFBE",
"r c #BEFBBAEABEFB",
"t c #AEBAAAAAAEBA",
"y c #9E799A699E79",
"u c #8E388A288E38",
"i c #49244D344924",
"p c #861782078617",
"a c #69A66DB669A6",
"s c #79E779E779E7",
"d c #618565956185",
"f c #514451445144",
"g c #618561856185",
"h c #410345144103",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" .Xo ",
" .O+@#$.%& ",
" $*==*-#$.;& ",
" $=:>:=,+O<123 ",
" .*:4454*+O6X%78 ",
" O=>4900>+O6X%qw ",
" +=:5000e+r<1%q3 ",
" .@*=4009=#$tyuq3i ",
" X#-,*>e=@r<Xopawi ",
" o$#++++#r6.yusdfi ",
" .$OOOr$<.1%pa3i ",
" %.<66<tXy%pqgf8 ",
" &;1XX1youpqdfih ",
" &2%%%upsagfih ",
" 37qqqad3fih ",
" 8w33wfi8h ",
" iii ",
" ",
" ",
" ",
" ",
" ",
" ",
" "};