Book Image

Panda3D 1.6 Game Engine Beginner's Guide

Book Image

Panda3D 1.6 Game Engine Beginner's Guide

Overview of this book

Panda3D is a game engine, a framework for 3D rendering and game development for Python and C++ programs. It includes graphics, audio, I/O, collision detection, and other abilities relevant to the creation of 3D games. Also, Panda3D is Open Source and free for any purpose, including commercial ventures. This book will enable you to create finished, marketable computer games using Panda3D and other entirely open-source tools and then sell those games without paying a cent for licensing. Panda3D 1.6 Game Engine Beginner's Guide follows a logical progression from a zero start through the game development process all the way to a finished, packaged installer. Packed with examples and detailed tutorials in every section, it teaches the reader through first-hand experience. These tutorials are followed by explanations that describe what happened in the tutorial and why. You will start by setting up a workspace, and then move on to the basics of starting up Panda3D. From there, you will begin adding objects like a level and a character to the world inside Panda3D. Then the book will teach you to put the game's player in control by adding change over time and response to user input. Then you will learn how to make it possible for objects in the world to interact with each other by using collision detection and beautify your game with Panda3D's built-in filters, shaders, and texturing. Finally, you will add an interface, audio, and package it all up for the customer.
Table of Contents (22 chapters)
Panda3D 1.6 Game Engine
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Blending layers


Controlling how the layers in Spacescape blend together is both the most important aspect of creating a skybox and also the most complicated. All of the layers have controls for blending that work similarly to the blending methods available in image editors, such as Photoshop or GIMP, but unlike those programs there aren't any control presets like "Multiply" or "Lighten". Instead, we get direct access to the equation those presets use.

Before we get into the equation itself, we need to define some things the equation uses. First off, let's talk about the destination and the source. These refer to the two things that are being blended. The source is the layer whose blending controls we're working with. The destination is the combination of all the layers beneath the layer we're working with. In other words, the source is the layer itself, and the destination is all the layers beneath it.

Here's an example with four layers named Red Point Stars, Nebula Mask, Blue Nebula, and Green Nebula. The source and destination of the Nebula Mask layer are labelled.

Spacescape v0.2, the most up-to-date version at the time of this writing, uses values ranging from 0 to 255 for color, but to understand the math in the blending equation we have to think of the colors as ranging from 0 to 1, like they do in Panda3D. That's because multiplying colors together makes them get darker, rather than lighter, and that only makes sense when we're using decimal numbers, rather than numbers greater than 1.

Keeping these things in mind, let's take a look at the following equation:

( Source * sourceFactor ) + ( Destinaton * destinationFactor )

The equation is composed of four parts. Two of those parts are the source and destination. The other two parts are multipliers that alter the source and destination. These multipliers, called the sourceFacto r and destinationFactor , are the items we get to change. The addition and multiplication operations are performed on the red, green, blue, and alpha channels separately. This means that for each pixel in the image, the equation is calculated four times, once for each channel.

( srceR * srceFactorR ) + ( destR * destFactorR ) = outR
( srceG * srceFactorG ) + ( destG * destFactorG ) = outG
( srceB * srceFactorB ) + ( destB * destFactorB ) = outB
( srceA * srceFactorA ) + ( destA * destFactorA ) = outA

To control blending of layers, we change the sourceFactor and destinationFactor. We have a bunch of options, all of which can be used for either the sourceFactor or the destinationFactor. Here's the list of options:

Option

Description

One

This gives a value of 1 for every pixel.

Zero

This gives a value of 0 for every pixel.

Dest_colour

This option inputs the color values of the destination.

Src_colour

This option inputs the color values of the source.

One_minus_dest_colour

This option inputs 1—value for each of the destination color channels. For example, a dark blue (.1,.1,.3) would be input as an orange-white (.9,.9,.7).

One_minus_src_colour

This is the same as one_minus_dest_colour, but it uses the source color channels instead.

Dest_alpha

This option uses the destination alpha values. In v0.2 of Spacescape, the color alpha values are not used. Instead, the noise value is used for alpha blending. The outer color shows through where the noise value is lower, and the inner color shows through where the noise value is higher.

Src_alpha

This option is the same as dest_alpha, but it uses the noise value from the source instead of the destination.

One_minus_dest_alpha

This uses the inverse of the noise value from the destination. If the noise value is .3, for example, a .7 will be used.

One_minus_src_alpha

This is the same as one_minus_dest_alpha, but it uses the source noise value instead of the destination noise value.

The default option for both sourceFactor and destinationFactor is one, which uses a value of 1 for every channel of every pixel. Since multiplying a value by 1 will cause it to stay the same, the default settings simply add the source and destination together. If the destinationFactor was changed to zero, which uses a value of 0 for every channel of every pixel, the destination would get thrown out entirely and only the source would show.

A Multiply layer in an image editor multiplies the source by the destination. To achieve the same effect in Spacescape, we could set the sourceFactor to dest_colour and the destinationFactor to zero.

To create a mask that hides a part of the destination, but allows some of it to show through, we could set the sourceFactor to zero (so the mask layer doesn't affect the color of the result at all) and set the destinationFactor to src_alpha or one_minus_src_alpha (so the noise value of the source controls the alpha of the destination).