Shader Program in Gamebryo. Introduction Shader? A complete Rendering Effect to apply to an object ...

Post on 05-Jan-2016

279 views 0 download

Tags:

Transcript of Shader Program in Gamebryo. Introduction Shader? A complete Rendering Effect to apply to an object ...

Shader Program in Gamebryo

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

Introduction (cont.)

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

Switching Process Mode NiD3DRenderState::SetSoftwareVertexProcessing

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

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

Shader System Class Interaction Diagram

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

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

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

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

Class Detail (cont.)

Decription classes NiShaderDescBase NiShaderRequirementDesc NiShaderAttributeDesc NiShaderDesc NiShaderLibraryDesc

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

NiMaterial System

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

on the flyNiMaterial NiSingleShaderMaterial NiFragmentMaterial

NiStandardMaterial

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?

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

NiMaterial (cont.)

NiStandardMaterial implements the default Ga

mebryo rendering pipeline

NiMaterial (cont.)

NiMaterial (cont.)

NiStandardMaterial (cont.) Fallback method

SplitPerPixelLights SplitPerVertexLights SplitTextureMaps DropParallaxMaps DropParallaxMapThenSplitLights