Gamebryo Shaders.

download Gamebryo Shaders.

If you can't read please download the document

description

Shader and Shader program Entire Rendering Pipeline Shader program Vertex or Pixel shader available in Gamebryo

Transcript of Gamebryo Shaders.

Gamebryo Shaders Shader and Shader program
Entire Rendering Pipeline Shader program Vertex or Pixel shader available in Gamebryo Gamebryo Shader System
Data Driven APP TOOL Shader Library Shaders Shader Programs NSF/NSB FX CG FX Lite xbox360 CGFX ps3 NSF/NSB Shader NSF NSB vs ps NSF NSB Data Driven NDL Shader File
Text-based NSB Shader Description NSFs Binary Version Compiled NSBs Filename .nsb Data Driven NSF compile NSB vs ps NSF Layout NSFShader < Name >{ Description UserDefinedData Objects Global_Attributes Attributes PackingDef Implementation } NSF Objects Access NiDynamicEffects From NiDynamicEffectState
Objects { ObjectType ObjectIndex LocalName } Example Objects { Effect_GeneralLight Light1 Effect_DirectionalLight Light2 Effect_PointLight Light3 Effect_GeneralLight Light4 Effect_GeneralLight Light5 } NSF Attributes(1) Global_Attributes / Attributes
[Global_]Attributes { AttributeType AttributeName Artist/Hidden InitialValue or AttributeType AttributeName[ArraySize] Artist/Hidden InitialValue } NSF Attributes(2) Example Attributes {
Attrib_Bool TestBool Artisttrue Attrib_UInt TestUInt Hidden [ ] Attrib_Float TestFloatArtist [ ] Attrib_Point TestPoint2 Artist0.0, [(0.0,0.0) (1.0,1.0)] Attrib_Point TestPoint3 Artist0.1,0.2, [(0.0,0.0,0.0) (1.0,1.0,1.0)] Attrib_Point TestPoint4 Artist0.1,0.2,0.3, [(0.0,0.0,0.0,1.0) (1.0,1.0,1.0,1.0)] Attrib_Matrix3 TestMatrix3Artist0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9 Attrib_Transform TestTransformArtist 0.1,0.2,0.3,0.4, 0.5,0.6,0.7,0.8, 0.9,1.0,1.1,1.2, 1.3,1.4,1.5,1.6 Attrib_Color TestColorArtist1.0,0.2,0.4 [(0.0,0.0,0.0) (1.0,1.0,1.0)] Attrib_Color TestColor2 Artist0.0,0.2,0.4,0.8 [(0.0,0.0,0.0,0.0) (1.0,1.0,1.0,1.0)] Attrib_Texture TestTextureArtist "DefaultTextures\Image000.bmp } Global_Attributes Attrib_Point4 TestArrayPoint4[5] Hidden 0.0,0.0,0.0,0.0 NSF PackingDef(1) PackingDef< Name > { PD_Stream # Parameter Register Type } Parameter RegisterType TesselatorUsageUsageIndex NSF PackingDef(2) Example PackingDef MultiStream {
PD_Stream 0// First set of vertex/normal/texture data PDP_Position PDT_Float3 PDP_Normal PDT_Float3 PDP_TexCoord PDT_Float2 PD_Stream 1// Second set of vertex/normal data PDP_ExtraData PDT_Float3 PDTESS_Default PDU_Position 1 PDP_ExtraData PDT_Float3 PDTESS_Default PDU_Normal 1 PD_Stream 2// Third set of vertex/normal data PDP_ExtraData PDT_Float3 PDTESS_Default PDU_Position 2 PDP_ExtraData PDT_Float3 PDTESS_Default PDU_Normal 2 } NSF-Implementation Need Packing Definition Declare
Fixed Pipeline Implementation < Name > { Description Requirements ClassName = NameOfDerivedClass UserDefinedData PackingDef RenderStates (VS,GS,PS)_ConstantMap Pass } Questions NSF Impl RenderStates
RenderState = value Save Save D10 Example RenderStates { Lighting = false AlphaBlendEnable = false Save ZEnable = ZB_True ZWriteEnable = true } NSF Impl Constantmap(1)
Platform Entries Object Entry Defined Entry Attribute Entry Constant Entry Global Entry Operator Entry NSF Impl Constantmap(2)
Object Entry CM_Object Name Parameter Register CM_Object Name Parameter VarName Parameters Dimmer, Ambient, Diffuse, WorldPostion Defined Entry CM_Defined Name Register ExtraData CM_Defined Name VarName ExtraData Example CM_Defined BoneMatrix NSF Impl Constantmap(3)
Attribute Entry CM_Attribute Name Register RegisterCount ExtraData Name NiExtraData at Runtime is not provide Hand Attach / Exposure to Tool ExtraData isnt valid right now(unsigned int) Constant Entry CM_Constant Name Register RegisterCount Values NSF Impl Constantmap(4)
Operator Entry Vertex Shader Constant Map Only CM_OperatorOpEntryName Register RegisterCount Entry1NameoperatorEntry2NameOPTIONAL_InverseOPTIONAL_Tanspose Operators ( * / + - ) Entries Point4, Color, Transform, Uint, float NSF Impl Constantmap(5)
VS_Constantmap { CM_Attribute SelectedColor 4 1 0 CM_Constant RandomConstant 5 1 0.2,0.4,0.5,0.1 CM_Defined World -1 0 CM_Defined ViewProj -1 0 CM_Operator TransformTranspose 0 4 World * ViewProj Transpose CM_Object Light1 ModelPosition 6 } Questions NSF Impl Pass Pass < Name >{ UserDefinedData RenderState (VS,GS,PS)Program (VS,GS,PS)_ConstantMap Stage Sampler Texture } RenderStates,ConstantMap in a Pass
Pass N Pass N+1 . Save Pass N Pass N+1 Pass N . Example Pass1 { RenderStates { AlphaBlendEnable = true Zenable = ZB_true } } Pass2 { RenderStates { Zenable = ZB_false } } NSF Impl Pass Shader Programs
Simple Declaration (VS,GS,PS)ProgramProgramName EntryPoint ShaderTarget EntryPoint for HLSL Complete Declaration VSProgram { Platform = DX9 Program = "VertexShaderDX9.hlsl" EntryPoint = VertexShader ShaderTarget = vs_2_0 } PSProgram { Platform = DX9 Program = "PixelShaderDX.psh" } NSF Impl Pass Stage(1)
Configure Fixed Function Pxel Pipeline Sampler and Texture Used with Pixel Shader instead Stage NOPTIONAL_StageN { Entries } NSF Impl Pass Stage(2)
Example Stage 0 { TSS_TexCoordIndex = TCI_PassThru 0 TSS_ColorOp = TOP_Modulate TSS_ColorArg1 = TA_Texture TSS_ColorArg2 = TA_Diffuse TSS_AlphaOp = TOP_SelectArg1 TSS_AlphaArg1 = TA_Texture TSS_Texture = } Stage 1 { TSS_Texture = NTM_Base TSS_TexCoordIndex = UseMapIndex TSS_ColorOp = TOP_Modulate TSS_ColorArg1 = TA_Texture TSS_ColorArg2 = TA_Diffuse TSS_AlphaOp = TOP_Disable } NSF Impl Pass Sampler/Texture
Sampler_state = sampler_state_value Save Texture N OPTIONALTextureN { source = TextureSource } TextureSource Texture mapping ID NTM_Base, NTM_Dark, NTM_Detail Attribute Name ObjectMap User Defined Data(1) Support NSF, Implementation, Pass Level
UserDefinedData NameOfUDDBlock { NameOfEntry0 = < data 0 > Quated Name = < data * > } Data Type Int/ unsigned int, boolean, float, string/quoted string User Defined Data(2) UserDefinedData ExampleBlock {
Test_Integer = 1234 Test_Boolean = true Test_1Float = 0.0 Test_2Floats = 0.0, 1.0 Test_3Floats = 0.0, 1.0, 2.0 Test_4Floats = 0.0, 1.0, 2.0, 3.0 Test_8Floats = 0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0 Test_9Floats = 0.0, 1.0, 2.0,3.0, 4.0, 5.0,6.0, 7.0, 8.0 Test_12Floats = 0.0, 1.0, 2.0,3.0, 4.0, 5.0,6.0, 7.0, 8.0,9.0,10.0,11.0 Test_16Floats = 0.0, 1.0, 2.0, 3.0,4.0, 5.0, 6.0, 7.0,8.0, 9.0,10.0,11.0, 12.0,13.0,14.0,15.0 Test_String = StringTest Test_QuotedString = "Quote Test" "Quoted Name" = "This is a test string" } Questions Sample Colorize vsh psh Sample TwoPass Sample BaseBumpWithSpatialGlow Extension of NSB Shader
ClassName = MyDerivedClass NiBinaryShader CreateNiBinaryShaderCallback typedef NiBinaryShader* (*CREATENIBINARYSHADER) ( const char* pacClassName ) Questions FX Shaders FX Shader NSB/NSF
FX Tool FX Shader Attributes Global Attributes / Attributes
float3 LightDirection : GLOBAL = {0,0,1.0} float3 LightDirection = {0,0,1.0} string description, bool hidden, bool color, min, max VarType GLOBAL / ATTRIBUTE FX Shader Predifined Constants
float4x4 WorldView : WORLDVIEW; PROJECTION, VIEW, WORLD BONEMATRIX3,4, SKINBONEMATRIX3,4 Declare as array Number of array is must same of bone defined by BonesPerPartition FX Shader Techniques int Implementation int BonePerPartition
Auto select or Explicit Select int BonePerPartition string NBTMethod bool UsesNIRenderState bool UsesNILightState technique ComplexEffect technique SimplerEffect FX Shader etc Preprocessor Definitions Limitations #define _DX9 1
No Procedural Texture Generation Texture file Path Full path, Relative path from apps working dir Mesh cannot bespecified in the file BG color or texture cannot ne specified D3D Effects cannot share parameters Sample PerPixelLightingEffect Questions Shader Library A collection of shaders available to the application at run-time Provide Interface for application and Tools DLL Compile for Tools(max, maya) Shader Library Architecture NiShaderFactory Handle Shader Libraries
NISHADERFACTORY_CLASSCREATIONCALLBACK Requested with LoadAndRegisterShaderLibrary via RegisterClassCreationCallback NISHADERFACTORY_RUNPARSERCALLBACK Requested with LoadAndRunParserLibrary NISHADERFACTORY_ERRORCALLBACK NiShaderLibrary A collection of shaders available to the application at run-time Provide Method Retrieve Shader Retreive Shader Description To Use Shader Library Register to Shader Factory NiShaderFactory::LoadAndRegisterShaderLibrary DLL for Tools Sample Demo/ShaderSample/ShaderLibrary Aniso,Halo Questions Shaders in Gamebryo Shaders in Gamebryo Shaders in Gamebryo Eturnum MetalWars