Revision: 44795
http://brlcad.svn.sourceforge.net/brlcad/?rev=44795&view=rev
Author: kunigami
Date: 2011-06-07 13:13:53 +0000 (Tue, 07 Jun 2011)
Log Message:
-----------
This is my first commit. It adds a ols shader as well as a osl-renderer which
by now just sets a color
Modified Paths:
--------------
brlcad/trunk/include/CMakeLists.txt
brlcad/trunk/src/liboptical/CMakeLists.txt
brlcad/trunk/src/liboptical/init.c
Added Paths:
-----------
brlcad/trunk/include/osl-renderer.h
brlcad/trunk/src/liboptical/osl-renderer.c
brlcad/trunk/src/liboptical/sh_osl.c
Modified: brlcad/trunk/include/CMakeLists.txt
===================================================================
--- brlcad/trunk/include/CMakeLists.txt 2011-06-07 12:06:28 UTC (rev 44794)
+++ brlcad/trunk/include/CMakeLists.txt 2011-06-07 13:13:53 UTC (rev 44795)
@@ -71,6 +71,12 @@
wdb.h
)
+# Just add the osl-renderer.h if we are going to enable OSL
+IF(BRLCAD-ENABLE_OSL)
+ SET(brlcadinclude_wanted ${brlcadinclude_wanted} osl-renderer.h)
+ENDIF(BRLCAD-ENABLE_OSL)
+
+
# headers used by multiple packages but still considered private.
# public headers should NOT include these headers.
SET(brlcadnoinst_HEADERS
Added: brlcad/trunk/include/osl-renderer.h
===================================================================
--- brlcad/trunk/include/osl-renderer.h (rev 0)
+++ brlcad/trunk/include/osl-renderer.h 2011-06-07 13:13:53 UTC (rev 44795)
@@ -0,0 +1,8 @@
+#ifndef OSL_RENDERER_H
+#define OSL_RENDERER_H
+
+#include "vmath.h"
+
+int Renderer(point_t *b);
+
+#endif
Property changes on: brlcad/trunk/include/osl-renderer.h
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:eol-style
+ native
Modified: brlcad/trunk/src/liboptical/CMakeLists.txt
===================================================================
--- brlcad/trunk/src/liboptical/CMakeLists.txt 2011-06-07 12:06:28 UTC (rev
44794)
+++ brlcad/trunk/src/liboptical/CMakeLists.txt 2011-06-07 13:13:53 UTC (rev
44795)
@@ -1,4 +1,5 @@
set(LIBOPTICAL_SOURCES
+
init.c
material.c
photonmap.c
@@ -44,7 +45,52 @@
${TCL_INCLUDE_DIRS}
)
-BRLCAD_ADDLIB(liboptical "${LIBOPTICAL_SOURCES}" "librt libbn libbu")
+IF(BRLCAD-ENABLE_OSL)
+
+ message("[Kunigami] OSL was enabled. Will compile shader OSL...")
+
+ ##########################################
+ # Build OSL-renderer
+ ##########################################
+
+ # Find dependencies (TODO: build this altogether)
+ include(FindOSL)
+
+ # NOTE(boulos): Boost can only detect that you've disabled RTTI for
+ # gcc >= 4.3. My poor mac doesn't have that.
+ add_definitions("-fno-rtti -DBOOST_NO_RTTI -DBOOST_NO_TYPEID -Wno-error
-no-pedantic -DOSL_ENABLED")
+
+ include_directories(${OSL_INCLUDES} ${OPENIMAGEIO_INCLUDES})
+
+ message("Oslexec: ${OSLEXEC_LIBRARY}")
+ message("Oslcomp: ${OSLCOMP_LIBRARY}")
+ message("Oslquery: ${OSLQUERY_LIBRARY}")
+
+ #add_library(osl-renderer osl-renderer.c)
+ set (OSLRT_SOURCES osl-renderer.c)
+ set (OSLRT_LIBS ${OSLEXEC_LIBRARY}
+ ${OSLCOMP_LIBRARY} ${OSLQUERY_LIBRARY} ${OPENIMAGEIO_LIBRARY}
+ ${Boost_LIBRARIES})
+ #target_link_libraries(osl-renderer )
+
+ BRLCAD_ADDLIB(osl-renderer ${OSLRT_SOURCES} ${OSLRT_LIBS})
+
+ ##########################################
+ # OSL Shader
+ ##########################################
+
+ # Add the osl shader to the list of shaders
+ set(LIBOPTICAL_SOURCES ${LIBOPTICAL_SOURCES} sh_osl.c)
+
+ # Link liboptical with osl-renderer library
+ BRLCAD_ADDLIB(liboptical "${LIBOPTICAL_SOURCES}" "librt libbn libbu
osl-renderer")
+
+ELSE(BRLCAD-ENABLE_OSL)
+
+ BRLCAD_ADDLIB(liboptical "${LIBOPTICAL_SOURCES}" "librt libbn libbu")
+
+ENDIF(BRLCAD-ENABLE_OSL)
+
SET_TARGET_PROPERTIES(liboptical PROPERTIES VERSION 19.0.1 SOVERSION 19)
SET(LIBRTMS_SRCS
Modified: brlcad/trunk/src/liboptical/init.c
===================================================================
--- brlcad/trunk/src/liboptical/init.c 2011-06-07 12:06:28 UTC (rev 44794)
+++ brlcad/trunk/src/liboptical/init.c 2011-06-07 13:13:53 UTC (rev 44795)
@@ -87,6 +87,11 @@
MFUNCS(flat_mfuncs);
MFUNCS(bbd_mfuncs);
MFUNCS(toon_mfuncs);
+
+#ifdef OSL_ENABLED
+ /* This shader requires OSL, so it won't be compiled if this library was
not enabled */
+ MFUNCS(osl_mfuncs);
+#endif
}
Added: brlcad/trunk/src/liboptical/osl-renderer.c
===================================================================
--- brlcad/trunk/src/liboptical/osl-renderer.c (rev 0)
+++ brlcad/trunk/src/liboptical/osl-renderer.c 2011-06-07 13:13:53 UTC (rev
44795)
@@ -0,0 +1,8 @@
+#include "osl-renderer.h"
+
+int Renderer(point_t *p){
+ (*p)[0] = 1.0;
+ (*p)[1] = 0.0;
+ (*p)[2] = 1.0;
+ return 1;
+}
Property changes on: brlcad/trunk/src/liboptical/osl-renderer.c
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:eol-style
+ native
Added: brlcad/trunk/src/liboptical/sh_osl.c
===================================================================
--- brlcad/trunk/src/liboptical/sh_osl.c (rev 0)
+++ brlcad/trunk/src/liboptical/sh_osl.c 2011-06-07 13:13:53 UTC (rev
44795)
@@ -0,0 +1,311 @@
+/* S H _ X X X . C
+ * BRL-CAD
+ *
+ * Copyright (c) 2004-2011 United States Government as represented by
+ * the U.S. Army Research Laboratory.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * version 2.1 as published by the Free Software Foundation.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this file; see the file named COPYING for more
+ * information.
+ */
+/** @file sh_xxx.c
+ *
+ * To add a new shader to the "rt" program's LIBOPTICAL library:
+ *
+ * 1) Copy this file to sh_shadername.c
+ *
+ * 2) edit sh_shadername.c:
+ * change "X X X" to "S H A D E R N A M E"
+ * change "xxx" to "shadername"
+ * Set a new number for the xxx_MAGIC define
+ * define shader specific structure and defaults
+ * edit/build parse table for bu_structparse from xxx_parse
+ * edit/build shader_mfuncs tables from xxx_mfuncs for
+ * each shader name being built.
+ * edit the xxx_setup function to do shader-specific setup
+ * edit the xxx_render function to do the actual rendering
+ *
+ * If you are building a dynamically loaded shader, compile this into a
+ * shared library called "shadername.so". If you have a number of shaders
+ * for you are adding, you can create a single library called "shaders.so"
+ * which contains all of your DSO shaders.
+ *
+ * RT will look in the following locations for DSO shaders:
+ * ./
+ * $prefix/lib/
+ * $LD_LIBRARY_PATH
+ *
+ * If you are adding the shader to "rt" as a permanent shader, then the
+ * following steps are necessary:
+ *
+ * 3) Edit init.c to add extern for osl_mfuncs and a call to
+ * mlib_add_shader().
+ *
+ * 4) Edit Makefile.am to add shader file to the compilation
+ *
+ * 5) replace this list with a description of the shader, its
+ * parameters and use.
+ *
+ * 6) Edit shaders.tcl and comb.tcl in the ../tclscripts/mged
+ * directory to add a new gui for this shader.
+ */
+
+#include "common.h"
+
+#include <stdlib.h>
+#include <stddef.h>
+#include <stdio.h>
+#include <math.h>
+#include <string.h>
+
+#include <osl-renderer.h>
+
+#include "vmath.h"
+#include "raytrace.h"
+#include "optical.h"
+
+
+#define OSL_MAGIC 0x1834 /* make this a unique number for each shader */
+#define CK_OSL_SP(_p) BU_CKMAG(_p, OSL_MAGIC, "osl_specific")
+
+/*
+ * the shader specific structure contains all variables which are unique
+ * to any particular use of the shader.
+ */
+struct osl_specific {
+ long magic; /* magic # for memory validity check, must come 1st */
+ double osl_val; /* variables for shader ... */
+ double osl_dist;
+ vect_t osl_delta;
+ point_t osl_min;
+ point_t osl_max;
+ mat_t osl_m_to_sh; /* model to shader space matrix */
+ mat_t osl_m_to_r; /* model to shader space matrix */
+};
+
+
+/* The default values for the variables in the shader specific structure */
+static const
+struct osl_specific osl_defaults = {
+ OSL_MAGIC,
+ 1.0, /* osl_val */
+ 0.0, /* osl_dist */
+ VINITALL(1.0), /* osl_delta */
+ VINIT_ZERO, /* osl_min */
+ VINIT_ZERO, /* osl_max */
+ MAT_INIT_ZERO, /* osl_m_to_sh */
+ MAT_INIT_ZERO /* osl_m_to_r */
+};
+
+
+#define SHDR_NULL ((struct osl_specific *)0)
+#define SHDR_O(m) bu_offsetof(struct osl_specific, m)
+#define SHDR_AO(m) bu_offsetofarray(struct osl_specific, m)
+
+
+/* description of how to parse/print the arguments to the shader
+ * There is at least one line here for each variable in the shader specific
+ * structure above
+ */
+struct bu_structparse osl_print_tab[] = {
+ {"%f", 1, "val", SHDR_O(osl_val),
BU_STRUCTPARSE_FUNC_NULL, NULL, NULL },
+ {"%f", 1, "dist", SHDR_O(osl_dist),
BU_STRUCTPARSE_FUNC_NULL, NULL, NULL },
+ {"%f", 3, "delta", SHDR_AO(osl_delta),
BU_STRUCTPARSE_FUNC_NULL, NULL, NULL },
+ {"%f", 3, "max", SHDR_AO(osl_max),
BU_STRUCTPARSE_FUNC_NULL, NULL, NULL },
+ {"%f", 3, "min", SHDR_AO(osl_min),
BU_STRUCTPARSE_FUNC_NULL, NULL, NULL },
+ {"", 0, (char *)0, 0,
BU_STRUCTPARSE_FUNC_NULL, NULL, NULL }
+
+};
+struct bu_structparse osl_parse_tab[] = {
+ {"%p", bu_byteoffset(osl_print_tab[0]), "osl_print_tab", 0,
BU_STRUCTPARSE_FUNC_NULL, NULL, NULL },
+ {"%f", 1, "v", SHDR_O(osl_val),
BU_STRUCTPARSE_FUNC_NULL, NULL, NULL },
+ {"%f", 1, "dist", SHDR_O(osl_dist), bu_mm_cvt, NULL, NULL },
+ {"%f", 3, "d", SHDR_AO(osl_delta),
BU_STRUCTPARSE_FUNC_NULL, NULL, NULL },
+ {"", 0, (char *)0, 0,
BU_STRUCTPARSE_FUNC_NULL, NULL, NULL }
+};
+
+
+HIDDEN int osl_setup(register struct region *rp, struct bu_vls *matparm, char
**dpp, struct mfuncs *mfp, struct rt_i *rtip), osl_render(struct application
*ap, struct partition *pp, struct shadework *swp, char *dp);
+HIDDEN void osl_print(register struct region *rp, char *dp), osl_free(char
*cp);
+
+/* The "mfuncs" structure defines the external interface to the shader.
+ * Note that more than one shader "name" can be associated with a given
+ * shader by defining more than one mfuncs struct in this array.
+ * See sh_phong.c for an example of building more than one shader "name"
+ * from a set of source functions. There you will find that "glass" "mirror"
+ * and "plastic" are all names for the same shader with different default
+ * values for the parameters.
+ */
+struct mfuncs osl_mfuncs[] = {
+ {MF_MAGIC, "osl", 0, MFI_NORMAL|MFI_HIT|MFI_UV, 0,
osl_setup, osl_render, osl_print, osl_free },
+ {0, (char *)0, 0, 0, 0,
0, 0, 0, 0 }
+};
+
+
+/* X X X _ S E T U P
+ *
+ * This routine is called (at prep time)
+ * once for each region which uses this shader.
+ * Any shader-specific initialization should be done here.
+ *
+ * Returns:
+ * 1 success
+ * 0 success, but delete region
+ * -1 failure
+ */
+HIDDEN int
+osl_setup(register struct region *rp, struct bu_vls *matparm, char **dpp,
struct mfuncs *UNUSED(mfp), struct rt_i *rtip)
+
+
+/* pointer to reg_udata in *rp */
+
+/* New since 4.4 release */
+{
+ register struct osl_specific *osl_sp;
+
+ /* check the arguments */
+ RT_CHECK_RTI(rtip);
+ BU_CK_VLS(matparm);
+ RT_CK_REGION(rp);
+
+
+ if (rdebug&RDEBUG_SHADE)
+ bu_log("osl_setup(%s)\n", rp->reg_name);
+
+ /* Get memory for the shader parameters and shader-specific data */
+ BU_GETSTRUCT(osl_sp, osl_specific);
+ *dpp = (char *)osl_sp;
+
+ /* initialize the default values for the shader */
+ memcpy(osl_sp, &osl_defaults, sizeof(struct osl_specific));
+
+ /* parse the user's arguments for this use of the shader. */
+ if (bu_struct_parse(matparm, osl_parse_tab, (char *)osl_sp) < 0)
+ return -1;
+
+ /* Optional:
+ *
+ * If the shader needs to operate in a coordinate system which stays
+ * fixed on the region when the region is moved (as in animation)
+ * we need to get a matrix to perform the appropriate transform(s).
+ *
+ * rt_shader_mat() returns a matrix which maps points on/in the
+ * region into the unit cube. This unit cube is formed by first
+ * mapping from world coordinates into "region coordinates" (the
+ * coordinate system in which the region is defined). Then the
+ * bounding box of the region is used to establish a mapping to
+ * the unit cube
+ *
+ * rt_shader_mat(osl_sp->osl_m_to_sh, rtip, rp, osl_sp->osl_min,
+ * osl_sp->osl_max);
+ *
+ * Alternatively, shading may be done in "region coordinates"
+ * if desired:
+ *
+ * db_region_mat(osl_sp->osl_m_to_r, rtip->rti_dbip, rp->reg_name,
&rt_uniresource);
+ *
+ */
+
+ if (rdebug&RDEBUG_SHADE) {
+ bu_struct_print(" Parameters:", osl_print_tab, (char *)osl_sp);
+ bn_mat_print("m_to_sh", osl_sp->osl_m_to_sh);
+ }
+
+ return 1;
+}
+
+
+/*
+ * X X X _ P R I N T
+ */
+HIDDEN void
+osl_print(register struct region *rp, char *dp)
+{
+ bu_struct_print(rp->reg_name, osl_print_tab, (char *)dp);
+}
+
+
+/*
+ * X X X _ F R E E
+ */
+HIDDEN void
+osl_free(char *cp)
+{
+ bu_free(cp, "osl_specific");
+}
+
+
+/*
+ * X X X _ R E N D E R
+ *
+ * This is called (from viewshade() in shade.c) once for each hit point
+ * to be shaded. The purpose here is to fill in values in the shadework
+ * structure.
+ */
+int
+osl_render(struct application *ap, struct partition *pp, struct shadework
*swp, char *dp)
+
+
+/* defined in ../h/shadework.h */
+/* ptr to the shader-specific struct */
+{
+ register struct osl_specific *osl_sp =
+ (struct osl_specific *)dp;
+ point_t pt;
+ VSETALL(pt, 0);
+
+ /* check the validity of the arguments we got */
+ RT_AP_CHECK(ap);
+ RT_CHECK_PT(pp);
+ CK_OSL_SP(osl_sp);
+
+ if (rdebug&RDEBUG_SHADE)
+ bu_struct_print("osl_render Parameters:", osl_print_tab, (char
*)osl_sp);
+
+ /* If we are performing the shading in "region" space, we must
+ * transform the hit point from "model" space to "region" space.
+ * See the call to db_region_mat in osl_setup().
+ MAT4X3PNT(pt, osl_sp->osl_m_to_sh, swp->sw_hit.hit_point);
+ MAT4X3PNT(pt, osl_sp->osl_m_to_r, swp->sw_hit.hit_point);
+
+ if (rdebug&RDEBUG_SHADE) {
+ bu_log("osl_render() model:(%g %g %g) shader:(%g %g %g)\n",
+ V3ARGS(swp->sw_hit.hit_point),
+ V3ARGS(pt));
+ }
+ */
+
+ Renderer(swp->sw_color);
+
+ /* OSL perform shading operations here */
+
+ /* shader must perform transmission/reflection calculations
+ *
+ * 0 < swp->sw_transmit <= 1 causes transmission computations
+ * 0 < swp->sw_reflect <= 1 causes reflection computations
+ */
+ if (swp->sw_reflect > 0 || swp->sw_transmit > 0)
+ (void)rr_render(ap, pp, swp);
+
+ return 1;
+}
+
+
+/*
+ * Local Variables:
+ * mode: C
+ * tab-width: 8
+ * indent-tabs-mode: t
+ * c-file-style: "stroustrup"
+ * End:
+ * ex: shiftwidth=4 tabstop=8
+ */
Property changes on: brlcad/trunk/src/liboptical/sh_osl.c
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:eol-style
+ native
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
------------------------------------------------------------------------------
EditLive Enterprise is the world's most technically advanced content
authoring tool. Experience the power of Track Changes, Inline Image
Editing and ensure content is compliant with Accessibility Checking.
http://p.sf.net/sfu/ephox-dev2dev
_______________________________________________
BRL-CAD Source Commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/brlcad-commits