shader program in gamebryo. introduction shader? a complete rendering effect to apply to an object ...

18
Shader Program in Gamebr yo

Upload: laura-peters

Post on 05-Jan-2016

279 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Shader Program in Gamebryo. Introduction Shader?  A complete Rendering Effect to apply to an object  Shader Program – Vertex/Pixel Shader Shader Programs

Shader Program in Gamebryo

Page 2: Shader Program in Gamebryo. Introduction Shader?  A complete Rendering Effect to apply to an object  Shader Program – Vertex/Pixel Shader Shader Programs

Introduction

Shader? A complete Rendering Effect to apply to an object Shader Program – Vertex/Pixel Shader

Shader Programs Assembly code - .vsh/.psh Compiled assembly code - .vso Microsoft HLSL - .hlsl nVidiaCG - .cg

Page 3: Shader Program in Gamebryo. Introduction Shader?  A complete Rendering Effect to apply to an object  Shader Program – Vertex/Pixel Shader Shader Programs

Introduction (cont.)

Shader Libraries NSB/NSF FX CGSoftware Vertex Processing DEVDESC_HAL_SWVERTEX / DEVDESC_HAL_MIXEDVERTEX

Switching Process Mode NiD3DRenderState::SetSoftwareVertexProcessing

Page 4: Shader Program in Gamebryo. Introduction Shader?  A complete Rendering Effect to apply to an object  Shader Program – Vertex/Pixel Shader Shader Programs

How to use shader program

Write a Shader NSB/NSF, FX, CG Derivation from NiShader

Win32 – NiD3DShaderInterface, NiD3DShader, NiD3DDefaultShader

Derive NiShaderLibrary

Create a Shader Library a bunch of shaders put into the shader libraryRegister Shader Library to a Shader Factory NiShaderFactory::LoadAndRegisterShaderLibraryUse shaders through the shader factory

Page 5: Shader Program in Gamebryo. Introduction Shader?  A complete Rendering Effect to apply to an object  Shader Program – Vertex/Pixel Shader Shader Programs

Shader Library

A collection of shaders available to the application at run-timeProvide Method Retrieve shader Retreive shader descriptionTo Use Shader Library Register to Shader Factory NiShaderFactory::LoadAndRegisterShaderLibrary

Page 6: Shader Program in Gamebryo. Introduction Shader?  A complete Rendering Effect to apply to an object  Shader Program – Vertex/Pixel Shader Shader Programs

Shader System Class Interaction Diagram

Page 7: Shader Program in Gamebryo. Introduction Shader?  A complete Rendering Effect to apply to an object  Shader Program – Vertex/Pixel Shader Shader Programs

Class Detail

NiShader A Common interface for NiShader-NiRenderer interaction NiShader-NiRenderer interaction

Obtaining a shader from the active material PreProcessPipeline Update Render-State : UsesNIRenderState Flag UpdatePipeline For all passes

SetupRenderingPass SetupTransformations PrepareGeometryForRendering – Packing streams

SetStreamSource, SetIndices SetupShaderPrograms

PostProcessPipeline

Page 8: Shader Program in Gamebryo. Introduction Shader?  A complete Rendering Effect to apply to an object  Shader Program – Vertex/Pixel Shader Shader Programs

Class Detail (cont.)

NiShaderLibrary A collection of shaders available to the applicat

ion at run-time Provide Method

Retrieve shader Retreive shader description

To Use Shader Library Register to Shader Factory NiShaderFactory::LoadAndRegisterShaderLibrary

Page 9: Shader Program in Gamebryo. Introduction Shader?  A complete Rendering Effect to apply to an object  Shader Program – Vertex/Pixel Shader Shader Programs

Class Detail (cont.)

NiShaderFactory Handling shaders through shader-libraries

Provide Callback Method NISHADERFACTORY_CLASSCREATIONCALLBACK NISHADERFACTORY_RUNPARSERCALLBACK NISHADERFACTORY_ERRORCALLBACK

Interface for Global Constants of shadersNiGPUProgram Vertex, pixel shader program

Page 10: Shader Program in Gamebryo. Introduction Shader?  A complete Rendering Effect to apply to an object  Shader Program – Vertex/Pixel Shader Shader Programs

Class Detail (cont.)

NiShaderConstantMap NiShaderConstantMapEntry

Constant Defined

common transformations, material colors Attribute

per-object settings of constant values Global Operator

result of some mathematical operation on other constant map entries Object

represents an object in the scene – light, projected effects Data Driven

NiExtraData

Page 11: Shader Program in Gamebryo. Introduction Shader?  A complete Rendering Effect to apply to an object  Shader Program – Vertex/Pixel Shader Shader Programs

Class Detail (cont.)

Decription classes NiShaderDescBase NiShaderRequirementDesc NiShaderAttributeDesc NiShaderDesc NiShaderLibraryDesc

Page 12: Shader Program in Gamebryo. Introduction Shader?  A complete Rendering Effect to apply to an object  Shader Program – Vertex/Pixel Shader Shader Programs

NSF/NSB Shaders

Provide a data-driven method for generating and using Gamebryo's shader systemWrite NSF Text based file

Fast Prototyping

Generate NSB from NSF Binary type file NiBinaryShaderLibReference external shader file

Page 13: Shader Program in Gamebryo. Introduction Shader?  A complete Rendering Effect to apply to an object  Shader Program – Vertex/Pixel Shader Shader Programs

NiMaterial System

Determine proper shader in given circumstance Generate vertex and pixel shader program code

on the flyNiMaterial NiSingleShaderMaterial NiFragmentMaterial

NiStandardMaterial

Page 14: Shader Program in Gamebryo. Introduction Shader?  A complete Rendering Effect to apply to an object  Shader Program – Vertex/Pixel Shader Shader Programs

NiMaterial

NiSingleShaderMaterialNiFragmentMaterial Connected graph

Shade tree (http://portal.acm.org/citation.cfm?id=808602&dl=GUIDE&coll=GUIDE)

NiMaterialDescriptor 128-bit bitfield GenerateDescriptor

Is the object skinned?What per-vertex data exists on the object?Is the object lit? How many lights are affecting it? What types of lights are affecting it?What textures are applied to the object? What UV sets do they use?Are there tangent-space bases per-vertex?Is the object affected by specularity?

Page 15: Shader Program in Gamebryo. Introduction Shader?  A complete Rendering Effect to apply to an object  Shader Program – Vertex/Pixel Shader Shader Programs

NiMaterial (cont.)

NiFragmentMaterial (cont.) Create shade tree

NiMaterialConfigurator – shade tree NiGPUProgramDescriptor NiMaterialNode – tree node NiMaterialResource – uniform constants NiMaterialResourceBinding – connections

Fallbacks Breaking into several pass or eliminate certain lights

or textures

Page 16: Shader Program in Gamebryo. Introduction Shader?  A complete Rendering Effect to apply to an object  Shader Program – Vertex/Pixel Shader Shader Programs

NiMaterial (cont.)

NiStandardMaterial implements the default Ga

mebryo rendering pipeline

Page 17: Shader Program in Gamebryo. Introduction Shader?  A complete Rendering Effect to apply to an object  Shader Program – Vertex/Pixel Shader Shader Programs

NiMaterial (cont.)

Page 18: Shader Program in Gamebryo. Introduction Shader?  A complete Rendering Effect to apply to an object  Shader Program – Vertex/Pixel Shader Shader Programs

NiMaterial (cont.)

NiStandardMaterial (cont.) Fallback method

SplitPerPixelLights SplitPerVertexLights SplitTextureMaps DropParallaxMaps DropParallaxMapThenSplitLights