@@ -196,8 +196,11 @@ static Bool wireframeForDebug = 0;
196
196
197
197
void WaterRenderObjClass::setupJbaWaterShader (void )
198
198
{
199
+ if (!TheWaterTransparency->m_additiveBlend )
200
+ DX8Wrapper::Set_Shader (ShaderClass::_PresetAlphaShader);
201
+ else
202
+ DX8Wrapper::Set_Shader (ShaderClass::_PresetAdditiveShader);
199
203
200
- DX8Wrapper::Set_Shader (ShaderClass::_PresetAlphaShader);
201
204
VertexMaterialClass *vmat=VertexMaterialClass::Get_Preset (VertexMaterialClass::PRELIT_DIFFUSE);
202
205
DX8Wrapper::Set_Material (vmat);
203
206
REF_PTR_RELEASE (vmat);
@@ -304,7 +307,8 @@ WaterRenderObjClass::~WaterRenderObjClass(void)
304
307
{ WaterSettings[i].m_skyTextureFile .clear ();
305
308
WaterSettings[i].m_waterTextureFile .clear ();
306
309
}
307
-
310
+ ((WaterTransparencySetting*)TheWaterTransparency.getNonOverloadedPointer ())->deleteInstance ();
311
+ TheWaterTransparency = NULL ;
308
312
ReleaseResources ();
309
313
310
314
if (m_waterTrackSystem)
@@ -365,9 +369,6 @@ WaterRenderObjClass::WaterRenderObjClass(void)
365
369
m_waterSparklesTexture=0 ;
366
370
m_riverXOffset=0 ;
367
371
m_riverYOffset=0 ;
368
-
369
-
370
-
371
372
}
372
373
373
374
// -------------------------------------------------------------------------------------------------
@@ -1088,8 +1089,8 @@ Int WaterRenderObjClass::init(Real waterLevel, Real dx, Real dy, SceneClass *par
1088
1089
REF_PTR_RELEASE (material);
1089
1090
}
1090
1091
1091
- m_riverTexture=WW3DAssetManager::Get_Instance ()->Get_Texture (" TWWater01.tga " );
1092
-
1092
+ m_riverTexture=WW3DAssetManager::Get_Instance ()->Get_Texture (TheWaterTransparency-> m_standingWaterTexture . str () );
1093
+
1093
1094
// For some reason setting a NULL texture does not result in 0xffffffff for pixel shaders so using explicit "white" texture.
1094
1095
m_whiteTexture=MSGNEW (" TextureClass" ) TextureClass (1 ,1 ,WW3D_FORMAT_A4R4G4B4,MIP_LEVELS_1);
1095
1096
SurfaceClass *surface=m_whiteTexture->Get_Surface_Level ();
@@ -1107,6 +1108,15 @@ Int WaterRenderObjClass::init(Real waterLevel, Real dx, Real dy, SceneClass *par
1107
1108
return 0 ;
1108
1109
}
1109
1110
1111
+ void WaterRenderObjClass::updateMapOverrides (void )
1112
+ {
1113
+ if (m_riverTexture && TheWaterTransparency->m_standingWaterTexture .compareNoCase (m_riverTexture->Get_Texture_Name ()) != 0 )
1114
+ {
1115
+ REF_PTR_RELEASE (m_riverTexture);
1116
+ m_riverTexture = WW3DAssetManager::Get_Instance ()->Get_Texture (TheWaterTransparency->m_standingWaterTexture .str ());
1117
+ }
1118
+ }
1119
+
1110
1120
// ------------------------------------------------------------------------------------------------
1111
1121
// ------------------------------------------------------------------------------------------------
1112
1122
void WaterRenderObjClass::reset ( void )
@@ -2713,29 +2723,49 @@ void WaterRenderObjClass::drawRiverWater(PolygonTrigger *pTrig)
2713
2723
}
2714
2724
2715
2725
2716
- Real shadeR, shadeG, shadeB;
2717
- shadeR = TheGlobalData->m_terrainAmbient [0 ].red ;
2718
- shadeG = TheGlobalData->m_terrainAmbient [0 ].green ;
2719
- shadeB = TheGlobalData->m_terrainAmbient [0 ].blue ;
2726
+ Real shadeR=TheWaterTransparency->m_standingWaterColor .red ;
2727
+ Real shadeG=TheWaterTransparency->m_standingWaterColor .green ;
2728
+ Real shadeB=TheWaterTransparency->m_standingWaterColor .blue ;
2720
2729
2721
- // Add in diffuse lighting from each terrain light
2722
- for (Int lightIndex= 0 ; lightIndex < TheGlobalData-> m_numGlobalLights ; lightIndex++ )
2730
+ // If the water color is not overridden, use legacy lighting code.
2731
+ if ( shadeR== 1 . 0f && shadeG== 1 . 0f && shadeB== 1 . 0f )
2723
2732
{
2724
- if (-TheGlobalData->m_terrainLightPos [lightIndex].z > 0 )
2725
- { shadeR += -TheGlobalData->m_terrainLightPos [lightIndex].z * TheGlobalData->m_terrainDiffuse [lightIndex].red ;
2726
- shadeG += -TheGlobalData->m_terrainLightPos [lightIndex].z * TheGlobalData->m_terrainDiffuse [lightIndex].green ;
2727
- shadeB += -TheGlobalData->m_terrainLightPos [lightIndex].z * TheGlobalData->m_terrainDiffuse [lightIndex].blue ;
2733
+ shadeR = TheGlobalData->m_terrainAmbient [0 ].red ;
2734
+ shadeG = TheGlobalData->m_terrainAmbient [0 ].green ;
2735
+ shadeB = TheGlobalData->m_terrainAmbient [0 ].blue ;
2736
+
2737
+ // Add in diffuse lighting from each terrain light
2738
+ for (Int lightIndex=0 ; lightIndex < TheGlobalData->m_numGlobalLights ; lightIndex++)
2739
+ {
2740
+ if (-TheGlobalData->m_terrainLightPos [lightIndex].z > 0 )
2741
+ { shadeR += -TheGlobalData->m_terrainLightPos [lightIndex].z * TheGlobalData->m_terrainDiffuse [lightIndex].red ;
2742
+ shadeG += -TheGlobalData->m_terrainLightPos [lightIndex].z * TheGlobalData->m_terrainDiffuse [lightIndex].green ;
2743
+ shadeB += -TheGlobalData->m_terrainLightPos [lightIndex].z * TheGlobalData->m_terrainDiffuse [lightIndex].blue ;
2744
+ }
2728
2745
}
2729
- }
2730
2746
2731
- // Get water material colors
2732
- Real waterShadeR = (m_settings[m_tod].waterDiffuse & 0xff ) / 255 .0f ;
2733
- Real waterShadeG = ((m_settings[m_tod].waterDiffuse >> 8 ) & 0xff ) / 255 .0f ;
2734
- Real waterShadeB = ((m_settings[m_tod].waterDiffuse >> 16 ) & 0xff ) / 255 .0f ;
2747
+ // Get water material colors
2748
+ Real waterShadeR = (m_settings[m_tod].waterDiffuse & 0xff ) / 255 .0f ;
2749
+ Real waterShadeG = ((m_settings[m_tod].waterDiffuse >> 8 ) & 0xff ) / 255 .0f ;
2750
+ Real waterShadeB = ((m_settings[m_tod].waterDiffuse >> 16 ) & 0xff ) / 255 .0f ;
2735
2751
2736
- shadeR=shadeR*waterShadeR*255 .0f ;
2737
- shadeG=shadeG*waterShadeG*255 .0f ;
2738
- shadeB=shadeB*waterShadeB*255 .0f ;
2752
+ shadeR=shadeR*waterShadeR*255 .0f ;
2753
+ shadeG=shadeG*waterShadeG*255 .0f ;
2754
+ shadeB=shadeB*waterShadeB*255 .0f ;
2755
+ }
2756
+ else
2757
+ {
2758
+ shadeR=shadeR*255 .0f ;
2759
+ shadeG=shadeG*255 .0f ;
2760
+ shadeB=shadeB*255 .0f ;
2761
+
2762
+ if (shadeR == 0 && shadeG == 0 && shadeB == 0 )
2763
+ { // special case where we disable lighting
2764
+ shadeR=255 ;
2765
+ shadeG=255 ;
2766
+ shadeB=255 ;
2767
+ }
2768
+ }
2739
2769
2740
2770
Int diffuse=REAL_TO_INT (shadeB) | (REAL_TO_INT (shadeG) << 8 ) | (REAL_TO_INT (shadeR) << 16 );
2741
2771
@@ -2840,9 +2870,15 @@ void WaterRenderObjClass::drawRiverWater(PolygonTrigger *pTrig)
2840
2870
DX8Wrapper::Set_Transform (D3DTS_WORLD,tm); // position the water surface
2841
2871
DX8Wrapper::Set_Index_Buffer (ib_access,0 );
2842
2872
DX8Wrapper::Set_Vertex_Buffer (vb_access);
2843
- DX8Wrapper::Set_Texture (0 ,m_riverTexture); // set to white
2873
+ DX8Wrapper::Set_Texture (0 ,m_riverTexture); // set to blue
2844
2874
2845
2875
setupJbaWaterShader ();
2876
+
2877
+ // In additive blending we need to use the alpha at the edges of river to darken
2878
+ // rgb instead.
2879
+ if (TheWaterTransparency->m_additiveBlend )
2880
+ DX8Wrapper::Set_DX8_Render_State (D3DRS_SRCBLEND, D3DBLEND_SRCALPHA );
2881
+
2846
2882
if (m_riverWaterPixelShader) DX8Wrapper::_Get_D3D_Device8 ()->SetPixelShader (m_riverWaterPixelShader);
2847
2883
DWORD cull;
2848
2884
DX8Wrapper::_Get_D3D_Device8 ()->GetRenderState (D3DRS_CULLMODE, &cull);
@@ -2860,6 +2896,9 @@ void WaterRenderObjClass::drawRiverWater(PolygonTrigger *pTrig)
2860
2896
2861
2897
if (m_riverWaterPixelShader) DX8Wrapper::_Get_D3D_Device8 ()->SetPixelShader (NULL );
2862
2898
2899
+ // restore blend mode to what W3D expects.
2900
+ if (TheWaterTransparency->m_additiveBlend )
2901
+ DX8Wrapper::Set_DX8_Render_State (D3DRS_SRCBLEND, D3DBLEND_ONE );
2863
2902
2864
2903
// do second pass to apply the shroud on water plane
2865
2904
if (TheTerrainRenderObject->getShroud ())
@@ -2904,7 +2943,11 @@ void WaterRenderObjClass::setupFlatWaterShader(void)
2904
2943
}
2905
2944
2906
2945
DX8Wrapper::Set_Texture (0 ,m_riverTexture);
2907
- DX8Wrapper::Set_Shader (ShaderClass::_PresetAlphaShader);
2946
+ if (!TheWaterTransparency->m_additiveBlend )
2947
+ DX8Wrapper::Set_Shader (ShaderClass::_PresetAlphaShader);
2948
+ else
2949
+ DX8Wrapper::Set_Shader (ShaderClass::_PresetAdditiveShader);
2950
+
2908
2951
VertexMaterialClass *vmat=VertexMaterialClass::Get_Preset (VertexMaterialClass::PRELIT_DIFFUSE);
2909
2952
DX8Wrapper::Set_Material (vmat);
2910
2953
REF_PTR_RELEASE (vmat);
@@ -2995,7 +3038,7 @@ void WaterRenderObjClass::drawTrapezoidWater(Vector3 points[4])
2995
3038
DynamicIBAccessClass::WriteLockClass lockib (&ib_access);
2996
3039
UnsignedShort *curIb = lockib.Get_Index_Array ();
2997
3040
for (j=0 ; j<vCount-1 ; j++)
2998
- for (i=0 ; i<uCount-1 ; i++)
3041
+ { for (i=0 ; i<uCount-1 ; i++)
2999
3042
{
3000
3043
// triangle 1
3001
3044
curIb[0 ] = (j)*uCount + i;
@@ -3009,32 +3052,53 @@ void WaterRenderObjClass::drawTrapezoidWater(Vector3 points[4])
3009
3052
3010
3053
curIb += 6 ; // skip the 6 indices we just added.
3011
3054
}
3055
+ }
3012
3056
}
3013
3057
3014
3058
Real waterFactor=150 ;
3015
- Real shadeR, shadeG, shadeB;
3016
- shadeR = TheGlobalData->m_terrainAmbient [0 ].red ;
3017
- shadeG = TheGlobalData->m_terrainAmbient [0 ].green ;
3018
- shadeB = TheGlobalData->m_terrainAmbient [0 ].blue ;
3059
+ Real shadeR=TheWaterTransparency->m_standingWaterColor .red ;
3060
+ Real shadeG=TheWaterTransparency->m_standingWaterColor .green ;
3061
+ Real shadeB=TheWaterTransparency->m_standingWaterColor .blue ;
3019
3062
3020
- // Add in diffuse lighting from each terrain light
3021
- for (Int lightIndex= 0 ; lightIndex < TheGlobalData-> m_numGlobalLights ; lightIndex++ )
3063
+ // If the water color is not overridden, use legacy lighting code.
3064
+ if ( shadeR== 1 . 0f && shadeG== 1 . 0f && shadeB== 1 . 0f )
3022
3065
{
3023
- if (-TheGlobalData->m_terrainLightPos [lightIndex].z > 0 )
3024
- { shadeR += -TheGlobalData->m_terrainLightPos [lightIndex].z * TheGlobalData->m_terrainDiffuse [lightIndex].red ;
3025
- shadeG += -TheGlobalData->m_terrainLightPos [lightIndex].z * TheGlobalData->m_terrainDiffuse [lightIndex].green ;
3026
- shadeB += -TheGlobalData->m_terrainLightPos [lightIndex].z * TheGlobalData->m_terrainDiffuse [lightIndex].blue ;
3066
+ shadeR = TheGlobalData->m_terrainAmbient [0 ].red ;
3067
+ shadeG = TheGlobalData->m_terrainAmbient [0 ].green ;
3068
+ shadeB = TheGlobalData->m_terrainAmbient [0 ].blue ;
3069
+
3070
+ // Add in diffuse lighting from each terrain light
3071
+ for (Int lightIndex=0 ; lightIndex < TheGlobalData->m_numGlobalLights ; lightIndex++)
3072
+ {
3073
+ if (-TheGlobalData->m_terrainLightPos [lightIndex].z > 0 )
3074
+ { shadeR += -TheGlobalData->m_terrainLightPos [lightIndex].z * TheGlobalData->m_terrainDiffuse [lightIndex].red ;
3075
+ shadeG += -TheGlobalData->m_terrainLightPos [lightIndex].z * TheGlobalData->m_terrainDiffuse [lightIndex].green ;
3076
+ shadeB += -TheGlobalData->m_terrainLightPos [lightIndex].z * TheGlobalData->m_terrainDiffuse [lightIndex].blue ;
3077
+ }
3027
3078
}
3028
- }
3029
3079
3030
- // Get water material colors
3031
- Real waterShadeR = (m_settings[m_tod].waterDiffuse & 0xff ) / 255 .0f ;
3032
- Real waterShadeG = ((m_settings[m_tod].waterDiffuse >> 8 ) & 0xff ) / 255 .0f ;
3033
- Real waterShadeB = ((m_settings[m_tod].waterDiffuse >> 16 ) & 0xff ) / 255 .0f ;
3080
+ // Get water material colors
3081
+ Real waterShadeR = (m_settings[m_tod].waterDiffuse & 0xff ) / 255 .0f ;
3082
+ Real waterShadeG = ((m_settings[m_tod].waterDiffuse >> 8 ) & 0xff ) / 255 .0f ;
3083
+ Real waterShadeB = ((m_settings[m_tod].waterDiffuse >> 16 ) & 0xff ) / 255 .0f ;
3034
3084
3035
- shadeR=shadeR*waterShadeR*255 .0f ;
3036
- shadeG=shadeG*waterShadeG*255 .0f ;
3037
- shadeB=shadeB*waterShadeB*255 .0f ;
3085
+ shadeR=shadeR*waterShadeR*255 .0f ;
3086
+ shadeG=shadeG*waterShadeG*255 .0f ;
3087
+ shadeB=shadeB*waterShadeB*255 .0f ;
3088
+ }
3089
+ else
3090
+ {
3091
+ shadeR=shadeR*255 .0f ;
3092
+ shadeG=shadeG*255 .0f ;
3093
+ shadeB=shadeB*255 .0f ;
3094
+
3095
+ if (shadeR == 0 && shadeG == 0 && shadeB == 0 )
3096
+ { // special case where we disable lighting
3097
+ shadeR=255 ;
3098
+ shadeG=255 ;
3099
+ shadeB=255 ;
3100
+ }
3101
+ }
3038
3102
3039
3103
Int diffuse=REAL_TO_INT (shadeB) | (REAL_TO_INT (shadeG) << 8 ) | (REAL_TO_INT (shadeR) << 16 );
3040
3104
@@ -3173,7 +3237,8 @@ void WaterRenderObjClass::drawTrapezoidWater(Vector3 points[4])
3173
3237
// If video card supports it and it's enabled, feather the water edge using destination alpha
3174
3238
if (DX8Wrapper::getBackBufferFormat () == WW3D_FORMAT_A8R8G8B8 && TheGlobalData->m_showSoftWaterEdge && TheWaterTransparency->m_transparentWaterDepth !=0 )
3175
3239
{ DX8Wrapper::Set_DX8_Render_State (D3DRS_SRCBLEND, D3DBLEND_DESTALPHA );
3176
- DX8Wrapper::Set_DX8_Render_State (D3DRS_DESTBLEND, D3DBLEND_INVDESTALPHA );
3240
+ if (!TheWaterTransparency->m_additiveBlend )
3241
+ DX8Wrapper::Set_DX8_Render_State (D3DRS_DESTBLEND, D3DBLEND_INVDESTALPHA );
3177
3242
}
3178
3243
3179
3244
@@ -3217,8 +3282,15 @@ void WaterRenderObjClass::drawTrapezoidWater(Vector3 points[4])
3217
3282
3218
3283
if (m_riverWaterPixelShader) DX8Wrapper::_Get_D3D_Device8 ()->SetPixelShader (NULL );
3219
3284
// Restore alpha blend to default values since we may have changed them to feather edges.
3220
- DX8Wrapper::Set_DX8_Render_State (D3DRS_SRCBLEND, D3DBLEND_SRCALPHA );
3221
- DX8Wrapper::Set_DX8_Render_State (D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA );
3285
+ if (!TheWaterTransparency->m_additiveBlend )
3286
+ { DX8Wrapper::Set_DX8_Render_State (D3DRS_SRCBLEND, D3DBLEND_SRCALPHA );
3287
+ DX8Wrapper::Set_DX8_Render_State (D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA );
3288
+ }
3289
+ else
3290
+ {
3291
+ DX8Wrapper::Set_DX8_Render_State (D3DRS_SRCBLEND, D3DBLEND_ONE );
3292
+ DX8Wrapper::Set_DX8_Render_State (D3DRS_DESTBLEND, D3DBLEND_ONE );
3293
+ }
3222
3294
3223
3295
if (TheTerrainRenderObject->getShroud ())
3224
3296
{
0 commit comments