remove old stale code

This commit is contained in:
David Rose 2004-12-06 19:33:57 +00:00
parent 28e0aaddec
commit 4ff080d0d1
61 changed files with 0 additions and 9727 deletions

View File

@ -1,21 +0,0 @@
#define BUILD_DIRECTORY $[HAVE_RIB]
#define OTHER_LIBS interrogatedb:c dconfig:c dtoolconfig:m \
dtoolutil:c dtoolbase:c dtool:m
#begin lib_target
#define TARGET ribdisplay
#define LOCAL_LIBS \
display ribgsg
#define SOURCES \
config_ribdisplay.cxx config_ribdisplay.h ribGraphicsPipe.I \
ribGraphicsPipe.cxx ribGraphicsPipe.h ribGraphicsWindow.I \
ribGraphicsWindow.cxx ribGraphicsWindow.h
#define INSTALL_HEADERS \
ribGraphicsPipe.I ribGraphicsPipe.h ribGraphicsWindow.I \
ribGraphicsWindow.h
#end lib_target

View File

@ -1,35 +0,0 @@
// Filename: config_ribdisplay.cxx
// Created by: cary (07Oct99)
//
////////////////////////////////////////////////////////////////////
//
// PANDA 3D SOFTWARE
// Copyright (c) 2001 - 2004, Disney Enterprises, Inc. All rights reserved
//
// All use of this software is subject to the terms of the Panda 3d
// Software license. You should have received a copy of this license
// along with this source code; you will also find a current copy of
// the license at http://etc.cmu.edu/panda3d/docs/license/ .
//
// To contact the maintainers of this program write to
// panda3d-general@lists.sourceforge.net .
//
////////////////////////////////////////////////////////////////////
#include "config_ribdisplay.h"
#include "ribGraphicsPipe.h"
#include "ribGraphicsWindow.h"
#include "dconfig.h"
Configure(config_ribdisplay);
NotifyCategoryDef(ribdisplay, "display");
ConfigureFn(config_ribdisplay) {
RIBGraphicsPipe::init_type();
GraphicsPipe::get_factory().register_factory(RIBGraphicsPipe::get_class_type(),
RIBGraphicsPipe::make_RIBGraphicsPipe);
RIBGraphicsWindow::init_type();
GraphicsWindow::get_factory().register_factory(RIBGraphicsWindow::get_class_type(),
RIBGraphicsWindow::make_RibGraphicsWindow);
}

View File

@ -1,27 +0,0 @@
// Filename: config_ribdisplay.h
// Created by: cary (07Oct99)
//
////////////////////////////////////////////////////////////////////
//
// PANDA 3D SOFTWARE
// Copyright (c) 2001 - 2004, Disney Enterprises, Inc. All rights reserved
//
// All use of this software is subject to the terms of the Panda 3d
// Software license. You should have received a copy of this license
// along with this source code; you will also find a current copy of
// the license at http://etc.cmu.edu/panda3d/docs/license/ .
//
// To contact the maintainers of this program write to
// panda3d-general@lists.sourceforge.net .
//
////////////////////////////////////////////////////////////////////
#ifndef CONFIG_RIBDISPLAY_H
#define CONFIG_RIBDISPLAY_H
#include "pandabase.h"
#include "notifyCategoryProxy.h"
NotifyCategoryDecl(ribdisplay, EXPCL_PANDARIB, EXPTP_PANDARIB);
#endif

View File

@ -1,70 +0,0 @@
// Filename: ribGraphicsPipe.I
// Created by: drose (17Feb99)
//
////////////////////////////////////////////////////////////////////
//
// PANDA 3D SOFTWARE
// Copyright (c) 2001 - 2004, Disney Enterprises, Inc. All rights reserved
//
// All use of this software is subject to the terms of the Panda 3d
// Software license. You should have received a copy of this license
// along with this source code; you will also find a current copy of
// the license at http://etc.cmu.edu/panda3d/docs/license/ .
//
// To contact the maintainers of this program write to
// panda3d-general@lists.sourceforge.net .
//
////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////
// Function: RIBGraphicsPipe::Constructor
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
INLINE RIBGraphicsPipe::
RIBGraphicsPipe(const PipeSpecifier& spec)
: NoninteractiveGraphicsPipe(spec), _filename(spec.get_file_name()) {
}
////////////////////////////////////////////////////////////////////
// Function: RIBGraphicsPipe::get_file_name
// Access: Public
// Description: gets the base filename
////////////////////////////////////////////////////////////////////
INLINE std::string RIBGraphicsPipe::
get_file_name(void) const {
return _filename;
}
////////////////////////////////////////////////////////////////////
// Function: RIBGraphicsPipe::Constructor
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
INLINE RIBGraphicsPipe::
RIBGraphicsPipe(void) {
cerr << "RIBGraphicsPipes should not be created with default constructor"
<< endl;
}
////////////////////////////////////////////////////////////////////
// Function: RIBGraphicsPipe::Constructor
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
INLINE RIBGraphicsPipe::
RIBGraphicsPipe(const RIBGraphicsPipe&) {
cerr << "RIBGraphicsPipes should not be copied" << endl;
}
////////////////////////////////////////////////////////////////////
// Function: RIBGraphicsPipe::operator=
// Access: Public
// Description: assignment operator
////////////////////////////////////////////////////////////////////
INLINE RIBGraphicsPipe& RIBGraphicsPipe::
operator=(const RIBGraphicsPipe&) {
cerr << "RIBGraphicsPipes should not be assigned" << endl;
return *this;
}

View File

@ -1,59 +0,0 @@
// Filename: ribGraphicsPipe.cxx
// Created by: drose (15Feb99)
//
////////////////////////////////////////////////////////////////////
//
// PANDA 3D SOFTWARE
// Copyright (c) 2001 - 2004, Disney Enterprises, Inc. All rights reserved
//
// All use of this software is subject to the terms of the Panda 3d
// Software license. You should have received a copy of this license
// along with this source code; you will also find a current copy of
// the license at http://etc.cmu.edu/panda3d/docs/license/ .
//
// To contact the maintainers of this program write to
// panda3d-general@lists.sourceforge.net .
//
////////////////////////////////////////////////////////////////////
#include "ribGraphicsPipe.h"
#include "ribGraphicsWindow.h"
#include "config_ribdisplay.h"
TypeHandle RIBGraphicsPipe::_type_handle;
////////////////////////////////////////////////////////////////////
// Function: RIBGraphicsPipe::get_window_type
// Access: Public, Virtual
// Description: Returns the TypeHandle of the kind of window
// preferred by this kind of pipe.
////////////////////////////////////////////////////////////////////
TypeHandle RIBGraphicsPipe::
get_window_type() const {
return RIBGraphicsWindow::get_class_type();
}
GraphicsPipe *RIBGraphicsPipe::
make_RIBGraphicsPipe(const FactoryParams &params) {
GraphicsPipe::PipeSpec *pipe_param;
if (!get_param_into(pipe_param, params)) {
return new RIBGraphicsPipe(PipeSpecifier());
} else {
return new RIBGraphicsPipe(pipe_param->get_specifier());
}
}
TypeHandle RIBGraphicsPipe::get_class_type(void) {
return _type_handle;
}
void RIBGraphicsPipe::init_type(void) {
NoninteractiveGraphicsPipe::init_type();
register_type(_type_handle, "RIBGraphicsPipe",
NoninteractiveGraphicsPipe::get_class_type());
}
TypeHandle RIBGraphicsPipe::get_type(void) const {
return get_class_type();
}

View File

@ -1,73 +0,0 @@
// Filename: ribGraphicsPipe.h
// Created by: drose (15Feb99)
//
////////////////////////////////////////////////////////////////////
//
// PANDA 3D SOFTWARE
// Copyright (c) 2001 - 2004, Disney Enterprises, Inc. All rights reserved
//
// All use of this software is subject to the terms of the Panda 3d
// Software license. You should have received a copy of this license
// along with this source code; you will also find a current copy of
// the license at http://etc.cmu.edu/panda3d/docs/license/ .
//
// To contact the maintainers of this program write to
// panda3d-general@lists.sourceforge.net .
//
////////////////////////////////////////////////////////////////////
#ifndef RIBGRAPHICSPIPE_H
#define RIBGRAPHICSPIPE_H
#include "pandabase.h"
#include <string>
#include "noninteractiveGraphicsPipe.h"
////////////////////////////////////////////////////////////////////
// Class : RIBGraphicsPipe
// Description : A place to grab RIBGraphicsWindows from. Not
// terribly exciting in itself. The name of the pipe is
// used as the default RIB output filename for each
// window, but the window may change this.
////////////////////////////////////////////////////////////////////
class RIBGraphicsPipe : public NoninteractiveGraphicsPipe {
public:
INLINE RIBGraphicsPipe(const PipeSpecifier&);
virtual TypeHandle get_window_type() const;
public:
static GraphicsPipe *make_RIBGraphicsPipe(const FactoryParams &params);
static TypeHandle get_class_type(void);
static void init_type(void);
virtual TypeHandle get_type(void) const;
virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
public:
INLINE std::string get_file_name(void) const;
protected:
std::string _filename;
private:
static TypeHandle _type_handle;
protected:
INLINE RIBGraphicsPipe(void);
INLINE RIBGraphicsPipe(const RIBGraphicsPipe&);
INLINE RIBGraphicsPipe& operator=(const RIBGraphicsPipe&);
};
#include "ribGraphicsPipe.I"
#endif

View File

@ -1,177 +0,0 @@
// Filename: ribGraphicsWindow.I
// Created by: drose (17Feb99)
//
////////////////////////////////////////////////////////////////////
//
// PANDA 3D SOFTWARE
// Copyright (c) 2001 - 2004, Disney Enterprises, Inc. All rights reserved
//
// All use of this software is subject to the terms of the Panda 3d
// Software license. You should have received a copy of this license
// along with this source code; you will also find a current copy of
// the license at http://etc.cmu.edu/panda3d/docs/license/ .
//
// To contact the maintainers of this program write to
// panda3d-general@lists.sourceforge.net .
//
////////////////////////////////////////////////////////////////////
#include "ribGraphicsStateGuardian.h"
////////////////////////////////////////////////////////////////////
// Function: RIBGraphicsWindow::set_rib_filename_template
// Access: Public
// Description: Specifies the string that defines the filename that
// will be generated for each RIB file output by the
// GraphicsWindow. The template may contain any of the
// % format characters described in ribGraphicsWindow.h.
// In particular, if it contains %f (or some variant),
// there will be a separate RIB file generated for each
// frame; otherwise, all the frames will be written to
// the same RIB file.
////////////////////////////////////////////////////////////////////
INLINE void RIBGraphicsWindow::
set_rib_filename_template(const string &str) {
_rib_filename_template = str;
_rib_per_frame = check_per_frame(str);
}
////////////////////////////////////////////////////////////////////
// Function: RIBGraphicsWindow::get_rib_filename_template
// Access: Public
// Description: Returns the string that defines the RIB filename.
// See set_rib_filename_template().
////////////////////////////////////////////////////////////////////
INLINE string RIBGraphicsWindow::
get_rib_filename_template() const {
return _rib_filename_template;
}
////////////////////////////////////////////////////////////////////
// Function: RIBGraphicsWindow::get_rib_filename
// Access: Public
// Description: Returns the name of the RIB file that will be created
// at the next (or possibly only the first) call to
// begin_frame().
////////////////////////////////////////////////////////////////////
INLINE string RIBGraphicsWindow::
get_rib_filename() const {
return format_name(_rib_filename_template);
}
////////////////////////////////////////////////////////////////////
// Function: RIBGraphicsWindow::rib_per_frame
// Access: Public
// Description: Returns true if the RIB filename template contains
// the format specification %f, which means there will
// be a separate RIB file generated for each frame.
////////////////////////////////////////////////////////////////////
INLINE bool RIBGraphicsWindow::
rib_per_frame() const {
return _rib_per_frame;
}
////////////////////////////////////////////////////////////////////
// Function: RIBGraphicsWindow::set_image_filename_template
// Access: Public
// Description: Specifies the string that defines the filename that
// will be written to the RIB file as an output filename
// request. The template may contain any of the
// % format characters descimageed in RIBGraphicsWindow.h.
// In particular, if it contains %f (or some variant),
// there will be a separate image file generated for each
// frame; otherwise, all the frames will be written to
// the same image file, whatever that might mean.
//
// This string may also be empty. If it is, no
// "Display" command will be written to the RIB file,
// and the renderer will choose whatever output filename
// is appropriate.
////////////////////////////////////////////////////////////////////
INLINE void RIBGraphicsWindow::
set_image_filename_template(const string &str) {
_image_filename_template = str;
_image_per_frame = check_per_frame(str);
}
////////////////////////////////////////////////////////////////////
// Function: RIBGraphicsWindow::get_image_filename_template
// Access: Public
// Description: Returns the string that defines the image filename.
// See set_image_filename_template().
////////////////////////////////////////////////////////////////////
INLINE string RIBGraphicsWindow::
get_image_filename_template() const {
return _image_filename_template;
}
////////////////////////////////////////////////////////////////////
// Function: RIBGraphicsWindow::get_image_filename
// Access: Public
// Description: Returns the name of the image file that will be
// created at the next call to begin_frame().
////////////////////////////////////////////////////////////////////
INLINE string RIBGraphicsWindow::
get_image_filename() const {
return format_name(_image_filename_template);
}
////////////////////////////////////////////////////////////////////
// Function: RIBGraphicsWindow::image_per_frame
// Access: Public
// Description: Returns true if the image filename template contains
// the format specification %f, which means there will
// be a separate image file generated for each frame.
////////////////////////////////////////////////////////////////////
INLINE bool RIBGraphicsWindow::
image_per_frame() const {
return _image_per_frame;
}
////////////////////////////////////////////////////////////////////
// Function: RIBGraphicsStateWindow::set_texture_directory
// Access: Public
// Description: Sets the name of the directory into which texture
// maps are copied to be available to the RIB file.
////////////////////////////////////////////////////////////////////
INLINE void RIBGraphicsWindow::
set_texture_directory(const string &directory) {
DCAST(RIBGraphicsStateGuardian, _gsg)->set_texture_directory(directory);
}
////////////////////////////////////////////////////////////////////
// Function: RIBGraphicsWindow::get_texture_directory
// Access: Public
// Description: Returns the name of the directory into which texture
// maps are copied to be available to the RIB file.
////////////////////////////////////////////////////////////////////
INLINE string RIBGraphicsWindow::
get_texture_directory() const {
return DCAST(RIBGraphicsStateGuardian, _gsg)->get_texture_directory();
}
////////////////////////////////////////////////////////////////////
// Function: RIBGraphicsWindow::set_texture_extension
// Access: Public
// Description: Specifies the filename extension that texture map
// files are given when they are copied into the
// directory for RIB files. This might also imply an
// image type. The default is "tiff", which implies
// TIFF files.
////////////////////////////////////////////////////////////////////
INLINE void RIBGraphicsWindow::
set_texture_extension(const string &extension) {
DCAST(RIBGraphicsStateGuardian, _gsg)->set_texture_extension(extension);
}
////////////////////////////////////////////////////////////////////
// Function: RIBGraphicsWindow::get_texture_extension
// Access: Public
// Description: Returns the filename extension that texture map
// files are given when they are copied into the
// directory for RIB files.
////////////////////////////////////////////////////////////////////
INLINE string RIBGraphicsWindow::
get_texture_extension() const {
return DCAST(RIBGraphicsStateGuardian, _gsg)->get_texture_extension();
}

View File

@ -1,411 +0,0 @@
// Filename: ribGraphicsWindow.cxx
// Created by: drose (15Feb99)
//
////////////////////////////////////////////////////////////////////
//
// PANDA 3D SOFTWARE
// Copyright (c) 2001 - 2004, Disney Enterprises, Inc. All rights reserved
//
// All use of this software is subject to the terms of the Panda 3d
// Software license. You should have received a copy of this license
// along with this source code; you will also find a current copy of
// the license at http://etc.cmu.edu/panda3d/docs/license/ .
//
// To contact the maintainers of this program write to
// panda3d-general@lists.sourceforge.net .
//
////////////////////////////////////////////////////////////////////
#include "ribGraphicsWindow.h"
#include "ribGraphicsPipe.h"
#include "config_ribdisplay.h"
#include "ribGraphicsStateGuardian.h"
#include <ctype.h>
TypeHandle RIBGraphicsWindow::_type_handle;
////////////////////////////////////////////////////////////////////
// Function: RIBGraphicsWindow::Constructor
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
RIBGraphicsWindow::
RIBGraphicsWindow(GraphicsPipe *pipe) : GraphicsWindow(pipe) {
setup_window(pipe);
}
////////////////////////////////////////////////////////////////////
// Function: RIBGraphicsWindow::Constructor
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
RIBGraphicsWindow::
RIBGraphicsWindow(GraphicsPipe *pipe,
const GraphicsWindow::Properties &props) :
GraphicsWindow(pipe, props)
{
setup_window(pipe);
}
////////////////////////////////////////////////////////////////////
// Function: RIBGraphicsWindow::Destructor
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
RIBGraphicsWindow::
~RIBGraphicsWindow(void) {
flush_file();
}
////////////////////////////////////////////////////////////////////
// Function: RIBGraphicsWindow::flush_file
// Access: Public
// Description: Finishes the RIB file currently being output and
// closes it.
////////////////////////////////////////////////////////////////////
void RIBGraphicsWindow::
flush_file() {
if (_file_begun) {
end_file();
}
}
////////////////////////////////////////////////////////////////////
// Function: RIBGraphicsWindow::begin_frame
// Access: Public, Virtual
// Description: Prepares to write a new frame to the RIB file.
////////////////////////////////////////////////////////////////////
void RIBGraphicsWindow::
begin_frame() {
if (!_file_begun) {
// Open a new RIB file if we need to.
begin_file();
}
_file << "FrameBegin " << _frame_number << "\n";
if (image_per_frame()) {
// If we're writing out an image file for each frame, specify it
// here, inside the Frame control group.
_file << " Display \"" << get_image_filename()
<< "\" \"file\" \"rgba\"\n";
}
}
////////////////////////////////////////////////////////////////////
// Function: RIBGraphicsWindow::end_frame
// Access: Public, Virtual
// Description: Finalizes a frame.
////////////////////////////////////////////////////////////////////
void RIBGraphicsWindow::
end_frame() {
_file << "FrameEnd\n";
if (rib_per_frame()) {
// If we're outputting a RIB file for each frame, close the file now.
end_file();
}
GraphicsWindow::end_frame();
}
////////////////////////////////////////////////////////////////////
// Function: RIBGraphicsWindow::setup_window
// Access: Protected
// Description: Called by the constructor to initialize whatever
// internal structures are necessary, given the
// indicated pipe and requested properties.
////////////////////////////////////////////////////////////////////
void RIBGraphicsWindow::
setup_window(GraphicsPipe *pipe) {
RIBGraphicsPipe *rp = DCAST(RIBGraphicsPipe, pipe);
_file_begun = false;
set_rib_filename_template(rp->get_file_name());
set_image_filename_template("");
make_gsg();
}
////////////////////////////////////////////////////////////////////
// Function: RIBGraphicsWindow::begin_file
// Access: Protected
// Description: Called internally when a new RIB file needs to be
// created and its suitable headers written.
////////////////////////////////////////////////////////////////////
void RIBGraphicsWindow::
begin_file() {
assert(!_file_begun);
RIBGraphicsStateGuardian *rgsg = DCAST(RIBGraphicsStateGuardian, _gsg);
_file_begun = true;
_current_rib_filename = Filename::text_filename(get_rib_filename());
assert(!_current_rib_filename.empty());
_current_rib_filename.open_write(_file);
rgsg->reset_file(_file);
if (!_file) {
cerr << "Unable to write to " << _current_rib_filename << "\n";
return;
}
_file <<
"#\n"
"# RIB file " << _current_rib_filename << "\n"
"#\n";
// World set-up
_file <<
// "TextureCoordinates 0 1 1 1 0 0 1 0\n"
"Option \"searchpath\" \"shader\" \"shaders:@\"\n";
// A default ambient light for when lighting is off
_file <<
"LightSource \"ambientlight\" 0 \"intensity\" 1 \"lightcolor\" [ 1 1 1 ]\n"
"Illuminate 0 1\n";
if (!get_image_filename_template().empty() &&
!image_per_frame()) {
// If we have an image filename, and it's the same file for all
// frames, specify it outside the Frame control group. Maybe the
// renderer will be able to generate a multi-frame output file
// somehow.
_file << "Display \"" << get_image_filename()
<< "\" \"file\" \"rgb\"\n";
}
}
////////////////////////////////////////////////////////////////////
// Function: RIBGraphicsWindow::end_file
// Access: Protected
// Description: Called internally to wrap up the current RIB file and
// close it.
////////////////////////////////////////////////////////////////////
void RIBGraphicsWindow::
end_file() {
assert(_file_begun);
RIBGraphicsStateGuardian *rgsg = DCAST(RIBGraphicsStateGuardian, _gsg);
rgsg->reset();
_file_begun = false;
_file.close();
cerr << "Wrote " << _current_rib_filename << "\n";
}
////////////////////////////////////////////////////////////////////
// Function: RIBGraphicsWindow::format_name
// Access: Protected
// Description: Given a filename template which contains symbols like
// %f etc., replaces the symbols with the appropriate
// values to generate an actual filename.
////////////////////////////////////////////////////////////////////
string RIBGraphicsWindow::
format_name(const string &name_template) const {
string name;
string::const_iterator ci;
ci = name_template.begin();
while (ci != name_template.end()) {
if (*ci == '%') {
++ci;
string::const_iterator pi = ci;
while (ci != name_template.end() && isdigit(*ci)) {
++ci;
}
string format_spec(pi, ci);
if (ci != name_template.end()) {
switch (*ci) {
case 'f':
// %f : insert frame number
name += format_integer(format_spec, _frame_number);
break;
case 't':
// %t : insert window title
name += format_string(format_spec, _props._title);
break;
case '%':
// %% : insert percent sign
name += '%';
break;
default:
cerr << "Invalid filename template specification: %"
<< format_spec << *ci << "\n";
}
++ci;
} else {
cerr << "Incomplete filename template specification: %"
<< format_spec << "\n";
}
} else {
name += *ci;
++ci;
}
}
return name;
}
////////////////////////////////////////////////////////////////////
// Function: RIBGraphicsWindow::format_integer
// Access: Protected, Static
// Description: Formats an integer according to a %d-like format
// specification found in a filename template.
// format_spec is the string between the percent sign
// and the command letter (which might be empty, or
// might contain a field width), and number is the value
// to format.
////////////////////////////////////////////////////////////////////
string RIBGraphicsWindow::
format_integer(const string &format_spec, int number) {
// Get the field width requirement. We don't care if it begins with
// a leading zero or not, since we always pad with zeroes.
int width = atoi(format_spec.c_str());
string result;
string sign;
// Is the number negative?
if (number < 0) {
sign = '-';
number = -number;
}
// Now build the number from the least-significant digit up. We
// keep going until the width runs out or the number does, whichever
// lasts longer.
do {
int digit = number % 10;
number /= 10;
result = (char)(digit + '0') + result;
width--;
} while (width > 0 || number != 0);
return sign + result;
}
////////////////////////////////////////////////////////////////////
// Function: RIBGraphicsWindow::format_string
// Access: Protected, Static
// Description: Formats a string according to a %s-like format
// specification found in a filename template.
// format_spec is the string between the percent sign
// and the command letter (which might be empty, or
// might contain a field width), and str is the value
// to format.
////////////////////////////////////////////////////////////////////
string RIBGraphicsWindow::
format_string(const string &format_spec, const string &str) {
int width = atoi(format_spec.c_str());
if (width <= str.length()) {
return str;
}
// Now we have to pad the string out.
string pad;
for (int extra = width; extra < str.length(); extra++) {
pad += '-';
}
return pad + str;
}
////////////////////////////////////////////////////////////////////
// Function: RIBGraphicsWindow::format_string
// Access: Protected, Static
// Description: Scans a name template for the appearance of %f (or
// some variant), and returns true if it appears, false
// otherwise.
////////////////////////////////////////////////////////////////////
bool RIBGraphicsWindow::
check_per_frame(const string &name_template) {
string::const_iterator ci;
ci = name_template.begin();
while (ci != name_template.end()) {
if (*ci == '%') {
++ci;
string::const_iterator pi = ci;
while (ci != name_template.end() && isdigit(*ci)) {
++ci;
}
if (ci != name_template.end()) {
if ((*ci) == 'f') {
return true;
}
++ci;
}
} else {
++ci;
}
}
return false;
}
void RIBGraphicsWindow::make_current(void) {
}
void RIBGraphicsWindow::unmake_current(void) {
}
////////////////////////////////////////////////////////////////////
// Function: RIBGraphicsWindow::get_gsg_type
// Access: Public, Virtual
// Description: Returns the TypeHandle of the kind of GSG preferred
// by this kind of window.
////////////////////////////////////////////////////////////////////
TypeHandle RIBGraphicsWindow::
get_gsg_type() const {
return RIBGraphicsStateGuardian::get_class_type();
}
GraphicsWindow*
RIBGraphicsWindow::make_RibGraphicsWindow(const FactoryParams &params) {
GraphicsWindow::WindowPipe *pipe_param;
if (!get_param_into(pipe_param, params)) {
ribdisplay_cat.error()
<< "No pipe specified for window creation!" << endl;
return NULL;
}
GraphicsPipe *pipe = pipe_param->get_pipe();
GraphicsWindow::WindowProps *props_param;
if (!get_param_into(props_param, params)) {
return new RIBGraphicsWindow(pipe);
} else {
return new RIBGraphicsWindow(pipe, props_param->get_properties());
}
}
TypeHandle RIBGraphicsWindow::get_class_type(void) {
return _type_handle;
}
void RIBGraphicsWindow::init_type(void) {
GraphicsWindow::init_type();
register_type(_type_handle, "RIBGraphicsWindow",
GraphicsWindow::get_class_type());
}
TypeHandle RIBGraphicsWindow::get_type(void) const {
return get_class_type();
}

View File

@ -1,147 +0,0 @@
// Filename: ribGraphicsWindow.h
// Created by: drose (15Feb99)
//
////////////////////////////////////////////////////////////////////
//
// PANDA 3D SOFTWARE
// Copyright (c) 2001 - 2004, Disney Enterprises, Inc. All rights reserved
//
// All use of this software is subject to the terms of the Panda 3d
// Software license. You should have received a copy of this license
// along with this source code; you will also find a current copy of
// the license at http://etc.cmu.edu/panda3d/docs/license/ .
//
// To contact the maintainers of this program write to
// panda3d-general@lists.sourceforge.net .
//
////////////////////////////////////////////////////////////////////
#ifndef RIBGRAPHICSWINDOW_H
#define RIBGRAPHICSWINDOW_H
////////////////////////////////////////////////////////////////////
//
// A RIBGraphicsWindow, instead of actually being a window on some
// raster display device, instead represents a file (or sequence of
// files) on disk that will be filled with a RIB scene description
// when the scene is "rendered" to the window. This RIB may
// subsequently be used as input to a standalone renderer such as
// prman or BMRT to generate one or more images.
//
// The output RIB filename as specified to the window is actually a
// filename template, and may contain any of the following:
//
// %f This stands for the current frame number. The frame number
// starts counting at zero when the window is created and
// increments by one each time a frame is rendered. An optional
// field width may appear after the %, printf-style.
//
// %t This stands for the window title.
//
// %% This stands for a single percent sign.
//
// If the RIB filename contains %f, a separate RIB file is generated
// for each frame rendered; otherwise, all frames are written into a
// single multi-frame RIB file.
//
//
// The image filename may also be specified. If specified, a
// "Display" command is written to the RIB file to output the image to
// the indicated filename. If unspecified or empty, the "Display"
// command is not written, and the renderer chooses the output
// filename. The image filename may also contain any of the %
// sequences described above.
//
////////////////////////////////////////////////////////////////////
#include "pandabase.h"
#include "graphicsWindow.h"
#include "filename.h"
class RIBGraphicsPipe;
////////////////////////////////////////////////////////////////////
// Class : RIBGraphicsWindow
// Description : Represents a specific RIB file (or sequence of files)
// that can be "rendered" to. Rendering to a RIB file
// means writing out a scene description to the file.
//
// The filename of the RIB file is initially taken from
// the name of the RIBGraphicsPipe used to create the
// window, but it may subsequently be changed via
// set_rib_filename_template(). The filename may
// contain any of the % sequences described above.
////////////////////////////////////////////////////////////////////
class RIBGraphicsWindow : public GraphicsWindow {
public:
RIBGraphicsWindow(GraphicsPipe *pipe);
RIBGraphicsWindow(GraphicsPipe *pipe,
const GraphicsWindow::Properties &props);
virtual ~RIBGraphicsWindow(void);
INLINE void set_rib_filename_template(const string &str);
INLINE string get_rib_filename_template() const;
INLINE string get_rib_filename() const;
INLINE bool rib_per_frame() const;
INLINE void set_image_filename_template(const string &str);
INLINE string get_image_filename_template() const;
INLINE string get_image_filename() const;
INLINE bool image_per_frame() const;
INLINE void set_texture_directory(const string &directory);
INLINE string get_texture_directory() const;
INLINE void set_texture_extension(const string &extension);
INLINE string get_texture_extension() const;
void flush_file();
virtual void begin_frame();
virtual void end_frame();
virtual void make_current(void);
virtual void unmake_current(void);
virtual TypeHandle get_gsg_type() const;
static GraphicsWindow* make_RibGraphicsWindow(const FactoryParams &params);
protected:
void setup_window(GraphicsPipe *pipe);
void begin_file();
void end_file();
string format_name(const string &name_template) const;
static string format_integer(const string &format_spec, int number);
static string format_string(const string &format_spec, const string &str);
static bool check_per_frame(const string &name_template);
string _rib_filename_template;
string _image_filename_template;
bool _rib_per_frame;
bool _image_per_frame;
bool _file_begun;
Filename _current_rib_filename;
ofstream _file;
public:
static TypeHandle get_class_type(void);
static void init_type(void);
virtual TypeHandle get_type(void) const;
virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
private:
static TypeHandle _type_handle;
};
#include "ribGraphicsWindow.I"
#endif

View File

@ -1,20 +0,0 @@
#define BUILD_DIRECTORY $[HAVE_RIB]
#define OTHER_LIBS interrogatedb:c dconfig:c dtoolconfig:m \
dtoolutil:c dtoolbase:c dtool:m
#begin lib_target
#define TARGET ribgsg
#define LOCAL_LIBS \
pgraph gsgmisc display gobj
#define SOURCES \
config_ribgsg.cxx config_ribgsg.h ribGraphicsStateGuardian.I \
ribGraphicsStateGuardian.cxx ribGraphicsStateGuardian.h \
ribStuffTraverser.cxx ribStuffTraverser.h
#define INSTALL_HEADERS \
ribGraphicsStateGuardian.h
#end lib_target

View File

@ -1,32 +0,0 @@
// Filename: config_ribgsg.cxx
// Created by: cary (08Oct99)
//
////////////////////////////////////////////////////////////////////
//
// PANDA 3D SOFTWARE
// Copyright (c) 2001 - 2004, Disney Enterprises, Inc. All rights reserved
//
// All use of this software is subject to the terms of the Panda 3d
// Software license. You should have received a copy of this license
// along with this source code; you will also find a current copy of
// the license at http://etc.cmu.edu/panda3d/docs/license/ .
//
// To contact the maintainers of this program write to
// panda3d-general@lists.sourceforge.net .
//
////////////////////////////////////////////////////////////////////
#include "config_ribgsg.h"
#include "ribGraphicsStateGuardian.h"
#include "dconfig.h"
Configure(config_ribgsg);
NotifyCategoryDef(ribgsg, ":display:gsg");
ConfigureFn(config_ribgsg) {
RIBGraphicsStateGuardian::init_type();
GraphicsStateGuardian::get_factory().
register_factory(RIBGraphicsStateGuardian::get_class_type(),
RIBGraphicsStateGuardian::make_RIBGraphicsStateGuardian);
}

View File

@ -1,27 +0,0 @@
// Filename: config_ribgsg.h
// Created by: cary (08Oct99)
//
////////////////////////////////////////////////////////////////////
//
// PANDA 3D SOFTWARE
// Copyright (c) 2001 - 2004, Disney Enterprises, Inc. All rights reserved
//
// All use of this software is subject to the terms of the Panda 3d
// Software license. You should have received a copy of this license
// along with this source code; you will also find a current copy of
// the license at http://etc.cmu.edu/panda3d/docs/license/ .
//
// To contact the maintainers of this program write to
// panda3d-general@lists.sourceforge.net .
//
////////////////////////////////////////////////////////////////////
#ifndef CONFIG_RIBGSG_H
#define CONFIG_RIBGSG_H
#include "pandabase.h"
#include "notifyCategoryProxy.h"
NotifyCategoryDecl(ribgsg, EXPCL_PANDARIB, EXPTP_PANDARIB);
#endif

View File

@ -1,17 +0,0 @@
// Filename: ribGraphicsStateGuardian.I
// Created by: drose (15Feb99)
//
////////////////////////////////////////////////////////////////////
//
// PANDA 3D SOFTWARE
// Copyright (c) 2001 - 2004, Disney Enterprises, Inc. All rights reserved
//
// All use of this software is subject to the terms of the Panda 3d
// Software license. You should have received a copy of this license
// along with this source code; you will also find a current copy of
// the license at http://etc.cmu.edu/panda3d/docs/license/ .
//
// To contact the maintainers of this program write to
// panda3d-general@lists.sourceforge.net .
//
////////////////////////////////////////////////////////////////////

File diff suppressed because it is too large Load Diff

View File

@ -1,182 +0,0 @@
// Filename: ribGraphicsStateGuardian.h
// Created by: drose (15Feb99)
//
////////////////////////////////////////////////////////////////////
//
// PANDA 3D SOFTWARE
// Copyright (c) 2001 - 2004, Disney Enterprises, Inc. All rights reserved
//
// All use of this software is subject to the terms of the Panda 3d
// Software license. You should have received a copy of this license
// along with this source code; you will also find a current copy of
// the license at http://etc.cmu.edu/panda3d/docs/license/ .
//
// To contact the maintainers of this program write to
// panda3d-general@lists.sourceforge.net .
//
////////////////////////////////////////////////////////////////////
#ifndef RIBGRAPHICSSTATEGUARDIAN_H
#define RIBGRAPHICSSTATEGUARDIAN_H
#include "pandabase.h"
#include "graphicsStateGuardian.h"
#include "filename.h"
class Geom;
class Texture;
class Light;
class Material;
class DisplayRegion;
class RenderBuffer;
class PixelBuffer;
class Fog;
////////////////////////////////////////////////////////////////////
// Class : RIBGraphicsStateGuardian
// Description : A GraphicsStateGuardian specialized for creating RIB
// files, suitable for shipping off to a
// Renderman-friendly non-real-time renderer.
////////////////////////////////////////////////////////////////////
class RIBGraphicsStateGuardian : public GraphicsStateGuardian {
public:
RIBGraphicsStateGuardian(GraphicsWindow *win);
virtual void reset();
void reset_file(ostream &out);
void reset_frame();
virtual void clear(const RenderBuffer &buffer);
virtual void clear(const RenderBuffer &buffer, const DisplayRegion *region);
virtual void prepare_display_region();
virtual void render_frame(const AllAttributesWrapper &initial_state);
virtual void render_scene(Node *root, ProjectionNode *projnode,
const AllAttributesWrapper &initial_state);
virtual void render_subgraph(RenderTraverser *traverser,
Node *subgraph, ProjectionNode *projnode,
const AllAttributesWrapper &initial_state,
const AllTransitionsWrapper &net_trans);
virtual void render_subgraph(RenderTraverser *traverser,
Node *subgraph,
const AllAttributesWrapper &initial_state,
const AllTransitionsWrapper &net_trans);
virtual bool wants_normals(void) const;
virtual bool wants_texcoords(void) const;
virtual bool wants_colors(void) const;
virtual float compute_distance_to(const LPoint3f &point) const;
virtual void draw_point(const GeomPoint *geom);
virtual void draw_line(const GeomLine *geom);
virtual void draw_linestrip(const GeomLinestrip *) { }
virtual void draw_sprite(const GeomSprite *geom);
virtual void draw_polygon(const GeomPolygon *geom);
virtual void draw_quad(const GeomQuad *geom);
virtual void draw_tri(const GeomTri *geom);
virtual void draw_tristrip(const GeomTristrip *geom);
virtual void draw_trifan(const GeomTrifan *geom);
virtual void draw_sphere(const GeomSphere *geom);
virtual TextureContext *prepare_texture(Texture *tex);
virtual void apply_texture(TextureContext *tc);
virtual void release_texture(TextureContext *tc);
virtual void copy_texture(TextureContext *tc, const DisplayRegion *dr);
virtual void copy_texture(TextureContext *tc, const DisplayRegion *dr,
const RenderBuffer &rb);
virtual void draw_texture(TextureContext *tc, const DisplayRegion *dr);
virtual void draw_texture(TextureContext *tc, const DisplayRegion *dr,
const RenderBuffer &rb);
virtual void texture_to_pixel_buffer(TextureContext *, PixelBuffer *) { }
virtual void texture_to_pixel_buffer(TextureContext *, PixelBuffer *,
const DisplayRegion *) { }
virtual void copy_pixel_buffer(PixelBuffer *pb, const DisplayRegion *dr);
virtual void copy_pixel_buffer(PixelBuffer *pb, const DisplayRegion *dr,
const RenderBuffer &rb);
virtual void draw_pixel_buffer(PixelBuffer *pb, const DisplayRegion *dr,
const NodeAttributes& na=NodeAttributes());
virtual void draw_pixel_buffer(PixelBuffer *pb, const DisplayRegion *dr,
const RenderBuffer &rb,
const NodeAttributes& na=NodeAttributes());
virtual void apply_material(Material*) { }
virtual void apply_fog(Fog*) { }
virtual void apply_light(PointLight*) { }
virtual void apply_light(DirectionalLight*) { }
virtual void apply_light(Spotlight*) { }
virtual void apply_light(AmbientLight*) { }
virtual void issue_transform(const TransformAttribute *attrib);
virtual void issue_color(const ColorAttribute *attrib);
virtual void issue_texture(const TextureAttribute *attrib);
virtual void issue_light(const LightAttribute *attrib);
// Normally, these functions are called through the RIBGraphicsWindow.
void set_texture_directory(const string &directory);
string get_texture_directory() const;
void set_texture_extension(const string &extension);
string get_texture_extension() const;
protected:
virtual PT(SavedFrameBuffer) save_frame_buffer(const RenderBuffer &buffer,
CPT(DisplayRegion) dr);
virtual void restore_frame_buffer(SavedFrameBuffer *frame_buffer);
void set_color(const RGBColorf &color);
void get_rib_stuff(Node *root, const AllAttributesWrapper &initial_state);
void define_texture(const Texture *tex);
void define_light(const Light *light);
void write_light_color(const Colorf &color) const;
void write_light_from(const Node *light) const;
void write_light_to(const Node *light) const;
ostream &new_line(int extra_indent = 0) const;
void reset_transform(const LMatrix4f &mat) const;
void concat_transform(const LMatrix4f &mat) const;
void draw_simple_poly(const Geom *geom);
void write_polygon(int num_verts);
static void get_color_and_intensity(const RGBColorf &input,
RGBColorf &output,
float &intensity);
RGBColorf _current_color;
string _texture_directory;
string _texture_extension;
ostream *_output;
int _indent_level;
typedef pmap<const Texture *, Filename> TextureNames;
TextureNames _texture_names;
typedef pmap<const Light *, int> LightIDs;
LightIDs _light_ids;
typedef pvector<bool> EnabledLights;
EnabledLights _enabled_lights;
public:
static GraphicsStateGuardian *
make_RIBGraphicsStateGuardian(const FactoryParams &params);
virtual TypeHandle get_type(void) const;
virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
static TypeHandle get_class_type(void);
static void init_type(void);
private:
static TypeHandle _type_handle;
friend class RibStuffTraverser;
};
#endif

View File

@ -1,52 +0,0 @@
// Filename: ribStuffTraverser.cxx
// Created by: drose (16Feb99)
//
////////////////////////////////////////////////////////////////////
//
// PANDA 3D SOFTWARE
// Copyright (c) 2001 - 2004, Disney Enterprises, Inc. All rights reserved
//
// All use of this software is subject to the terms of the Panda 3d
// Software license. You should have received a copy of this license
// along with this source code; you will also find a current copy of
// the license at http://etc.cmu.edu/panda3d/docs/license/ .
//
// To contact the maintainers of this program write to
// panda3d-general@lists.sourceforge.net .
//
////////////////////////////////////////////////////////////////////
#include "ribStuffTraverser.h"
#include "ribGraphicsStateGuardian.h"
#include "textureTransition.h"
#include "lightTransition.h"
#include "geomNode.h"
////////////////////////////////////////////////////////////////////
// Function: RibStuffTraverser::reached_node
// Access: Public
// Description: Called for each node of the scene graph; this does
// the work of identifying new things and registering
// them in the RIB file.
////////////////////////////////////////////////////////////////////
bool RibStuffTraverser::
reached_node(Node *node, AllTransitionsWrapper &state, NullLevelState &) {
if (node->is_of_type(GeomNode::get_class_type())) {
const TextureTransition *tex_attrib;
if (!get_transition_into(tex_attrib, state)) {
if (tex_attrib->is_on()) {
_gsg->define_texture(tex_attrib->get_texture());
}
}
const LightTransition *light_attrib;
if (!get_transition_into(light_attrib, state)) {
LightTransition::const_iterator li;
for (li = light_attrib->begin(); li != light_attrib->end(); ++li) {
_gsg->define_light(*li);
}
}
}
return true;
}

View File

@ -1,48 +0,0 @@
// Filename: ribStuffTraverser.h
// Created by: drose (16Feb99)
//
////////////////////////////////////////////////////////////////////
//
// PANDA 3D SOFTWARE
// Copyright (c) 2001 - 2004, Disney Enterprises, Inc. All rights reserved
//
// All use of this software is subject to the terms of the Panda 3d
// Software license. You should have received a copy of this license
// along with this source code; you will also find a current copy of
// the license at http://etc.cmu.edu/panda3d/docs/license/ .
//
// To contact the maintainers of this program write to
// panda3d-general@lists.sourceforge.net .
//
////////////////////////////////////////////////////////////////////
#ifndef RIBSTUFFTRAVERSER_H
#define RIBSTUFFTRAVERSER_H
#include "pandabase.h"
#include "traverserVisitor.h"
#include "renderRelation.h"
#include "allAttributesWrapper.h"
#include "allTransitionsWrapper.h"
#include "nullLevelState.h"
class RIBGraphicsStateGuardian;
////////////////////////////////////////////////////////////////////
// Class : RibStuffTraverser
// Description :
////////////////////////////////////////////////////////////////////
class RibStuffTraverser :
public TraverserVisitor<AllTransitionsWrapper, NullLevelState> {
public:
RibStuffTraverser(RIBGraphicsStateGuardian *gsg) : _gsg(gsg) { }
bool reached_node(Node *node, AllAttributesWrapper &state,
NullLevelState &);
public:
RIBGraphicsStateGuardian *_gsg;
};
#endif

View File

@ -1,37 +0,0 @@
// This directory is temporarily commented out so I don't have to port
// it to the new attribute-less environment yet.
// #define OTHER_LIBS dtoolconfig dtool
//
// #define BUILDING_DLL BUILDING_SHADER
//
// #begin lib_target
// #define TARGET shader
// #define LOCAL_LIBS \
// putil express display graph sgattrib light sgraphutil
//
// #define COMBINED_SOURCES $[TARGET]_composite1.cxx $[TARGET]_composite2.cxx
//
// #define SOURCES \
// casterShader.I casterShader.h config_shader.h outlineShader.h \
// planarReflector.h projtexShader.h projtexShadower.h shader.I \
// shader.h shaderTransition.I shaderTransition.h \
// spheretexHighlighter.h spheretexReflector.h \
// spheretexShader.h spotlightShader.h \
//
// #define INCLUDED_SOURCES \
// casterShader.cxx config_shader.cxx outlineShader.cxx \
// planarReflector.cxx projtexShader.cxx projtexShadower.cxx \
// shader.cxx shaderTransition.cxx spheretexHighlighter.cxx \
// spheretexReflector.cxx spheretexShader.cxx \
// spotlightShader.cxx
//
// #define INSTALL_HEADERS \
// casterShader.I casterShader.h outlineShader.h planarReflector.h \
// projtexShader.h projtexShadower.h shader.I shader.h \
// shaderTransition.I shaderTransition.h spheretexHighlighter.h \
// spheretexReflector.h spheretexShader.h spotlightShader.h
//
// #end lib_target
//

View File

@ -1,41 +0,0 @@
// Filename: casterShader.I
// Created by: mike (09Jan97)
//
////////////////////////////////////////////////////////////////////
//
// PANDA 3D SOFTWARE
// Copyright (c) 2001 - 2004, Disney Enterprises, Inc. All rights reserved
//
// All use of this software is subject to the terms of the Panda 3d
// Software license. You should have received a copy of this license
// along with this source code; you will also find a current copy of
// the license at http://etc.cmu.edu/panda3d/docs/license/ .
//
// To contact the maintainers of this program write to
// panda3d-general@lists.sourceforge.net .
//
////////////////////////////////////////////////////////////////////
int CasterShader::add_caster(NamedNode* node)
{
make_dirty();
_casters.push_back(node);
return (_casters.size());
}
////////////////////////////////////////////////////////////////////
// Function: CasterShader::remove_caster
// Access:
// Description:
////////////////////////////////////////////////////////////////////
int CasterShader::remove_caster(NamedNode* node)
{
make_dirty();
NamedNodeVector::iterator i;
for (i = _casters.begin(); i != _casters.end(); ++i) {
if ((*i) == node) {
_casters.erase(i);
return true;
}
}
return false;
}

View File

@ -1,23 +0,0 @@
// Filename: casterShader.cxx
// Created by: mike (09Jan97)
//
////////////////////////////////////////////////////////////////////
//
// PANDA 3D SOFTWARE
// Copyright (c) 2001 - 2004, Disney Enterprises, Inc. All rights reserved
//
// All use of this software is subject to the terms of the Panda 3d
// Software license. You should have received a copy of this license
// along with this source code; you will also find a current copy of
// the license at http://etc.cmu.edu/panda3d/docs/license/ .
//
// To contact the maintainers of this program write to
// panda3d-general@lists.sourceforge.net .
//
////////////////////////////////////////////////////////////////////
#include "casterShader.h"
////////////////////////////////////////////////////////////////////
// Static variables
////////////////////////////////////////////////////////////////////
TypeHandle CasterShader::_type_handle;

View File

@ -1,79 +0,0 @@
// Filename: casterShader.h
// Created by: mike (09Jan97)
//
////////////////////////////////////////////////////////////////////
//
// PANDA 3D SOFTWARE
// Copyright (c) 2001 - 2004, Disney Enterprises, Inc. All rights reserved
//
// All use of this software is subject to the terms of the Panda 3d
// Software license. You should have received a copy of this license
// along with this source code; you will also find a current copy of
// the license at http://etc.cmu.edu/panda3d/docs/license/ .
//
// To contact the maintainers of this program write to
// panda3d-general@lists.sourceforge.net .
//
////////////////////////////////////////////////////////////////////
#ifndef CASTERSHADER_H
#define CASTERSHADER_H
//
////////////////////////////////////////////////////////////////////
// Includes
////////////////////////////////////////////////////////////////////
#include "pandabase.h"
#include "shader.h"
////////////////////////////////////////////////////////////////////
// Defines
////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////
// Class : CasterShader
// Description : Frustum Shader that computes effect based on a list
// of "casting" objects
////////////////////////////////////////////////////////////////////
class EXPCL_SHADER CasterShader : public FrustumShader
{
protected:
CasterShader(void) : FrustumShader() { }
public:
virtual ~CasterShader(void) { }
INLINE int get_num_casters(void) const { return _casters.size(); }
INLINE int add_caster(NamedNode* node);
INLINE int remove_caster(NamedNode* node);
typedef pvector<NamedNode *> NamedNodeVector;
protected:
NamedNodeVector _casters;
public:
static TypeHandle get_class_type() {
return _type_handle;
}
static void init_type() {
FrustumShader::init_type();
register_type(_type_handle, "CasterShader",
FrustumShader::get_class_type());
}
virtual TypeHandle get_type() const {
return get_class_type();
}
virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
private:
static TypeHandle _type_handle;
};
#include "casterShader.I"
#endif

View File

@ -1,68 +0,0 @@
// Filename: config_shader.cxx
// Created by: drose (19Mar00)
//
////////////////////////////////////////////////////////////////////
//
// PANDA 3D SOFTWARE
// Copyright (c) 2001 - 2004, Disney Enterprises, Inc. All rights reserved
//
// All use of this software is subject to the terms of the Panda 3d
// Software license. You should have received a copy of this license
// along with this source code; you will also find a current copy of
// the license at http://etc.cmu.edu/panda3d/docs/license/ .
//
// To contact the maintainers of this program write to
// panda3d-general@lists.sourceforge.net .
//
////////////////////////////////////////////////////////////////////
#include "config_shader.h"
#include "casterShader.h"
#include "outlineShader.h"
#include "planarReflector.h"
#include "projtexShader.h"
#include "projtexShadower.h"
#include "shader.h"
#include "shaderTransition.h"
#include "spheretexHighlighter.h"
#include "spheretexReflector.h"
#include "spheretexShader.h"
#include "spotlightShader.h"
#include "dconfig.h"
Configure(config_shader);
NotifyCategoryDef(shader, "");
ConfigureFn(config_shader) {
CasterShader::init_type();
OutlineShader::init_type();
PlanarReflector::init_type();
ProjtexShader::init_type();
ProjtexShadower::init_type();
Shader::init_type();
FrustumShader::init_type();
ShaderTransition::init_type();
SpheretexHighlighter::init_type();
SpheretexReflector::init_type();
SpheretexShader::init_type();
SpotlightShader::init_type();
//Setup shader rendering orders
ShaderTransition::set_shader_order(ProjtexShadower::get_class_type(), 2);
ShaderTransition::set_shader_order(OutlineShader::get_class_type(), 4);
ShaderTransition::set_shader_order(ProjtexShader::get_class_type(), 4);
ShaderTransition::set_shader_order(SpheretexShader::get_class_type(), 4);
ShaderTransition::set_shader_order(SpotlightShader::get_class_type(), 4);
ShaderTransition::set_shader_order(SpheretexHighlighter::get_class_type(), 6);
ShaderTransition::set_shader_order(SpheretexReflector::get_class_type(), 8);
ShaderTransition::set_shader_order(PlanarReflector::get_class_type(), 10);
//Tell shaderTransition the shaders that require blending
ShaderTransition::set_shader_always_blend(SpotlightShader::get_class_type());
ShaderTransition::set_shader_always_blend(SpheretexHighlighter::get_class_type());
}

View File

@ -1,27 +0,0 @@
// Filename: config_shader.h
// Created by: drose (19Mar00)
//
////////////////////////////////////////////////////////////////////
//
// PANDA 3D SOFTWARE
// Copyright (c) 2001 - 2004, Disney Enterprises, Inc. All rights reserved
//
// All use of this software is subject to the terms of the Panda 3d
// Software license. You should have received a copy of this license
// along with this source code; you will also find a current copy of
// the license at http://etc.cmu.edu/panda3d/docs/license/ .
//
// To contact the maintainers of this program write to
// panda3d-general@lists.sourceforge.net .
//
////////////////////////////////////////////////////////////////////
#ifndef CONFIG_SHADER_H
#define CONFIG_SHADER_H
#include "pandabase.h"
#include "notifyCategoryProxy.h"
NotifyCategoryDecl(shader, EXPCL_SHADER, EXPTP_SHADER);
#endif

View File

@ -1,110 +0,0 @@
// Filename: outlineShader.cxx
// Created by: mike (09Jan97)
//
////////////////////////////////////////////////////////////////////
//
// PANDA 3D SOFTWARE
// Copyright (c) 2001 - 2004, Disney Enterprises, Inc. All rights reserved
//
// All use of this software is subject to the terms of the Panda 3d
// Software license. You should have received a copy of this license
// along with this source code; you will also find a current copy of
// the license at http://etc.cmu.edu/panda3d/docs/license/ .
//
// To contact the maintainers of this program write to
// panda3d-general@lists.sourceforge.net .
//
////////////////////////////////////////////////////////////////////
#include "outlineShader.h"
#include "lightTransition.h"
#include "dftraverser.h"
#include "depthTestTransition.h"
#include "graphicsStateGuardian.h"
#include "attribTraverser.h"
#include "renderModeTransition.h"
#include "cullFaceTransition.h"
#include "colorTransition.h"
#include "linesmoothTransition.h"
#include "directRenderTraverser.h"
#include "renderRelation.h"
////////////////////////////////////////////////////////////////////
// Static variables
////////////////////////////////////////////////////////////////////
TypeHandle OutlineShader::_type_handle;
////////////////////////////////////////////////////////////////////
// Function: OutlineShader::constructor
// Access:
// Description:
////////////////////////////////////////////////////////////////////
OutlineShader::OutlineShader(void) : Shader() {
set_color(Colorf(0, 0, 0, 1));
}
////////////////////////////////////////////////////////////////////
// Function: OutlineShader::constructor
// Access:
// Description:
////////////////////////////////////////////////////////////////////
OutlineShader::OutlineShader(const Colorf &color) : Shader() {
set_color(color);
}
////////////////////////////////////////////////////////////////////
// Function: OutlineShader::config
// Access:
// Description:
////////////////////////////////////////////////////////////////////
void OutlineShader::config(void) {
Configurable::config();
}
////////////////////////////////////////////////////////////////////
// Function: OutlineShader::apply
// Access:
// Description:
////////////////////////////////////////////////////////////////////
void OutlineShader::
apply(Node *node, const AllAttributesWrapper &init_state,
const AllTransitionsWrapper &net_trans, GraphicsStateGuardian *gsg) {
Shader::apply(node, init_state, net_trans, gsg);
DirectRenderTraverser drt(gsg, RenderRelation::get_class_type());
// If the node is un-textured, we need to render it once first (since
// the shader transition won't have drawn it unless it is textured
if (!is_textured(node, init_state)) {
gsg->render_subgraph(&drt, node, init_state, net_trans);
}
// Copy the transition wrapper so we can modify it freely.
AllTransitionsWrapper trans(net_trans);
// Turn lighting off
trans.set_transition(new LightTransition(LightTransition::all_off()));
// Enable line drawing
RenderModeTransition *rm =
new RenderModeTransition(RenderModeProperty::M_wireframe, 2.0);
trans.set_transition(rm);
// Enable line smooth
// LinesmoothTransition *lsm = new LinesmoothTransition;
// trans.set_transition(lsm);
// Draw shared edges
DepthTestTransition *dta =
new DepthTestTransition(DepthTestProperty::M_less_equal);
trans.set_transition(dta);
// Draw back facing edges only
CullFaceTransition *cf =
new CullFaceTransition(CullFaceProperty::M_cull_counter_clockwise);
trans.set_transition(cf);
// Set the outline color
ColorTransition *c = new ColorTransition(_color);
trans.set_transition(c);
gsg->render_subgraph(&drt, node, init_state, trans);
}

View File

@ -1,70 +0,0 @@
// Filename: outlineShader.h
// Created by: mike (09Jan97)
//
////////////////////////////////////////////////////////////////////
//
// PANDA 3D SOFTWARE
// Copyright (c) 2001 - 2004, Disney Enterprises, Inc. All rights reserved
//
// All use of this software is subject to the terms of the Panda 3d
// Software license. You should have received a copy of this license
// along with this source code; you will also find a current copy of
// the license at http://etc.cmu.edu/panda3d/docs/license/ .
//
// To contact the maintainers of this program write to
// panda3d-general@lists.sourceforge.net .
//
////////////////////////////////////////////////////////////////////
#ifndef OUTILNESHADER_H
#define OUTLINESHADER_H
//
////////////////////////////////////////////////////////////////////
// Includes
////////////////////////////////////////////////////////////////////
#include "pandabase.h"
#include "shader.h"
////////////////////////////////////////////////////////////////////
// Defines
////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////
// Class : OutlineShader
// Description :
////////////////////////////////////////////////////////////////////
class EXPCL_SHADER OutlineShader : public Shader {
public:
OutlineShader(void);
OutlineShader(const Colorf &color);
~OutlineShader() { }
virtual void config(void);
virtual void apply(Node *node, const AllAttributesWrapper &init_state,
const AllTransitionsWrapper &net_trans,
GraphicsStateGuardian *gsg);
INLINE void set_color(const Colorf &color) { _color = color; }
protected:
Colorf _color;
public:
static TypeHandle get_class_type() {
return _type_handle;
}
static void init_type() {
Shader::init_type();
register_type(_type_handle, "OutlineShader",
Shader::get_class_type());
}
virtual TypeHandle get_type() const {
return get_class_type();
}
virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
private:
static TypeHandle _type_handle;
};
#endif

View File

@ -1,360 +0,0 @@
// Filename: planarReflector.cxx
// Created by: mike (09Jan97)
//
////////////////////////////////////////////////////////////////////
//
// PANDA 3D SOFTWARE
// Copyright (c) 2001 - 2004, Disney Enterprises, Inc. All rights reserved
//
// All use of this software is subject to the terms of the Panda 3d
// Software license. You should have received a copy of this license
// along with this source code; you will also find a current copy of
// the license at http://etc.cmu.edu/panda3d/docs/license/ .
//
// To contact the maintainers of this program write to
// panda3d-general@lists.sourceforge.net .
//
////////////////////////////////////////////////////////////////////
#include "planarReflector.h"
#include "config_shader.h"
#include "pt_Node.h"
#include "dftraverser.h"
#include "attribTraverser.h"
#include "displayRegion.h"
#include "graphicsWindow.h"
#include "renderBuffer.h"
#include "perspectiveProjection.h"
#include "look_at.h"
#include "get_rel_pos.h"
#include "lightTransition.h"
#include "depthTestTransition.h"
#include "depthWriteTransition.h"
#include "depthWriteTransition.h"
#include "textureTransition.h"
#include "stencilTransition.h"
#include "colorBlendTransition.h"
#include "colorBlendAttribute.h"
#include "cullFaceTransition.h"
#include "transformTransition.h"
#include "colorMaskTransition.h"
#include "colorTransition.h"
#include "clipPlaneTransition.h"
#include "directRenderTraverser.h"
#include "nodeAttributes.h"
////////////////////////////////////////////////////////////////////
// Static variables
////////////////////////////////////////////////////////////////////
TypeHandle PlanarReflector::_type_handle;
////////////////////////////////////////////////////////////////////
// Function: PlanarReflector::Constructor
// Access:
// Description:
////////////////////////////////////////////////////////////////////
PlanarReflector::PlanarReflector(void) : CasterShader()
{
Colorf c(0.8f, 0.8f, 0.8f, 1.0f);
init(NULL, c);
}
////////////////////////////////////////////////////////////////////
// Function: PlanarReflector::Constructor
// Access:
// Description:
////////////////////////////////////////////////////////////////////
PlanarReflector::
PlanarReflector(PlaneNode* plane_node) : CasterShader()
{
Colorf c(0.8f, 0.8f, 0.8f, 1.0f);
init(plane_node, c);
}
////////////////////////////////////////////////////////////////////
// Function: PlanarReflector::Constructor
// Access:
// Description:
////////////////////////////////////////////////////////////////////
PlanarReflector::
PlanarReflector(const Colorf& c) : CasterShader()
{
init(NULL, c);
}
////////////////////////////////////////////////////////////////////
// Function: PlanarReflector::Constructor
// Access:
// Description:
////////////////////////////////////////////////////////////////////
PlanarReflector::
PlanarReflector(PlaneNode* plane_node, const Colorf& c) : CasterShader()
{
init(plane_node, c);
}
////////////////////////////////////////////////////////////////////
// Function: PlanarReflector::init
// Access:
// Description:
////////////////////////////////////////////////////////////////////
void PlanarReflector::init(PlaneNode *plane_node, const Colorf& c)
{
if (plane_node == NULL)
plane_node = new PlaneNode;
_save_color_buffer = true;
_save_depth_buffer = true;
_clip_to_plane = true;
_color_buffer = NULL;
_depth_buffer = NULL;
_plane_node = plane_node;
_color = c;
}
////////////////////////////////////////////////////////////////////
// Function: PlanarReflector::pre_apply
// Access:
// Description:
////////////////////////////////////////////////////////////////////
void PlanarReflector::
pre_apply(Node *, const AllAttributesWrapper &,
const AllTransitionsWrapper &, GraphicsStateGuardian *gsg)
{
int xo, yo, w, h;
gsg->get_current_display_region()->get_region_pixels(xo, yo, w, h);
_color_buffer = new PixelBuffer(PixelBuffer::rgb_buffer(w, h));
_depth_buffer = new PixelBuffer(PixelBuffer::depth_buffer(w, h));
}
////////////////////////////////////////////////////////////////////
// Function: PlanarReflector::apply
// Access:
// Description:
////////////////////////////////////////////////////////////////////
void PlanarReflector::
apply(Node *node, const AllAttributesWrapper &init_state,
const AllTransitionsWrapper &net_trans, GraphicsStateGuardian *gsg) {
DirectRenderTraverser drt(gsg, RenderRelation::get_class_type());
Shader::apply(node, init_state, net_trans, gsg);
init_state.write(shader_cat->debug(false), 4);
if (get_num_casters() == 0) {
shader_cat.error()
<< "PlanarReflector::apply() - no casters in caster list" << endl;
return;
}
//Due to possible priority problems, make an Off TextureTransition
//with a high priority to ensure that textures are indeed turned of
PT(TextureTransition) tex_off = new TextureTransition(TextureTransition::off());
tex_off->set_priority(100);
// If the node is un-textured, we need to render it once first (since
// the shader transition won't have drawn it unless it is textured)
if (!_multipass_on) {
gsg->render_subgraph(&drt, node, init_state, net_trans);
}
// Save the stencil buffer clear value for below
bool clear_stencil = gsg->get_stencil_clear_value();
gsg->set_stencil_clear_value(false);
{
// Copy the transition wrapper so we can modify it freely.
AllTransitionsWrapper trans(net_trans);
// Save the current fully-rendered scene that is in the back buffer
int buffer_mask = RenderBuffer::T_stencil;
if (_save_color_buffer) {
gsg->copy_pixel_buffer(_color_buffer,
gsg->get_current_display_region(),
gsg->get_render_buffer(RenderBuffer::T_back));
buffer_mask |= RenderBuffer::T_back;
ColorMaskTransition *cm = new ColorMaskTransition(0);
trans.set_transition(cm);
} else {
ColorMaskTransition *cm =
new ColorMaskTransition(ColorMaskProperty::M_a);
trans.set_transition(cm);
}
if (_save_depth_buffer)
{
gsg->copy_pixel_buffer(_depth_buffer,
gsg->get_current_display_region(),
gsg->get_render_buffer(RenderBuffer::T_depth));
// gsg->get_render_buffer(RenderBuffer::T_back));
}
// The scene has already been rendered so we need to stencil in an area
// on the reflecting plane that is covered by the reflected objects.
// Turn lighting off
trans.set_transition(new LightTransition(LightTransition::all_off()));
// Set the depth test to M_equal (? Or should this be M_none?)
DepthTestTransition *dta =
new DepthTestTransition(DepthTestProperty::M_equal);
trans.set_transition(dta);
// Turn off writes to the depth buffer
DepthWriteTransition *dwa = new DepthWriteTransition;
dwa->set_off();
trans.set_transition(dwa);
// Enable the stencil buffer
StencilTransition *sa =
new StencilTransition(StencilProperty::M_not_equal,
StencilProperty::A_replace);
trans.set_transition(sa);
// Disable texturing
trans.set_transition(tex_off);
// Disable blending
trans.set_transition(new ColorBlendTransition(ColorBlendProperty::M_none));
// Clear the stencil buffer (and color buffer if we're saving it)
gsg->clear(gsg->get_render_buffer(buffer_mask));
// Draw the reflecting object
gsg->render_subgraph(&drt, node, init_state, trans);
}
{
// Reflecting area on the plane has a stencil value of 1. We can now
// draw the reflected objects into this area.
gsg->clear(gsg->get_render_buffer(RenderBuffer::T_depth));
// Copy the transition wrapper so we can modify it freely.
AllTransitionsWrapper trans(net_trans);
// Adjust the stencil buffer properties
StencilTransition *sa =
new StencilTransition(StencilProperty::M_equal,
StencilProperty::A_keep);
trans.set_transition(sa);
// Draw back facing polys only
CullFaceTransition *cf =
new CullFaceTransition(CullFaceProperty::M_cull_counter_clockwise);
trans.set_transition(cf);
if (_clip_to_plane) {
// Clip to the indicated plane.
ClipPlaneTransition *cp = new ClipPlaneTransition;
cp->set_on(_plane_node);
trans.set_transition(cp);
}
// Reflect objects about the given plane
PT_Node caster_group = new Node;
NamedNodeVector::iterator c;
for (c = _casters.begin(); c != _casters.end(); ++c) {
Node *caster = (*c);
LMatrix4f mat;
get_rel_mat(caster, _plane_node, mat);
RenderRelation *arc = new RenderRelation(caster_group, caster);
arc->set_transition(new TransformTransition(mat));
}
// Parent this caster group to the node itself, since it's already
// converted to the coordinate space of the node.
PT(RenderRelation) caster_arc =
new RenderRelation(_plane_node, caster_group);
LMatrix4f plane_mat = _plane_node->get_plane().get_reflection_mat();
caster_arc->set_transition(new TransformTransition(plane_mat));
// Draw the reflected objects
gsg->render_subgraph(&drt, _plane_node, init_state, trans);
// Remove the caster group from the scene graph. This will also
// delete the temporary group node (since the reference count is
// zero), but not the caster objects themselves.
remove_arc(caster_arc);
}
{
// Draw the reflecting object once more to modulate the reflected objects
// by the reflectivity color
AllTransitionsWrapper trans(net_trans);
trans.set_transition(new StencilTransition(StencilProperty::M_none));
ColorBlendTransition *cb =
new ColorBlendTransition(ColorBlendProperty::M_multiply);
trans.set_transition(cb);
ColorTransition *c = new ColorTransition;
c->set_on(_color);
trans.set_transition(c);
trans.set_transition(new LightTransition(LightTransition::all_off()));
trans.set_transition(tex_off);
gsg->render_subgraph(&drt, node, init_state, trans);
}
// Blend the previously rendered image with the reflected image
if (_save_color_buffer) {
NodeAttributes na;
ColorBlendAttribute *cb =
new ColorBlendAttribute;
cb->set_mode(ColorBlendProperty::M_add);
na.set_attribute(ColorBlendTransition::get_class_type(), cb);
gsg->draw_pixel_buffer(_color_buffer, gsg->get_current_display_region(),
gsg->get_render_buffer(RenderBuffer::T_back), na);
} else {
// One more pass to redraw the reflecting object (additive blending)
// Final color is reflecting obj color + (ref. obj. color * reflectivity)
AllTransitionsWrapper trans(net_trans);
StencilTransition *sa =
new StencilTransition(StencilProperty::M_equal,
StencilProperty::A_keep);
trans.set_transition(sa);
DepthTestTransition *dta =
new DepthTestTransition(DepthTestProperty::M_equal);
trans.set_transition(dta);
DepthWriteTransition *dwa = new DepthWriteTransition;
dwa->set_off();
trans.set_transition(dwa);
ColorBlendTransition *cb =
new ColorBlendTransition(ColorBlendProperty::M_add);
trans.set_transition(cb);
gsg->render_subgraph(&drt, node, init_state, trans);
}
if (_save_depth_buffer)
{
gsg->draw_pixel_buffer(_depth_buffer, gsg->get_current_display_region(),
gsg->get_render_buffer(RenderBuffer::T_depth));
// gsg->get_render_buffer(RenderBuffer::T_back));
}
// Restore the stencil buffer clear value
gsg->set_stencil_clear_value(clear_stencil);
}

View File

@ -1,94 +0,0 @@
// Filename: planarReflector.h
// Created by: mike (09Jan97)
//
////////////////////////////////////////////////////////////////////
//
// PANDA 3D SOFTWARE
// Copyright (c) 2001 - 2004, Disney Enterprises, Inc. All rights reserved
//
// All use of this software is subject to the terms of the Panda 3d
// Software license. You should have received a copy of this license
// along with this source code; you will also find a current copy of
// the license at http://etc.cmu.edu/panda3d/docs/license/ .
//
// To contact the maintainers of this program write to
// panda3d-general@lists.sourceforge.net .
//
////////////////////////////////////////////////////////////////////
#ifndef PLANARREFLECTOR_H
#define PLANARREFLECTOR_H
//
////////////////////////////////////////////////////////////////////
// Includes
////////////////////////////////////////////////////////////////////
#include "pandabase.h"
#include "casterShader.h"
#include "pixelBuffer.h"
#include "planeNode.h"
////////////////////////////////////////////////////////////////////
// Defines
////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////
// Class : PlanarReflector
// Description : Reflects about a specified plane
////////////////////////////////////////////////////////////////////
class EXPCL_SHADER PlanarReflector : public CasterShader
{
public:
PlanarReflector(void);
PlanarReflector(PlaneNode* plane_node);
PlanarReflector(const Colorf& c);
PlanarReflector(PlaneNode* plane_node, const Colorf& c);
virtual void pre_apply(Node *node, const AllAttributesWrapper &init_state,
const AllTransitionsWrapper &net_trans,
GraphicsStateGuardian *gsg);
virtual void apply(Node *node, const AllAttributesWrapper &init_state,
const AllTransitionsWrapper &net_trans,
GraphicsStateGuardian *gsg);
INLINE void set_save_color_buffer(bool val) { _save_color_buffer = val; }
INLINE void set_save_depth_buffer(bool val) { _save_depth_buffer = val; }
INLINE void set_clip_to_plane(bool val) { _clip_to_plane = val; }
INLINE void set_plane_node(PlaneNode* p) { _plane_node = p; }
INLINE void set_color(const Colorf& c) { _color = c; }
protected:
void init(PlaneNode* plane_node, const Colorf& c);
protected:
bool _save_color_buffer;
bool _save_depth_buffer;
bool _clip_to_plane;
PT(PixelBuffer) _color_buffer;
PT(PixelBuffer) _depth_buffer;
PT(PlaneNode) _plane_node;
Colorf _color;
public:
static TypeHandle get_class_type() {
return _type_handle;
}
static void init_type() {
CasterShader::init_type();
register_type(_type_handle, "PlanarReflector",
CasterShader::get_class_type());
}
virtual TypeHandle get_type() const {
return get_class_type();
}
virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
private:
static TypeHandle _type_handle;
};
#endif

View File

@ -1,154 +0,0 @@
// Filename: projtexShader.cxx
// Created by: mike (09Jan97)
//
////////////////////////////////////////////////////////////////////
//
// PANDA 3D SOFTWARE
// Copyright (c) 2001 - 2004, Disney Enterprises, Inc. All rights reserved
//
// All use of this software is subject to the terms of the Panda 3d
// Software license. You should have received a copy of this license
// along with this source code; you will also find a current copy of
// the license at http://etc.cmu.edu/panda3d/docs/license/ .
//
// To contact the maintainers of this program write to
// panda3d-general@lists.sourceforge.net .
//
////////////////////////////////////////////////////////////////////
#include "projtexShader.h"
#include "config_shader.h"
#include "lightTransition.h"
#include "textureTransition.h"
#include "get_rel_pos.h"
#include "dftraverser.h"
#include "colorBlendTransition.h"
#include "depthTestTransition.h"
#include "graphicsStateGuardian.h"
#include "texGenTransition.h"
#include "texMatrixTransition.h"
#include "perspectiveProjection.h"
#include "attribTraverser.h"
#include "textureApplyTransition.h"
#include "directRenderTraverser.h"
////////////////////////////////////////////////////////////////////
// Static variables
////////////////////////////////////////////////////////////////////
TypeHandle ProjtexShader::_type_handle;
////////////////////////////////////////////////////////////////////
// Function: ProjtexShader::constructor
// Access:
// Description:
////////////////////////////////////////////////////////////////////
ProjtexShader::ProjtexShader(Texture* texture,
ColorBlendProperty::Mode mode)
: FrustumShader(), _blend(mode)
{
set_texture(texture);
}
////////////////////////////////////////////////////////////////////
// Function: ProjtexShader::config
// Access:
// Description:
////////////////////////////////////////////////////////////////////
void ProjtexShader::config(void)
{
Configurable::config();
nassertv(_texture != (Texture *)NULL);
}
////////////////////////////////////////////////////////////////////
// Function: ProjtexShader::apply
// Access:
// Description:
////////////////////////////////////////////////////////////////////
void ProjtexShader::
apply(Node *node, const AllAttributesWrapper &init_state,
const AllTransitionsWrapper &net_trans, GraphicsStateGuardian *gsg) {
Shader::apply(node, init_state, net_trans, gsg);
// Make sure the shader has been configured properly
if (get_num_frusta() == 0) {
shader_cat.error()
<< "ProjtexShader::apply() - frusta list is empty" << endl;
return;
} else if (get_num_frusta() > 1) {
shader_cat.warning()
<< "ProjtexShader::apply() - frusta list has more than one "
<< "- ignoring all but first one for now..." << endl;
}
// Copy the transition wrapper so we can modify it freely.
AllTransitionsWrapper trans(net_trans);
// Create the texture projector transition
// NOTE: If the node being projected upon has its own textures,
// we need to render it first with its own texturing before
// this projected texture pass and then blend the results
LMatrix4f model_mat;
const Projection* projection = _frusta[0]->get_projection();
get_rel_mat(node, _frusta[0], model_mat);
// Create the texture generation transition
TexGenTransition *tg = new TexGenTransition;
tg->set_texture_projector();
trans.set_transition(tg);
// Create the texture transition
nassertv(_texture != (Texture *)NULL);
TextureTransition *t = new TextureTransition;
t->set_on(_texture);
t->set_priority(_priority);
trans.set_transition(t);
if (_viz != (Shader::Visualize*)0L)
_viz->DisplayTexture(_texture, this);
// Create the texture matrix transition
// Define texture matrix so that object space coords used as
// tex coords will be projected onto the frustum's viewing plane
// An additional scale and translate is required to go from x,y
// NDC coords in [-1,1] to tex coords [0,1]
LMatrix4f tex_mat, proj_mat;
const PerspectiveProjection *pp = DCAST(PerspectiveProjection, projection);
proj_mat = pp->get_projection_mat();
tex_mat = model_mat * proj_mat *
LMatrix4f::scale_mat(LVector3f(0.5,0.5,1)) *
LMatrix4f::translate_mat(LVector3f(0.5,0.5,0));
TexMatrixTransition *tm = new TexMatrixTransition;
tm->set_matrix(tex_mat);
trans.set_transition(tm);
// Turn lighting off
trans.set_transition(new LightTransition(LightTransition::all_off()));
// Do some extra work if we're doing the 2-pass version (e.g. the
// object we are shading is textured)
if (_multipass_on) {
//Probably should move the brains for determing blending out to
//shader transition
// Set a color blend mode that assumes this is a second pass over
// textured geometry
ColorBlendTransition *cb = new ColorBlendTransition(_blend);
trans.set_transition(cb);
TextureApplyTransition *ta =
new TextureApplyTransition(TextureApplyProperty::M_decal);
trans.set_transition(ta);
// Set the depth test to M_equal (? Or should this be M_none?)
DepthTestTransition *dta =
new DepthTestTransition(DepthTestProperty::M_equal);
trans.set_transition(dta);
}
DirectRenderTraverser drt(gsg, RenderRelation::get_class_type());
gsg->render_subgraph(&drt, node, init_state, trans);
}

View File

@ -1,72 +0,0 @@
// Filename: projtexShader.h
// Created by: mike (09Jan97)
//
////////////////////////////////////////////////////////////////////
//
// PANDA 3D SOFTWARE
// Copyright (c) 2001 - 2004, Disney Enterprises, Inc. All rights reserved
//
// All use of this software is subject to the terms of the Panda 3d
// Software license. You should have received a copy of this license
// along with this source code; you will also find a current copy of
// the license at http://etc.cmu.edu/panda3d/docs/license/ .
//
// To contact the maintainers of this program write to
// panda3d-general@lists.sourceforge.net .
//
////////////////////////////////////////////////////////////////////
#ifndef PROJTEXSHADER_H
#define PROJTEXSHADER_H
#include "pandabase.h"
#include "shader.h"
#include "texture.h"
#include "colorBlendProperty.h"
////////////////////////////////////////////////////////////////////
// Class : ProjtexShader
// Description :
////////////////////////////////////////////////////////////////////
class EXPCL_SHADER ProjtexShader : public FrustumShader {
public:
ProjtexShader(Texture* texture = NULL,
ColorBlendProperty::Mode mode = ColorBlendProperty::M_multiply);
~ProjtexShader() { }
virtual void config();
virtual void apply(Node *node, const AllAttributesWrapper &init_state,
const AllTransitionsWrapper &net_trans,
GraphicsStateGuardian *gsg);
INLINE void set_texture(Texture* texture) {
_texture = texture;
make_dirty();
}
INLINE Texture* get_texture() { return _texture; }
protected:
PT(Texture) _texture;
ColorBlendProperty::Mode _blend;
public:
static TypeHandle get_class_type() {
return _type_handle;
}
static void init_type() {
FrustumShader::init_type();
register_type(_type_handle, "ProjtexShader",
FrustumShader::get_class_type());
}
virtual TypeHandle get_type() const {
return get_class_type();
}
virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
private:
static TypeHandle _type_handle;
};
#endif

View File

@ -1,259 +0,0 @@
// Filename: projtexShadower.cxx
// Created by: mike (09Jan97)
//
////////////////////////////////////////////////////////////////////
//
// PANDA 3D SOFTWARE
// Copyright (c) 2001 - 2004, Disney Enterprises, Inc. All rights reserved
//
// All use of this software is subject to the terms of the Panda 3d
// Software license. You should have received a copy of this license
// along with this source code; you will also find a current copy of
// the license at http://etc.cmu.edu/panda3d/docs/license/ .
//
// To contact the maintainers of this program write to
// panda3d-general@lists.sourceforge.net .
//
////////////////////////////////////////////////////////////////////
#include "projtexShadower.h"
#include "config_shader.h"
#include "light.h"
#include "spotlight.h"
#include "renderBuffer.h"
#include "transformTransition.h"
#include "lightTransition.h"
#include "textureTransition.h"
#include "colorBlendTransition.h"
#include "colorTransition.h"
#include "depthTestTransition.h"
#include "depthWriteTransition.h"
#include "polygonOffsetTransition.h"
#include "get_rel_pos.h"
#include "dftraverser.h"
#include "displayRegion.h"
#include "graphicsWindow.h"
#include "directRenderTraverser.h"
////////////////////////////////////////////////////////////////////
// Static variables
////////////////////////////////////////////////////////////////////
TypeHandle ProjtexShadower::_type_handle;
////////////////////////////////////////////////////////////////////
// Function: ProjtexShadower::Constructor
// Access:
// Description:
////////////////////////////////////////////////////////////////////
ProjtexShadower::ProjtexShadower(int size) : CasterShader()
{
set_size(size);
Texture* texture = new Texture;
texture->set_minfilter(Texture::FT_linear);
texture->set_magfilter(Texture::FT_linear);
texture->set_wrapu(Texture::WM_clamp);
texture->set_wrapv(Texture::WM_clamp);
texture->_pbuffer->set_xsize(_size);
texture->_pbuffer->set_ysize(_size);
_projtex_shader = new ProjtexShader(texture, ColorBlendProperty::M_multiply);
}
////////////////////////////////////////////////////////////////////
// Function: ProjtexShadower::set_priority
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
void ProjtexShadower::
set_priority(int priority)
{
Shader::set_priority(priority);
_projtex_shader->set_priority(priority);
}
////////////////////////////////////////////////////////////////////
// Function: ProjtexShadower::set_multipass
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
void ProjtexShadower::
set_multipass(bool on)
{
Shader::set_multipass(on);
_projtex_shader->set_multipass(on);
}
////////////////////////////////////////////////////////////////////
// Function: ProjtexShadower::pre_apply
// Access:
// Description:
////////////////////////////////////////////////////////////////////
void ProjtexShadower::
pre_apply(Node *node, const AllAttributesWrapper &init_state,
const AllTransitionsWrapper &net_trans, GraphicsStateGuardian *gsg)
{
DirectRenderTraverser drt(gsg, RenderRelation::get_class_type());
int num_lights = 1;
if (get_num_casters() == 0) {
shader_cat.error()
<< "ProjtexShadower::config() - no casters in caster list" << endl;
return;
}
if (get_num_frusta() == 0) {
shader_cat.error()
<< "ProjtexShadower::config() - no lights in frusta list" << endl;
return;
} else if (get_num_frusta() > 1) {
shader_cat.warning()
<< "ProjtexShadower::config() - frusta list has more than one "
<< "frustum - ignore all but the first one for now..." << endl;
num_lights = 1;
}
if (_frusta[0]->get_type() != Spotlight::get_class_type()) {
shader_cat.error()
<< "ProjtexShadower::config() - only works for Spotlights" << endl;
return;
}
Spotlight* light = (Spotlight *)_frusta[0];
// Save the current display region from the gsg
Colorf clear_color = gsg->get_color_clear_value();
// Make sure the projtex shader has the same frustum
_projtex_shader->remove_frustum(light);
_projtex_shader->add_frustum(light);
// Compute an approximation for the shadow color
Colorf diffuse = light->get_color();
Colorf shadow_color;
for (int i = 0; i < 4; i++) {
shadow_color[i] = 1.0 / ((diffuse[i] + 1) * num_lights);
}
nassertv(node != (Node *)NULL && gsg != (GraphicsStateGuardian *)NULL);
// First, draw the receiving node quickly (with no rendering attributes)
// from the point of view of the light
// Make a display region of the proper size and clear it to prepare for
// rendering the shadow map
PT(DisplayRegion) disp_region =
gsg->get_window()->make_scratch_display_region(_size, _size);
DisplayRegionStack old_dr = gsg->push_display_region(disp_region);
// Save scratch region before clearing it to be non-destructive
FrameBufferStack old_fb = gsg->push_frame_buffer
(gsg->get_render_buffer(RenderBuffer::T_back | RenderBuffer::T_depth),
disp_region);
gsg->set_color_clear_value(Colorf(1., 1., 1., 1.));
gsg->clear(gsg->get_render_buffer(RenderBuffer::T_back |
RenderBuffer::T_depth), disp_region);
// Copy the transition wrapper so we can modify it freely.
AllTransitionsWrapper trans(net_trans);
// Disable lighting, texturing, blending, dithering
trans.set_transition(new LightTransition(LightTransition::all_off()));
//The 100 is to set the priority of this transition high enough
//(hopefully) to turn off any existing texture in the geometry
TextureTransition *t = new TextureTransition(TextureTransition::off());
t->set_priority(100);
trans.set_transition(t);
trans.set_transition(new ColorBlendTransition(ColorBlendProperty::M_none));
//We need a state that we can modify to remove the camera transform
//that is passed to us
AllAttributesWrapper state(init_state);
state.clear_attribute(TransformTransition::get_class_type());
// Render the node with the new transitions from the viewpoint of the light
gsg->render_subgraph(&drt, node, light, state, trans);
// Now draw each of the casting objects in the shadow color using the
// depth buffer from the receiving object (this will project the shadows
// onto the surface properly), and use this to generate the shadow texture
// map
DepthTestTransition *dta =
new DepthTestTransition(DepthTestProperty::M_less);
trans.set_transition(dta);
DepthWriteTransition *dwa = new DepthWriteTransition;
trans.set_transition(dwa);
ColorTransition *ca = new ColorTransition(shadow_color);
trans.set_transition(ca);
// Create a temporary node that is the parent of all of the caster
// objects, so we can render them from the point of view of the
// light.
PT_Node caster_group = new Node;
NamedNodeVector::iterator ci;
for (ci = _casters.begin(); ci != _casters.end(); ++ci) {
Node *caster = (*ci);
LMatrix4f mat;
get_rel_mat(caster, node, mat);
RenderRelation *arc = new RenderRelation(caster_group, caster);
arc->set_transition(new TransformTransition(mat));
}
// Parent this caster group to the node itself, since it's already
// converted to the coordinate space of the node
PT(RenderRelation) caster_arc = new RenderRelation(node, caster_group);
// Now render the group.
gsg->render_subgraph(&drt, caster_group, light, state, trans);
// Remove the caster group from the scene graph. This will also
// delete the temporary group node (since the reference count is
// zero), but not the caster objects themselves.
remove_arc(caster_arc);
// Copy the results of the render from the framebuffer into the projtex
// shader's texture
// _projtex_shader->get_texture()->prepare(gsg);
_projtex_shader->get_texture()->copy(gsg, disp_region, gsg->get_render_buffer(RenderBuffer::T_back));
// Restore the original display region and clear value
gsg->set_color_clear_value(clear_color);
gsg->pop_frame_buffer(old_fb);
gsg->pop_display_region(old_dr);
}
////////////////////////////////////////////////////////////////////
// Function: ProjtexShadower::apply
// Access:
// Description:
////////////////////////////////////////////////////////////////////
void ProjtexShadower::
apply(Node *node, const AllAttributesWrapper &init_state,
const AllTransitionsWrapper &net_trans, GraphicsStateGuardian *gsg) {
Shader::apply(node, init_state, net_trans, gsg);
// Now apply the projected shadow map
_projtex_shader->apply(node, init_state, net_trans, gsg);
}

View File

@ -1,88 +0,0 @@
// Filename: projtexShadower.h
// Created by: mike (09Jan97)
//
////////////////////////////////////////////////////////////////////
//
// PANDA 3D SOFTWARE
// Copyright (c) 2001 - 2004, Disney Enterprises, Inc. All rights reserved
//
// All use of this software is subject to the terms of the Panda 3d
// Software license. You should have received a copy of this license
// along with this source code; you will also find a current copy of
// the license at http://etc.cmu.edu/panda3d/docs/license/ .
//
// To contact the maintainers of this program write to
// panda3d-general@lists.sourceforge.net .
//
////////////////////////////////////////////////////////////////////
#ifndef PROJTEXSHADOWER_H
#define PROJTEXSHADOWER_H
//
////////////////////////////////////////////////////////////////////
// Includes
////////////////////////////////////////////////////////////////////
#include "pandabase.h"
#include "casterShader.h"
#include "projtexShader.h"
#include "pt_Node.h"
////////////////////////////////////////////////////////////////////
// Defines
////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////
// Class : ProjtexShadower
// Description : Creates the shadow of a casting object(s) and projects
// it onto a receiving object(s) from a given light
// frustum
////////////////////////////////////////////////////////////////////
class EXPCL_SHADER ProjtexShadower : public CasterShader {
public:
ProjtexShadower(int size = 256);
virtual void pre_apply(Node *node, const AllAttributesWrapper &init_state,
const AllTransitionsWrapper &net_trans,
GraphicsStateGuardian *gsg);
virtual void apply(Node *node, const AllAttributesWrapper &init_state,
const AllTransitionsWrapper &net_trans,
GraphicsStateGuardian *gsg);
// MPG - should we make this check for powers of 2?
INLINE void set_size(int size) { _size = size; }
INLINE int get_size(void) { return _size; }
//Override base class shader's set_priority to allow
//us to set the priority of the contained projtex_shader at
//the same time
virtual void set_priority(int priority);
virtual void set_multipass(bool on);
protected:
PT(ProjtexShader) _projtex_shader;
int _size;
public:
static TypeHandle get_class_type() {
return _type_handle;
}
static void init_type() {
CasterShader::init_type();
register_type(_type_handle, "ProjtexShadower",
CasterShader::get_class_type());
}
virtual TypeHandle get_type() const {
return get_class_type();
}
virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
private:
static TypeHandle _type_handle;
};
#endif

View File

@ -1,61 +0,0 @@
// Filename: shader.I
// Created by: mike (09Jan97)
//
////////////////////////////////////////////////////////////////////
//
// PANDA 3D SOFTWARE
// Copyright (c) 2001 - 2004, Disney Enterprises, Inc. All rights reserved
//
// All use of this software is subject to the terms of the Panda 3d
// Software license. You should have received a copy of this license
// along with this source code; you will also find a current copy of
// the license at http://etc.cmu.edu/panda3d/docs/license/ .
//
// To contact the maintainers of this program write to
// panda3d-general@lists.sourceforge.net .
//
////////////////////////////////////////////////////////////////////
INLINE Shader::
Visualize* Shader::get_viz(void) {
return _viz;
}
////////////////////////////////////////////////////////////////////
// Function: Shader::set_viz
// Access:
// Description:
////////////////////////////////////////////////////////////////////
INLINE void Shader::
set_viz(Shader::Visualize* v) {
_viz = v;
}
////////////////////////////////////////////////////////////////////
// Function: FrustumShader::add_frustum
// Access:
// Description:
////////////////////////////////////////////////////////////////////
INLINE int FrustumShader::
add_frustum(LensNode* frust) {
make_dirty();
_frusta.push_back(frust);
return (_frusta.size());
}
////////////////////////////////////////////////////////////////////
// Function: FrustumShader::remove_frustum
// Access:
// Description:
////////////////////////////////////////////////////////////////////
INLINE int FrustumShader::
remove_frustum(LensNode* frust) {
make_dirty();
LensVector::iterator i;
for (i = _frusta.begin(); i != _frusta.end(); ++i) {
if ((*i) == frust) {
_frusta.erase(i);
return true;
}
}
return false;
}

View File

@ -1,120 +0,0 @@
// Filename: shader.cxx
// Created by: mike (09Jan97)
//
////////////////////////////////////////////////////////////////////
//
// PANDA 3D SOFTWARE
// Copyright (c) 2001 - 2004, Disney Enterprises, Inc. All rights reserved
//
// All use of this software is subject to the terms of the Panda 3d
// Software license. You should have received a copy of this license
// along with this source code; you will also find a current copy of
// the license at http://etc.cmu.edu/panda3d/docs/license/ .
//
// To contact the maintainers of this program write to
// panda3d-general@lists.sourceforge.net .
//
////////////////////////////////////////////////////////////////////
#include "shader.h"
////////////////////////////////////////////////////////////////////
// Static variables
////////////////////////////////////////////////////////////////////
TypeHandle Shader::_type_handle;
TypeHandle FrustumShader::_type_handle;
Shader::Visualize* Shader::_viz = (Shader::Visualize*)0L;
////////////////////////////////////////////////////////////////////
// Function: Shader::Constructor
// Access: Protected
// Description:
////////////////////////////////////////////////////////////////////
Shader::
Shader() : Configurable(), _priority(0) {
MemoryUsage::update_type(this, this);
}
Shader::Visualize::Visualize(void)
{
}
Shader::Visualize::~Visualize(void)
{
}
void Shader::Visualize::DisplayTexture(PT(Texture)&, Shader*)
{
}
void Shader::Visualize::DisplayPixelBuffer(PT(PixelBuffer)&, Shader*)
{
}
void Shader::Visualize::Flush(void)
{
}
////////////////////////////////////////////////////////////////////
// Function: Shader::apply
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
void Shader::
apply(Node *, const AllAttributesWrapper &,
const AllTransitionsWrapper &,
GraphicsStateGuardian *)
{
if (is_dirty()) config();
}
////////////////////////////////////////////////////////////////////
// Function: Shader::pre_apply
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
void Shader::
pre_apply(Node *, const AllAttributesWrapper &,
const AllTransitionsWrapper &,
GraphicsStateGuardian *)
{
}
////////////////////////////////////////////////////////////////////
// Function: Shader::set_priority
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
void Shader::
set_priority(int priority)
{
_priority = priority;
}
////////////////////////////////////////////////////////////////////
// Function: Shader::get_priority
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
int Shader::
get_priority(void) const
{
return _priority;
}
////////////////////////////////////////////////////////////////////
// Function: Shader::set_multipass
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
void Shader::
set_multipass(bool on)
{
_multipass_on = on;
}

View File

@ -1,153 +0,0 @@
// Filename: shader.h
// Created by: mike (09Jan97)
//
////////////////////////////////////////////////////////////////////
//
// PANDA 3D SOFTWARE
// Copyright (c) 2001 - 2004, Disney Enterprises, Inc. All rights reserved
//
// All use of this software is subject to the terms of the Panda 3d
// Software license. You should have received a copy of this license
// along with this source code; you will also find a current copy of
// the license at http://etc.cmu.edu/panda3d/docs/license/ .
//
// To contact the maintainers of this program write to
// panda3d-general@lists.sourceforge.net .
//
////////////////////////////////////////////////////////////////////
#ifndef SHADER_H
#define SHADER_H
//
////////////////////////////////////////////////////////////////////
// Includes
////////////////////////////////////////////////////////////////////
#include "pandabase.h"
#include "configurable.h"
#include "namedNode.h"
#include "lensNode.h"
#include "typedReferenceCount.h"
#include "graphicsStateGuardian.h"
#include "allAttributesWrapper.h"
#include "allTransitionsWrapper.h"
#include "pointerTo.h"
////////////////////////////////////////////////////////////////////
// Defines
////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////
// Class : Shader
// Description : Renders an effect on a list of receiving objects
////////////////////////////////////////////////////////////////////
class EXPCL_SHADER Shader : public ReferenceCount, public Configurable
{
protected:
Shader();
int _priority;
bool _multipass_on;
public:
virtual ~Shader(void) { }
virtual void pre_apply(Node *, const AllAttributesWrapper &,
const AllTransitionsWrapper &,
GraphicsStateGuardian *);
virtual void apply(Node *, const AllAttributesWrapper &,
const AllTransitionsWrapper &,
GraphicsStateGuardian *);
virtual void set_priority(int priority);
virtual int get_priority(void) const;
virtual void set_multipass(bool on);
public:
// This is used to visualize partial results, for debugging (and demos)
class EXPCL_SHADER Visualize {
public:
Visualize(void);
virtual ~Visualize(void);
virtual void DisplayTexture(PT(Texture)&, Shader*) = 0;
virtual void DisplayPixelBuffer(PT(PixelBuffer)&, Shader*) = 0;
virtual void Flush(void) = 0;
};
static INLINE Visualize* get_viz(void);
static INLINE void set_viz(Visualize*);
static TypeHandle get_class_type() {
return _type_handle;
}
static void init_type() {
ReferenceCount::init_type();
Configurable::init_type();
register_type(_type_handle, "Shader",
ReferenceCount::get_class_type(),
Configurable::get_class_type());
}
virtual TypeHandle get_type() const {
return get_class_type();
}
virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
static Visualize* _viz;
private:
static TypeHandle _type_handle;
};
////////////////////////////////////////////////////////////////////
// Class : FrustumShader
// Description : Shader that computes effect based on a frustum
// (most often a light or a camera) for a list of
// receiving objects
////////////////////////////////////////////////////////////////////
class EXPCL_SHADER FrustumShader : public Shader
{
protected:
FrustumShader(void) : Shader() { }
public:
virtual ~FrustumShader(void) { }
INLINE int get_num_frusta(void) const { return _frusta.size(); }
INLINE int add_frustum(LensNode* frust);
INLINE int remove_frustum(LensNode* frust);
typedef pvector<LensNode *> LensVector;
protected:
LensVector _frusta;
public:
static TypeHandle get_class_type() {
return _type_handle;
}
static void init_type() {
Shader::init_type();
register_type(_type_handle, "FrustumShader",
Shader::get_class_type());
}
virtual TypeHandle get_type() const {
return get_class_type();
}
private:
static TypeHandle _type_handle;
};
#include "shader.I"
#endif

View File

@ -1,80 +0,0 @@
// Filename: shaderTransition.I
// Created by: drose (24Mar00)
//
////////////////////////////////////////////////////////////////////
//
// PANDA 3D SOFTWARE
// Copyright (c) 2001 - 2004, Disney Enterprises, Inc. All rights reserved
//
// All use of this software is subject to the terms of the Panda 3d
// Software license. You should have received a copy of this license
// along with this source code; you will also find a current copy of
// the license at http://etc.cmu.edu/panda3d/docs/license/ .
//
// To contact the maintainers of this program write to
// panda3d-general@lists.sourceforge.net .
//
////////////////////////////////////////////////////////////////////
#include <algorithm>
////////////////////////////////////////////////////////////////////
// Function: ShaderTransition::Constructor
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
INLINE ShaderTransition::
ShaderTransition() {
}
////////////////////////////////////////////////////////////////////
// Function: set_shader
// Description: An external function, handy for setting shaders
// directly onto arcs. This will add the indicated
// shader to an existing ShaderTransition, or create a
// new ShaderTransition if necessary.
////////////////////////////////////////////////////////////////////
INLINE bool
set_shader(NodeRelation *arc, Shader *shader) {
ShaderTransition *st;
if (get_transition_into(st, arc)) {
return st->set_shader(shader);
}
st = new ShaderTransition;
st->set_shader(shader);
arc->set_transition(st);
return true;
}
////////////////////////////////////////////////////////////////////
// Function: clear_shader
// Description: An external function, handy for setting shaders
// directly onto arcs. This will remove the indicated
// shader from the existing ShaderTransition, if there
// is one.
////////////////////////////////////////////////////////////////////
INLINE bool
clear_shader(NodeRelation *arc, Shader *shader) {
ShaderTransition *st;
if (get_transition_into(st, arc)) {
return st->clear_shader(shader);
}
return false;
}
////////////////////////////////////////////////////////////////////
// Function: has_shader
// Description: An external function, handy for setting shaders
// directly onto arcs. This returns true if there
// exists a ShaderTransition and it contains the
// indicated shader, false otherwise.
////////////////////////////////////////////////////////////////////
INLINE bool
has_shader(const NodeRelation *arc, Shader *shader) {
const ShaderTransition *st;
if (get_transition_into(st, arc)) {
return st->has_shader(shader);
}
return false;
}

View File

@ -1,323 +0,0 @@
// Filename: shaderTransition.cxx
// Created by: mike (06Feb99)
//
////////////////////////////////////////////////////////////////////
//
// PANDA 3D SOFTWARE
// Copyright (c) 2001 - 2004, Disney Enterprises, Inc. All rights reserved
//
// All use of this software is subject to the terms of the Panda 3d
// Software license. You should have received a copy of this license
// along with this source code; you will also find a current copy of
// the license at http://etc.cmu.edu/panda3d/docs/license/ .
//
// To contact the maintainers of this program write to
// panda3d-general@lists.sourceforge.net .
//
////////////////////////////////////////////////////////////////////
#include "shaderTransition.h"
#include "indent.h"
#include "graphicsStateGuardian.h"
#include "textureTransition.h"
#include "attribTraverser.h"
#include "directRenderTraverser.h"
#include "renderRelation.h"
#include "config_shader.h"
TypeHandle ShaderTransition::_type_handle;
ShaderTransition::ShaderOrder* ShaderTransition::_shader_order = (ShaderTransition::ShaderOrder *)NULL;
ShaderTransition::ShaderBlend* ShaderTransition::_shader_always_blend = (ShaderTransition::ShaderBlend *)NULL;
////////////////////////////////////////////////////////////////////
// Function: ShaderTransition::make_copy
// Access: Public, Virtual
// Description: Returns a newly allocated ShaderTransition just like
// this one.
////////////////////////////////////////////////////////////////////
NodeTransition *ShaderTransition::
make_copy() const {
return new ShaderTransition(*this);
}
////////////////////////////////////////////////////////////////////
// Function: ShaderTransition::set_shader_order
// Access: Public, Static
// Description: Stores the order "priority" of a shader. (Note, there
// is nothing to prevent you from adding a none shader
// handle type, but it won't really do you any good).
// This order value is used to make sure that multiple
// shaders are ordered in a defined, hopefully
// intelligent order.
////////////////////////////////////////////////////////////////////
void ShaderTransition::
set_shader_order(TypeHandle shader, int order) {
if (_shader_order == (ShaderOrder *)NULL)
{
_shader_order = new ShaderOrder;
}
(*_shader_order)[shader] = order;
}
////////////////////////////////////////////////////////////////////
// Function: ShaderTransition::set_shader_blend
// Access: Public, Static
// Description: Some shaders (i.e. spotlight and highlight) need to
// blend with the scene no matter what.
////////////////////////////////////////////////////////////////////
void ShaderTransition::
set_shader_always_blend(TypeHandle shader) {
if (_shader_always_blend == (ShaderBlend *)NULL)
{
_shader_always_blend = new ShaderBlend;
}
_shader_always_blend->insert(shader);
}
////////////////////////////////////////////////////////////////////
// Function: ShaderTransition::clear
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
void ShaderTransition::
clear() {
_shaders.clear();
}
////////////////////////////////////////////////////////////////////
// Function: ShaderTransition::is_empty
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
bool ShaderTransition::
is_empty() const {
return _shaders.empty();
}
////////////////////////////////////////////////////////////////////
// Function: ShaderTransition::insert
// Access: Public
// Description: Inserts the shader into the list, based
// on the set order of the list. If there is no order set for
// the shader, it is put at the end of the list.
////////////////////////////////////////////////////////////////////
void ShaderTransition::
insert(Shader *shader) {
PT(Shader) sp(shader);
Shaders::iterator si = _shaders.begin();
int order = -1;
if ((_shader_order == NULL) && (_overrides.find(sp) == _overrides.end()))
{
si = _shaders.end();
}
if (_overrides.find(sp) != _overrides.end())
{
order = _overrides[sp];
}
else if (_shader_order->find(sp->get_type()) != _shader_order->end())
{
order = (*_shader_order)[sp->get_type()];
}
if (order == -1)
{
si = _shaders.end();
}
while(si != _shaders.end())
{
if (_overrides.find((*si)) != _overrides.end())
{
if (order < _overrides[(*si)])
{
break;
}
}
else if (order < (*_shader_order)[(*si)->get_type()])
{
break;
}
si++;
}
_shaders.insert(si, shader);
}
////////////////////////////////////////////////////////////////////
// Function: ShaderTransition::set_shader
// Access: Public
// Description: Adds the shader to the transition, if it is not
// already there. Returns true if the shader was added,
// false if it was there already. If the shader *was*
// already on the list, it is moved to the end of the
// list.
////////////////////////////////////////////////////////////////////
bool ShaderTransition::
set_shader(Shader *shader, int override) {
// We need to search for a PT(Shader), not a Shader* .
PT(Shader) sp(shader);
if (override != -1)
{
_overrides[sp] = override;
}
Shaders::iterator si = find(_shaders.begin(), _shaders.end(), sp);
if (si != _shaders.end()) {
// The shader was there already; move it to the end.
return false;
}
insert(shader);
return true;
}
////////////////////////////////////////////////////////////////////
// Function: ShaderTransition::clear_shader
// Access: Public
// Description: Removes the first occurrence of the indicated shader
// from the list, and returns true if anything was
// removed, false if there were no occurrences.
////////////////////////////////////////////////////////////////////
bool ShaderTransition::
clear_shader(Shader *shader) {
// We need to search for a PT(Shader), not a Shader* .
PT(Shader) sp(shader);
Shaders::iterator si = find(_shaders.begin(), _shaders.end(), sp);
if (si != _shaders.end()) {
_shaders.erase(si);
return true;
}
return false;
}
////////////////////////////////////////////////////////////////////
// Function: ShaderTransition::has_shader
// Access: Public
// Description: Returns true if the indicated shader appears on the
// list, false otherwise.
////////////////////////////////////////////////////////////////////
bool ShaderTransition::
has_shader(Shader *shader) const {
// We need to search for a PT(Shader), not a Shader* .
PT(Shader) sp(shader);
Shaders::const_iterator si = find(_shaders.begin(), _shaders.end(), sp);
return (si != _shaders.end());
}
////////////////////////////////////////////////////////////////////
// Function: ShaderTransition::begin
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
ShaderTransition::const_iterator ShaderTransition::
begin() const {
return _shaders.begin();
}
////////////////////////////////////////////////////////////////////
// Function: ShaderTransition::end
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
ShaderTransition::const_iterator ShaderTransition::
end() const {
return _shaders.end();
}
////////////////////////////////////////////////////////////////////
// Function: ShaderTransition::must_blend
// Access: Public
// Description: Checks to see if one of the shaders on the shaderTransition
// is a kind that requires blending
////////////////////////////////////////////////////////////////////
bool ShaderTransition::
must_blend()
{
const_iterator si;
for(si = begin(); si != end(); si++)
{
if (_shader_always_blend->find((*si)->get_type()) != _shader_always_blend->end())
{
return true;
}
}
return false;
}
////////////////////////////////////////////////////////////////////
// Function: ShaderTransition::sub_render
// Access: Public, Virtual
// Description: This is called by the RenderTraverser to tell the
// shader to do its thing.
////////////////////////////////////////////////////////////////////
bool ShaderTransition::
sub_render(NodeRelation *arc, const AllAttributesWrapper &attrib,
AllTransitionsWrapper &trans, RenderTraverser *trav) {
Node *node = arc->get_child();
GraphicsStateGuardian *gsg = trav->get_gsg();
bool multipass_on = false;
// No shaders; never mind.
if (is_empty()) {
return true;
}
AllAttributesWrapper node_attrib;
node_attrib.apply_from(attrib, trans);
multipass_on = must_blend() | is_textured(node, node_attrib) |
is_shaded(node) | (_shaders.size() > 1);
const_iterator si;
// In order to avoid strange nasty looking artifacts due to(?) the
// depth buffer not being restored properly when we employ scratch
// display regions. Call pre-apply before the scene has been
// rendered. Any shader that uses a scratch region will do it's
// thing and then when the scene is actually rendered, it will blow
// those artifacts away. Those shaders will store their work to be
// actually applied later when we call apply.
for (si = begin(); si != end(); ++si)
{
// We'll go ahead and tell each shader in turn if multipass is
// needed or not now.
(*si)->set_multipass(multipass_on);
(*si)->pre_apply(node, node_attrib, AllTransitionsWrapper(), gsg);
}
if ( multipass_on )
{
// Multipass is needed at this point. Render the node with its normal
// attributes (including texturing).
DirectRenderTraverser drt(gsg, RenderRelation::get_class_type());
gsg->render_subgraph(&drt, node, node_attrib, AllTransitionsWrapper());
}
// Now apply each shader in turn.
for (si = begin(); si != end(); ++si)
{
(*si)->apply(node, node_attrib, AllTransitionsWrapper(), gsg);
}
return false;
}
////////////////////////////////////////////////////////////////////
// Function: ShaderTransition::has_sub_render
// Access: Public, Virtual
// Description: Should be redefined to return true if the function
// sub_render(), above, expects to be called during
// traversal.
////////////////////////////////////////////////////////////////////
bool ShaderTransition::
has_sub_render() const {
return true;
}

View File

@ -1,122 +0,0 @@
// Filename: shaderTransition.h
// Created by: mike (19Jan99)
//
////////////////////////////////////////////////////////////////////
//
// PANDA 3D SOFTWARE
// Copyright (c) 2001 - 2004, Disney Enterprises, Inc. All rights reserved
//
// All use of this software is subject to the terms of the Panda 3d
// Software license. You should have received a copy of this license
// along with this source code; you will also find a current copy of
// the license at http://etc.cmu.edu/panda3d/docs/license/ .
//
// To contact the maintainers of this program write to
// panda3d-general@lists.sourceforge.net .
//
////////////////////////////////////////////////////////////////////
#ifndef SHADERTRANSITION_H
#define SHADERTRANSITION_H
#include "pandabase.h"
#include "shader.h"
#include "immediateTransition.h"
#include "pointerTo.h"
#include "nodeRelation.h"
#include "plist.h"
#include "pmap.h"
#include "pset.h"
////////////////////////////////////////////////////////////////////
// Class : ShaderTransition
// Description : A ShaderTransition holds the set of shaders that
// might be in effect to render a particular part of the
// subgraph. These shaders can range from lightweight
// rendering effects to full-blown multipass renderings;
// use with caution.
////////////////////////////////////////////////////////////////////
class EXPCL_SHADER ShaderTransition : public ImmediateTransition {
private:
// typedef pvector< PT(Shader) > Shaders;
typedef plist< PT(Shader) > Shaders;
typedef pmap<TypeHandle, int> ShaderOrder;
typedef pmap<PT(Shader), int> ShaderOverride;
typedef pset<TypeHandle> ShaderBlend;
public:
INLINE ShaderTransition();
public:
// Functions to access and adjust the list of shaders.
typedef Shaders::const_iterator iterator;
typedef Shaders::const_iterator const_iterator;
void clear();
bool is_empty() const;
void insert(Shader *shader);
//If you wish to override the ordering of your shader. Say for some
//reason you don't want this Shadow to appear in the reflections, or you want
//Spheremaped objects to reflect the reflections in planar objects instead of
//the other way around. Then set override appropriately.
bool set_shader(Shader *shader, int override = -1);
bool clear_shader(Shader *shader);
bool has_shader(Shader *shader) const;
const_iterator begin() const;
const_iterator end() const;
public:
static void set_shader_order(TypeHandle shader, int order);
static void set_shader_always_blend(TypeHandle shader);
private:
bool must_blend();
public:
virtual NodeTransition *make_copy() const;
virtual bool sub_render(NodeRelation *arc,
const AllTransitionsWrapper &input_trans,
AllTransitionsWrapper &modify_trans,
RenderTraverser *trav);
virtual bool has_sub_render() const;
private:
Shaders _shaders;
static ShaderOrder* _shader_order;
static ShaderBlend* _shader_always_blend;
ShaderOverride _overrides;
public:
virtual TypeHandle get_type() const {
return get_class_type();
}
virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
static TypeHandle get_class_type() {
return _type_handle;
}
static void init_type() {
ImmediateTransition::init_type();
register_type(_type_handle, "ShaderTransition",
ImmediateTransition::get_class_type());
}
private:
static TypeHandle _type_handle;
friend class ShaderAttribute;
};
INLINE bool set_shader(NodeRelation *arc, Shader *shader);
INLINE bool clear_shader(NodeRelation *arc, Shader *shader);
INLINE bool has_shader(const NodeRelation *arc, Shader *shader);
#include "shaderTransition.I"
#endif

View File

@ -1,7 +0,0 @@
#include "casterShader.cxx"
#include "config_shader.cxx"
#include "planarReflector.cxx"
#include "projtexShader.cxx"
#include "projtexShadower.cxx"
#include "spotlightShader.cxx"

View File

@ -1,8 +0,0 @@
#include "shader.cxx"
#include "outlineShader.cxx"
#include "shaderTransition.cxx"
#include "spheretexHighlighter.cxx"
#include "spheretexReflector.cxx"
#include "spheretexShader.cxx"

View File

@ -1,185 +0,0 @@
// Filename: spheretexHighlighter.cxx
// Created by: mike (09Jan97)
//
////////////////////////////////////////////////////////////////////
//
// PANDA 3D SOFTWARE
// Copyright (c) 2001 - 2004, Disney Enterprises, Inc. All rights reserved
//
// All use of this software is subject to the terms of the Panda 3d
// Software license. You should have received a copy of this license
// along with this source code; you will also find a current copy of
// the license at http://etc.cmu.edu/panda3d/docs/license/ .
//
// To contact the maintainers of this program write to
// panda3d-general@lists.sourceforge.net .
//
////////////////////////////////////////////////////////////////////
#include "spheretexHighlighter.h"
#include "config_shader.h"
#include "light.h"
#include "spotlight.h"
#include "renderBuffer.h"
#include "get_rel_pos.h"
#include "dftraverser.h"
#include "displayRegion.h"
#include "graphicsWindow.h"
#include "materialTransition.h"
#include "materialAttribute.h"
////////////////////////////////////////////////////////////////////
// Static variables
////////////////////////////////////////////////////////////////////
TypeHandle SpheretexHighlighter::_type_handle;
////////////////////////////////////////////////////////////////////
// Function: SpheretexHighlighter::Constructor
// Access:
// Description:
////////////////////////////////////////////////////////////////////
SpheretexHighlighter::SpheretexHighlighter(int size) : FrustumShader()
{
set_size(size);
Texture* texture = new Texture;
texture->set_minfilter(Texture::FT_linear);
texture->set_magfilter(Texture::FT_linear);
texture->set_wrapu(Texture::WM_clamp);
texture->set_wrapv(Texture::WM_clamp);
texture->_pbuffer = new PixelBuffer(PixelBuffer::rgb_buffer(_size, _size));
_spheretex_shader.set_texture(texture);
_spheretex_shader.set_blend_mode(ColorBlendProperty::M_add);
}
////////////////////////////////////////////////////////////////////
// Function: SpheretexHighlighter::set_multipass
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
void SpheretexHighlighter::
set_multipass(bool)
{
//A highlight shader always needs to blend
_multipass_on = true;
_spheretex_shader.set_multipass(true);
}
////////////////////////////////////////////////////////////////////
// Function: SpheretexHighlighter::set_priority
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
void SpheretexHighlighter::
set_priority(int priority)
{
Shader::set_priority(priority);
_spheretex_shader.set_priority(priority);
}
////////////////////////////////////////////////////////////////////
// Function: SpheretexHighlighter::pre_apply
// Access:
// Description:
///////////////////////////////////////////////////////////////////
void SpheretexHighlighter::
pre_apply(Node *node, const AllAttributesWrapper &init_state,
const AllTransitionsWrapper &, GraphicsStateGuardian *gsg)
{
if (get_num_frusta() == 0) {
shader_cat.error()
<< "SpheretexHighlighter::config() - no lights in frusta list"
<< endl;
return;
} else if (get_num_frusta() > 1) {
shader_cat.warning()
<< "SpheretexHighlighter::config() - frusta list has more than one "
<< "frustum - ignore all but the first one for now..." << endl;
}
if (_frusta[0]->get_type() != Spotlight::get_class_type()) {
shader_cat.error()
<< "SpheretexHighlighter::config() - only works for Spotlights"
<< " so far - we'll add point lights later" << endl;
return;
}
// MPG - we could make this work for point lights as well
Spotlight* light = (Spotlight *)_frusta[0];
// Figure out how shiny the highlighted object is
float shininess = 0.0;
const NodeAttribute *mat_attrib =
init_state.get_attribute(MaterialTransition::get_class_type());
if (mat_attrib != (NodeAttribute *)NULL) {
const Material *material =
DCAST(MaterialAttribute, mat_attrib)->get_material();
shininess = material->get_shininess();
}
if (shininess == 0.0) {
shininess = 100.0;
}
// Figure out where the highlight is relative to the object's center and
// the light
const LensNode* projnode = gsg->get_current_camera();
LVector3f model_pos = get_rel_pos(node, projnode);
LVector3f norm_model_pos = normalize(model_pos);
LPoint3f light_pos = get_rel_pos(light, projnode);
LVector3f light_vec = light_pos - model_pos;
light_vec = normalize(light_vec);
// Compute highlight for all pixels on the image that are on the sphere
LVector3f view_vec(0, -1, 0); // Looking down +y axis
LVector3f norm, S;
float ZZ, XX_ZZ, intensity, grazing;
uchar color[3];
float scale = 1.0 / ((float)(_size - 1));
Texture* texture = _spheretex_shader.get_texture();
for (int y = 0; y < _size; ++y) {
norm[2] = 2. * ((float)y * scale) - 1.; // 0.._size-1 -> -1..1
ZZ = norm[2] * norm[2]; // z^2
for (int x = 0; x < _size; ++x) {
norm[0] = 2. * ((float)x * scale) -1.; // 0.._size-1 -> -1..1
XX_ZZ = (norm[0] * norm[0]) + ZZ; // x^2 + z^2
color[0] = color[1] = color[2] = 0;
if (XX_ZZ <= 1.) { // Are we on the unit sphere?
norm[1] = -(float)sqrt(1. - XX_ZZ); // This yields a unit vector
grazing = dot(norm, light_vec);
if (grazing > 0.) { // Does any light actually reflect off this point?
S = norm;
S *= 2. * grazing;
S = S - light_vec; // the reflection vector
intensity = -dot(S, norm_model_pos); // approximate R . V
// If, relative to the viewer, the normal doesn't point towards the
// light (even slightly), no reflection will be seen
if (intensity > 0.) {
intensity = pow(intensity, shininess);
color[0] = color[1] = color[2] = (uchar)(intensity * 255.);
}
}
}
texture->_pbuffer->set_uchar_rgb_texel(color, x, y, _size);
texture->unprepare();
}
}
}
////////////////////////////////////////////////////////////////////
// Function: SpheretexHighlighter::apply
// Access:
// Description:
////////////////////////////////////////////////////////////////////
void SpheretexHighlighter::
apply(Node *node, const AllAttributesWrapper &init_state,
const AllTransitionsWrapper &net_trans, GraphicsStateGuardian *gsg) {
Shader::apply(node, init_state, net_trans, gsg);
_spheretex_shader.apply(node, init_state, net_trans, gsg);
}

View File

@ -1,87 +0,0 @@
// Filename: spheretexHighlighter.h
// Created by: mike (09Jan97)
//
////////////////////////////////////////////////////////////////////
//
// PANDA 3D SOFTWARE
// Copyright (c) 2001 - 2004, Disney Enterprises, Inc. All rights reserved
//
// All use of this software is subject to the terms of the Panda 3d
// Software license. You should have received a copy of this license
// along with this source code; you will also find a current copy of
// the license at http://etc.cmu.edu/panda3d/docs/license/ .
//
// To contact the maintainers of this program write to
// panda3d-general@lists.sourceforge.net .
//
////////////////////////////////////////////////////////////////////
#ifndef SPHERETEXHIGHLIGHTER_H
#define SPHERETEXHIGHLIGHTER_H
//
////////////////////////////////////////////////////////////////////
// Includes
////////////////////////////////////////////////////////////////////
#include "pandabase.h"
#include "shader.h"
#include "spheretexShader.h"
#include "pt_Node.h"
////////////////////////////////////////////////////////////////////
// Defines
////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////
// Class : SpheretexHighlighter
// Description : Creates a highlight texture from a given light and
// projects this onto the receiving object
////////////////////////////////////////////////////////////////////
class EXPCL_SHADER SpheretexHighlighter : public FrustumShader
{
public:
SpheretexHighlighter(int size = 128);
virtual void pre_apply(Node *node, const AllAttributesWrapper &init_state,
const AllTransitionsWrapper &net_trans,
GraphicsStateGuardian *gsg);
virtual void apply(Node *node, const AllAttributesWrapper &init_state,
const AllTransitionsWrapper &net_trans,
GraphicsStateGuardian *gsg);
// MPG - should we make this check for powers of 2?
INLINE void set_size(int size) { _size = size; }
INLINE int get_size(void) { return _size; }
//Override base class shader's set_priority to allow
//us to set the priority of the contained projtex_shader at
//the same time
virtual void set_priority(int priority);
virtual void set_multipass(bool on);
protected:
SpheretexShader _spheretex_shader;
int _size;
public:
static TypeHandle get_class_type() {
return _type_handle;
}
static void init_type() {
FrustumShader::init_type();
register_type(_type_handle, "SpheretexHighlighter",
FrustumShader::get_class_type());
}
virtual TypeHandle get_type() const {
return get_class_type();
}
virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
private:
static TypeHandle _type_handle;
};
#endif

View File

@ -1,234 +0,0 @@
// Filename: spheretexReflector.cxx
// Created by: mike (09Jan97)
//
////////////////////////////////////////////////////////////////////
//
// PANDA 3D SOFTWARE
// Copyright (c) 2001 - 2004, Disney Enterprises, Inc. All rights reserved
//
// All use of this software is subject to the terms of the Panda 3d
// Software license. You should have received a copy of this license
// along with this source code; you will also find a current copy of
// the license at http://etc.cmu.edu/panda3d/docs/license/ .
//
// To contact the maintainers of this program write to
// panda3d-general@lists.sourceforge.net .
//
////////////////////////////////////////////////////////////////////
#include "spheretexReflector.h"
#include "config_shader.h"
#include "pt_Node.h"
#include "frustum.h"
#include "get_rel_pos.h"
#include "dftraverser.h"
#include "displayRegion.h"
#include "graphicsWindow.h"
#include "renderBuffer.h"
#include "perspectiveLens.h"
#include "look_at.h"
#include "cullFaceTransition.h"
#include "colorBlendTransition.h"
#include "transformTransition.h"
#include "directRenderTraverser.h"
////////////////////////////////////////////////////////////////////
// Static variables
////////////////////////////////////////////////////////////////////
TypeHandle SpheretexReflector::_type_handle;
////////////////////////////////////////////////////////////////////
// Function: SpheretexReflector::Constructor
// Access:
// Description:
////////////////////////////////////////////////////////////////////
SpheretexReflector::SpheretexReflector(int size) : CasterShader()
{
set_size(size);
_is_reflector = true;
_fnear = 0.1f;
_ffar = 1000.0f;
Texture* texture = new Texture;
texture->set_minfilter(Texture::FT_linear);
texture->set_magfilter(Texture::FT_linear);
texture->set_wrapu(Texture::WM_clamp);
texture->set_wrapv(Texture::WM_clamp);
texture->_pbuffer->set_xsize(_size);
texture->_pbuffer->set_ysize(_size);
_spheretex_shader.set_texture(texture);
_spheretex_shader.set_blend_mode(ColorBlendProperty::M_add);
}
////////////////////////////////////////////////////////////////////
// Function: SpheretexReflector::destructor
// Access:
// Description:
////////////////////////////////////////////////////////////////////
SpheretexReflector::~SpheretexReflector(void) {
}
////////////////////////////////////////////////////////////////////
// Function: SpheretexReflector::set_priority
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
void SpheretexReflector::
set_priority(int priority)
{
Shader::set_priority(priority);
_spheretex_shader.set_priority(priority);
}
////////////////////////////////////////////////////////////////////
// Function: SpheretexReflector::set_multipass
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
void SpheretexReflector::
set_multipass(bool on)
{
Shader::set_multipass(on);
_spheretex_shader.set_multipass(on);
}
////////////////////////////////////////////////////////////////////
// Function: SpheretexHighlighter::pre_apply
// Access:
// Description:
////////////////////////////////////////////////////////////////////
void SpheretexReflector::
pre_apply(Node *node, const AllAttributesWrapper &init_state,
const AllTransitionsWrapper &net_trans, GraphicsStateGuardian *gsg)
{
if (get_num_casters() == 0) {
shader_cat.error()
<< "SpheretexReflector::config() - no casters in caster list" << endl;
return;
}
//We need a state that we can modify to remove the camera transform
//that is passed to us
AllAttributesWrapper state(init_state);
state.clear_attribute(TransformTransition::get_class_type());
// Get the current camera from the gsg
const LensNode* camera = gsg->get_current_camera();
// Save the clear color.
Colorf clear_color = gsg->get_color_clear_value();
// Make a display region of the proper size and clear it to prepare for
// rendering the shadow map
PT(DisplayRegion) scratch_region =
gsg->get_window()->make_scratch_display_region(_size, _size);
DisplayRegionStack old_dr = gsg->push_display_region(scratch_region);
// Save scratch region before clearing it to be non-destructive
FrameBufferStack old_fb = gsg->push_frame_buffer
(gsg->get_render_buffer(RenderBuffer::T_back | RenderBuffer::T_depth),
scratch_region);
gsg->set_color_clear_value(Colorf(0., 0., 0., 1.));
gsg->clear(gsg->get_render_buffer(RenderBuffer::T_back |
RenderBuffer::T_depth), scratch_region);
// Copy the transition wrapper so we can modify it freely.
AllTransitionsWrapper trans(net_trans);
// Create a temporary node that is the parent of all of the caster
// objects, so we can render them from the point of view of the
// reflector.
PT_Node caster_group = new Node;
NamedNodeVector::iterator ci;
for (ci = _casters.begin(); ci != _casters.end(); ++ci) {
Node *caster = (*ci);
// Get the transform of the caster from the point of view of the
// reflector.
LMatrix4f mat;
get_rel_mat(caster, node, mat);
RenderRelation *arc = new RenderRelation(caster_group, caster);
arc->set_transition(new TransformTransition(mat));
}
// Build a LensNode that represents a wide-angle view from the
// reflecting object towards the camera.
PT(Lens) *lens = new PerspectiveLens;
lens->set_fov(150.0f);
lens->set_near(_fnear);
lens->set_far(_ffar);
LensNode *projnode = new LensNode;
projnode->set_lens(lens);
// How shall we rotate the LensNode?
LMatrix4f r_mat;
// Get camera pos in the coordinate space of the reflecting object
LVector3f camera_pos = get_rel_pos(camera, node);
LVector3f camera_up = get_rel_up(camera, node);
if (_is_reflector == true)
{
// Take the picture looking toward the camera
look_at(r_mat, camera_pos, camera_up, gsg->get_coordinate_system());
// Flip along the X axis to make it behave like a mirror
r_mat = LMatrix4f::scale_mat(LVector3f(-1.0f, 1.0f, 1.0f)) * r_mat;
// And the vertex order for front facing polygons to compensate
// for the above flip.
CullFaceTransition *cf =
new CullFaceTransition(CullFaceProperty::M_cull_counter_clockwise);
trans.set_transition(cf);
}
else
{
// For a refractor, take the picture looking away from the camera.
look_at(r_mat, -camera_pos, camera_up, gsg->get_coordinate_system());
}
RenderRelation *projarc = new RenderRelation(caster_group, projnode);
projarc->set_transition(new TransformTransition(r_mat));
// Now render the casters.
DirectRenderTraverser drt(gsg, RenderRelation::get_class_type());
gsg->render_subgraph(&drt, caster_group, projnode, state, trans);
// The caster group, and all of the temporary group nodes below,
// will automatically be destructed when the caster_group PointerTo
// object goes out of scope. We don't have to remove it from the
// scene graph because we never actually inserted it.
// Copy the results of the render from the framebuffer into the spheretex
// shader's texture
_spheretex_shader.get_texture()->copy(gsg, scratch_region, gsg->get_render_buffer(RenderBuffer::T_back));
// Restore the original display region and clear value
//Make sure the restore the depth buffer. There's only one you know.
gsg->set_color_clear_value(clear_color);
gsg->pop_frame_buffer(old_fb);
gsg->pop_display_region(old_dr);
}
////////////////////////////////////////////////////////////////////
// Function: SpheretexHighlighter::apply
// Access:
// Description:
////////////////////////////////////////////////////////////////////
void SpheretexReflector::
apply(Node *node, const AllAttributesWrapper &init_state,
const AllTransitionsWrapper &net_trans, GraphicsStateGuardian *gsg)
{
Shader::apply(node, init_state, net_trans, gsg);
// Apply the spheremap reflection
//gsg->prepare_display_region();
_spheretex_shader.apply(node, init_state, net_trans, gsg);
}

View File

@ -1,99 +0,0 @@
// Filename: spheretexReflector.h
// Created by: mike (09Jan97)
//
////////////////////////////////////////////////////////////////////
//
// PANDA 3D SOFTWARE
// Copyright (c) 2001 - 2004, Disney Enterprises, Inc. All rights reserved
//
// All use of this software is subject to the terms of the Panda 3d
// Software license. You should have received a copy of this license
// along with this source code; you will also find a current copy of
// the license at http://etc.cmu.edu/panda3d/docs/license/ .
//
// To contact the maintainers of this program write to
// panda3d-general@lists.sourceforge.net .
//
////////////////////////////////////////////////////////////////////
#ifndef SPHERETEXREFLECTOR_H
#define SPHERETEXREFLECTOR_H
//
////////////////////////////////////////////////////////////////////
// Includes
////////////////////////////////////////////////////////////////////
#include "pandabase.h"
#include "shader.h"
#include "spheretexShader.h"
#include "casterShader.h"
////////////////////////////////////////////////////////////////////
// Defines
////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////
// Class : SpheretexReflector
// Description : Creates a reflection texture map for a given object
////////////////////////////////////////////////////////////////////
class EXPCL_SHADER SpheretexReflector : public CasterShader
{
public:
SpheretexReflector(int size = 256);
~SpheretexReflector(void);
virtual void pre_apply(Node *node, const AllAttributesWrapper &init_state,
const AllTransitionsWrapper &net_trans,
GraphicsStateGuardian *gsg);
virtual void apply(Node *node, const AllAttributesWrapper &init_state,
const AllTransitionsWrapper &net_trans,
GraphicsStateGuardian *gsg);
// MPG - should we make this check for powers of 2?
INLINE void set_size(int size) { _size = size; }
INLINE int get_size(void) const { return _size; }
INLINE bool is_reflector(void) const { return _is_reflector; }
INLINE void make_reflector(void) { _is_reflector = true; }
INLINE void make_refractor(void) { _is_reflector = false; }
INLINE void set_near(float fnear) { _fnear = fnear; }
INLINE float get_near(void) const { return _fnear; }
INLINE void set_far(float ffar) { _ffar = ffar; }
INLINE float get_far(void) const { return _ffar; }
//Override base class shader's set_priority to allow
//us to set the priority of the contained projtex_shader at
//the same time
virtual void set_priority(int priority);
virtual void set_multipass(bool on);
protected:
SpheretexShader _spheretex_shader;
int _size;
bool _is_reflector;
float _fnear;
float _ffar;
public:
static TypeHandle get_class_type() {
return _type_handle;
}
static void init_type() {
CasterShader::init_type();
register_type(_type_handle, "SpheretexReflector",
CasterShader::get_class_type());
}
virtual TypeHandle get_type() const {
return get_class_type();
}
virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
private:
static TypeHandle _type_handle;
};
#endif

View File

@ -1,131 +0,0 @@
// Filename: spheretexShader.cxx
// Created by: mike (09Jan97)
//
////////////////////////////////////////////////////////////////////
//
// PANDA 3D SOFTWARE
// Copyright (c) 2001 - 2004, Disney Enterprises, Inc. All rights reserved
//
// All use of this software is subject to the terms of the Panda 3d
// Software license. You should have received a copy of this license
// along with this source code; you will also find a current copy of
// the license at http://etc.cmu.edu/panda3d/docs/license/ .
//
// To contact the maintainers of this program write to
// panda3d-general@lists.sourceforge.net .
//
////////////////////////////////////////////////////////////////////
#include "spheretexShader.h"
#include "config_shader.h"
#include "lightTransition.h"
#include "textureTransition.h"
#include "textureTransition.h"
#include "texMatrixTransition.h"
#include "depthTestTransition.h"
#include "texGenTransition.h"
#include "textureApplyTransition.h"
#include "colorBlendTransition.h"
#include "get_rel_pos.h"
#include "dftraverser.h"
#include "graphicsStateGuardian.h"
#include "colorBlendTransition.h"
#include "attribTraverser.h"
#include "directRenderTraverser.h"
////////////////////////////////////////////////////////////////////
// Static variables
////////////////////////////////////////////////////////////////////
TypeHandle SpheretexShader::_type_handle;
////////////////////////////////////////////////////////////////////
// Function: SpheretexShader::constructor
// Access:
// Description:
////////////////////////////////////////////////////////////////////
SpheretexShader::SpheretexShader(Texture* texture) : Shader()
{
set_texture(texture);
_blend_mode = ColorBlendProperty::M_multiply_add;
}
////////////////////////////////////////////////////////////////////
// Function: SpheretexShader::config
// Access:
// Description:
////////////////////////////////////////////////////////////////////
void SpheretexShader::config(void)
{
Configurable::config();
nassertv(_texture != (Texture *)NULL);
_texture->set_minfilter(Texture::FT_linear);
_texture->set_magfilter(Texture::FT_linear);
_texture->set_wrapu(Texture::WM_clamp);
_texture->set_wrapv(Texture::WM_clamp);
}
////////////////////////////////////////////////////////////////////
// Function: SpheretexShader::apply
// Access:
// Description:
////////////////////////////////////////////////////////////////////
void SpheretexShader::
apply(Node *node, const AllAttributesWrapper &init_state,
const AllTransitionsWrapper &net_trans, GraphicsStateGuardian *gsg) {
Shader::apply(node, init_state, net_trans, gsg);
// Copy the transition wrapper so we can modify it freely.
AllTransitionsWrapper trans(net_trans);
// Create the texture generation transition
TexGenTransition *tg = new TexGenTransition;
tg->set_sphere_map();
trans.set_transition(tg);
// Create the texture transition
nassertv(_texture != (Texture *)NULL);
TextureTransition *t = new TextureTransition;
t->set_on(_texture);
t->set_priority(_priority);
trans.set_transition(t);
if (_viz != (Shader::Visualize*)0L)
_viz->DisplayTexture(_texture, this);
// Clear the texture matrix transition
trans.set_transition(new TexMatrixTransition(LMatrix4f::ident_mat()));
// Turn lighting off - we still want to issue normals, though
trans.set_transition(new LightTransition(LightTransition::all_off()));
gsg->force_normals();
// Do some extra work if we're doing the 2-pass version (e.g. the
// object we are shading is textured)
if (_multipass_on) {
// Set a color blend mode that assumes this is a second pass over
// textured geometry
ColorBlendTransition *cb =
new ColorBlendTransition(_blend_mode);
trans.set_transition(cb);
TextureApplyTransition *ta =
new TextureApplyTransition(TextureApplyProperty::M_decal);
trans.set_transition(ta);
// Set the depth test to M_equal (? Or should this be M_none?)
DepthTestTransition *dta =
new DepthTestTransition(DepthTestProperty::M_equal);
trans.set_transition(dta);
}
// Render the node with the new transitions.
DirectRenderTraverser drt(gsg, RenderRelation::get_class_type());
gsg->render_subgraph(&drt, node, init_state, trans);
gsg->undo_force_normals();
}

View File

@ -1,84 +0,0 @@
// Filename: spheretexShader.h
// Created by: mike (09Jan97)
//
////////////////////////////////////////////////////////////////////
//
// PANDA 3D SOFTWARE
// Copyright (c) 2001 - 2004, Disney Enterprises, Inc. All rights reserved
//
// All use of this software is subject to the terms of the Panda 3d
// Software license. You should have received a copy of this license
// along with this source code; you will also find a current copy of
// the license at http://etc.cmu.edu/panda3d/docs/license/ .
//
// To contact the maintainers of this program write to
// panda3d-general@lists.sourceforge.net .
//
////////////////////////////////////////////////////////////////////
#ifndef SPHERETEXSHADER_H
#define SPHERETEXSHADER_H
//
////////////////////////////////////////////////////////////////////
// Includes
////////////////////////////////////////////////////////////////////
#include "pandabase.h"
#include "shader.h"
#include "texture.h"
#include "colorBlendTransition.h"
////////////////////////////////////////////////////////////////////
// Defines
////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////
// Class : SpheretexShader
// Description :
////////////////////////////////////////////////////////////////////
class EXPCL_SHADER SpheretexShader : public Shader
{
public:
SpheretexShader(Texture* texture = NULL);
~SpheretexShader() { }
virtual void config(void);
virtual void apply(Node *node, const AllAttributesWrapper &init_state,
const AllTransitionsWrapper &net_trans,
GraphicsStateGuardian *gsg);
INLINE void set_texture(Texture* texture) {
_texture = texture;
make_dirty();
}
INLINE Texture* get_texture(void) { return _texture; }
INLINE void set_blend_mode(ColorBlendProperty::Mode mode) {
_blend_mode = mode;
}
protected:
PT(Texture) _texture;
ColorBlendProperty::Mode _blend_mode;
public:
static TypeHandle get_class_type() {
return _type_handle;
}
static void init_type() {
Shader::init_type();
register_type(_type_handle, "SpheretexShader",
Shader::get_class_type());
}
virtual TypeHandle get_type() const {
return get_class_type();
}
virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
private:
static TypeHandle _type_handle;
};
#endif

View File

@ -1,76 +0,0 @@
// Filename: spotlightShader.cxx
// Created by: mike (09Jan97)
//
////////////////////////////////////////////////////////////////////
//
// PANDA 3D SOFTWARE
// Copyright (c) 2001 - 2004, Disney Enterprises, Inc. All rights reserved
//
// All use of this software is subject to the terms of the Panda 3d
// Software license. You should have received a copy of this license
// along with this source code; you will also find a current copy of
// the license at http://etc.cmu.edu/panda3d/docs/license/ .
//
// To contact the maintainers of this program write to
// panda3d-general@lists.sourceforge.net .
//
////////////////////////////////////////////////////////////////////
#include "spotlightShader.h"
#include "config_shader.h"
#include "spotlight.h"
////////////////////////////////////////////////////////////////////
// Static variables
////////////////////////////////////////////////////////////////////
TypeHandle SpotlightShader::_type_handle;
////////////////////////////////////////////////////////////////////
// Function: SpotlightShader::constructor
// Access:
// Description:
////////////////////////////////////////////////////////////////////
SpotlightShader::SpotlightShader(int size, float radius) : ProjtexShader(NULL, ColorBlendProperty::M_multiply_add)
{
Texture* texture = new Texture;
texture->set_minfilter(Texture::FT_linear);
texture->set_magfilter(Texture::FT_linear);
texture->set_wrapu(Texture::WM_clamp);
texture->set_wrapv(Texture::WM_clamp);
texture->_pbuffer = new PixelBuffer(PixelBuffer::rgb_buffer(size, size));
set_texture(texture);
_radius = radius;
}
////////////////////////////////////////////////////////////////////
// Function: SpotlightShader::config
// Access:
// Description:
////////////////////////////////////////////////////////////////////
void SpotlightShader::config(void)
{
Configurable::config();
if (get_num_frusta() == 0) {
shader_cat.error()
<< "SpotlightShader::config() - no lights in frusta list" << endl;
return;
} else if (get_num_frusta() > 1) {
shader_cat.warning()
<< "SpotlightShader::config() - frusta list has more than one "
<< "frustum - ignore all but the first one for now..." << endl;
}
if (_frusta[0]->get_type() != Spotlight::get_class_type()) {
shader_cat.error()
<< "SpotlightShader::config() - frusta is not a spotlight" << endl;
return;
}
Spotlight* spotlight = (Spotlight *)_frusta[0];
spotlight->make_image(_texture, _radius);
}

View File

@ -1,67 +0,0 @@
// Filename: spotlightShader.h
// Created by: mike (09Jan97)
//
////////////////////////////////////////////////////////////////////
//
// PANDA 3D SOFTWARE
// Copyright (c) 2001 - 2004, Disney Enterprises, Inc. All rights reserved
//
// All use of this software is subject to the terms of the Panda 3d
// Software license. You should have received a copy of this license
// along with this source code; you will also find a current copy of
// the license at http://etc.cmu.edu/panda3d/docs/license/ .
//
// To contact the maintainers of this program write to
// panda3d-general@lists.sourceforge.net .
//
////////////////////////////////////////////////////////////////////
#ifndef SPOTLIGHTSHADER_H
#define SPOTLIGHTSHADER_H
//
////////////////////////////////////////////////////////////////////
// Includes
////////////////////////////////////////////////////////////////////
#include "pandabase.h"
#include "projtexShader.h"
////////////////////////////////////////////////////////////////////
// Defines
////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////
// Class : SpotlightShader
// Description :
////////////////////////////////////////////////////////////////////
class EXPCL_SHADER SpotlightShader : public ProjtexShader
{
public:
SpotlightShader(int size = 256, float radius = 0.7);
virtual void config(void);
// SpotlightShader uses ProjtexShader::apply()
protected:
float _radius;
public:
static TypeHandle get_class_type() {
return _type_handle;
}
static void init_type() {
ProjtexShader::init_type();
register_type(_type_handle, "SpotlightShader",
ProjtexShader::get_class_type());
}
virtual TypeHandle get_type() const {
return get_class_type();
}
virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
private:
static TypeHandle _type_handle;
};
#endif

View File

@ -1,84 +0,0 @@
// Filename: downloader_test.cxx
// Created by:
//
////////////////////////////////////////////////////////////////////
//
// PANDA 3D SOFTWARE
// Copyright (c) 2001 - 2004, Disney Enterprises, Inc. All rights reserved
//
// All use of this software is subject to the terms of the Panda 3d
// Software license. You should have received a copy of this license
// along with this source code; you will also find a current copy of
// the license at http://etc.cmu.edu/panda3d/docs/license/ .
//
// To contact the maintainers of this program write to
// panda3d-general@lists.sourceforge.net .
//
////////////////////////////////////////////////////////////////////
#include "eventHandler.h"
#include "chancfg.h"
#include "downloader.h"
#include "framework.h"
#include "decompressor.h"
#include "extractor.h"
Downloader downloader;
Decompressor decompressor;
Extractor extractor;
Filename src_file;
Filename dest_file;
void event_y(CPT_Event) {
downloader.request_download(src_file, dest_file, "");
}
void event_u(CPT_Event) {
downloader.request_download("/oldfoobar.mfz", "/fit/people/mike/download/oldfoobar.mfz", "");
}
void event_i(CPT_Event) {
downloader.request_download("/foobar.mfz", "/fit/people/mike/download/partfoobar.mfz", "", 0, 99, 151);
}
void event_o(CPT_Event) {
downloader.request_download("/foobar.mfz", "/fit/people/mike/download/partfoobar.mfz", "", 100, 151, 151);
}
void event_p(CPT_Event) {
decompressor.request_decompress("/fit/people/mike/download/dload.mf.pz", "");
}
void event_la(CPT_Event) {
extractor.request_extract("/fit/people/mike/download/dload.mf", "");
}
void loader_keys(EventHandler& eh) {
eh.add_hook("y", event_y);
eh.add_hook("u", event_u);
eh.add_hook("i", event_i);
eh.add_hook("o", event_o);
eh.add_hook("p", event_p);
eh.add_hook("[", event_la);
}
int main(int argc, char *argv[]) {
if (argc < 4) {
cerr << "Usage: download <server> <source file> <dest file>" << endl;
return 0;
}
string server_name = argv[1];
src_file = argv[2];
dest_file = argv[3];
argc -= 3;
argv += 3;
define_keys = &loader_keys;
downloader.create_thread();
downloader.connect_to_server(server_name);
decompressor.create_thread();
extractor.create_thread();
return framework_main(argc, argv);
}

View File

@ -1,530 +0,0 @@
// Filename: herc.cxx
// Created by:
//
////////////////////////////////////////////////////////////////////
//
// PANDA 3D SOFTWARE
// Copyright (c) 2001 - 2004, Disney Enterprises, Inc. All rights reserved
//
// All use of this software is subject to the terms of the Panda 3d
// Software license. You should have received a copy of this license
// along with this source code; you will also find a current copy of
// the license at http://etc.cmu.edu/panda3d/docs/license/ .
//
// To contact the maintainers of this program write to
// panda3d-general@lists.sourceforge.net .
//
////////////////////////////////////////////////////////////////////
#include "eventHandler.h"
#include "projtexShader.h"
#include "shaderTransition.h"
#include "renderRelation.h"
#include "nodeRelation.h"
#include "chancfg.h"
#include <string>
#include "texGenTransition.h"
#include "colorBlendTransition.h"
#include "colorMaskTransition.h"
#include "textureTransition.h"
#include "texMatrixTransition.h"
#include "spotlightShader.h"
#include "light.h"
#include "loader.h"
#include "look_at.h"
#include "get_rel_pos.h"
#include "transformTransition.h"
#include "geomNode.h"
#include "lightTransition.h"
#include "spotlight.h"
#include "projtexShadower.h"
#include "spheretexHighlighter.h"
#include "spheretexReflector.h"
#include "trackball.h"
#include "planarSlider.h"
#include "transform2sg.h"
#include "mouse.h"
#include "graphicsWindow.h"
#include "planarReflector.h"
#include "stencilTransition.h"
#include "plane.h"
#include "auto_bind.h"
#include "animControl.h"
#include "animControlCollection.h"
#include "renderBuffer.h"
#include "planeNode.h"
#include "outlineShader.h"
#include "pt_NamedNode.h"
#include "geomLine.h"
#include "dconfig.h"
Configure(shader_test);
ConfigureFn(shader_test) {}
PT(LensNode) tex_proj;
PT(Trackball) tex_proj_trackball;
PT(ProjtexShader) proj_shader;
PT(ProjtexShadower) proj_shadow;
PT(SpheretexShader) spheretex;
PT(SpheretexHighlighter) highlight;
PT(SpheretexReflector) sreflect;
PT(PlanarReflector) preflect;
PT(OutlineShader) outline_shader;
PT(GeomNode) proj_geom_node;
PT_NamedNode spot_shaft;
PT_NamedNode herc;
PT_NamedNode ball;
PT_NamedNode hide_ball;
ShaderTransition shader_trans;
PT(Spotlight) tex_proj_spot;
PT(Trackball) tex_spot_trackball;
PT(SpotlightShader) spot_shader;
PT(PlanarSlider) ball_slider;
bool follow_ball;
RenderRelation* room_arc;
RenderRelation* spot_arc;
RenderRelation* ball_arc;
RenderRelation* hide_ball_arc;
RenderRelation* herc_arc;
RenderRelation* herc_rot_arc;
RenderRelation* camera_model_arc;
extern PT_NamedNode render;
extern NodeAttributes initial_state;
extern PT_NamedNode lights;
extern PT_NamedNode root;
extern PT(GeomNode) geomnode;
extern PT_NamedNode cameras;
extern PT(MouseAndKeyboard) mak;
extern void set_alt_trackball(Node *trackball);
extern PT(GraphicsWindow) main_win;
extern int framework_main(int argc, char *argv[]);
extern void (*extra_display_func)();
extern void (*define_keys)(EventHandler&);
extern void (*extra_overrides_func)(ChanCfgOverrides&, std::string&);
extern void (*additional_idle)();
// nothing extra to do for either of these
void herc_display_func(void) {
Shader::Visualize* v = Shader::get_viz();
if (v != (Shader::Visualize*)0L)
v->Flush();
}
void herc_overrides_func(ChanCfgOverrides &override, std::string&) {
override.setField(ChanCfgOverrides::Mask,
((unsigned int)(W_DOUBLE|W_DEPTH|W_MULTISAMPLE|W_STENCIL)));
override.setField(ChanCfgOverrides::Title, "Lighting Demo");
}
void herc_idle() {
static const double walk_speed = 4.0; // feet per second
if (follow_ball) {
LPoint3f bp = get_rel_pos(ball, herc);
LVector2f bv2(bp[0], bp[1]);
float dist = length(bv2);
if (dist > 0.0001) {
LMatrix4f mat;
look_at(mat, LPoint3f(-bp[0], -bp[1], 0.0));
herc_rot_arc->set_transition(new TransformTransition(mat));
float stride = walk_speed * ClockObject::get_global_clock()->get_dt();
if (dist > stride) {
LVector2f step = bv2 / dist * stride;
const TransformTransition *tt;
if (!get_transition_into(tt, herc_arc)) {
herc_arc->set_transition
(new TransformTransition
(LMatrix4f::translate_mat(step[0], step[1], 0.0)));
} else {
LMatrix4f mat = tt->get_matrix();
mat(3, 0) += step[0];
mat(3, 1) += step[1];
herc_arc->set_transition(new TransformTransition(mat));
}
}
}
}
}
void event_p(CPT_Event) {
// The "p" key was pressed. Toggle projected texture.
static bool projtex_mode = false;
projtex_mode = !projtex_mode;
if (!projtex_mode) {
// Set the normal mode on the render arc.
clear_shader(room_arc, proj_shader);
clear_shader(herc_arc, proj_shader);
clear_shader(ball_arc, proj_shader);
set_alt_trackball(NULL);
remove_child(tex_proj, proj_geom_node, RenderRelation::get_class_type());
} else {
set_shader(room_arc, proj_shader);
set_shader(herc_arc, proj_shader);
set_shader(ball_arc, proj_shader);
set_alt_trackball(tex_proj_trackball);
// Display the texture projector frustum
RenderRelation *prr = new RenderRelation(tex_proj, proj_geom_node);
LightTransition *plt = new LightTransition(LightTransition::all_off());
prr->set_transition(plt);
}
}
void event_s(CPT_Event) {
// The "s" key was pressed. Toggle projected texture spotlight.
static bool projtexspot_mode = false;
LightTransition light_trans;
projtexspot_mode = !projtexspot_mode;
if (!projtexspot_mode) {
// Set the normal mode on the render arc.
clear_shader(room_arc, spot_shader);
clear_shader(herc_arc, spot_shader);
clear_shader(ball_arc, spot_shader);
set_alt_trackball(NULL);
remove_child(tex_proj_spot, spot_shaft, RenderRelation::get_class_type());
} else {
set_shader(room_arc, spot_shader);
set_shader(herc_arc, spot_shader);
set_shader(ball_arc, spot_shader);
set_alt_trackball(tex_spot_trackball);
new RenderRelation(tex_proj_spot, spot_shaft, 10);
}
}
void event_d(CPT_Event) {
// The "d" key was pressed. Toggle projected texture shadows.
static bool projtex_shadow_mode = false;
projtex_shadow_mode = !projtex_shadow_mode;
if (!projtex_shadow_mode) {
// Set the normal mode on the render arc.
clear_shader(room_arc, proj_shadow);
set_alt_trackball(NULL);
} else {
set_shader(room_arc, proj_shadow);
set_alt_trackball(tex_spot_trackball);
}
}
void event_h(CPT_Event) {
// The "h" key was pressed. Toggle highlight.
static bool highlight_mode = false;
highlight_mode = !highlight_mode;
if (!highlight_mode) {
// Set the normal mode on the render arc.
clear_shader(ball_arc, highlight);
} else {
set_shader(ball_arc, highlight);
}
}
void event_e(CPT_Event) {
// The "e" key was pressed. Toggle sphere texture.
static bool spheretex_mode = false;
spheretex_mode = !spheretex_mode;
if (!spheretex_mode) {
// Set the normal mode on the render arc.
clear_shader(ball_arc, spheretex);
} else {
// Set an override on the initial state.
set_shader(ball_arc, spheretex);
}
}
void event_m(CPT_Event) {
// The "m" key was pressed. Toggle sphere reflection.
static bool sphere_reflect_mode = false;
sphere_reflect_mode = !sphere_reflect_mode;
if (!sphere_reflect_mode) {
// Set the normal mode on the render arc.
clear_shader(ball_arc, sreflect);
} else {
// Set an override on the initial state.
set_shader(ball_arc, sreflect);
}
}
void event_r(CPT_Event) {
// The "r" key was pressed. Toggle planar reflection.
static bool plane_reflect_mode = false;
plane_reflect_mode = !plane_reflect_mode;
if (!plane_reflect_mode) {
// Set the normal mode on the render arc.
clear_shader(room_arc, preflect);
} else {
// Set an override on the initial state.
set_shader(room_arc, preflect);
}
}
void event_z(CPT_Event) {
// The "z" key was pressed. Allow the user to move the ball around.
set_alt_trackball(ball_slider);
}
void event_Z(CPT_Event) {
// The "Z" key was pressed. Toggle follow-ball mode.
follow_ball = !follow_ball;
if (follow_ball) {
// Hide the ball while we're following it.
remove_arc(hide_ball_arc);
} else {
// Reveal the ball when we're done following it.
hide_ball_arc = new RenderRelation(render, hide_ball);
}
}
void event_o(CPT_Event) {
// The "o" key was pressed. Toggle outlining.
static bool outline_mode = false;
outline_mode = !outline_mode;
if (!outline_mode) {
// Set the normal mode on the render arc.
clear_shader(herc_arc, outline_shader);
} else {
set_shader(herc_arc, outline_shader);
}
}
void herc_keys(EventHandler &eh) {
eh.add_hook("p", event_p); // Projected Texture Shader
eh.add_hook("s", event_s); // Projected Texture Spotlight
eh.add_hook("d", event_d); // Projected Texture Shadower
eh.add_hook("e", event_e); // Sphere Texture Shader
eh.add_hook("h", event_h); // Sphere Texture Highlighter
eh.add_hook("m", event_m); // Sphere Texture Reflector
eh.add_hook("r", event_r); // Planar Reflector
eh.add_hook("z", event_z); // Move ball
eh.add_hook("Z", event_Z); // Follow ball
eh.add_hook("o", event_o); // Outlining
//==========================================================================
// Models
//==========================================================================
// Load herc
PT_NamedNode herc_model = loader.load_sync("herc-6000.egg");
PT_NamedNode herc_anim = loader.load_sync("HB_1_HE1.egg");
assert(herc_model != (NamedNode *)NULL &&
herc_anim != (NamedNode *)NULL);
PT_NamedNode herc_parent = new NamedNode("herc_parent");
new RenderRelation(herc_parent, herc_model);
new RenderRelation(herc_parent, herc_anim);
AnimControlCollection anim_controls;
auto_bind(herc_parent, anim_controls, ~0);
// And start looping any animations we successfully bound.
anim_controls.loop_all(true);
PT_NamedNode herc_rot = new NamedNode("herc_rot");
RenderRelation *herc_arc1 = new RenderRelation(herc_rot, herc_parent);
herc_arc1->set_transition
(new TransformTransition
(LMatrix4f::scale_mat(LVector3f(0.25, 0.25, 0.25))));
herc = new NamedNode("herc");
herc_rot_arc = new RenderRelation(herc, herc_rot);
herc_arc = new RenderRelation(render, herc);
// Load ball
ball = loader.load_sync("marble_ball.egg");
assert(ball != (NamedNode *)NULL);
PT_NamedNode scaled_ball = new NamedNode("scaled_ball");
RenderRelation *ball_arc1 = new RenderRelation(scaled_ball, ball);
ball_arc1->set_transition
(new TransformTransition(LMatrix4f::scale_mat(0.2)));
hide_ball = new NamedNode("hide_ball");
ball_arc = new RenderRelation(hide_ball, scaled_ball);
ball_arc->set_transition
(new TransformTransition(LMatrix4f::translate_mat(4., 2., 1.)));
hide_ball_arc = new RenderRelation(render, hide_ball);
// Control the ball using a PlanarSlider tform.
ball_slider = new PlanarSlider("ball_slider");
ball_slider->set_transform(LMatrix4f::translate_mat(0.0, 0.0, 1.0) *
LMatrix4f::scale_mat(7.0, -7.0, 1.0));
ball_slider->set_mouse_pos(LPoint2f(4.0 / 7.0, 2.0 / -7.0));
Transform2SG *slider2ball = new Transform2SG("slider2ball");
slider2ball->set_arc(ball_arc);
new RenderRelation(ball_slider, slider2ball);
follow_ball = false;
// Load the room file
PT_NamedNode room = loader.load_sync("lfloor.egg");
assert(room != (NamedNode *)NULL);
room_arc = new RenderRelation(render, room);
// Load up a camera model to visualize our eyepoint.
PT_NamedNode camera_model = loader.load_sync("camera.egg");
assert(camera_model != (NamedNode *)NULL);
camera_model_arc = new RenderRelation(cameras, camera_model);
// Remove any model that was loaded by default or on command line
if (root != (NamedNode *)NULL)
remove_child(render, root, RenderRelation::get_class_type());
if (geomnode != (GeomNode *)NULL)
remove_child(render, geomnode, RenderRelation::get_class_type());
//==========================================================================
// Projected Texture Shader
//==========================================================================
// Load a texture to project
Texture* tex = new Texture;
tex->read("smiley.rgba");
tex->set_name("smiley.rgba");
// Put the texture projector into the scene graph
tex_proj = new LensNode("texture_projector");
RenderRelation* proj_arc = new RenderRelation(render, tex_proj);
// Create a trackball to spin this around.
tex_proj_trackball = new Trackball("tex_proj_trackball");
tex_proj_trackball->set_invert(false);
tex_proj_trackball->set_rel_to(cameras);
Transform2SG *tball2cam = new Transform2SG("tball2cam");
tball2cam->set_arc(proj_arc);
new RenderRelation(tex_proj_trackball, tball2cam);
// Raise it and aim it at the origin
LMatrix4f proj_mat;
LPoint3f proj_pos = LPoint3f::rfu(2., 3., 8.);
LVector3f fwd_vec = proj_pos - LPoint3f::origin();
look_at(proj_mat, -fwd_vec);
proj_mat.set_row(3, proj_pos);
tex_proj_trackball->set_mat(proj_mat);
proj_arc->set_transition(new TransformTransition(proj_mat));
// Create a shader for the texture projector
proj_shader = new ProjtexShader(tex);
proj_shader->add_frustum(tex_proj);
// Create a wireframe representation of the texture projector frustum
PT(Geom) proj_geom =
tex_proj->get_lens()->make_geometry();
proj_geom_node = new GeomNode("proj_geometry");
proj_geom_node->add_geom(proj_geom);
//==========================================================================
// Projected Texture Spotlight Shader
//==========================================================================
tex_proj_spot = new Spotlight("tex_proj_spotlight");
spot_arc = new RenderRelation(render, tex_proj_spot, 10);
// Create a trackball to spin this around.
tex_spot_trackball = new Trackball("tex_spot_trackball");
tex_spot_trackball->set_invert(false);
tex_spot_trackball->set_rel_to(cameras);
tball2cam = new Transform2SG("tball2cam");
tball2cam->set_arc(spot_arc);
new RenderRelation(tex_spot_trackball, tball2cam);
// Raise it and aim it at the origin
LMatrix4f spot_mat;
LPoint3f spot_pos = LPoint3f::rfu(-4., -3., 8.);
LVector3f spot_vec = spot_pos - LPoint3f::origin();
look_at(spot_mat, -spot_vec);
spot_mat.set_row(3, spot_pos);
tex_spot_trackball->set_mat(spot_mat);
spot_arc->set_transition(new TransformTransition(spot_mat));
// Create a shader for the spotlight
spot_shader = new SpotlightShader;
spot_shader->add_frustum(tex_proj_spot);
// Create a light shaft for the spotlight
spot_shaft = tex_proj_spot->make_geometry(0.05, 8.0, 36);
//==========================================================================
// Projected Texture Shadower
//==========================================================================
proj_shadow = new ProjtexShadower;
proj_shadow->add_frustum(tex_proj_spot);
proj_shadow->add_caster(herc);
proj_shadow->add_caster(ball);
proj_shadow->add_caster(camera_model);
//==========================================================================
// Sphere Texture Shader
//==========================================================================
spheretex = new SpheretexShader(tex);
//==========================================================================
// Sphere Texture Highlighter
//==========================================================================
highlight = new SpheretexHighlighter;
highlight->add_frustum(tex_proj_spot);
//==========================================================================
// Sphere Texture Reflector
//==========================================================================
sreflect = new SpheretexReflector;
sreflect->add_frustum(tex_proj_spot);
sreflect->add_caster(room);
sreflect->add_caster(herc);
sreflect->add_caster(camera_model);
//==========================================================================
// Planar Reflector
//==========================================================================
// Create a plane that corresponds to the floor of the room
Planef p(LVector3f::up(), LPoint3f::origin());
PlaneNode* plane_node = new PlaneNode;
plane_node->set_plane(p);
new RenderRelation(room, plane_node);
preflect = new PlanarReflector(plane_node);
preflect->add_caster(ball);
preflect->add_caster(herc);
preflect->add_caster(camera_model);
//==========================================================================
// Outline Shader
//==========================================================================
outline_shader = new OutlineShader;
additional_idle = &herc_idle;
}
int main(int argc, char *argv[]) {
extra_display_func = &herc_display_func;
define_keys = &herc_keys;
extra_overrides_func = &herc_overrides_func;
return framework_main(argc, argv);
}

View File

@ -1,173 +0,0 @@
// Filename: indirect.cxx
// Created by: cary (25Mar99)
//
////////////////////////////////////////////////////////////////////
//
// PANDA 3D SOFTWARE
// Copyright (c) 2001 - 2004, Disney Enterprises, Inc. All rights reserved
//
// All use of this software is subject to the terms of the Panda 3d
// Software license. You should have received a copy of this license
// along with this source code; you will also find a current copy of
// the license at http://etc.cmu.edu/panda3d/docs/license/ .
//
// To contact the maintainers of this program write to
// panda3d-general@lists.sourceforge.net .
//
////////////////////////////////////////////////////////////////////
#include "eventHandler.h"
#include "texture.h"
#include "graphicsWindow.h"
#include "graphicsStateGuardian.h"
#include "pixelBuffer.h"
#include "dconfig.h"
#include "chancfg.h"
#include <string>
Configure(indirect);
extern GraphicsWindow* win;
extern std::string chan_config;
extern int framework_main(int argc, char *argv[]);
extern void (*extra_display_func)();
extern void (*define_keys)(EventHandler&);
extern void (*first_init)();
Texture* t = (Texture*)0L;
PixelBuffer* pb = (PixelBuffer *)0L;
DisplayRegion* dr1 = (DisplayRegion*)0L;
DisplayRegion* dr2 = (DisplayRegion*)0L;
bool use_canned_texture = indirect.GetBool("canned-texture", false);
bool use_texture = indirect.GetBool("use-texture", true);
bool full_region = indirect.GetBool("full-region", true);
bool side_by_side = indirect.GetBool("side-by-side", true);
bool right_to_left = indirect.GetBool("right-to-left", true);
int logs[] = { 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 0 };
int binary_log_cap(int x) {
int i = 0;
for (; (x > logs[i])&&(logs[i] != 0); ++i);
if (logs[i] == 0)
return 4096;
return logs[i];
}
void indirect_display_func( void ) {
GraphicsStateGuardian* g = win->get_gsg();
const RenderBuffer& rf = g->get_render_buffer(RenderBuffer::T_front);
const RenderBuffer& rb = g->get_render_buffer(RenderBuffer::T_back);
if (use_texture) {
if (t == (Texture*)0L) {
t = new Texture;
if (use_canned_texture)
t->read( "smiley.rgba" );
else if (full_region) {
int a, b, w, h;
dr1->get_region_pixels(a, b, w, h);
t->_pbuffer->set_xsize(binary_log_cap(w));
t->_pbuffer->set_ysize(binary_log_cap(h));
} else {
t->_pbuffer->set_xsize( 512 );
t->_pbuffer->set_ysize( 512 );
}
}
if (side_by_side) {
if (right_to_left)
g->prepare_display_region(dr2);
else
g->prepare_display_region(dr1);
}
if (!use_canned_texture) {
if (full_region) {
if (side_by_side) {
if (right_to_left)
t->copy_from( rb, dr2 );
else
t->copy_from( rb, dr1 );
} else
t->copy_from( rb, dr1 );
} else
t->copy_from( rb );
}
if (side_by_side) {
if (right_to_left)
g->prepare_display_region(dr1);
else
g->prepare_display_region(dr2);
}
if (full_region) {
if (side_by_side) {
if (right_to_left)
t->draw_to( rf, dr1 );
else
t->draw_to( rf, dr2 );
} else
t->draw_to( rf, dr1 );
} else
t->draw_to( rf );
} else {
if (pb == (PixelBuffer*)0L) {
pb = new PixelBuffer;
if (use_canned_texture)
pb->read( "smiley.rgba" );
else if (full_region) {
int a, b, w, h;
dr1->get_region_pixels(a, b, w, h);
w = binary_log_cap(w);
h = binary_log_cap(h);
pb->set_xsize(w);
pb->set_ysize(h);
pb->_image = PTA_uchar(w * h * 3);
} else {
pb->set_xsize(512);
pb->set_ysize(512);
pb->_image = PTA_uchar(512 * 512 * 3);
}
}
if (side_by_side) {
if (right_to_left)
g->prepare_display_region(dr2);
else
g->prepare_display_region(dr1);
}
if (!use_canned_texture)
pb->copy_from( rf );
if (side_by_side) {
if (right_to_left)
g->prepare_display_region(dr1);
else
g->prepare_display_region(dr2);
}
pb->draw_to( rf );
}
}
void indirect_init(void) {
if (side_by_side)
chan_config = "two-frame";
}
void indirect_keys(EventHandler&) {
DRList::iterator i = win->getDRBegin();
dr1 = *i;
if (side_by_side) {
++i;
dr2 = *i;
if (right_to_left)
dr1->set_active(false);
else
dr2->set_active(false);
}
}
int main(int argc, char *argv[]) {
define_keys = &indirect_keys;
extra_display_func = &indirect_display_func;
first_init = &indirect_init;
return framework_main(argc, argv);
}

View File

@ -1,68 +0,0 @@
// Filename: loader_test.cxx
// Created by:
//
////////////////////////////////////////////////////////////////////
//
// PANDA 3D SOFTWARE
// Copyright (c) 2001 - 2004, Disney Enterprises, Inc. All rights reserved
//
// All use of this software is subject to the terms of the Panda 3d
// Software license. You should have received a copy of this license
// along with this source code; you will also find a current copy of
// the license at http://etc.cmu.edu/panda3d/docs/license/ .
//
// To contact the maintainers of this program write to
// panda3d-general@lists.sourceforge.net .
//
////////////////////////////////////////////////////////////////////
#include "eventHandler.h"
#include "chancfg.h"
#include "get_rel_pos.h"
#include "loader.h"
#include "pt_NamedNode.h"
#include "framework.h"
uint model_id;
const int MAX_LOOPS = 100;
void event_p(CPT_Event) {
//model_id = loader.request_load("jafar-statue.egg");
//model_id = loader.request_load("camera.egg");
//model_id = loader.request_load("box.egg");
//model_id = loader.request_load("yup-axis.egg");
//model_id = loader.request_load("hand.egg");
//model_id = loader.request_load("frowney.egg", "");
//model_id = loader.request_load("trolley.bam", "");
//model_id = loader.request_load("smiley.egg", "");
//model_id = loader.request_load("jack.bam", "");
model_id = loader.request_load("herc-6000.egg", "");
}
void event_c(CPT_Event) {
if (loader.check_load(model_id))
cerr << "load is complete" << endl;
else
cerr << "loading not finished yet" << endl;
}
void event_s(CPT_Event) {
PT_Node model = loader.fetch_load(model_id);
if (model != (NamedNode*)0L)
new RenderRelation(render, model);
else
cerr << "null model!" << endl;
}
void loader_keys(EventHandler& eh) {
eh.add_hook("p", event_p);
eh.add_hook("c", event_c);
eh.add_hook("s", event_s);
}
int main(int argc, char *argv[]) {
define_keys = &loader_keys;
// loader.fork_asynchronous_thread();
return framework_main(argc, argv);
}

View File

@ -1,444 +0,0 @@
// Filename: min_herc.cxx
// Created by: jason (28Jun00)
//
////////////////////////////////////////////////////////////////////
//
// PANDA 3D SOFTWARE
// Copyright (c) 2001 - 2004, Disney Enterprises, Inc. All rights reserved
//
// All use of this software is subject to the terms of the Panda 3d
// Software license. You should have received a copy of this license
// along with this source code; you will also find a current copy of
// the license at http://etc.cmu.edu/panda3d/docs/license/ .
//
// To contact the maintainers of this program write to
// panda3d-general@lists.sourceforge.net .
//
////////////////////////////////////////////////////////////////////
//Shaders
#include "projtexShader.h"
#include "spotlightShader.h"
#include "projtexShadower.h"
#include "planarReflector.h"
//Channel stuff
#include "chancfg.h"
//Textures
#include "texture.h"
#include "texturePool.h"
//Transitions
#include "textureTransition.h"
#include "shaderTransition.h"
#include "lightTransition.h"
#include "transformTransition.h"
#include "colorBlendTransition.h"
//Light stuff
#include "light.h"
#include "spotlight.h"
//Nodes
#include "pt_NamedNode.h"
#include "geomNode.h"
//Relations (arcs)
#include "renderRelation.h"
#include "nodeRelation.h"
#include "dataRelation.h"
//Misc
#include "dconfig.h"
#include "framework.h"
#include "loader.h"
#include "eventHandler.h"
#include "geomLine.h"
//Math/Matrix/Vector/Transformation stuff
#include "transform2sg.h"
#include "look_at.h"
#include "perspectiveLens.h"
#include "get_rel_pos.h"
//Control/IO
#include "planarSlider.h"
#include "mouse.h"
//Animation
#include "animControl.h"
#include "animControlCollection.h"
#include "auto_bind.h"
Configure(min_herc);
ConfigureFn(min_herc) {
}
PT(LensNode) tex_proj;
PT(Trackball) tex_proj_trackball;
PT(ProjtexShader) proj_shader;
PT(ProjtexShadower) proj_shadow;
PT(PlanarReflector) preflect;
PT(GeomNode) proj_geom_node;
PT_NamedNode spot_shaft;
PT_NamedNode herc;
PT_NamedNode ball;
PT_NamedNode hide_ball;
ShaderTransition shader_trans;
PT(Spotlight) tex_proj_spot;
PT(Trackball) tex_spot_trackball;
PT(SpotlightShader) spot_shader;
PT(PlanarSlider) ball_slider;
bool follow_ball;
RenderRelation* room_arc;
RenderRelation* spot_arc;
RenderRelation* ball_arc;
RenderRelation* hide_ball_arc;
RenderRelation* herc_arc;
RenderRelation* herc_rot_arc;
RenderRelation* camera_model_arc;
extern PT_NamedNode render;
extern NodeAttributes initial_state;
extern PT_NamedNode lights;
extern PT_NamedNode egg_root;
extern PT(GeomNode) geomnode;
extern PT_NamedNode cameras;
extern PT(MouseAndKeyboard) mak;
extern void set_alt_trackball(Node *trackball);
extern PT(GraphicsWindow) main_win;
extern int framework_main(int argc, char *argv[]);
extern void (*extra_display_func)();
extern void (*define_keys)(EventHandler&);
extern void (*extra_overrides_func)(ChanCfgOverrides&, std::string&);
extern void (*additional_idle)();
void herc_overrides_func(ChanCfgOverrides &override, std::string&) {
override.setField(ChanCfgOverrides::Mask,
((unsigned int)(W_DOUBLE|W_DEPTH|W_MULTISAMPLE|W_STENCIL)));
override.setField(ChanCfgOverrides::Title, "Lighting Demo");
}
void herc_idle() {
static const double walk_speed = 4.0; // feet per second
if (follow_ball) {
LPoint3f bp = get_rel_pos(ball, herc);
LVector2f bv2(bp[0], bp[1]);
float dist = length(bv2);
if (dist > 0.0001) {
LMatrix4f mat;
look_at(mat, LPoint3f(-bp[0], -bp[1], 0.0));
herc_rot_arc->set_transition(new TransformTransition(mat));
float stride = walk_speed * ClockObject::get_global_clock()->get_dt();
if (dist > stride) {
LVector2f step = bv2 / dist * stride;
const TransformTransition *tt;
if (!get_transition_into(tt, herc_arc)) {
herc_arc->set_transition
(new TransformTransition
(LMatrix4f::translate_mat(step[0], step[1], 0.0)));
} else {
LMatrix4f mat = tt->get_matrix();
mat(3, 0) += step[0];
mat(3, 1) += step[1];
herc_arc->set_transition(new TransformTransition(mat));
}
}
}
}
}
void event_p(CPT_Event) {
// The "p" key was pressed. Toggle projected texture.
static bool projtex_mode = false;
projtex_mode = !projtex_mode;
if (!projtex_mode) {
// Set the normal mode on the render arc.
clear_shader(room_arc, proj_shader);
clear_shader(herc_arc, proj_shader);
clear_shader(ball_arc, proj_shader);
set_alt_trackball(NULL);
remove_child(tex_proj, proj_geom_node, RenderRelation::get_class_type());
} else {
set_shader(room_arc, proj_shader);
set_shader(herc_arc, proj_shader);
set_shader(ball_arc, proj_shader);
set_alt_trackball(tex_proj_trackball);
// Display the texture projector frustum
RenderRelation *prr = new RenderRelation(tex_proj, proj_geom_node);
LightTransition *plt = new LightTransition(LightTransition::all_off());
prr->set_transition(plt);
}
}
void event_s(CPT_Event) {
// The "s" key was pressed. Toggle projected texture spotlight.
static bool projtexspot_mode = false;
LightTransition light_trans;
projtexspot_mode = !projtexspot_mode;
if (!projtexspot_mode) {
// Set the normal mode on the render arc.
clear_shader(room_arc, spot_shader);
clear_shader(herc_arc, spot_shader);
clear_shader(ball_arc, spot_shader);
set_alt_trackball(NULL);
remove_child(tex_proj_spot, spot_shaft, RenderRelation::get_class_type());
} else {
set_shader(room_arc, spot_shader);
set_shader(herc_arc, spot_shader);
set_shader(ball_arc, spot_shader);
set_alt_trackball(tex_spot_trackball);
new RenderRelation(tex_proj_spot, spot_shaft, 10);
}
}
void event_d(CPT_Event) {
// The "d" key was pressed. Toggle projected texture shadows.
static bool projtex_shadow_mode = false;
projtex_shadow_mode = !projtex_shadow_mode;
if (!projtex_shadow_mode) {
// Set the normal mode on the render arc.
clear_shader(room_arc, proj_shadow);
set_alt_trackball(NULL);
} else {
set_shader(room_arc, proj_shadow);
set_alt_trackball(tex_spot_trackball);
}
}
void event_r(CPT_Event) {
// The "r" key was pressed. Toggle planar reflection.
static bool plane_reflect_mode = false;
plane_reflect_mode = !plane_reflect_mode;
if (!plane_reflect_mode) {
// Set the normal mode on the render arc.
clear_shader(room_arc, preflect);
} else {
// Set an override on the initial state.
set_shader(room_arc, preflect);
}
}
void event_z(CPT_Event) {
// The "z" key was pressed. Allow the user to move the ball around.
set_alt_trackball(ball_slider);
}
void event_Z(CPT_Event) {
// The "Z" key was pressed. Toggle follow-ball mode.
follow_ball = !follow_ball;
if (follow_ball) {
// Hide the ball while we're following it.
remove_arc(hide_ball_arc);
} else {
// Reveal the ball when we're done following it.
hide_ball_arc = new RenderRelation(render, hide_ball);
}
}
void herc_keys(EventHandler &eh) {
Loader loader;
eh.add_hook("p", event_p); // Projected Texture Shader
eh.add_hook("s", event_s); // Projected Texture Spotlight
eh.add_hook("d", event_d); // Projected Texture Shadower
eh.add_hook("r", event_r); // Planar Reflector
eh.add_hook("z", event_z); // Move ball
eh.add_hook("Z", event_Z); // Follow ball
//==========================================================================
// Models
//==========================================================================
// Load herc
PT_NamedNode herc_model = DCAST(NamedNode, loader.load_sync("herc-6000.egg"));
PT_NamedNode herc_anim = DCAST(NamedNode, loader.load_sync("HB_1_HE1.egg"));
assert(herc_model != (NamedNode *)NULL &&
herc_anim != (NamedNode *)NULL);
PT_NamedNode herc_parent = new NamedNode("herc_parent");
new RenderRelation(herc_parent, herc_model);
new RenderRelation(herc_parent, herc_anim);
AnimControlCollection anim_controls;
auto_bind(herc_parent, anim_controls, ~0);
// And start looping any animations we successfully bound.
anim_controls.loop_all(true);
PT_NamedNode herc_rot = new NamedNode("herc_rot");
RenderRelation *herc_arc1 = new RenderRelation(herc_rot, herc_parent);
herc_arc1->set_transition
(new TransformTransition
(LMatrix4f::scale_mat(LVector3f(0.25, 0.25, 0.25))));
herc = new NamedNode("herc");
herc_rot_arc = new RenderRelation(herc, herc_rot);
herc_arc = new RenderRelation(render, herc);
// Load ball
ball = DCAST(NamedNode, loader.load_sync("marble_ball.egg"));
assert(ball != (NamedNode *)NULL);
PT_NamedNode scaled_ball = new NamedNode("scaled_ball");
RenderRelation *ball_arc1 = new RenderRelation(scaled_ball, ball);
ball_arc1->set_transition
(new TransformTransition(LMatrix4f::scale_mat(0.2)));
hide_ball = new NamedNode("hide_ball");
ball_arc = new RenderRelation(hide_ball, scaled_ball);
ball_arc->set_transition
(new TransformTransition(LMatrix4f::translate_mat(4., 2., 1.)));
hide_ball_arc = new RenderRelation(render, hide_ball);
// Control the ball using a PlanarSlider tform.
ball_slider = new PlanarSlider("ball_slider");
ball_slider->set_transform(LMatrix4f::translate_mat(0.0, 0.0, 1.0) *
LMatrix4f::scale_mat(7.0, -7.0, 1.0));
ball_slider->set_mouse_pos(LPoint2f(4.0 / 7.0, 2.0 / -7.0));
Transform2SG *slider2ball = new Transform2SG("slider2ball");
slider2ball->set_arc(ball_arc);
new RenderRelation(ball_slider, slider2ball);
follow_ball = false;
// Load the room file
PT_NamedNode room = DCAST(NamedNode, loader.load_sync("lfloor.egg"));
assert(room != (NamedNode *)NULL);
room_arc = new RenderRelation(render, room);
// Load up a camera model to visualize our eyepoint.
PT_NamedNode camera_model = DCAST(NamedNode, loader.load_sync("camera.egg"));
assert(camera_model != (NamedNode *)NULL);
camera_model_arc = new RenderRelation(cameras, camera_model);
// Remove any model that was loaded by default or on command line
if (root != (NamedNode *)NULL)
remove_child(render, root, RenderRelation::get_class_type());
if (geomnode != (GeomNode *)NULL)
remove_child(render, geomnode, RenderRelation::get_class_type());
//==========================================================================
// Projected Texture Shader
//==========================================================================
// Load a texture to project
Texture* tex = TexturePool::load_texture("smiley.rgba");
tex->set_minfilter(Texture::FT_linear);
tex->set_magfilter(Texture::FT_linear);
tex->set_wrapu(Texture::WM_clamp);
tex->set_wrapv(Texture::WM_clamp);
// Put the texture projector into the scene graph
tex_proj = new LensNode("texture_projector");
RenderRelation* proj_arc = new RenderRelation(render, tex_proj);
// Create a trackball to spin this around.
tex_proj_trackball = new Trackball("tex_proj_trackball");
tex_proj_trackball->set_invert(false);
tex_proj_trackball->set_rel_to(cameras);
Transform2SG *tball2cam = new Transform2SG("tball2cam");
tball2cam->set_arc(proj_arc);
new RenderRelation(tex_proj_trackball, tball2cam);
// Raise it and aim it at the origin
LMatrix4f proj_mat;
LPoint3f proj_pos = LPoint3f::rfu(2., 3., 8.);
LVector3f fwd_vec = proj_pos - LPoint3f::origin();
look_at(proj_mat, -fwd_vec);
proj_mat.set_row(3, proj_pos);
tex_proj_trackball->set_mat(proj_mat);
proj_arc->set_transition(new TransformTransition(proj_mat));
// Create a shader for the texture projector
proj_shader = new ProjtexShader(tex);
proj_shader->add_frustum(tex_proj);
// Create a wireframe representation of the texture projector frustum
PT(Geom) proj_geom =
tex_proj->get_lens()->make_geometry();
proj_geom_node = new GeomNode("proj_geometry");
proj_geom_node->add_geom(proj_geom);
//==========================================================================
// Projected Texture Spotlight Shader
//==========================================================================
tex_proj_spot = new Spotlight("tex_proj_spotlight");
spot_arc = new RenderRelation(render, tex_proj_spot, 10);
// Create a trackball to spin this around.
tex_spot_trackball = new Trackball("tex_spot_trackball");
tex_spot_trackball->set_invert(false);
tex_spot_trackball->set_rel_to(cameras);
tball2cam = new Transform2SG("tball2cam");
tball2cam->set_arc(spot_arc);
new RenderRelation(tex_spot_trackball, tball2cam);
// Raise it and aim it at the origin
LMatrix4f spot_mat;
LPoint3f spot_pos = LPoint3f::rfu(-4., -3., 8.);
LVector3f spot_vec = spot_pos - LPoint3f::origin();
look_at(spot_mat, -spot_vec);
spot_mat.set_row(3, spot_pos);
tex_spot_trackball->set_mat(spot_mat);
spot_arc->set_transition(new TransformTransition(spot_mat));
// Create a shader for the spotlight
spot_shader = new SpotlightShader;
spot_shader->add_frustum(tex_proj_spot);
// Create a light shaft for the spotlight
spot_shaft = tex_proj_spot->make_geometry(0.05, 8.0, 36);
//==========================================================================
// Projected Texture Shadower
//==========================================================================
proj_shadow = new ProjtexShadower;
proj_shadow->add_frustum(tex_proj_spot);
proj_shadow->add_caster(herc);
proj_shadow->add_caster(ball);
proj_shadow->add_caster(camera_model);
//==========================================================================
// Planar Reflector
//==========================================================================
// Create a plane that corresponds to the floor of the room
Planef p(LVector3f::up(), LPoint3f::origin());
PlaneNode* plane_node = new PlaneNode;
plane_node->set_plane(p);
new RenderRelation(room, plane_node);
preflect = new PlanarReflector(plane_node);
preflect->add_caster(ball);
preflect->add_caster(herc);
preflect->add_caster(camera_model);
additional_idle = &herc_idle;
}
int main(int argc, char *argv[]) {
define_keys = &herc_keys;
extra_overrides_func = &herc_overrides_func;
return framework_main(argc, argv);
}

View File

@ -1,823 +0,0 @@
// Filename: min_shader.cxx
// Created by: jason (28Jun00)
//
////////////////////////////////////////////////////////////////////
//
// PANDA 3D SOFTWARE
// Copyright (c) 2001 - 2004, Disney Enterprises, Inc. All rights reserved
//
// All use of this software is subject to the terms of the Panda 3d
// Software license. You should have received a copy of this license
// along with this source code; you will also find a current copy of
// the license at http://etc.cmu.edu/panda3d/docs/license/ .
//
// To contact the maintainers of this program write to
// panda3d-general@lists.sourceforge.net .
//
////////////////////////////////////////////////////////////////////
//Shaders
#include "projtexShader.h"
#include "spotlightShader.h"
#include "projtexShadower.h"
#include "planarReflector.h"
#include "spheretexReflector.h"
#include "spheretexHighlighter.h"
#include "spheretexReflector.h"
#include "outlineShader.h"
//Channel stuff
#include "chancfg.h"
//Textures
#include "texture.h"
#include "texturePool.h"
//Transitions
#include "textureTransition.h"
#include "shaderTransition.h"
#include "lightTransition.h"
#include "transformTransition.h"
#include "colorBlendTransition.h"
//Light stuff
#include "light.h"
#include "spotlight.h"
//Nodes
#include "pt_NamedNode.h"
#include "geomNode.h"
//Relations (arcs)
#include "renderRelation.h"
#include "nodeRelation.h"
#include "dataRelation.h"
//Misc
#include "dconfig.h"
#include "framework.h"
#include "loader.h"
#include "eventHandler.h"
//Math/Matrix/Vector/Transformation stuff
#include "transform2sg.h"
#include "look_at.h"
#include "perspectiveLens.h"
#include "geomLine.h"
Configure(min_shader);
ConfigureFn(min_shader) {
}
//--------Projective texture stuff--------
PT(LensNode) tex_proj;
PT(Trackball) tex_proj_trackball;
PT(ProjtexShader) proj_shader;
//--------Spotlight stuff-----------------
PT(Spotlight) tex_proj_spot;
PT(Trackball) tex_spot_trackball;
PT(SpotlightShader) spot_shader;
//--------Projective Shadow stuff--------
PT(ProjtexShadower) proj_shadow;
//--------Planar reflecter stuff---------
PT(PlanarReflector) preflect;
//--------Sphere texture stuff---------
PT(SpheretexShader) spheretex;
//--------Sphere texture highlight stuff---------
PT(SpheretexHighlighter) highlight;
//--------Sphere texture reflector stuff---------
PT(SpheretexReflector) sreflect;
//--------Outline shader stuff---------
PT(OutlineShader) outline_shader;
ShaderTransition shader_trans;
RenderRelation* room_arc;
RenderRelation* spot_arc;
RenderRelation* jack_arc;
RenderRelation* camera_model_arc;
RenderRelation* smiley_arc;
PT(LightTransition) light_transition;
//Framework extern variables and functions
extern PT_NamedNode render;
extern NodeAttributes initial_state;
extern RenderRelation* first_arc;
extern PT_NamedNode lights;
extern PT_NamedNode root;
extern PT(GeomNode) geomnode;
extern PT_NamedNode cameras;
extern PT(MouseAndKeyboard) mak;
extern void set_alt_trackball(Node *trackball);
extern int framework_main(int argc, char *argv[]);
extern void (*extra_display_func)();
extern void (*define_keys)(EventHandler&);
extern PT(GraphicsWindow) main_win;
//GLOBALS
LPoint3f center_pos = LPoint3f::origin();
Transform2SG *tball2cam;
Texture* tex;
//VIZ STUFF
class BaseViz : public Shader::Visualize {
public:
BaseViz(void);
virtual ~BaseViz(void);
virtual void DisplayTexture(PT(Texture)&, Shader*);
virtual void DisplayPixelBuffer(PT(PixelBuffer)&, Shader*);
protected:
typedef std::plist<PT(Texture) > texlist;
typedef texlist::iterator texiter;
typedef std::plist<PT(PixelBuffer) > pblist;
typedef pblist::iterator pbiter;
texlist _texs;
pblist _pbs;
};
BaseViz::BaseViz(void) {}
BaseViz::~BaseViz(void) {}
void BaseViz::DisplayTexture(PT(Texture)& tex, Shader*) {
if (tex->has_ram_image())
_texs.push_back(tex);
else {
GraphicsStateGuardian* g = main_win->get_gsg();
PT(PixelBuffer) pb(new PixelBuffer);
g->texture_to_pixel_buffer(tex->prepare(g), pb);
_pbs.push_back(pb);
}
}
void BaseViz::DisplayPixelBuffer(PT(PixelBuffer)& pb, Shader*) {
_pbs.push_back(pb);
}
class Oldviz : public BaseViz {
public:
Oldviz(PT(GraphicsWindow)&);
virtual ~Oldviz(void);
virtual void Flush(void);
protected:
PT(GraphicsWindow) _w;
};
Oldviz::Oldviz(PT(GraphicsWindow)& win) : _w(win) {}
Oldviz::~Oldviz(void) {}
void Oldviz::Flush(void) {
GraphicsStateGuardian* g = _w->get_gsg();
const RenderBuffer& r = g->get_render_buffer(RenderBuffer::T_front);
PT(DisplayRegion) d(_w->make_scratch_display_region(256, 256));
for (texiter i=_texs.begin(); i!=_texs.end(); ++i)
(*i)->draw(g, d, r);
for (pbiter j=_pbs.begin(); j!=_pbs.end(); ++j)
(*j)->draw(g, d, r);
_texs.erase(_texs.begin(), _texs.end());
_pbs.erase(_pbs.begin(), _pbs.end());
}
class Viztex : public BaseViz {
public:
Viztex(PT(GraphicsPipe)&);
virtual ~Viztex(void);
virtual void Flush(void);
protected:
typedef std::plist< PT(GraphicsWindow) > winlist;
typedef winlist::iterator winiter;
winlist _wins;
PT(GraphicsPipe) _pipe;
};
Viztex::Viztex(PT(GraphicsPipe)& p) : _pipe(p) {}
Viztex::~Viztex(void) {}
void Viztex::Flush(void) {
winiter _witer = _wins.begin();
for (texiter i=_texs.begin(); i!=_texs.end(); ++i) {
GraphicsWindow* w;
if (_witer == _wins.end()) {
ChanCfgOverrides override;
override.setField(ChanCfgOverrides::Mask,
((unsigned int)(W_SINGLE)));
override.setField(ChanCfgOverrides::Title, "Multipass partial");
override.setField(ChanCfgOverrides::SizeX, 256);
override.setField(ChanCfgOverrides::SizeY, 256);
override.setField(ChanCfgOverrides::Cameras, false);
w = ChanConfig(_pipe, "single", (Node *)NULL, render, override);
_wins.push_back(w);
}
else
{
w = *_witer;
++_witer;
}
GraphicsStateGuardian* g = w->get_gsg();
const RenderBuffer& r = g->get_render_buffer(RenderBuffer::T_front);
PT(DisplayRegion) d(w->make_scratch_display_region(w->get_width(),
w->get_height()));
// g->prepare_display_region(d);
(*i)->draw(g, d, r);
}
for (pbiter j=_pbs.begin(); j!=_pbs.end(); ++j) {
GraphicsWindow* w;
if (_witer == _wins.end()) {
ChanCfgOverrides override;
override.setField(ChanCfgOverrides::Mask,
((unsigned int)(W_SINGLE)));
override.setField(ChanCfgOverrides::Title, "Multipass partial");
override.setField(ChanCfgOverrides::SizeX, 256);
override.setField(ChanCfgOverrides::SizeY, 256);
override.setField(ChanCfgOverrides::Cameras, false);
w = ChanConfig(_pipe, "single", cameras, render, override);
_wins.push_back(w);
} else {
w = *_witer;
++_witer;
}
GraphicsStateGuardian* g = w->get_gsg();
const RenderBuffer& r = g->get_render_buffer(RenderBuffer::T_front);
PT(DisplayRegion) d(w->make_scratch_display_region(w->get_width(),
w->get_height()));
// g->prepare_display_region(d);
(*j)->draw(g, d, r);
}
_texs.erase(_texs.begin(), _texs.end());
_pbs.erase(_pbs.begin(), _pbs.end());
}
class Tiledviz : public Viztex {
public:
Tiledviz(PT(GraphicsPipe)&);
virtual ~Tiledviz(void);
virtual void Flush(void);
};
Tiledviz::Tiledviz(PT(GraphicsPipe)& p) : Viztex(p) {}
Tiledviz::~Tiledviz(void) {}
void Tiledviz::Flush(void) {
int count = 0;
int layer_count = 0;
winiter _witer = _wins.begin();
for (texiter texi=_texs.begin(); texi!=_texs.end(); ++texi) {
GraphicsWindow* w;
DisplayRegion* d;
if (_witer == _wins.end()) {
ChanCfgOverrides override;
override.setField(ChanCfgOverrides::Mask,
((unsigned int)(W_SINGLE)));
override.setField(ChanCfgOverrides::Title, "Multipass partial");
override.setField(ChanCfgOverrides::SizeX, main_win->get_width());
override.setField(ChanCfgOverrides::SizeY, main_win->get_height());
override.setField(ChanCfgOverrides::Cameras, false);
w = ChanConfig(_pipe, "multipass-tile", cameras, render, override);
_wins.push_back(w);
_witer = --(_wins.end());
} else
w = *_witer;
int dridx;
GraphicsStateGuardian* g = w->get_gsg();
GraphicsChannel *chan = w->get_channel(0);
GraphicsLayer *layer = chan->get_layer(layer_count);
const RenderBuffer& r = g->get_render_buffer(RenderBuffer::T_front);
d = layer->get_dr(count);
(*texi)->draw(g, d, r);
++count;
if (count == layer->get_num_drs()) {
count = 0;
++layer_count;
}
if (layer_count == chan->get_num_layers())
{
layer_count = 0;
++_witer;
}
}
for (pbiter pbi=_pbs.begin(); pbi!=_pbs.end(); ++pbi) {
GraphicsWindow* w;
DisplayRegion* d;
if (_witer == _wins.end()) {
ChanCfgOverrides override;
override.setField(ChanCfgOverrides::Mask,
((unsigned int)(W_SINGLE)));
override.setField(ChanCfgOverrides::Title, "Multipass partial");
override.setField(ChanCfgOverrides::SizeX, main_win->get_width());
override.setField(ChanCfgOverrides::SizeY, main_win->get_height());
override.setField(ChanCfgOverrides::Cameras, false);
w = ChanConfig(_pipe, "multipass-tile", cameras, render, override);
_wins.push_back(w);
_witer = --(_wins.end());
} else
w = *_witer;
int dridx;
GraphicsStateGuardian* g = w->get_gsg();
GraphicsChannel *chan = w->get_channel(0);
GraphicsLayer *layer = chan->get_layer(layer_count);
const RenderBuffer& r = g->get_render_buffer(RenderBuffer::T_front);
d = layer->get_dr(count);
(*pbi)->draw(g, d, r);
++count;
if (count == layer->get_num_drs()) {
count = 0;
++layer_count;
}
if (layer_count == chan->get_num_layers())
{
layer_count = 0;
++_witer;
}
}
_texs.erase(_texs.begin(), _texs.end());
_pbs.erase(_pbs.begin(), _pbs.end());
}
void shader_display_func(void) {
Shader::Visualize* v = Shader::get_viz();
if (v != (Shader::Visualize*)0L)
v->Flush();
}
//END VIZ STUFF
////////////////////////////////////////////////////////////////////
// Function: event_p
// Access: Public
// Description: Toggle the projective texture being on and off
////////////////////////////////////////////////////////////////////
void event_p(CPT_Event) {
static bool projtex_mode = false;
projtex_mode = !projtex_mode;
if (!projtex_mode) {
// Set the normal mode on the render arc.
clear_shader(room_arc, proj_shader);
//clear_shader(first_arc, proj_shader);
//clear_shader(jack_arc, proj_shader);
set_alt_trackball(NULL);
} else {
// Set an override on the initial state.
set_shader(room_arc, proj_shader);
//set_shader(first_arc, proj_shader);
//set_shader(jack_arc, proj_shader);
set_alt_trackball(tex_proj_trackball);
}
}
////////////////////////////////////////////////////////////////////
// Function: event_s
// Access: Public
// Description: Toggle the spotlight being on and off
////////////////////////////////////////////////////////////////////
void event_s(CPT_Event) {
static bool projtexspot_mode = false;
projtexspot_mode = !projtexspot_mode;
if (!projtexspot_mode) {
// Set the normal mode on the render arc.
clear_shader(room_arc, spot_shader);
set_alt_trackball(NULL);
} else {
// Set an override on the initial state.
set_shader(room_arc, spot_shader);
set_alt_trackball(tex_spot_trackball);
}
}
////////////////////////////////////////////////////////////////////
// Function: event_d
// Access: Public
// Description: Toggle projected shadows
////////////////////////////////////////////////////////////////////
void event_d(CPT_Event)
{
static bool projtex_shadow_mode = false;
projtex_shadow_mode = !projtex_shadow_mode;
if (!projtex_shadow_mode) {
// Set the normal mode on the render arc.
clear_shader(room_arc, proj_shadow);
set_alt_trackball(NULL);
}
else
{
set_shader(room_arc, proj_shadow);
set_alt_trackball(tex_spot_trackball);
}
}
////////////////////////////////////////////////////////////////////
// Function: event_r
// Access: Public
// Description: Toggle planar reflection
////////////////////////////////////////////////////////////////////
void event_r(CPT_Event)
{
static bool plane_reflect_mode = false;
plane_reflect_mode = !plane_reflect_mode;
if (!plane_reflect_mode) {
// Set the normal mode on the render arc.
clear_shader(room_arc, preflect);
}
else
{
// Set an override on the initial state.
set_shader(room_arc, preflect);
}
}
////////////////////////////////////////////////////////////////////
// Function: event_e
// Access: Public
// Description: Toggle sphere texture
////////////////////////////////////////////////////////////////////
void event_e(CPT_Event) {
static bool spheretex_mode = false;
spheretex_mode = !spheretex_mode;
if (!spheretex_mode) {
// Set the normal mode on the render arc.
//clear_shader(first_arc, spheretex);
clear_shader(jack_arc, spheretex);
} else {
// Set an override on the initial state.
//set_shader(first_arc, spheretex);
set_shader(jack_arc, spheretex);
}
}
////////////////////////////////////////////////////////////////////
// Function: event_h
// Access: Public
// Description: Toggle sphere texture highlight
////////////////////////////////////////////////////////////////////
void event_h(CPT_Event) {
static bool highlight_mode = false;
highlight_mode = !highlight_mode;
if (!highlight_mode) {
// Set the normal mode on the render arc.
clear_shader(jack_arc, highlight);
} else {
set_shader(jack_arc, highlight);
}
}
////////////////////////////////////////////////////////////////////
// Function: event_h
// Access: Public
// Description: Toggle sphere texture reflector
////////////////////////////////////////////////////////////////////
void event_m(CPT_Event) {
static bool sphere_reflect_mode = false;
sphere_reflect_mode = !sphere_reflect_mode;
if (!sphere_reflect_mode) {
// Set the normal mode on the render arc.
clear_shader(jack_arc, sreflect);
} else {
// Set an override on the initial state.
set_shader(jack_arc, sreflect);
}
}
////////////////////////////////////////////////////////////////////
// Function: event_o
// Access: Public
// Description: Toggle outline shader
////////////////////////////////////////////////////////////////////
void event_o(CPT_Event) {
static bool outline_mode = false;
outline_mode = !outline_mode;
if (!outline_mode) {
// Set the normal mode on the render arc.
clear_shader(jack_arc, outline_shader);
} else {
set_shader(jack_arc, outline_shader);
}
}
////////////////////////////////////////////////////////////////////
// Function: setup_projtex
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
void setup_projtex(void)
{
// Create a projected texture shader
// Put the texture projector into the scene graph
tex_proj = new LensNode("texture_projector");
RenderRelation* proj_arc = new RenderRelation(render, tex_proj);
// Create a trackball to spin this around.
tex_proj_trackball = new Trackball("tex_proj_trackball");
tex_proj_trackball->set_invert(false);
tex_proj_trackball->set_rel_to(cameras);
tball2cam = new Transform2SG("tball2cam");
tball2cam->set_arc(proj_arc);
new DataRelation(tex_proj_trackball, tball2cam);
// Raise it and aim it at the origin
LMatrix4f proj_mat;
LPoint3f proj_pos = LPoint3f::rfu(2., 3., 8.);
LVector3f fwd_vec = proj_pos - center_pos;
look_at(proj_mat, -fwd_vec);
proj_mat.set_row(3, proj_pos);
tex_proj_trackball->set_mat(proj_mat);
proj_arc->set_transition(new TransformTransition(proj_mat));
// Create a shader for the texture projector
proj_shader = new ProjtexShader(tex);
proj_shader->set_priority(150);
proj_shader->add_frustum(tex_proj);
#define DISPLAY_TEXPROJFRUST
#ifdef DISPLAY_TEXPROJFRUST
// Display a wireframe representation of the texture projector frustum
PT(Geom) proj_geom =
tex_proj->get_lens()->make_geometry();
GeomNode* proj_geom_node = new GeomNode("proj_geometry");
proj_geom_node->add_geom(proj_geom);
RenderRelation *prr = new RenderRelation(tex_proj, proj_geom_node);
LightTransition *plt = new LightTransition(LightTransition::all_off());
prr->set_transition(plt);
#endif
}
////////////////////////////////////////////////////////////////////
// Function: setup_spotlight
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
void setup_spotlight(void)
{
// Create a projected texture spotlight shader
tex_proj_spot = new Spotlight("tex_proj_spotlight");
//Push out the far clipping plane of the spotlight frustum
PT(Lens) lens = new PerspectiveLens;
lens->set_fov(45.0f);
lens->set_near(f._fnear);
lens->set_far(13.0f);
tex_proj_spot->set_lens(lens);
spot_arc = new RenderRelation(render, tex_proj_spot, 10);
// Create a trackball to spin this around.
tex_spot_trackball = new Trackball("tex_spot_trackball");
tex_spot_trackball->set_invert(false);
tex_spot_trackball->set_rel_to(cameras);
tball2cam = new Transform2SG("tball2cam");
tball2cam->set_arc(spot_arc);
new DataRelation(tex_spot_trackball, tball2cam);
// Raise it and aim it at the origin
LMatrix4f spot_mat;
LPoint3f spot_pos = LPoint3f::rfu(-4., -3., 8.);
LVector3f spot_vec = spot_pos - center_pos;
look_at(spot_mat, -spot_vec);
spot_mat.set_row(3, spot_pos);
tex_spot_trackball->set_mat(spot_mat);
spot_arc->set_transition(new TransformTransition(spot_mat));
// Create a shader for the spotlight
spot_shader = new SpotlightShader;
spot_shader->set_priority(150);
spot_shader->add_frustum(tex_proj_spot);
#define DISPLAY_TEXPROJSPOTFRUST
#ifdef DISPLAY_TEXPROJSPOTFRUST
// Display a wireframe representation of the spotlight frustum
Colorf color_red(1., 0., 0., 1.);
PT(Geom) frust_geom =
tex_proj_spot->get_lens()->make_geometry();
GeomNode* frust_geom_node = new GeomNode("frustum_geometry");
frust_geom_node->add_geom(frust_geom);
RenderRelation *rr = new RenderRelation(tex_proj_spot, frust_geom_node);
LightTransition *lt = new LightTransition(LightTransition::all_off());
rr->set_transition(lt);
#endif
#define DISPLAY_SHAFT
#ifdef DISPLAY_SHAFT
// Draw a light shaft for the spotlight
NamedNode* shaft = tex_proj_spot->make_geometry(0.05, 8.0, 36);
RenderRelation *sr = new RenderRelation(tex_proj_spot, shaft, 10);
#endif
}
////////////////////////////////////////////////////////////////////
// Function: setup_planar
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
void setup_planar(void)
{
// Create a planar reflection
Planef p(LVector3f(0., 0., 1.), LVector3f(0., 0., -10.));
PlaneNode* plane_node = new PlaneNode;
plane_node->set_plane(p);
preflect = new PlanarReflector(plane_node);
}
////////////////////////////////////////////////////////////////////
// Function: setup_projshadow
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
void setup_projshadow(void)
{
// Create a projected texture shadower
proj_shadow = new ProjtexShadower;
proj_shadow->add_frustum(tex_proj_spot);
proj_shadow->set_priority(150);
if (root != (NamedNode *)NULL) {
proj_shadow->add_caster(root);
preflect->add_caster(root);
} else if (geomnode != (GeomNode *)NULL) {
proj_shadow->add_caster(geomnode);
preflect->add_caster(geomnode);
}
}
////////////////////////////////////////////////////////////////////
// Function: setup_vizes
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
void setup_vizes(void)
{
// and now for some multipass partial visualization
Shader::Visualize* v = Shader::get_viz();
std::string viztype = min_shader.GetString("multipass-viz", "none");
if (viztype == "old-style")
{
PT(GraphicsWindow) w(main_win);
v = new Oldviz(w);
}
else if (viztype == "new-single")
{
PT(GraphicsPipe) p(((GraphicsPipe*)(main_win->get_pipe())));
v = new Viztex(p);
}
else if (viztype == "new-tile")
{
PT(GraphicsPipe) p(((GraphicsPipe*)(main_win->get_pipe())));
v = new Tiledviz(p);
}
Shader::set_viz(v);
}
////////////////////////////////////////////////////////////////////
// Function: min_shader_keys
// Access: Public
// Description: Set event handlers for the various keys needed, and
// do any initialization necessary
////////////////////////////////////////////////////////////////////
void min_shader_keys(EventHandler &eh) {
Loader loader;
eh.add_hook("p", event_p);
eh.add_hook("s", event_s);
eh.add_hook("d", event_d);
eh.add_hook("r", event_r);
eh.add_hook("e", event_e);
eh.add_hook("h", event_h);
eh.add_hook("m", event_m);
eh.add_hook("o", event_o);
// Load a texture to project
tex = TexturePool::load_texture("smiley.rgba");
tex->set_minfilter(Texture::FT_linear);
tex->set_magfilter(Texture::FT_linear);
tex->set_wrapu(Texture::WM_clamp);
tex->set_wrapv(Texture::WM_clamp);
//--------------------PROJECTED TEXTURE SHADER-------------------
setup_projtex();
//--------------------SPOTLIGHT SHADER-------------------
setup_spotlight();
//--------------------PLANAR REFLECTOR SHADER-------------------
setup_planar();
//--------------------SHADOW SHADER-------------------
setup_projshadow();
//--------------------SPHERE TEXTURE SHADER-------------------
spheretex = new SpheretexShader(tex);
spheretex->set_priority(150);
//--------------------SPHERE HIGHLIGHTER TEXTURE SHADER-------------------
highlight = new SpheretexHighlighter(32);
highlight->add_frustum(tex_proj_spot);
highlight->set_priority(150);
//--------------------SPHERE REFLECTOR TEXTURE SHADER-------------------
sreflect = new SpheretexReflector;
sreflect->add_frustum(tex_proj_spot);
sreflect->set_priority(150);
sreflect->add_caster(root);
//--------------------OUTLINE SHADER-------------------
outline_shader = new OutlineShader;
outline_shader->set_priority(150);
// Load the room file
PT_NamedNode room = DCAST(NamedNode, loader.load_sync("big-room.egg"));
if (room != (NamedNode *)NULL) {
room_arc = new RenderRelation(render, room, 20);
sreflect->add_caster(room);
}
// Load jack
PT_NamedNode jack = DCAST(NamedNode, loader.load_sync("jack.egg"));
if (jack != (NamedNode *)NULL) {
jack_arc = new RenderRelation(render, jack);
LMatrix4f jack_mat = LMatrix4f::ident_mat();
LPoint3f jack_pos = LPoint3f::rfu(-2., -2., -6.);
jack_mat.set_row(3, jack_pos);
jack_arc->set_transition(new TransformTransition(jack_mat));
proj_shadow->add_caster(jack);
preflect->add_caster(jack);
}
// Load jack
PT_NamedNode smiley = DCAST(NamedNode, loader.load_sync("smiley.egg"));
if (jack != (NamedNode *)NULL) {
smiley_arc = new RenderRelation(render, smiley);
proj_shadow->add_caster(smiley);
preflect->add_caster(smiley);
}
// Load up a camera model to visualize our eyepoint.
PT_NamedNode camera_model = DCAST(NamedNode, loader.load_sync("camera.egg"));
if (camera_model != (NamedNode *)NULL) {
camera_model_arc = new RenderRelation(cameras, camera_model);
sreflect->add_caster(camera_model);
proj_shadow->add_caster(camera_model);
preflect->add_caster(camera_model);
}
// Set up a transition for the spotlight
light_transition = new LightTransition;
if (first_arc != (NodeRelation *)NULL) {
first_arc->set_transition(light_transition);
}
if (jack_arc != (NodeRelation *)NULL) {
jack_arc->set_transition(light_transition);
}
setup_vizes();
}
int main(int argc, char *argv[]) {
extra_display_func = &shader_display_func;
define_keys = &min_shader_keys;
return framework_main(argc, argv);
}

View File

@ -1,126 +0,0 @@
// Filename: motion.cxx
// Created by: frang (23Mar99)
//
////////////////////////////////////////////////////////////////////
//
// PANDA 3D SOFTWARE
// Copyright (c) 2001 - 2004, Disney Enterprises, Inc. All rights reserved
//
// All use of this software is subject to the terms of the Panda 3d
// Software license. You should have received a copy of this license
// along with this source code; you will also find a current copy of
// the license at http://etc.cmu.edu/panda3d/docs/license/ .
//
// To contact the maintainers of this program write to
// panda3d-general@lists.sourceforge.net .
//
////////////////////////////////////////////////////////////////////
#include "eventHandler.h"
#include "texture.h"
#include "graphicsWindow.h"
#include "graphicsStateGuardian.h"
#include "chancfg.h"
#include "notify.h"
#include <string>
#include "plist.h"
extern GraphicsWindow* win;
extern int framework_main(int argc, char *argv[]);
extern void (*extra_display_func)();
extern void (*define_keys)(EventHandler&);
#include <GL/gl.h>
typedef plist<Texture*> TexList;
TexList screenshots;
typedef plist<PixelBuffer*> PBList;
PBList sshots;
int num_frames = 4;
int frame_num = 0;
void motion_display_func( void ) {
GraphicsStateGuardian* g = win->get_gsg();
const RenderBuffer& r = g->get_render_buffer(RenderBuffer::T_front);
Texture* t;
PixelBuffer* p;
if (frame_num < num_frames) {
t = new Texture;
t->_pbuffer->set_xsize(win->get_width());
t->_pbuffer->set_ysize(win->get_height());
p = new PixelBuffer;
p->set_xsize(win->get_width());
p->set_ysize(win->get_height());
p->_image = PTA_uchar(win->get_width() * win->get_height() * 4);
} else {
TexList::iterator i = screenshots.begin();
PBList::iterator l = sshots.begin();
for (int j=0, k=frame_num%num_frames; j<k; ++i, ++j, ++l);
t = *i;
p = *l;
}
// g->copy_texture_from(t, r);
g->copy_pixel_buffer_from(p, r);
const RenderBuffer& rb = g->get_render_buffer(RenderBuffer::T_back);
if (frame_num < num_frames) {
// screenshots.push_back(t);
sshots.push_back(p);
}
// now we accumulate. Off the top of my head I have 3 plans for this:
// 1) apply the screen shots to one or several whole-screen polygon(s) with
// appropriate alpha
// 2) accumulate this into an accumulation buffer every frame
// 3) blend the new frame into the accumulation buffer, and subtractively
// blend the old one out.
// version 2. Even this could be better if we didn't start by blowing away
// the frame we just rendered.
GLfloat d = 1. / GLfloat(screenshots.size() + 1.);
TexList::iterator i = screenshots.begin();
PBList::iterator j = sshots.begin();
// for (TexList::iterator i=screenshots.begin(); i!=screenshots.end(); ++i) {
for (; j!=sshots.end(); ++j) {
// t = *i;
// g->draw_texture_to(t, rb);
p = *j;
g->draw_pixel_buffer_to(p, rb);
// if (i == screenshots.begin())
if (j == sshots.begin())
glAccum(GL_LOAD, d);
else
glAccum(GL_ACCUM, d);
}
glAccum(GL_RETURN, 1.0);
g->end_frame();
++frame_num;
}
void event_plus(CPT_Event) {
frame_num %= num_frames++;
nout << "now blending " << num_frames << " frames." << endl;
}
void event_minus(CPT_Event) {
frame_num %= --num_frames;
nout << "now blending " << num_frames << " frames." << endl;
// screenshots.erase(--(screenshots.end()));
sshots.erase(--(sshots.end()));
}
void motion_keys(EventHandler& eh) {
eh.add_hook("plus", event_plus);
eh.add_hook("minus", event_minus);
}
int main(int argc, char *argv[]) {
extra_display_func = &motion_display_func;
define_keys = &motion_keys;
return framework_main(argc, argv);
}

View File

@ -1,150 +0,0 @@
// Filename: dxwindow.cxx
// Created by: drose (09Jan02)
//
////////////////////////////////////////////////////////////////////
//
// PANDA 3D SOFTWARE
// Copyright (c) 2001 - 2004, Disney Enterprises, Inc. All rights reserved
//
// All use of this software is subject to the terms of the Panda 3d
// Software license. You should have received a copy of this license
// along with this source code; you will also find a current copy of
// the license at http://etc.cmu.edu/panda3d/docs/license/ .
//
// To contact the maintainers of this program write to
// panda3d-general@lists.sourceforge.net .
//
////////////////////////////////////////////////////////////////////
#include "graphicsWindow.h"
#include "graphicsChannel.h"
#include "graphicsLayer.h"
#include "displayRegion.h"
#include "camera.h"
#include "perspectiveLens.h"
#include "namedNode.h"
#include "renderRelation.h"
#include "transformTransition.h"
#include "loader.h"
#include "clockObject.h"
#ifdef USE_GLX
#include "glxGraphicsPipe.h"
#else
#include "wglGraphicsPipe.h"
#include "wdxGraphicsPipe.h"
#include "wcrGraphicsPipe.h"
#endif
// This program demonstrates creating a graphics window in Panda
// explicitly, without using ChanCfg as an interface wrapper.
// Normally we use ChanCfg to create the window and automatically set
// up many of its parameters.
void
get_models(Node *root, int argc, char *argv[]) {
Loader loader;
for (int i = 1; i < argc; i++) {
Filename filename = argv[i];
cerr << "Loading " << filename << "\n";
PT_Node node = loader.load_sync(filename);
if (node == (Node *)NULL) {
cerr << "Unable to load " << filename << "\n";
} else {
new RenderRelation(root, node);
}
}
}
int
main(int argc, char *argv[]) {
// First, create a GraphicsPipe. For this we need a PipeSpecifier
// to specify the parameters we want to pass to the pipe. Yeah, I
// know it's a weird way to pass parameters to an object.
PipeSpecifier pipe_spec;
PT(GraphicsPipe) pipe;
#ifdef USE_GLX
pipe = new glxGraphicsPipe(pipe_spec);
#else
// Yes, this is a stupid hard coded switch, but this is a test app, and
// I'm just making it easier to see the choices (and switch between them).
switch (2) {
case 1:
// ...OpenGL pipe
pipe = new wglGraphicsPipe(pipe_spec);
break;
case 2:
// ...Chromium OpenGL pipe (cr == chromium)
pipe = new wcrGraphicsPipe(pipe_spec);
break;
default:
// ...DirectX pipe
pipe = new wdxGraphicsPipe(pipe_spec);
break;
}
#endif
// Now create a window on that pipe.
GraphicsWindow::Properties window_prop;
window_prop._xorg = 0;
window_prop._yorg = 0;
window_prop._xsize = 640;
window_prop._ysize = 480;
window_prop._title = "Window";
// window_prop._fullscreen = true;
PT(GraphicsWindow) window = pipe->make_window(window_prop);
// Get the first channel on the window. This will be the only
// channel on non-SGI hardware.
PT(GraphicsChannel) channel = window->get_channel(0);
// Make a layer on the channel to hold our display region.
PT(GraphicsLayer) layer = channel->make_layer();
// And create a display region that covers the entire window.
PT(DisplayRegion) dr = layer->make_display_region();
// Finally, we need a camera to associate with the display region.
PT(Camera) camera = new Camera;
PT(Lens) lens = new PerspectiveLens;
lens->set_film_size(640, 480);
camera->set_lens(lens);
dr->set_camera(camera);
// Window setup is complete. Now we just need to make a scene graph
// for the camera to render.
PT_Node render_top = new NamedNode("render_top");
camera->set_scene(render_top);
PT_Node render = new NamedNode("render");
NodeRelation *render_arc = new RenderRelation(render_top, render);
// Put something in the scene graph to look at.
get_models(render, argc, argv);
// Put the scene a distance in front of our face so we can see it.
LMatrix4f mat = LMatrix4f::translate_mat(0, 20, 0);
TransformTransition *tt = new TransformTransition(mat);
render_arc->set_transition(tt);
// This is our main update loop. Run for 5 seconds, then shut down.
ClockObject *clock = ClockObject::get_global_clock();
clock->tick();
double now = clock->get_frame_time();
while (clock->get_frame_time() - now < 5.0) {
clock->tick();
window->get_gsg()->render_frame();
window->update();
}
cerr << "Exiting.\n";
return (0);
}

Binary file not shown.

View File

@ -1,721 +0,0 @@
// Filename: shader_test.cxx
// Created by:
//
////////////////////////////////////////////////////////////////////
//
// PANDA 3D SOFTWARE
// Copyright (c) 2001 - 2004, Disney Enterprises, Inc. All rights reserved
//
// All use of this software is subject to the terms of the Panda 3d
// Software license. You should have received a copy of this license
// along with this source code; you will also find a current copy of
// the license at http://etc.cmu.edu/panda3d/docs/license/ .
//
// To contact the maintainers of this program write to
// panda3d-general@lists.sourceforge.net .
//
////////////////////////////////////////////////////////////////////
#include "eventHandler.h"
#include "projtexShader.h"
#include "shaderTransition.h"
#include "renderRelation.h"
#include "nodeRelation.h"
#include "chancfg.h"
#include <string>
#include "texGenTransition.h"
#include "colorBlendTransition.h"
#include "colorMaskTransition.h"
#include "textureTransition.h"
#include "texMatrixTransition.h"
#include "spotlightShader.h"
#include "light.h"
#include "eggLoader.h"
#include "look_at.h"
#include "transformTransition.h"
#include "geomNode.h"
#include "lightTransition.h"
#include "spotlight.h"
#include "projtexShadower.h"
#include "spheretexHighlighter.h"
#include "spheretexReflector.h"
#include "trackball.h"
#include "transform2sg.h"
#include "mouse.h"
#include "graphicsWindow.h"
#include "planarReflector.h"
#include "stencilTransition.h"
#include "plane.h"
#include "renderBuffer.h"
#include "outlineShader.h"
#include "pt_NamedNode.h"
#include "dataRelation.h"
#include "geomLine.h"
#include "dconfig.h"
#ifdef SHADER_VERBOSE
#include "indent.h"
#endif
Configure(shader_test);
ConfigureFn(shader_test) {
}
PT(LensNode) tex_proj;
PT(Trackball) tex_proj_trackball;
PT(ProjtexShader) proj_shader;
PT(ProjtexShadower) proj_shadow;
PT(SpheretexShader) spheretex;
PT(SpheretexHighlighter) highlight;
PT(SpheretexReflector) sreflect;
PT(PlanarReflector) preflect;
PT(OutlineShader) outline_shader;
ShaderTransition shader_trans;
PT(Spotlight) tex_proj_spot;
PT(Trackball) tex_spot_trackball;
PT(SpotlightShader) spot_shader;
RenderRelation* room_arc;
RenderRelation* spot_arc;
RenderRelation* jack_arc;
RenderRelation* camera_model_arc;
PT(LightTransition) light_transition;
extern PT_NamedNode render;
extern NodeAttributes initial_state;
extern RenderRelation* first_arc;
extern PT_NamedNode lights;
extern PT_NamedNode root;
extern PT(GeomNode) geomnode;
extern PT_NamedNode cameras;
extern PT(MouseAndKeyboard) mak;
extern void set_alt_trackball(Node *trackball);
extern int framework_main(int argc, char *argv[]);
extern void (*extra_display_func)();
extern void (*define_keys)(EventHandler&);
extern PT(GraphicsWindow) main_win;
class SomeViz : public Shader::Visualize {
public:
SomeViz(void);
virtual ~SomeViz(void);
virtual void DisplayTexture(PT(Texture)&, Shader*);
virtual void DisplayPixelBuffer(PT(PixelBuffer)&, Shader*);
protected:
typedef std::plist<PT(Texture) > texlist;
typedef texlist::iterator texiter;
typedef std::plist<PT(PixelBuffer) > pblist;
typedef pblist::iterator pbiter;
texlist _texs;
pblist _pbs;
};
SomeViz::SomeViz(void) {}
SomeViz::~SomeViz(void) {}
void SomeViz::DisplayTexture(PT(Texture)& tex, Shader*) {
if (tex->has_ram_image())
_texs.push_back(tex);
else {
GraphicsStateGuardian* g = main_win->get_gsg();
PT(PixelBuffer) pb(new PixelBuffer);
g->texture_to_pixel_buffer(tex->prepare(g), pb);
_pbs.push_back(pb);
}
}
void SomeViz::DisplayPixelBuffer(PT(PixelBuffer)& pb, Shader*) {
_pbs.push_back(pb);
}
class Oldviz : public SomeViz {
public:
Oldviz(PT(GraphicsWindow)&);
virtual ~Oldviz(void);
virtual void Flush(void);
protected:
PT(GraphicsWindow) _w;
};
Oldviz::Oldviz(PT(GraphicsWindow)& win) : _w(win) {}
Oldviz::~Oldviz(void) {}
void Oldviz::Flush(void) {
GraphicsStateGuardian* g = _w->get_gsg();
const RenderBuffer& r = g->get_render_buffer(RenderBuffer::T_front);
PT(DisplayRegion) d(_w->make_scratch_display_region(256, 256));
for (texiter i=_texs.begin(); i!=_texs.end(); ++i)
(*i)->draw(g, d, r);
for (pbiter j=_pbs.begin(); j!=_pbs.end(); ++j)
(*j)->draw(g, d, r);
_texs.erase(_texs.begin(), _texs.end());
_pbs.erase(_pbs.begin(), _pbs.end());
}
class Viztex : public SomeViz {
public:
Viztex(PT(GraphicsPipe)&);
virtual ~Viztex(void);
virtual void Flush(void);
protected:
typedef std::plist< PT(GraphicsWindow) > winlist;
typedef winlist::iterator winiter;
winlist _wins;
PT(GraphicsPipe) _pipe;
};
Viztex::Viztex(PT(GraphicsPipe)& p) : _pipe(p) {}
Viztex::~Viztex(void) {}
void Viztex::Flush(void) {
winiter _witer = _wins.begin();
for (texiter i=_texs.begin(); i!=_texs.end(); ++i) {
GraphicsWindow* w;
if (_witer == _wins.end()) {
ChanCfgOverrides override;
override.setField(ChanCfgOverrides::Mask,
((unsigned int)(W_SINGLE)));
override.setField(ChanCfgOverrides::Title, "Multipass partial");
override.setField(ChanCfgOverrides::SizeX, 256);
override.setField(ChanCfgOverrides::SizeY, 256);
override.setField(ChanCfgOverrides::Cameras, false);
//JMC: Addeded cameras and render for parameters of ChanConfig
w = ChanConfig(_pipe, "single", (Node *)NULL, render, override);
//JMC: Removed set_active calls to channels
_wins.push_back(w);
} else {
w = *_witer;
++_witer;
}
GraphicsStateGuardian* g = w->get_gsg();
const RenderBuffer& r = g->get_render_buffer(RenderBuffer::T_front);
PT(DisplayRegion) d(w->make_scratch_display_region(w->get_width(),
w->get_height()));
// g->prepare_display_region(d);
(*i)->draw(g, d, r);
}
for (pbiter j=_pbs.begin(); j!=_pbs.end(); ++j) {
GraphicsWindow* w;
if (_witer == _wins.end()) {
ChanCfgOverrides override;
override.setField(ChanCfgOverrides::Mask,
((unsigned int)(W_SINGLE)));
override.setField(ChanCfgOverrides::Title, "Multipass partial");
override.setField(ChanCfgOverrides::SizeX, 256);
override.setField(ChanCfgOverrides::SizeY, 256);
override.setField(ChanCfgOverrides::Cameras, false);
//JMC: Addeded cameras and render for parameters of ChanConfig
w = ChanConfig(_pipe, "single", cameras, render, override);
//JMC: Removed set_active calls to channels
_wins.push_back(w);
} else {
w = *_witer;
++_witer;
}
GraphicsStateGuardian* g = w->get_gsg();
const RenderBuffer& r = g->get_render_buffer(RenderBuffer::T_front);
PT(DisplayRegion) d(w->make_scratch_display_region(w->get_width(),
w->get_height()));
// g->prepare_display_region(d);
(*j)->draw(g, d, r);
}
_texs.erase(_texs.begin(), _texs.end());
_pbs.erase(_pbs.begin(), _pbs.end());
}
class Tiledviz : public Viztex {
public:
Tiledviz(PT(GraphicsPipe)&);
virtual ~Tiledviz(void);
virtual void Flush(void);
};
Tiledviz::Tiledviz(PT(GraphicsPipe)& p) : Viztex(p) {}
Tiledviz::~Tiledviz(void) {}
void Tiledviz::Flush(void) {
int count = 0;
//JMC: Added layer count
int layer_count = 0;
winiter _witer = _wins.begin();
#ifdef SHADER_VERBOSE
int _level = 2;
if (!_texs.empty())
{
nout << "Tiledvid::Flush:" << endl;
}
#endif
#ifdef SHADER_VERBOSE
if (!_texs.empty())
{
indent(nout, _level) << "TexList Loop" << endl;
}
_level += 2;
#endif
for (texiter texi=_texs.begin(); texi!=_texs.end(); ++texi) {
GraphicsWindow* w;
DisplayRegion* d;
if (_witer == _wins.end()) {
ChanCfgOverrides override;
override.setField(ChanCfgOverrides::Mask,
((unsigned int)(W_SINGLE)));
override.setField(ChanCfgOverrides::Title, "Multipass partial");
override.setField(ChanCfgOverrides::SizeX, 512);
override.setField(ChanCfgOverrides::SizeY, 512);
override.setField(ChanCfgOverrides::Cameras, false);
//JMC: Addeded cameras and render for parameters of ChanConfig
w = ChanConfig(_pipe, "multipass-tile", cameras, render, override);
//JMC: Removed set_active calls to channels
_wins.push_back(w);
_witer = --(_wins.end());
} else
w = *_witer;
int dridx;
GraphicsStateGuardian* g = w->get_gsg();
GraphicsChannel *chan = w->get_channel(0);
//JMC: Added call to get_layer
GraphicsLayer *layer = chan->get_layer(layer_count);
const RenderBuffer& r = g->get_render_buffer(RenderBuffer::T_front);
//JMC: Removed display region iterators for GraphicsChannel. They
//no longer exist.
//JMC: Added call to get_dr
#ifdef SHADER_VERBOSE
indent(nout, _level) << "Getting display region " << count
<< " from graphics layer" << endl;
#endif
d = layer->get_dr(count);
(*texi)->draw(g, d, r);
++count;
if (count == layer->get_num_drs()) {
count = 0;
++layer_count;
}
if (layer_count == chan->get_num_layers())
{
layer_count = 0;
++_witer;
}
}
#ifdef SHADER_VERBOSE
_level -= 2;
#endif
for (pbiter pbi=_pbs.begin(); pbi!=_pbs.end(); ++pbi) {
GraphicsWindow* w;
DisplayRegion* d;
if (_witer == _wins.end()) {
ChanCfgOverrides override;
override.setField(ChanCfgOverrides::Mask,
((unsigned int)(W_SINGLE)));
override.setField(ChanCfgOverrides::Title, "Multipass partial");
override.setField(ChanCfgOverrides::SizeX, 512);
override.setField(ChanCfgOverrides::SizeY, 512);
override.setField(ChanCfgOverrides::Cameras, false);
//JMC: Addeded cameras and render for parameters of ChanConfig
w = ChanConfig(_pipe, "multipass-tile", cameras, render, override);
//JMC: Removed set_active calls to channels
_wins.push_back(w);
_witer = --(_wins.end());
} else
w = *_witer;
int dridx;
GraphicsStateGuardian* g = w->get_gsg();
GraphicsChannel *chan = w->get_channel(0);
//JMC: Added call to get_layer
GraphicsLayer *layer = chan->get_layer(0);
const RenderBuffer& r = g->get_render_buffer(RenderBuffer::T_front);
//JMC: Removed display region iterators for GraphicsChannel. They
//no longer exist.
//JMC: Added call to get_dr
d = layer->get_dr(count);
// g->prepare_display_region(d);
(*pbi)->draw(g, d, r);
++count;
if (count == 16) {
count = 0;
++_witer;
}
}
_texs.erase(_texs.begin(), _texs.end());
_pbs.erase(_pbs.begin(), _pbs.end());
}
// nothing extra to do for either of these
void shader_display_func(void) {
Shader::Visualize* v = Shader::get_viz();
if (v != (Shader::Visualize*)0L)
v->Flush();
}
void event_p(CPT_Event) {
// The "p" key was pressed. Toggle projected texture.
static bool projtex_mode = false;
projtex_mode = !projtex_mode;
if (!projtex_mode) {
// Set the normal mode on the render arc.
clear_shader(room_arc, proj_shader);
clear_shader(first_arc, proj_shader);
clear_shader(jack_arc, proj_shader);
set_alt_trackball(NULL);
} else {
// Set an override on the initial state.
set_shader(room_arc, proj_shader);
set_shader(first_arc, proj_shader);
set_shader(jack_arc, proj_shader);
set_alt_trackball(tex_proj_trackball);
}
}
void event_s(CPT_Event) {
// The "s" key was pressed. Toggle projected texture spotlight.
static bool projtexspot_mode = false;
projtexspot_mode = !projtexspot_mode;
if (!projtexspot_mode) {
// Set the normal mode on the render arc.
clear_shader(room_arc, spot_shader);
set_alt_trackball(NULL);
} else {
// Set an override on the initial state.
set_shader(room_arc, spot_shader);
set_alt_trackball(tex_spot_trackball);
}
}
void event_d(CPT_Event) {
// The "d" key was pressed. Toggle projected texture shadows.
static bool projtex_shadow_mode = false;
projtex_shadow_mode = !projtex_shadow_mode;
if (!projtex_shadow_mode) {
// Set the normal mode on the render arc.
clear_shader(room_arc, proj_shadow);
set_alt_trackball(NULL);
} else {
set_shader(room_arc, proj_shadow);
set_alt_trackball(tex_spot_trackball);
}
}
void event_h(CPT_Event) {
// The "h" key was pressed. Toggle highlight.
static bool highlight_mode = false;
highlight_mode = !highlight_mode;
if (!highlight_mode) {
// Set the normal mode on the render arc.
clear_shader(first_arc, highlight);
} else {
set_shader(first_arc, highlight);
}
}
void event_e(CPT_Event) {
// The "e" key was pressed. Toggle sphere texture.
static bool spheretex_mode = false;
spheretex_mode = !spheretex_mode;
if (!spheretex_mode) {
// Set the normal mode on the render arc.
clear_shader(first_arc, spheretex);
} else {
// Set an override on the initial state.
set_shader(first_arc, spheretex);
}
}
void event_m(CPT_Event) {
// The "m" key was pressed. Toggle sphere reflection.
static bool sphere_reflect_mode = false;
sphere_reflect_mode = !sphere_reflect_mode;
if (!sphere_reflect_mode) {
// Set the normal mode on the render arc.
clear_shader(first_arc, sreflect);
} else {
// Set an override on the initial state.
set_shader(first_arc, sreflect);
}
}
void event_r(CPT_Event) {
// The "r" key was pressed. Toggle planar reflection.
static bool plane_reflect_mode = false;
plane_reflect_mode = !plane_reflect_mode;
if (!plane_reflect_mode) {
// Set the normal mode on the render arc.
clear_shader(first_arc, preflect);
} else {
// Set an override on the initial state.
set_shader(first_arc, preflect);
}
}
void event_n(CPT_Event) {
// The "n" key was pressed. Toggle the spot light.
static bool spotlight_on = false;
spotlight_on = !spotlight_on;
if (!spotlight_on) {
light_transition->set_off(tex_proj_spot.p());
set_alt_trackball(NULL);
} else {
light_transition->set_on(tex_proj_spot.p());
set_alt_trackball(tex_spot_trackball);
}
}
void event_o(CPT_Event) {
// The "o" key was pressed. Toggle outlining.
static bool outline_mode = false;
outline_mode = !outline_mode;
if (!outline_mode) {
// Set the normal mode on the render arc.
clear_shader(first_arc, outline_shader);
} else {
set_shader(first_arc, outline_shader);
}
}
void shader_keys(EventHandler &eh) {
eh.add_hook("p", event_p);
eh.add_hook("s", event_s);
eh.add_hook("d", event_d);
eh.add_hook("h", event_h);
eh.add_hook("e", event_e);
eh.add_hook("m", event_m);
eh.add_hook("r", event_r);
eh.add_hook("n", event_n);
eh.add_hook("o", event_o);
LPoint3f center_pos = LPoint3f::origin();
// Create a projected texture shader
// Load a texture to project
Texture* tex = new Texture;
tex->read("smiley.rgba");
tex->set_name("smiley.rgba");
// Put the texture projector into the scene graph
tex_proj = new LensNode("texture_projector");
RenderRelation* proj_arc = new RenderRelation(render, tex_proj);
// Create a trackball to spin this around.
tex_proj_trackball = new Trackball("tex_proj_trackball");
tex_proj_trackball->set_invert(false);
tex_proj_trackball->set_rel_to(cameras);
Transform2SG *tball2cam = new Transform2SG("tball2cam");
tball2cam->set_arc(proj_arc);
new DataRelation(tex_proj_trackball, tball2cam);
// Raise it and aim it at the origin
LMatrix4f proj_mat;
LPoint3f proj_pos = LPoint3f::rfu(2., 3., 8.);
LVector3f fwd_vec = proj_pos - center_pos;
look_at(proj_mat, -fwd_vec);
proj_mat.set_row(3, proj_pos);
tex_proj_trackball->set_mat(proj_mat);
proj_arc->set_transition(new TransformTransition(proj_mat));
// Create a shader for the texture projector
proj_shader = new ProjtexShader(tex);
proj_shader->add_frustum(tex_proj);
#define DISPLAY_TEXPROJFRUST
#ifdef DISPLAY_TEXPROJFRUST
// Display a wireframe representation of the texture projector frustum
PT(Geom) proj_geom =
tex_proj->get_lens()->make_geometry();
GeomNode* proj_geom_node = new GeomNode("proj_geometry");
//JMC: Removed _drawable_vector.push_back call and added add_geom
//call
proj_geom_node->add_geom(proj_geom);
RenderRelation *prr = new RenderRelation(tex_proj, proj_geom_node);
LightTransition *plt = new LightTransition(LightTransition::all_off());
prr->set_transition(plt);
#endif
// Create a projected texture spotlight shader
tex_proj_spot = new Spotlight("tex_proj_spotlight");
spot_arc = new RenderRelation(render, tex_proj_spot, 10);
// Create a trackball to spin this around.
tex_spot_trackball = new Trackball("tex_spot_trackball");
tex_spot_trackball->set_invert(false);
tex_spot_trackball->set_rel_to(cameras);
tball2cam = new Transform2SG("tball2cam");
tball2cam->set_arc(spot_arc);
new DataRelation(tex_spot_trackball, tball2cam);
// Raise it and aim it at the origin
LMatrix4f spot_mat;
LPoint3f spot_pos = LPoint3f::rfu(-4., -3., 8.);
LVector3f spot_vec = spot_pos - center_pos;
look_at(spot_mat, -spot_vec);
spot_mat.set_row(3, spot_pos);
tex_spot_trackball->set_mat(spot_mat);
spot_arc->set_transition(new TransformTransition(spot_mat));
// Create a shader for the spotlight
spot_shader = new SpotlightShader;
spot_shader->add_frustum(tex_proj_spot);
#define DISPLAY_TEXPROJSPOTFRUST
#ifdef DISPLAY_TEXPROJSPOTFRUST
// Display a wireframe representation of the spotlight frustum
Colorf color_red(1., 0., 0., 1.);
PT(Geom) frust_geom =
tex_proj_spot->get_lens()->make_geometry(color_red);
GeomNode* frust_geom_node = new GeomNode("frustum_geometry");
//JMC: Removed _drawable_vector.push_back call and added add_geom
//call
frust_geom_node->add_geom(frust_geom);
RenderRelation *rr = new RenderRelation(tex_proj_spot, frust_geom_node);
LightTransition *lt = new LightTransition(LightTransition::all_off());
rr->set_transition(lt);
#endif
#ifdef DISPLAY_SHAFT
// Draw a light shaft for the spotlight
NamedNode* shaft = tex_proj_spot->make_geometry(0.05, 8.0, 36);
new RenderRelation(tex_proj_spot, shaft, 10);
#endif
// Create a planar reflection
Planef p(LVector3f(0., 0., 1.), LVector3f(0., 0., -10.));
PlaneNode* plane_node = new PlaneNode;
plane_node->set_plane(p);
preflect = new PlanarReflector(plane_node);
// Create a projected texture shadower
proj_shadow = new ProjtexShadower;
proj_shadow->add_frustum(tex_proj_spot);
if (root != (NamedNode *)NULL) {
proj_shadow->add_caster(root);
preflect->add_caster(root);
} else if (geomnode != (GeomNode *)NULL) {
proj_shadow->add_caster(geomnode);
preflect->add_caster(geomnode);
}
// Create a spheretex shader
spheretex = new SpheretexShader(tex);
// Create a highlight
highlight = new SpheretexHighlighter;
highlight->add_frustum(tex_proj_spot);
// Create a spheremap reflection
sreflect = new SpheretexReflector;
sreflect->add_frustum(tex_proj_spot);
// Create an outline shader
outline_shader = new OutlineShader;
// Load the room file
PT_NamedNode room = loader.load_sync("big-room.egg");
if (room != (NamedNode *)NULL) {
room_arc = new RenderRelation(render, room, 20);
sreflect->add_caster(room);
new RenderRelation(room, plane_node);
}
// Load jack
PT_NamedNode jack = loader.load_sync("jack.egg");
if (jack != (NamedNode *)NULL) {
jack_arc = new RenderRelation(render, jack);
LMatrix4f jack_mat = LMatrix4f::ident_mat();
LPoint3f jack_pos = LPoint3f::rfu(-2., -2., 2.);
jack_mat.set_row(3, jack_pos);
jack_arc->set_transition(new TransformTransition(jack_mat));
sreflect->add_caster(jack);
proj_shadow->add_caster(jack);
preflect->add_caster(jack);
}
// Load up a camera model to visualize our eyepoint.
PT_NamedNode camera_model = loader.load_sync("camera.egg");
if (camera_model != (NamedNode *)NULL) {
camera_model_arc = new RenderRelation(cameras, camera_model);
sreflect->add_caster(camera_model);
proj_shadow->add_caster(camera_model);
preflect->add_caster(camera_model);
}
// Set up a transition for the spotlight
light_transition = new LightTransition;
if (first_arc != (NodeRelation *)NULL) {
first_arc->set_transition(light_transition);
}
if (jack_arc != (NodeRelation *)NULL) {
jack_arc->set_transition(light_transition);
}
// and now for some multipass partial visualization
Shader::Visualize* v = Shader::get_viz();
std::string viztype = shader_test.GetString("multipass-viz", "none");
if (viztype == "old-style") {
PT(GraphicsWindow) w(main_win);
v = new Oldviz(w);
} else if (viztype == "new-single") {
PT(GraphicsPipe) p(((GraphicsPipe*)(main_win->get_pipe())));
v = new Viztex(p);
} else if (viztype == "new-tile") {
PT(GraphicsPipe) p(((GraphicsPipe*)(main_win->get_pipe())));
v = new Tiledviz(p);
}
Shader::set_viz(v);
}
int main(int argc, char *argv[]) {
extra_display_func = &shader_display_func;
define_keys = &shader_keys;
return framework_main(argc, argv);
}

View File

@ -1,112 +0,0 @@
// Filename: test_eggWrite.cxx
// Created by: jason (16Jun00)
//
////////////////////////////////////////////////////////////////////
//
// PANDA 3D SOFTWARE
// Copyright (c) 2001 - 2004, Disney Enterprises, Inc. All rights reserved
//
// All use of this software is subject to the terms of the Panda 3d
// Software license. You should have received a copy of this license
// along with this source code; you will also find a current copy of
// the license at http://etc.cmu.edu/panda3d/docs/license/ .
//
// To contact the maintainers of this program write to
// panda3d-general@lists.sourceforge.net .
//
////////////////////////////////////////////////////////////////////
#include "renderRelation.h"
#include "transformTransition.h"
#include "namedNode.h"
#include "geom.h"
#include "geomNode.h"
#include "pt_NamedNode.h"
#include "nodeTransitionWrapper.h"
#include "nodeAttributeWrapper.h"
#include "allTransitionsWrapper.h"
#include "allAttributesWrapper.h"
#include "nullTransitionWrapper.h"
#include "nullAttributeWrapper.h"
#include "traverserVisitor.h"
#include "dftraverser.h"
#include "nullLevelState.h"
#include "filename.h"
#include "character.h"
#include "indent.h"
#include <ipc_file.h>
#include "bamWriter.h"
#include "bam.h"
template<class TW>
class PrintNodes : public TraverserVisitor<TW, NullLevelState> {
public:
PrintNodes() {
_indent_level = 0;
}
bool reached_node(Node *node, AttributeWrapper &state, NullLevelState &)
{
indent(nout, _indent_level) << "Reached " << *node << ", state is " << state << "\n";
// if (node->is_of_type(GeomNode::get_class_type()))
// {
// GeomNode *geomNode = (GeomNode *)node;
// int num_geoms = geomNode->get_num_geoms();
// for (int i = 0; i < num_geoms; i++)
// {
// dDrawable *draw = geomNode->get_geom(i);
// Geom *geom = DCAST(Geom, draw);
// indent(nout, _indent_level+1) << *geom << ":\n";
// geom->output_verbose(nout);
// }
// }
return true;
}
bool forward_arc(NodeRelation *, TransitionWrapper &, AttributeWrapper &, AttributeWrapper &, NullLevelState &)
{
_indent_level += 2;
return true;
}
void backward_arc(NodeRelation *, TransitionWrapper &, AttributeWrapper &, AttributeWrapper &, const NullLevelState &)
{
_indent_level -= 2;
}
int _indent_level;
};
int main(int argc, char* argv[]) {
if (argc < 2)
{
nout << "Need an egg file" << endl;
exit(0);
}
Filename file(argv[1]);
if (file.get_extension().compare("egg") != 0)
{
nout << "Need an egg file" << endl;
exit(0);
}
datagram_file stream(file.get_basename_wo_extension()+string(".bam"));
BamWriter manager(&stream);
PT_NamedNode smiley = loader.load_sync(file);
nout << "\n";
PrintNodes<NodeTransitionWrapper> pn;
df_traverse(smiley, pn,
NodeAttributeWrapper(TransformTransition::get_class_type()),
NullLevelState(),
RenderRelation::get_class_type());
nout << "\n";
stream.open(file::FILE_WRITE, _bam_header);
manager.init();
manager.write_object(smiley);
stream.close();
return 0;
}

View File

@ -1,163 +0,0 @@
// Filename: test_recparticles.cxx
// Created by:
//
////////////////////////////////////////////////////////////////////
//
// PANDA 3D SOFTWARE
// Copyright (c) 2001 - 2004, Disney Enterprises, Inc. All rights reserved
//
// All use of this software is subject to the terms of the Panda 3d
// Software license. You should have received a copy of this license
// along with this source code; you will also find a current copy of
// the license at http://etc.cmu.edu/panda3d/docs/license/ .
//
// To contact the maintainers of this program write to
// panda3d-general@lists.sourceforge.net .
//
////////////////////////////////////////////////////////////////////
#include "framework.h"
#include "eventHandler.h"
#include "chancfg.h"
#include <string>
#include "renderModeTransition.h"
#include "colorTransition.h"
#include "cullFaceTransition.h"
#include "depthTestTransition.h"
#include "depthWriteTransition.h"
#include "textureTransition.h"
#include "lightTransition.h"
#include "materialTransition.h"
#include "transformTransition.h"
#include "get_rel_pos.h"
#include "boundingSphere.h"
#include "geomSphere.h"
#include "geomNode.h"
#include "notify.h"
#include "directionalLight.h"
#include "renderRelation.h"
#include "camera.h"
#include "frustum.h"
#include "orthoProjection.h"
#include "perspectiveProjection.h"
#include "textNode.h"
#include "physicsManager.h"
#include "particleSystem.h"
#include "emitters.h"
#include "forces.h"
#include "sparkleParticleRenderer.h"
#include "pointParticleRenderer.h"
#include "spriteParticleRenderer.h"
#include "pointParticleFactory.h"
#include "particleSystemManager.h"
#include "clockObject.h"
#include "nodePath.h"
#include "memoryUsage.h"
#include "texture.h"
#include "texturePool.h"
// physics. particle systems.
PhysicsManager physics_manager;
ParticleSystemManager ps_manager;
static void
event_csn_update(CPT_Event) {
float dt = ClockObject::get_global_clock()->get_dt();
physics_manager.do_physics(dt);
ps_manager.do_particles(dt);
}
PT(ParticleSystem) explosion_system = new ParticleSystem(128);
PT(PointParticleFactory) explosion_factory = new PointParticleFactory;
PT(SpriteParticleRenderer) explosion_renderer = new SpriteParticleRenderer;
PT(SphereSurfaceEmitter) explosion_emitter = new SphereSurfaceEmitter;
PT(ParticleSystem) fireworks_system = new ParticleSystem(32);
PT(PointParticleFactory) fireworks_factory = new PointParticleFactory;
PT(PointParticleRenderer) fireworks_renderer = new PointParticleRenderer;
PT(LineEmitter) fireworks_emitter = new LineEmitter;
PT(Texture) fireworks_texture;
static void
event_add_particles(CPT_Event) {
// set up the base system
fireworks_factory->set_lifespan_base(1.5f);
fireworks_factory->set_lifespan_delta(0.5f);
fireworks_emitter->set_endpoints(LPoint3f(-2.0f, 0.0f, 0.0f),
LPoint3f(2.0f, 0.0f, 0.0f));
fireworks_emitter->set_launch_vec(LVector3f(0.0f, 0.0f, 1.0f));
fireworks_renderer->set_point_size(4.0f);
fireworks_renderer->set_color1(Colorf(1, 1, 1, 1));
fireworks_renderer->set_color2(Colorf(1, 0, 0, 1));
fireworks_renderer->set_blend_type(PP_BLEND_LIFE);
fireworks_renderer->set_blend_method(PP_BLEND_LINEAR);
fireworks_renderer->set_alpha_decay(PR_ALPHA_OUT);
fireworks_system->set_birth_rate(0.25f);
fireworks_system->set_litter_size(1);
fireworks_system->set_birth_node(render);
fireworks_system->set_emitter(fireworks_emitter);
fireworks_system->set_renderer(fireworks_renderer);
fireworks_system->set_factory(fireworks_factory);
fireworks_system->set_render_parent(render);
fireworks_system->set_spawn_on_death_flag(true);
fireworks_system->set_spawn_render_node(render);
// set up the explosion system
explosion_factory->set_lifespan_base(1.0f);
explosion_factory->set_lifespan_delta(0.0f);
explosion_emitter->set_radius(0.1f);
explosion_emitter->set_amplitude(2.0f);
explosion_emitter->set_offset_force(LVector3f(2.0f, 0.0f, 2.0f));
explosion_renderer->set_texture(fireworks_texture);
explosion_renderer->set_alpha_decay(PR_ALPHA_OUT);
explosion_renderer->set_color(Colorf(1, 0, 0, 1));
explosion_system->set_birth_rate(5.0f);
explosion_system->set_litter_size(64);
explosion_system->set_template_system_flag(true);
explosion_system->set_system_grows_older_flag(true);
explosion_system->set_system_lifespan(1.0f);
explosion_system->set_emitter(explosion_emitter);
explosion_system->set_renderer(explosion_renderer);
explosion_system->set_factory(explosion_factory);
fireworks_system->add_spawn_template(explosion_system);
// fireworks_system->add_force(new VectorForce(0, 0, -9.8f));
/*
particle_system->add_spawn_template(explosion_system);
particle_system->add_spawn_template(explosion_system2);
particle_system->add_spawn_template(explosion_system3);
particle_system->set_spawn_on_death_flag(true);
particle_system->set_birth_node(render);
particle_system->set_render_parent(render);
particle_system->set_spawn_render_node(render);
*/
ps_manager.attach_particlesystem(fireworks_system);
physics_manager.attach_physical(fireworks_system);
nout << "Added particles." << endl;
event_handler.add_hook("NewFrame", event_csn_update);
}
void demo_keys(EventHandler&) {
event_handler.add_hook("p", event_add_particles);
}
int main(int argc, char *argv[]) {
fireworks_texture = TexturePool::load_texture("firework.rgba");
define_keys = &demo_keys;
return framework_main(argc, argv);
}

View File

@ -1,308 +0,0 @@
// Filename: test_sprite_particles.cxx
// Created by:
//
////////////////////////////////////////////////////////////////////
//
// PANDA 3D SOFTWARE
// Copyright (c) 2001 - 2004, Disney Enterprises, Inc. All rights reserved
//
// All use of this software is subject to the terms of the Panda 3d
// Software license. You should have received a copy of this license
// along with this source code; you will also find a current copy of
// the license at http://etc.cmu.edu/panda3d/docs/license/ .
//
// To contact the maintainers of this program write to
// panda3d-general@lists.sourceforge.net .
//
////////////////////////////////////////////////////////////////////
#include "framework.h"
#include "eventHandler.h"
#include "chancfg.h"
#include <string>
#include "renderModeTransition.h"
#include "colorTransition.h"
#include "cullFaceTransition.h"
#include "depthTestTransition.h"
#include "depthWriteTransition.h"
#include "textureTransition.h"
#include "lightTransition.h"
#include "materialTransition.h"
#include "transformTransition.h"
#include "get_rel_pos.h"
#include "boundingSphere.h"
#include "geomSphere.h"
#include "geomNode.h"
#include "notify.h"
#include "directionalLight.h"
#include "renderRelation.h"
#include "camera.h"
#include "frustum.h"
#include "orthoProjection.h"
#include "perspectiveProjection.h"
#include "textNode.h"
#include "physicsManager.h"
#include "particleSystem.h"
#include "emitters.h"
#include "particlefactories.h"
#include "forces.h"
#include "sparkleParticleRenderer.h"
#include "pointParticleRenderer.h"
#include "lineParticleRenderer.h"
#include "geomParticleRenderer.h"
#include "spriteParticleRenderer.h"
#include "colorTransition.h"
#include "particleSystemManager.h"
#include "clockObject.h"
#include "nodePath.h"
#include "pointShapeTransition.h"
#include "texture.h"
#include "texturePool.h"
#include "physicalNode.h"
#include "forceNode.h"
#include "linearEulerIntegrator.h"
// physics. particle systems.
/////////////////////////////////////////////////
// particle system manager params
#define PARTICLE_SYSTEM_MANAGER_FRAME_STEPPING 1
// particle system params
#define PARTICLE_SYSTEM_POOL_SIZE 1024
#define PARTICLE_SYSTEM_BIRTH_RATE 0.02f
#define PARTICLE_SYSTEM_LITTER_SIZE 10
#define PARTICLE_SYSTEM_LITTER_SPREAD 0
/////////////////////////////////////////////////
// particle factory selection
#define POINT_PARTICLES
// particle renderer selection
#define POINT_PARTICLE_RENDERER
//#define SPRITE_PARTICLE_RENDERER
// particle emitter selection
#define SPHERE_VOLUME_EMITTER
/////////////////////////////////////////////////
// particle factory params
#define PARTICLE_FACTORY_LIFESPAN_BASE 0.5f
#define SPRITE_PARTICLE_RENDERER_ALPHA_DISABLE false
#define PARTICLE_RENDERER_ALPHA_MODE BaseParticleRenderer::PR_ALPHA_NONE
//#define PARTICLE_RENDERER_ALPHA_MODE BaseParticleRenderer::PR_ALPHA_IN
//#define PARTICLE_RENDERER_ALPHA_MODE BaseParticleRenderer::PR_ALPHA_OUT
//#define PARTICLE_RENDERER_ALPHA_MODE BaseParticleRenderer::PR_ALPHA_USER
//#define PARTICLE_RENDERER_USER_ALPHA 1.0
#if defined POINT_PARTICLE_RENDERER
#define POINT_PARTICLE_RENDERER_POINT_SIZE 1.0f
#elif defined SPRITE_PARTICLE_RENDERER
#define SPRITE_PARTICLE_RENDERER_TEXTURE_FILE "rock-floor.rgb"
#define SPRITE_PARTICLE_RENDERER_COLOR Colorf(1.0f, 1.0f, 1.0f, 1.0f)
// #define SPRITE_PARTICLE_RENDERER_X_SCALE_FLAG true
// #define SPRITE_PARTICLE_RENDERER_Y_SCALE_FLAG true
#define SPRITE_PARTICLE_RENDERER_ANIM_ANGLE_FLAG true
// #define SPRITE_PARTICLE_RENDERER_INITIAL_X_SCALE 0.1
// #define SPRITE_PARTICLE_RENDERER_FINAL_X_SCALE 0.0
// #define SPRITE_PARTICLE_RENDERER_INITIAL_Y_SCALE 0.0
// #define SPRITE_PARTICLE_RENDERER_FINAL_Y_SCALE 0.5
#define SPRITE_PARTICLE_RENDERER_NONANIMATED_THETA 45.0f
#define SPRITE_PARTICLE_RENDERER_BLEND_METHOD BaseParticleRenderer::PP_BLEND_LINEAR
// #define SPRITE_PARTICLE_RENDERER_BLEND_METHOD BaseParticleRenderer::PP_BLEND_CUBIC
// #define SPRITE_PARTICLE_RENDERER_ALPHA_DISABLE false
#endif
// particle emitter params
#define EMISSION_TYPE_RADIATE
//#define EMISSION_TYPE_EXPLICIT
#define EMITTER_AMPLITUDE 1.0
#if defined EMISSION_TYPE_EXPLICIT
#define EXPLICIT_LAUNCH_VEC LVector3f(-1.0f, -1.0f, 1.0f)
// #define EXPLICIT_LAUNCH_VEC LVector3f(0.0f, 0.0f, 0.0f)
#elif defined EMISSION_TYPE_RADIATE
#define RADIATE_ORIGIN LPoint3f(0.0f, 0.0f, 0.0f)
#endif
#if defined SPHERE_VOLUME_EMITTER
#define SPHERE_VOLUME_EMITTER_RADIUS 1.0f
#endif
/////////////////////////////////////////////////
PhysicsManager physics_manager;
ParticleSystemManager ps_manager;
PT(ParticleSystem) particle_system = new ParticleSystem(1024);
PT(PointParticleFactory) pf = new PointParticleFactory;
PT(SphereVolumeEmitter) pe = new SphereVolumeEmitter;
#if defined POINT_PARTICLE_RENDERER
PT(PointParticleRenderer) pr = new PointParticleRenderer;
#elif defined SPRITE_PARTICLE_RENDERER
PT(SpriteParticleRenderer) pr = new SpriteParticleRenderer;
#endif
PT(Texture) texture;
PT(PhysicalNode) pn = new PhysicalNode;
PT(ForceNode) fn = new ForceNode;
static void
event_csn_update(CPT_Event) {
float dt = ClockObject::get_global_clock()->get_dt();
physics_manager.do_physics(dt);
ps_manager.do_particles(dt);
}
static void
event_add_particles(CPT_Event) {
static initialized = 0;
// guard against additional "P" presses (bad things happen)
if(initialized) return;
initialized = 1;
// renderer setup
pr->set_alpha_mode(BaseParticleRenderer::PR_ALPHA_USER);
pr->set_user_alpha(1.0);
#if defined POINT_PARTICLE_RENDERER
pr->set_point_size(1.0);
#elif defined SPRITE_PARTICLE_RENDERER
pr->set_texture(texture);
#ifdef SPRITE_PARTICLE_RENDERER_COLOR
pr->set_color(SPRITE_PARTICLE_RENDERER_COLOR);
#endif
#ifdef SPRITE_PARTICLE_RENDERER_X_SCALE_FLAG
pr->set_x_scale_flag(SPRITE_PARTICLE_RENDERER_X_SCALE_FLAG);
#endif
#ifdef SPRITE_PARTICLE_RENDERER_Y_SCALE_FLAG
pr->set_y_scale_flag(SPRITE_PARTICLE_RENDERER_Y_SCALE_FLAG);
#endif
#ifdef SPRITE_PARTICLE_RENDERER_ANIM_ANGLE_FLAG
pr->set_anim_angle_flag(SPRITE_PARTICLE_RENDERER_ANIM_ANGLE_FLAG);
#endif
#ifdef SPRITE_PARTICLE_RENDERER_INITIAL_X_SCALE
pr->set_initial_x_scale(SPRITE_PARTICLE_RENDERER_INITIAL_X_SCALE);
#endif
#ifdef SPRITE_PARTICLE_RENDERER_FINAL_X_SCALE
pr->set_final_x_scale(SPRITE_PARTICLE_RENDERER_FINAL_X_SCALE);
#endif
#ifdef SPRITE_PARTICLE_RENDERER_INITIAL_Y_SCALE
pr->set_initial_y_scale(SPRITE_PARTICLE_RENDERER_INITIAL_Y_SCALE);
#endif
#ifdef SPRITE_PARTICLE_RENDERER_FINAL_Y_SCALE
pr->set_final_y_scale(SPRITE_PARTICLE_RENDERER_FINAL_Y_SCALE);
#endif
#ifdef SPRITE_PARTICLE_RENDERER_NONANIMATED_THETA
pr->set_nonanimated_theta(SPRITE_PARTICLE_RENDERER_NONANIMATED_THETA);
#endif
#ifdef SPRITE_PARTICLE_RENDERER_BLEND_METHOD
//pr->set_alpha_blend_method(SPRITE_PARTICLE_RENDERER_BLEND_METHOD);
#endif
#define SPRITE_PARTICLE_RENDERER_ALPHA_DISABLE false
#ifdef SPRITE_PARTICLE_RENDERER_ALPHA_DISABLE
pr->set_alpha_disable(SPRITE_PARTICLE_RENDERER_ALPHA_DISABLE);
#endif
#endif
// factory setup
#ifdef PARTICLE_FACTORY_LIFESPAN_BASE
pf->set_lifespan_base(PARTICLE_FACTORY_LIFESPAN_BASE);
#endif
#ifdef PARTICLE_FACTORY_LIFESPAN_SPREAD
pf->set_lifespan_spread(PARTICLE_FACTORY_LIFESPAN_SPREAD);
#endif
#ifdef PARTICLE_FACTORY_MASS_BASE
pf->set_mass_base(PARTICLE_FACTORY_MASS_BASE);
#endif
#ifdef PARTICLE_FACTORY_MASS_SPREAD
pf->set_mass_spread(PARTICLE_FACTORY_MASS_SPREAD);
#endif
#ifdef PARTICLE_FACTORY_TERMINAL_VELOCITY_BASE
pf->set_terminal_velocity_base(PARTICLE_FACTORY_TERMINAL_VELOCITY_BASE);
#endif
#ifdef PARTICLE_FACTORY_TERMINAL_VELOCITY_SPREAD
pf->set_terminal_velocity_spread(PARTICLE_FACTORY_TERMINAL_VELOCITY_SPREAD);
#endif
// emitter setup
#ifdef EMITTER_AMPLITUDE
pe->set_amplitude(EMITTER_AMPLITUDE);
#endif
#ifdef EMITTER_AMPLITUDE_SPREAD
pe->set_amplitude_spread(EMITTER_AMPLITUDE_SPREAD);
#endif
#ifdef EMITTER_OFFSET_FORCE
pe->set_offset_force(EMITTER_OFFSET_FORCE);
#endif
#if defined EMISSION_TYPE_EXPLICIT
pe->set_emission_type(BaseParticleEmitter::ET_EXPLICIT);
#ifdef EXPLICIT_LAUNCH_VEC
pe->set_explicit_launch_vector(EXPLICIT_LAUNCH_VEC);
#endif
#elif defined EMISSION_TYPE_RADIATE
pe->set_emission_type(BaseParticleEmitter::ET_RADIATE);
#ifdef RADIATE_ORIGIN
pe->set_radiate_origin(RADIATE_ORIGIN);
#endif
#endif
pe->set_radius(SPHERE_VOLUME_EMITTER_RADIUS);
// system setup
particle_system->set_birth_rate(PARTICLE_SYSTEM_BIRTH_RATE);
particle_system->set_litter_size(PARTICLE_SYSTEM_LITTER_SIZE);
particle_system->set_litter_spread(PARTICLE_SYSTEM_LITTER_SPREAD);
particle_system->set_emitter(pe);
particle_system->set_renderer(pr);
particle_system->set_factory(pf);
particle_system->set_render_parent(render);
pn->add_physical(particle_system);
new RenderRelation(render, pn);
new RenderRelation(render, fn);
physics_manager.attach_linear_integrator(new LinearEulerIntegrator);
physics_manager.attach_physical(particle_system);
#ifdef PARTICLE_SYSTEM_MANAGER_FRAME_STEPPING
ps_manager.set_frame_stepping(PARTICLE_SYSTEM_MANAGER_FRAME_STEPPING);
#endif
ps_manager.attach_particlesystem(particle_system);
nout << "Added particles." << endl;
event_handler.add_hook("NewFrame", event_csn_update);
}
void demo_keys(EventHandler&) {
new RenderRelation( lights, dlight );
have_dlight = true;
event_handler.add_hook("p", event_add_particles);
}
int main(int argc, char *argv[]) {
define_keys = &demo_keys;
#ifdef SPRITE_PARTICLE_RENDERER
texture = TexturePool::load_texture(SPRITE_PARTICLE_RENDERER_TEXTURE_FILE);
#endif
return framework_main(argc, argv);
}

View File

@ -1,66 +0,0 @@
// Filename: vrpn_demo.cxx
// Created by:
//
////////////////////////////////////////////////////////////////////
//
// PANDA 3D SOFTWARE
// Copyright (c) 2001 - 2004, Disney Enterprises, Inc. All rights reserved
//
// All use of this software is subject to the terms of the Panda 3d
// Software license. You should have received a copy of this license
// along with this source code; you will also find a current copy of
// the license at http://etc.cmu.edu/panda3d/docs/license/ .
//
// To contact the maintainers of this program write to
// panda3d-general@lists.sourceforge.net .
//
////////////////////////////////////////////////////////////////////
#include "framework.h"
#include "eventHandler.h"
#include <string>
#include "transform2sg.h"
#include "trackerTransform.h"
#include "trackerNode.h"
#include "vrpnClient.h"
#include "dataRelation.h"
#include "renderRelation.h"
#include "namedNode.h"
#include "trackball.h"
#include "mouseWatcher.h"
////////////////////////////////////////////////
//Globals
////////////////////////////////////////////////
VrpnClient *vrpn_client;
Transform2SG *tracker2cam;
TrackerTransform *evil_transform;
TrackerNode *evil_tracker;
//From framework
extern PT_NamedNode data_root;
extern RenderRelation* first_arc;
extern PT(Trackball) trackball;
extern PT(MouseWatcher) mouse_watcher;
void demo_keys(EventHandler&) {
vrpn_client = new VrpnClient(string("evildyne"));
evil_tracker = new TrackerNode(vrpn_client, string("Isense"), 2);
evil_transform = new TrackerTransform("evil_transform");
new DataRelation(data_root, evil_tracker);
new DataRelation(evil_tracker, evil_transform);
tracker2cam = new Transform2SG("tracker2cam");
tracker2cam->set_arc(first_arc);
new DataRelation(evil_transform, tracker2cam);
}
int main(int argc, char *argv[]) {
define_keys = &demo_keys;
return framework_main(argc, argv);
}