/*---------------------------------------------------------------------------* Project: Horizon File: gr_FragmentLight.cpp Copyright (C)2010 Nintendo Co., Ltd. All rights reserved. These coded instructions, statements, and computer programs contain proprietary information of Nintendo of America Inc. and/or Nintendo Company Ltd., and are protected by Federal copyright law. They may not be disclosed to third parties or copied or duplicated in any form, in whole or in part, without the prior written consent of Nintendo. $Rev: 26237 $ *---------------------------------------------------------------------------*/ #include namespace nn { namespace gr { namespace CTR { u32* FragmentLight::Source::MakeCommand( u32* command ) const { u32 reg = PICA_REG_FRAG_LIGHT_START + id * PICA_FRAG_LIGHT_STRIDE; *command++ = specular0B | specular0G << 10 | specular0R << 20; // specular0 *command++ = PICA_CMD_HEADER_BURSTSEQ( reg, 12 ); // header *command++ = specular1B | specular1G << 10 | specular1R << 20; // specular1 *command++ = diffuseB | diffuseG << 10 | diffuseR << 20; // diffuse *command++ = ambientB | ambientG << 10 | ambientR << 20; // ambient *command++ = posXY; *command++ = posZ; *command++ = spotDirectionXY; *command++ = spotDirectionZ; *command++ = 0; *command++ = isInfinity | ( isEnableTwoSideDiffuse ? 1 : 0 ) << 1 | ( isEnableGeomFactor0 ? 1 : 0 ) << 2 | ( isEnableGeomFactor1 ? 1 : 0 ) << 3; *command++ = distAttnBias; *command++ = distAttnScale; *command++ = 0; return command; } //------------------------------------------------------------------------------ FragmentLight::Source::Source() : id( 0 ), isEnableTwoSideDiffuse( false ), isEnableGeomFactor0( false ), isEnableGeomFactor1( false ), diffuseR( 255 ), diffuseG( 255 ), diffuseB( 255 ), ambientR( 0 ), ambientG( 0 ), ambientB( 0 ), specular0R( 255 ), specular0G( 255 ), specular0B( 255 ), specular1R( 255 ), specular1G( 255 ), specular1B( 255 ), posXY( 0 ), posZ( 0 ), isInfinity( 0 ), distAttnBias( 0 ), distAttnScale( 0 ), spotDirectionXY( 0 ), spotDirectionZ( 0 ) { } //------------------------------------------------------------------------------ u32* FragmentLight::MakeLutConfigCommand( u32* command ) const { // 0x1d0 *command++ = PICA_CMD_DATA_FRAG_LIGHT_ABSLUTINPUT( lutConfigD0.isAbs, lutConfigD1.isAbs, lutConfigSP.isAbs, lutConfigFR.isAbs, lutConfigRB.isAbs, lutConfigRG.isAbs, lutConfigRR.isAbs ); *command++ = PICA_CMD_HEADER_SINGLE( PICA_REG_FRAG_LIGHT_ABSLUTINPUT ); // 0x1d1 *command++ = PICA_CMD_DATA_FRAG_LIGHT_LUTINPUT( lutConfigD0.input, lutConfigD1.input, lutConfigSP.input, lutConfigFR.input, lutConfigRB.input, lutConfigRG.input, lutConfigRR.input ); *command++ = PICA_CMD_HEADER_SINGLE( PICA_REG_FRAG_LIGHT_LUTINPUT ); // 0x1d2 *command++ = PICA_CMD_DATA_FRAG_LIGHT_LUTSCALE( lutConfigD0.scale, lutConfigD1.scale, lutConfigSP.scale, lutConfigFR.scale, lutConfigRB.scale, lutConfigRG.scale, lutConfigRR.scale ); *command++ = PICA_CMD_HEADER_SINGLE( PICA_REG_FRAG_LIGHT_LUTSCALE ); return command; } //------------------------------------------------------------------------------ u32* FragmentLight::MakeLightEnvCommand( u32* command ) const { u32 regLightEnable = 0xff00ffff; u32 regLightEnableEach = 0; s32 count = 0; regLightEnable |= PICA_CMD_DATA_FRAG_LIGHT_FUNC_MODE1_LUT( isEnableLutD0, isEnableLutD1, fresnelSelector, isEnableLutRef1 ); for ( int i = 0; i < LIGHT_SOURCE_MAX; ++i ) { if ( isEnable[ i ] == false ) continue; if ( isShadowed[ i ] ) { regLightEnable &= ~( i << i ); } if ( isEnableSpot[ i ] ) { regLightEnable &= ~( 1 << ( 8 + i ) ); } if ( isEnableDistAttn[ i ] ) { regLightEnable &= ~( 1 << ( 24 + i ) ); } regLightEnableEach |= ( i << ( count++ * 4 ) ); } // 0x08f ライトの有効無効を設定 *command++ = PICA_CMD_DATA_FRAG_LIGHT_EN( count ); *command++ = PICA_CMD_HEADER_SINGLE( PICA_REG_FRAG_LIGHT_EN0 ); // 0x1c0 グローバルアンビエントの設定 *command++ = globalAmbientB | globalAmbientG << 10 | globalAmbientR << 20; *command++ = PICA_CMD_HEADER_SINGLE( PICA_REG_FRAG_LIGHT_AMBIENT ); // 0x1c2 光源数の設定 *command++ = PICA_CMD_DATA_FRAG_LIGHT_NUM( count ); *command++ = PICA_CMD_HEADER_SINGLE( PICA_REG_FRAG_LIGHT_SRC_NUM ); // 0x1c3 *command++ = PICA_CMD_DATA_FRAG_LIGHT_FUNC_MODE0( fresnelSelector, layerConfig, isEnableShadowPrimary, isEnableShadowSecondary, isInvertShadow, isEnableShadowAlpha, bumpSelector, shadowSelector, isEnableClampHighLights, bumpMode, isEnableBumpRenorm ); *command++ = PICA_CMD_HEADER_SINGLE( PICA_REG_FRAG_LIGHT_FUNC_MODE0 ); // 0x1c4 *command++ = regLightEnable; *command++ = PICA_CMD_HEADER_SINGLE( PICA_REG_FRAG_LIGHT_FUNC_MODE1 ); // 0x1c6 ライトの有効無効を設定 *command++ = PICA_CMD_DATA_FRAG_LIGHT_EN_INV( count ); *command++ = PICA_CMD_HEADER_SINGLE( PICA_REG_FRAG_LIGHT_EN1 ); // 0x1d9 *command++ = regLightEnableEach; *command++ = PICA_CMD_HEADER_SINGLE( PICA_REG_FRAG_LIGHT_SRC_EN_ID ); return command; } //------------------------------------------------------------------------------ u32* FragmentLight::MakeLightSourceCommand( u32* command ) const { // 各光源ごとの設定 for ( int i = 0; i < LIGHT_SOURCE_MAX; ++i ) { if ( isEnable[ i ] == false ) continue; command = source[ i ].MakeCommand( command ); } return command; } //------------------------------------------------------------------------------ u32* FragmentLight::MakeAllCommand( u32* command ) const { #if defined( NN_GR_FRAGMENT_LIGHT_DUMP ) // デバッグ用 u32 * start = command; #endif command = MakeLutConfigCommand( command ); command = MakeLightEnvCommand( command ); command = MakeLightSourceCommand( command ); #if defined( NN_GR_FRAGMENT_LIGHT_DUMP ) // デバッグ用 static int a = 0; if ( ++a == 10 ) { for ( u32* i = start; i != command; i +=2 ) { NN_LOG( "0x%08x 0x%08x\n", *i, *(i+1) ); } } #endif return command; } //------------------------------------------------------------------------------ FragmentLight::FragmentLight() : globalAmbientR( 0 ), globalAmbientG( 0 ), globalAmbientB( 0 ), layerConfig( PICA_DATA_FRAG_LIGHT_ENV_LAYER_CONFIG0 ), fresnelSelector( PICA_DATA_FRAG_LIGHT_ENV_NO_FRESNEL ), shadowSelector( PICA_DATA_FRAG_LIGHT_ENV_TEXTURE0 ), bumpMode( PICA_DATA_FRAG_LIGHT_ENV_BUMP_NOT_USED_DMP ), bumpSelector( PICA_DATA_FRAG_LIGHT_ENV_TEXTURE0 ), isEnableShadowPrimary( false ), isEnableShadowSecondary( false ), isEnableShadowAlpha( false ), isInvertShadow( false ), isEnableBumpRenorm( false ), isEnableClampHighLights( true ), isEnableLutD0( false ), isEnableLutD1( false ), isEnableLutRef1( true ) { for ( int i = 0; i < LIGHT_SOURCE_MAX; ++i ) { isEnable[ i ] = false; isEnableSpot[ i ] = false; isEnableDistAttn[ i ] = false; isShadowed[ i ] = false; source[ i ].id = i; } } //------------------------------------------------------------------------------ FragmentLight::LutConfig::LutConfig() : input( PICA_DATA_FRAG_LIGHT_ENV_NH_DMP ), isAbs( false ), scale( PICA_DATA_FRAG_LIGHT_ENV_LUTSCALE_1_0 ) { } } // namespace CTR } // namespace gr } // namespace nn