トップページ > 過去ログ > 記事閲覧
3Dの環境光(アンビエント?)の調整
名前:cdd 日時: 2009/12/14 23:01

こんにちは。 DrawPolygon3Dなどで表示した三角形ポリゴンに、ライティング計算を有効にしポリゴンに影をつけると、 光源側はポリゴンがきれいに表示されますが、反対側は 影が黒くなりすぎてしまいます。 ポリゴンの環境光(アンビエント?)の色の濃さは調整できないのでしょうか? 影側が真っ暗になりすぎて困ります。 宜しくお願いします。 --- #include "DxLib.h" int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow ) { VERTEX3D Vertex[ 6 ] ; // ウインドウモードに変更 ChangeWindowMode( TRUE ); // DXライブラリの初期化 if( DxLib_Init() < 0 ) { // エラーが発生したら直ちに終了 return -1 ; } //ライティング設定 ChangeLightTypeDir( VGet( 0.1f, 0.0f, 1.0f ) ) ; //カメラ SetCameraPositionAndTarget_UpVecY( VGet(-100.0f, 100.0f, 300.0f) , VGet(100.0f, 100.0f, 0.0f) ) ; // 2ポリゴン分の頂点のデータをセット Vertex[ 0 ].pos = VGet( 100.0f, 100.0f, 0.0f ) ; Vertex[ 0 ].norm = VGet( 0.0f, 0.0f, -1.0f ) ; Vertex[ 0 ].dif = GetColorU8( 255,255,255,255 ) ; Vertex[ 0 ].spc = GetColorU8( 0, 0, 0, 0 ) ; Vertex[ 0 ].u = 0.0f ; Vertex[ 0 ].v = 0.0f ; Vertex[ 0 ].su = 0.0f ; Vertex[ 0 ].sv = 0.0f ; Vertex[ 1 ].pos = VGet( 250.0f, 100.0f, 0.0f ) ; Vertex[ 1 ].norm = VGet( 0.0f, 0.0f, -1.0f ) ; Vertex[ 1 ].dif = GetColorU8( 255,255,255,255 ) ; Vertex[ 1 ].spc = GetColorU8( 0, 0, 0, 0 ) ; Vertex[ 1 ].u = 0.0f ; Vertex[ 1 ].v = 0.0f ; Vertex[ 1 ].su = 0.0f ; Vertex[ 1 ].sv = 0.0f ; Vertex[ 2 ].pos = VGet( 100.0f, 300.0f, 0.0f ) ; Vertex[ 2 ].norm = VGet( 0.0f, 0.0f, -1.0f ) ; Vertex[ 2 ].dif = GetColorU8( 255,255,255,255 ) ; Vertex[ 2 ].spc = GetColorU8( 0, 0, 0, 0 ) ; Vertex[ 2 ].u = 0.0f ; Vertex[ 2 ].v = 0.0f ; Vertex[ 2 ].su = 0.0f ; Vertex[ 2 ].sv = 0.0f ; Vertex[ 3 ].pos = VGet( 100.0f, 100.0f, 0.0f ) ; Vertex[ 3 ].norm = VGet( -1.0f, 0.0f, 0.0f ) ; Vertex[ 3 ].dif = GetColorU8( 255,255,255,255 ) ; Vertex[ 3 ].spc = GetColorU8( 0, 0, 0, 0 ) ; Vertex[ 3 ].u = 0.0f ; Vertex[ 3 ].v = 0.0f ; Vertex[ 3 ].su = 0.0f ; Vertex[ 3 ].sv = 0.0f ; Vertex[ 4 ].pos = VGet( 100.0f, 100.0f, -100.0f ) ; Vertex[ 4 ].norm = VGet( -1.0f, 0.0f, 0.0f ) ; Vertex[ 4 ].dif = GetColorU8( 255,255,255,255 ) ; Vertex[ 4 ].spc = GetColorU8( 0, 0, 0, 0 ) ; Vertex[ 4 ].u = 0.0f ; Vertex[ 4 ].v = 0.0f ; Vertex[ 4 ].su = 0.0f ; Vertex[ 4 ].sv = 0.0f ; Vertex[ 5 ].pos = VGet( 100.0f, 300.0f, 0.0f ) ; Vertex[ 5 ].norm = VGet( -1.0f, 0.0f, 0.0f ) ; Vertex[ 5 ].dif = GetColorU8( 255,255,255,255 ) ; Vertex[ 5 ].spc = GetColorU8( 0, 0, 0, 0 ) ; Vertex[ 5 ].u = 0.0f ; Vertex[ 5 ].v = 0.0f ; Vertex[ 5 ].su = 0.0f ; Vertex[ 5 ].sv = 0.0f ; // 2ポリゴンの描画 DrawPolygon3D( Vertex, 2, DX_NONE_GRAPH, FALSE ) ; // キー入力待ちをする WaitKey() ; // DXライブラリの後始末 DxLib_End() ; // ソフトの終了 return 0 ; }

Page: 1 |

Re: 3Dの環境光(アンビエント?)の調整 ( No.1 )
名前:管理人 日時:2009/12/18 00:37

ライトのアンビエントカラーと描画するポリゴンのマテリアルのパラメータを変更することで可能です 掲載していただいたプログラムの ChangeLightTypeDir と SetCameraPositionAndTarget_UpVecY の間に 以下の記述を追加してみてください // ライトのアンビエントカラーを赤色に変更 SetLightAmbColor( GetColorF( 0.4f, 0.0f, 0.0f, 0.0f ) ) ; MATERIALPARAM MatParam ; MatParam.Diffuse = GetColorF( 1.0f, 1.0f, 1.0f, 1.0f ) ; // ディフューズカラーは白 MatParam.Ambient = GetColorF( 1.0f, 1.0f, 1.0f, 1.0f ) ; // アンビエントカラーは白( ライトのアンビエントカラーをそのまま反映する ) MatParam.Specular = GetColorF( 0.0f, 0.0f, 0.0f, 0.0f ) ; // スペキュラカラーは無し MatParam.Emissive = GetColorF( 0.0f, 0.0f, 0.0f, 0.0f ) ; // エミッシブカラー( 自己発光 )もなし MatParam.Power = 0.0f ; // スペキュラはないので0 // マテリアルのパラメータをセット SetMaterialParam( MatParam ) ;
Re: 3Dの環境光(アンビエント?)の調整 ( No.2 )
名前:cdd 日時:2009/12/19 17:08

ポリゴン自体にもマテリアルの設定が必要なのですか。 分かりました。 ありがとうございました。解決しました。

Page: 1 |