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 NSF’s Binary Version Compiled NSB’s Filename <Shader Name in NSF FILE>.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 1 Light1 Effect_DirectionalLight 0 Light2 Effect_PointLight 0 Light3 Effect_GeneralLight 2 Light4 Effect_GeneralLight 3 Light5 }
NSF – Attributes(1) Global_Attributes / Attributes [Global_]Attributes { AttributeType AttributeName Artist/Hidden InitialValue <OptionalRange> or AttributeType AttributeName[ArraySize] Artist/Hidden InitialValue }
NSF – Attributes(2) Example Attributes { Attrib_Bool TestBool Artist true Attrib_UInt TestUInt Hidden 1024 [0 2048] Attrib_Float TestFloat Artist 0.65 [0.0 1.0] Attrib_Point2 TestPoint2 Artist 0.0,0.5 [(0.0,0.0) (1.0,1.0)] Attrib_Point3 TestPoint3 Artist 0.1,0.2,0.3 [(0.0,0.0,0.0) (1.0,1.0,1.0)] Attrib_Point4 TestPoint4 Artist 0.1,0.2,0.3,0.4 [(0.0,0.0,0.0,1.0) (1.0,1.0,1.0,1.0)] Attrib_Matrix3 TestMatrix3 Artist 0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9 Attrib_Transform TestTransform Artist 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 TestColor Artist 1.0,0.2,0.4 [(0.0,0.0,0.0) (1.0,1.0,1.0)] Attrib_Color TestColor2 Artist 0.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 TestTexture Artist 0 "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 Register Type Tesselator Usage UsageIndex
NSF – PackingDef(2) Example PackingDef MultiStream { PD_Stream 0 // First set of vertex/normal/texture data PDP_Position 0 PDT_Float3 PDP_Normal 3 PDT_Float3 PDP_TexCoord0 6 PDT_Float2 PD_Stream 1 // Second set of vertex/normal data PDP_ExtraData 0 1 PDT_Float3 PDTESS_Default PDU_Position 1 PDP_ExtraData 1 4 PDT_Float3 PDTESS_Default PDU_Normal 1 PD_Stream 2 // Third set of vertex/normal data PDP_ExtraData 2 2 PDT_Float3 PDTESS_Default PDU_Position 2 PDP_ExtraData 3 5 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 BoneMatrix3 10 0 20
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 isn’t 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_Operator OpEntryName Register RegisterCount Entry1Name operator Entry2Name OPTIONAL_Inverse OPTIONAL_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)Program ProgramName 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 N OPTIONAL_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 = <TestMap> } 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 < string VarType = “Global”; > = {0,0,1.0} string description, bool hidden, bool color, <type> min, <type> 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 <string shadername = "NeatEffect"; int implementation = 0;> technique SimplerEffect <string shadername = "NeatEffect"; int implementation = 1;>
FX Shader – etc Preprocessor Definitions Limitations #define _DX9 1 No Procedural Texture Generation Texture file Path Full path, Relative path from app’s working dir Mesh cannot be specified 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