コード例 #1
0
 /// ライトの設定
 public void SetLight( int idx, Light light )
 {
     if( idx < lights.Length ){
     this.lights[ idx ] = light;
     }
 }
コード例 #2
0
ファイル: BasicProgram.cs プロジェクト: hatano0x06/Coroppoxus
        /// ライトの設定
        public void SetLights( 
                          ref Matrix4 target, ///< モデルローカルに変換するための、モデルの位置
                          ref Vector4 eyePos, ///< ワールド上での視点の位置
                          ref Light[] lights
                           )
        {
            if( lights != null ){
            Matrix4 invWorld = target.Inverse();
            Vector4 localEyePosistion = invWorld * eyePos;

            if( idWorldInverse >= 0 ){
                this.SetUniformValue( idWorldInverse, ref invWorld );
            }

            if( idLocalEyePosition >= 0 ){
                this.SetUniformValue( idLocalEyePosition, ref localEyePosistion );
            }

            // ライト : 0
            if( lights[ 0 ] != null ){
                Vector4 localLightPosition = invWorld * lights[ 0 ].Position;
                if( idLocalLightPosition00 >= 0 ){
                    // Vector4 V = localLightPosition.Normalize();
                    this.SetUniformValue( idLocalLightPosition00, ref localLightPosition );
                }

                // 並行光源(トゥーン用)
                if( idLocalLightDir >= 0 ){
                    Vector4 localLightPos = invWorld * lights[ 0 ].Position;
                    Vector3 localLightDir = new Vector3( -localLightPos.X, -localLightPos.Y, -localLightPos.Z );
                    localLightDir = localLightDir.Normalize();

                    this.SetUniformValue( idLocalLightDir, ref localLightDir );
                }

                if( idKDiffuse00 >= 0 ){
                    this.SetUniformValue( idKDiffuse00, ref lights[ 0 ].KDiffuse );
                }
                if( idKSpecular00 >= 0 ){
                    this.SetUniformValue( idKSpecular00, ref lights[ 0 ].KSpecular );
                }
            }
            // ライト : 1
            if( lights[ 1 ] != null ){
                if( idLocalLightPosition01 >= 0 ){
                    Vector4 localLightPosition = invWorld * lights[ 1 ].Position;
                    this.SetUniformValue( idLocalLightPosition01, ref localLightPosition );
                }
                if( idKDiffuse01 >= 0 ){
                    this.SetUniformValue( idKDiffuse01, ref lights[ 1 ].KDiffuse );
                }
                if( idKSpecular01 >= 0 ){
                    this.SetUniformValue( idKSpecular01, ref lights[ 1 ].KSpecular );
                }
            }

            // ライト : 2
            if( lights[ 2 ] != null ){
                if( idLocalLightPosition02 >= 0 ){
                    Vector4 localLightPosition = invWorld * lights[ 2 ].Position;
                    this.SetUniformValue( idLocalLightPosition02, ref localLightPosition );
                }
                if( idKDiffuse02 >= 0 ){
                    this.SetUniformValue( idKDiffuse02, ref lights[ 2 ].KDiffuse );
                }
                if( idKSpecular02 >= 0 ){
                    this.SetUniformValue( idKSpecular02, ref lights[ 2 ].KSpecular );
                }
            }

            }else{
            if( idLIGHT_COUNT >= 0 ){
                this.SetUniformValue( idLIGHT_COUNT, 0 );
            }

            }
        }