/// BasicProgram を指定した描画(一番オリジナルに近い形) public void Draw( GraphicsContext graphics, BasicProgram program ) { List <LocalPart> localPartList = updateLocalPart(); // パーツを DrawOrder 順にソート localPartList.Sort(); // パーツの描画 foreach (LocalPart localPart in localPartList) { if (localPart.material != null) { setPolygonMode(graphics, localPart.material); program.SetMaterial(ref localPart.material); setLayers(graphics, program, localPart.material); } program.SetMatrixPalette(localPart.worldCount, ref localPart.matrixPalette); program.Update(); graphics.SetVertexBuffer(0, localPart.vertexBuffer); graphics.DrawArrays(localPart.primitives); } }
/// コンテナに BasicProgram の読み込みを行う public BasicProgram Load( string key, string vsfilename, string fsfilename ) { BasicProgram ret = this.Find( key ); if( ret == null ){ ret = this.Regist( key, new BasicProgram( vsfilename, fsfilename ) ); } return ret; }
/// BasicProgram の登録 public BasicProgram Regist( string key, BasicProgram shader ) { if( Find( key ) != null ){ return null; } shaderTable[ key ] = shader; return shader; }
/// BasicProgram の登録 public BasicProgram Regist( string key, BasicProgram shader ) { if( Find( key ) != null ){ return null; } shaderTable[ key ] = shader; return shader; }
/// 指定 BasicProgram を必ず利用して描画する /** * Material は、BasicModel に設定された Material を利用する */ public void Draw(GraphicsContext graphics, BasicProgram program, Matrix4 viewProj, Vector4 eye) { List <LocalPart> localPartList = updateLocalPart(); // パーツを DrawOrder 順にソート localPartList.Sort(); // パーツの描画 foreach (LocalPart localPart in localPartList) { if (localPart.material != null) { setPolygonMode(graphics, localPart.material); // [note] local 参照なしの変数(だが、debug用途に残しておきたい) /* * int worldCount = localPart.worldCount; * bool texAnim = localPart.material.UseTexAnim; * int texCount = (localPart.material.Layers.Length <= 3) ? localPart.material.Layers.Length : 3; */ graphics.SetShaderProgram(program); program.SetViewProj(viewProj); program.SetMaterial(ref localPart.material); if (localPart.material.LightEnable != 0) { program.SetLightCount(lightCount); program.SetLights(ref localPart.matrixPalette[0], ref eye, ref lights); } else { program.SetLightCount(0); } setLayers(graphics, program, localPart.material); program.SetMatrixPalette(localPart.worldCount, ref localPart.matrixPalette); program.Update(); } graphics.SetVertexBuffer(0, localPart.vertexBuffer); graphics.DrawArrays(localPart.primitives); } }
public BasicProgram Find( BasicShaderName name ) { string key = name.Key(); BasicProgram ret = Find( key ); if( ret == null ){ string nameVS = name.VSName(); string nameFS = name.FSName(); try{ ret = Load( key, shaderRoot + nameVS + ".vp.cgx", shaderRoot + nameFS + ".fp.cgx" ); // 開発用シェーダ // ret = Load( key, shaderRoot + "_testVSH.vp.cgx", shaderRoot + "_testFSH.fp.cgx" ); }catch( System.IO.FileLoadException ){ ret = Find( "ASSERT" ); } } return ret; }
/// Material::Layer の設定を Shader に作用する void setLayers( GraphicsContext graphics, BasicProgram program, BasicMaterial material ) { if( material.Layers == null ){ return ; } Texture texture = null ; int layerCount = (material.Layers.Length <= 3) ? material.Layers.Length : 3; program.SetTexCount( layerCount ); int texID = 0; if( NormalizeCubeMap != null ){ graphics.SetTexture( texID, NormalizeCubeMap ); texID++; } for( int i = 0; i < layerCount; i++ ){ BasicLayer layer = material.Layers[ i ]; texture = Textures[ layer.Texture ].Texture ; if( texture != null ){ // TexAnimation if( layer.TexAnimBoneIdx >= 0 ){ Vector3 st = new Vector3(); st.X = 1.0f - Bones[ layer.TexAnimBoneIdx ].Scaling.X; st.Y = 1.0f - Bones[ layer.TexAnimBoneIdx ].Scaling.Y; st.Z = 1.0f - Bones[ layer.TexAnimBoneIdx ].Scaling.Z; texAnims[ i ] = Matrix4.Transformation( Bones[ layer.TexAnimBoneIdx ].Translation + st, Bones[ layer.TexAnimBoneIdx ].Rotation, Bones[ layer.TexAnimBoneIdx ].Scaling ) ; }else{ texAnims[ i ] = Matrix4.Identity; } texture.SetWrap( (TextureWrapMode)layer.TexWrapU, (TextureWrapMode)layer.TexWrapV ); texture.SetFilter( (TextureFilterMode)layer.magFilter, (TextureFilterMode)layer.minFilter, (TextureFilterMode)layer.mipFilter ); // graphics.SetTexture( i + 1, texture ); graphics.SetTexture( texID, texture ); texID++; } program.SetTexMtx( texAnims ); program.SetTexCoord( i, material.Layers[ i ].TexCoord ); program.SetTangentID( material.Layers[ i ].TangentID ); program.SetTexType( i, material.Layers[ i ].TexType ); program.SetTexBlendFunc( i, material.Layers[ i ].TexBlendFunc ); } }
/// BasicProgram を指定した描画(一番オリジナルに近い形) public void Draw( GraphicsContext graphics, BasicProgram program ) { List< LocalPart > localPartList = updateLocalPart(); // パーツを DrawOrder 順にソート localPartList.Sort(); // パーツの描画 foreach( LocalPart localPart in localPartList ){ if( localPart.material != null ){ setPolygonMode( graphics, localPart.material ); program.SetMaterial( ref localPart.material ); setLayers( graphics, program, localPart.material ); } program.SetMatrixPalette( localPart.worldCount, ref localPart.matrixPalette ); program.Update(); graphics.SetVertexBuffer( 0, localPart.vertexBuffer ) ; graphics.DrawArrays( localPart.primitives ) ; } }
/// 指定 BasicProgram を必ず利用して描画する /** * Material は、BasicModel に設定された Material を利用する */ public void Draw( GraphicsContext graphics, BasicProgram program, Matrix4 viewProj, Vector4 eye ) { List< LocalPart > localPartList = updateLocalPart(); // パーツを DrawOrder 順にソート localPartList.Sort(); // パーツの描画 foreach( LocalPart localPart in localPartList ){ if( localPart.material != null ){ setPolygonMode( graphics, localPart.material ); // [note] local 参照なしの変数(だが、debug用途に残しておきたい) /* * int worldCount = localPart.worldCount; * bool texAnim = localPart.material.UseTexAnim; *int texCount = (localPart.material.Layers.Length <= 3) ? localPart.material.Layers.Length : 3; */ graphics.SetShaderProgram( program ); program.SetViewProj( viewProj ); program.SetMaterial( ref localPart.material ); if( localPart.material.LightEnable != 0 ){ program.SetLightCount( lightCount ); program.SetLights( ref localPart.matrixPalette[ 0 ], ref eye, ref lights ); }else{ program.SetLightCount( 0 ); } setLayers( graphics, program, localPart.material ); program.SetMatrixPalette( localPart.worldCount, ref localPart.matrixPalette ); program.Update(); } graphics.SetVertexBuffer( 0, localPart.vertexBuffer ) ; graphics.DrawArrays( localPart.primitives ) ; } }
/// Material::Layer の設定を Shader に作用する void setLayers( GraphicsContext graphics, BasicProgram program, BasicMaterial material ) { if (material.Layers == null) { return; } Texture texture = null; int layerCount = (material.Layers.Length <= 3) ? material.Layers.Length : 3; program.SetTexCount(layerCount); int texID = 0; if (NormalizeCubeMap != null) { graphics.SetTexture(texID, NormalizeCubeMap); texID++; } // bool flag = false; for (int i = 0; i < layerCount; i++) { BasicLayer layer = material.Layers[i]; // Console.WriteLine(layer.Texture); // layer.Texture = 5; /* * if(flag == false){ * layer.Texture = 0; * flag = true; * } */ texture = Textures[layer.Texture].Texture; // texture = Textures[ 1 ].Texture ; if (texture != null) { // TexAnimation if (layer.TexAnimBoneIdx >= 0) { Vector3 st = new Vector3(); st.X = 1.0f - Bones[layer.TexAnimBoneIdx].Scaling.X; st.Y = 1.0f - Bones[layer.TexAnimBoneIdx].Scaling.Y; st.Z = 1.0f - Bones[layer.TexAnimBoneIdx].Scaling.Z; texAnims[i] = Matrix4.Transformation(Bones[layer.TexAnimBoneIdx].Translation + st, Bones[layer.TexAnimBoneIdx].Rotation, Bones[layer.TexAnimBoneIdx].Scaling); } else { texAnims[i] = Matrix4.Identity; } texture.SetWrap((TextureWrapMode)layer.TexWrapU, (TextureWrapMode)layer.TexWrapV); texture.SetFilter((TextureFilterMode)layer.magFilter, (TextureFilterMode)layer.minFilter, (TextureFilterMode)layer.mipFilter); // graphics.SetTexture( i + 1, texture ); graphics.SetTexture(texID, texture); texID++; } program.SetTexMtx(texAnims); program.SetTexCoord(i, material.Layers[i].TexCoord); program.SetTangentID(material.Layers[i].TangentID); program.SetTexType(i, material.Layers[i].TexType); program.SetTexBlendFunc(i, material.Layers[i].TexBlendFunc); } }
/// BasicMaterial に設定された ShaderName から、ShaderProgram を探して描画する public void Draw( GraphicsContext graphics, ShaderContainer shaderContainer, Matrix4 viewProj, Vector4 eye, float Brightness ) { foreach (var bone in Bones) { int worldCount = 0; // sky00_nami; // bone.Name = "sky00_nami"; int[] blendBones = bone.BlendBones; if (blendBones == null) { worldCount = 1; matrixBuffer = new Matrix4[1]; matrixBuffer[0] = bone.WorldMatrix; } else { int blendCount = blendBones.Length; if (blendCount > matrixBuffer.Length) { matrixBuffer = new Matrix4[blendCount]; } for (int i = 0; i < blendCount; i++) { matrixBuffer[i] = Bones[blendBones[i]].WorldMatrix * bone.BlendOffsets[i]; } } int[] blendSubset = defaultBlendSubset; foreach (var index in bone.DrawParts) { BasicPart part = Parts[index]; foreach (var mesh in part.Meshes) { if (blendBones != null && blendSubset != mesh.BlendSubset) { blendSubset = (mesh.BlendSubset != null) ? mesh.BlendSubset : defaultBlendSubset; worldCount = blendSubset.Length; if (worldCount > blendBones.Length) { worldCount = blendBones.Length; } } BasicMaterial material = Materials[mesh.Material]; if (material != null) { setPolygonMode(graphics, material); BasicProgram program = findBasicProgram(shaderContainer, material, worldCount, this.lightCount); graphics.SetShaderProgram(program); program.SetViewProj(viewProj); program.SetMaterial(ref material); if (material.LightEnable != 0) { program.SetLightCount(lightCount); program.SetLights(ref matrixBuffer[0], ref eye, ref lights); } else { program.SetLightCount(0); } program.SetRateLight(Brightness); setLayers(graphics, program, material); program.SetWorldCount(worldCount); for (int i = 0; i < worldCount; i++) { program.SetMatrixPalette(i, ref matrixBuffer[blendSubset[i]]); } program.Update(); } graphics.SetVertexBuffer(0, mesh.VertexBuffer); graphics.DrawArrays(mesh.Primitives); } } } }