Book Image

Panda3D 1.7 Game Developer's Cookbook

Book Image

Panda3D 1.7 Game Developer's Cookbook

Overview of this book

Table of Contents (20 chapters)
Panda3D 1.7 Game Developer's Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Applying a custom Cg shader


Shaders are one of the most powerful concepts in today's graphics programming, allowing programmers to program the graphics hardware and thus provide great flexibility for creating amazing effects.

This recipe will show you how to use shaders written in the Cg shading language with the Panda3D engine.

Getting ready

Setup your project as described in Setting up the game structure found in Chapter 1. Add an additional folder called shaders in the top-level source directory and add it to Panda3D's resource search paths.

How to do it...

Let's create a shader and apply it to a model:

  1. Add the following code snippet to Application.py:

    from direct.showbase.ShowBase import ShowBase
    from panda3d.core import *
    
    class Application(ShowBase):
        def __init__(self):
            ShowBase.__init__(self)
    
            self.world = loader.loadModel("environment")
            self.world.reparentTo(render)
            self.world.setScale(0.5)
            self.world.setPos(-8, 80, 0)
    
            shader = loader...