@@ -33,13 +33,15 @@ static DWORD* g_vsHandles = nullptr;
3333#define WATER_TEXTURE_SLOT_DUDV 2
3434#define WATER_TEXTURE_SLOT_CAUSTICS 3
3535
36- #define WATER_DUDV_SCALE_PS_CB_SLOT 5
37- #define WATER_DUDV_SPEC_SCALE_PS_CB_SLOT 6
38- #define WATER_SPEC_MULT_PS_CB_SLOT 7
36+ #define WATER_DUDV_SCALE_PS_CB_SLOT 4
37+ #define WATER_DUDV_SPEC_SCALE_PS_CB_SLOT 5
38+ #define WATER_SPEC_MULT_PS_CB_SLOT 6
39+ #define WATER_FOG_COLOUR_PS_CB_SLOT 7
3940
4041#define WATER_UVADD_VS_CB_SLOT 90
4142#define WATER_UVMUL_VS_CB_SLOT 91
4243#define WATER_WORLD_VS_CB_SLOT 92
44+ #define WATER_COLOUR_VS_CB_SLOT 93
4345
4446/*
4547vs.1.1
@@ -84,8 +86,9 @@ add oT1, r1, c90
8486mov oT2, r0
8587// scale caustics UVs
8688mul oT3, r1, c91
87- // pass-through vertex colour
89+ // pass-through vertex colour (contains fog)
8890mov oD0, v5
91+
8992*/
9093DWORD g_WaterPondVSBytecode[] = {
9194 0xfffe0101 , 0x0009fffe , 0x58443344 , 0x68532038 ,
@@ -113,7 +116,7 @@ texcrd r4.xyz, t0
113116texcrd r5.xyz, t3
114117// sample dudv map, restore and rescale
115118texld r2, t1
116- mul r1, c5 , r2_bx2
119+ mul r1, c4 , r2_bx2
117120// fill the void
118121mov r3.zw, c0
119122mov r4.zw, c0
@@ -123,7 +126,7 @@ mad r3, r3, c1, c0
123126// disturb projected uv
124127add r3, r3, r1
125128// disturb caustics uv
126- mad r5, r2_bx2, c6 , r5
129+ mad r5, r2_bx2, c5 , r5
127130// pass along the disturbed base texture coords
128131add r2, r4, r1
129132
@@ -140,7 +143,7 @@ mul r0, r0, v0
140143// blend them
141144lrp_sat r0, r0.w, r0, r1
142145// add modulated caustics
143- mad_sat r0, r3, c7 , r0
146+ mad_sat r0, r3, c6 , r0
144147// fill alpha
145148mov r0.w, c0
146149*/
@@ -154,26 +157,95 @@ DWORD g_WaterPSBytecode[] = {
154157 0x80030003 , 0xbaf40002 , 0x00000040 , 0x80070004 ,
155158 0xb0e40000 , 0x00000040 , 0x80070005 , 0xb0e40003 ,
156159 0x00000042 , 0x800f0002 , 0xb0e40001 , 0x00000005 ,
157- 0x800f0001 , 0xa0e40005 , 0x84e40002 , 0x00000001 ,
160+ 0x800f0001 , 0xa0e40004 , 0x84e40002 , 0x00000001 ,
158161 0x800c0003 , 0xa0e40000 , 0x00000001 , 0x800c0004 ,
159162 0xa0e40000 , 0x00000001 , 0x800c0005 , 0xa0e40000 ,
160163 0x00000004 , 0x800f0003 , 0x80e40003 , 0xa0e40001 ,
161164 0xa0e40000 , 0x00000002 , 0x800f0003 , 0x80e40003 ,
162165 0x80e40001 , 0x00000004 , 0x800f0005 , 0x84e40002 ,
163- 0xa0e40006 , 0x80e40005 , 0x00000002 , 0x800f0002 ,
166+ 0xa0e40005 , 0x80e40005 , 0x00000002 , 0x800f0002 ,
164167 0x80e40004 , 0x80e40001 , 0x0000fffd , 0x00000042 ,
165168 0x800f0000 , 0x80e40002 , 0x00000042 , 0x800f0001 ,
166169 0x80e40003 , 0x00000042 , 0x800f0003 , 0x80e40005 ,
167170 0x00000005 , 0x800f0000 , 0x80e40000 , 0x90e40000 ,
168171 0x00000012 , 0x801f0000 , 0x80ff0000 , 0x80e40000 ,
169172 0x80e40001 , 0x00000004 , 0x801f0000 , 0x80e40003 ,
170- 0xa0e40007 , 0x80e40000 , 0x00000001 , 0x80080000 ,
173+ 0xa0e40006 , 0x80e40000 , 0x00000001 , 0x80080000 ,
174+ 0xa0e40000 , 0x0000ffff
175+ };
176+
177+ /*
178+ ps.1.4
179+ def c0, 0.5, 0.5, 1, 1
180+ def c1, 0.5, -0.5, 1, 1
181+
182+ // calc projected uv
183+ texcrd r3.xy, t2_dw.xyw
184+ // save aside base texture coords
185+ texcrd r4.xyz, t0
186+ // save aside caustics texture coords
187+ texcrd r5.xyz, t3
188+ // sample dudv map, restore and rescale
189+ texld r2, t1
190+ mul r1, c4, r2_bx2
191+ // fill the void
192+ mov r3.zw, c0
193+ mov r4.zw, c0
194+ mov r5.zw, c0
195+ // [-1;1] -> [0;1]
196+ mad r3, r3, c1, c0
197+ // disturb projected uv
198+ add r3, r3, r1
199+ // disturb caustics uv
200+ mad r5, r2_bx2, c5, r5
201+ // pass along the disturbed base texture coords
202+ add r2, r4, r1
203+
204+ phase
205+
206+ // sample water texture
207+ texld r0, r2
208+ // sample refraction texture
209+ texld r1, r3
210+ // sample caustics texture
211+ texld r3, r5
212+ // blend water colour and refraction
213+ lrp r0, v0.w, v0, r1
214+ // add modulated caustics
215+ mad_sat r0.xyz, r3, c6, r0
216+ // fill alpha
217+ + mov r0.w, c0
218+ */
219+ DWORD g_WaterPondPSBytecode[] = {
220+ 0xffff0104 , 0x0009fffe , 0x58443344 , 0x68532038 ,
221+ 0x72656461 , 0x73734120 , 0x6c626d65 , 0x56207265 ,
222+ 0x69737265 , 0x30206e6f , 0x0031392e , 0x00000051 ,
223+ 0xa00f0000 , 0x3f000000 , 0x3f000000 , 0x3f800000 ,
224+ 0x3f800000 , 0x00000051 , 0xa00f0001 , 0x3f000000 ,
225+ 0xbf000000 , 0x3f800000 , 0x3f800000 , 0x00000040 ,
226+ 0x80030003 , 0xbaf40002 , 0x00000040 , 0x80070004 ,
227+ 0xb0e40000 , 0x00000040 , 0x80070005 , 0xb0e40003 ,
228+ 0x00000042 , 0x800f0002 , 0xb0e40001 , 0x00000005 ,
229+ 0x800f0001 , 0xa0e40004 , 0x84e40002 , 0x00000001 ,
230+ 0x800c0003 , 0xa0e40000 , 0x00000001 , 0x800c0004 ,
231+ 0xa0e40000 , 0x00000001 , 0x800c0005 , 0xa0e40000 ,
232+ 0x00000004 , 0x800f0003 , 0x80e40003 , 0xa0e40001 ,
233+ 0xa0e40000 , 0x00000002 , 0x800f0003 , 0x80e40003 ,
234+ 0x80e40001 , 0x00000004 , 0x800f0005 , 0x84e40002 ,
235+ 0xa0e40005 , 0x80e40005 , 0x00000002 , 0x800f0002 ,
236+ 0x80e40004 , 0x80e40001 , 0x0000fffd , 0x00000042 ,
237+ 0x800f0000 , 0x80e40002 , 0x00000042 , 0x800f0001 ,
238+ 0x80e40003 , 0x00000042 , 0x800f0003 , 0x80e40005 ,
239+ 0x00000012 , 0x800f0000 , 0x90ff0000 , 0x90e40000 ,
240+ 0x80e40001 , 0x00000004 , 0x80170000 , 0x80e40003 ,
241+ 0xa0e40006 , 0x80e40000 , 0x40000001 , 0x80080000 ,
171242 0xa0e40000 , 0x0000ffff
172243};
173244
174245DWORD g_WaterVSHandle = 0 ;
175246DWORD g_WaterPondVSHandle = 0 ;
176247DWORD g_WaterPSHandle = 0 ;
248+ DWORD g_WaterPondPSHandle = 0 ;
177249
178250IDirect3DTexture8* g_ScreenCopyTexture = nullptr ;
179251IDirect3DSurface8* g_ScreenCopySurface = nullptr ;
@@ -336,6 +408,8 @@ static void GetWaterConstantsByRoom(D3DXVECTOR4& specMult, D3DXVECTOR4& specUvMu
336408 // Pond
337409 case R_FOREST_CEMETERY:
338410 dudvScale = { 0 .005f , 0 .005f , 0 .005f , 0 .005f };
411+ specMult = { water_spec_mult_cemetery, water_spec_mult_cemetery, water_spec_mult_cemetery, 0 .0f };
412+ specUvMult = { water_spec_uv_mult_cemetery, water_spec_uv_mult_cemetery, water_spec_uv_mult_cemetery, water_spec_uv_mult_cemetery };
339413 break ;
340414 // Pyramidhead submerge
341415 case R_APT_W_STAIRCASE_N:
@@ -411,7 +485,7 @@ HRESULT DrawWaterEnhanced(bool needToGrabScreenForWater, LPDIRECT3DDEVICE8 Devic
411485 Device->GetTexture (WATER_TEXTURE_SLOT_CAUSTICS, &tex2);
412486
413487 Device->SetVertexShader ((roomID == R_FOREST_CEMETERY) ? g_WaterPondVSHandle : g_WaterVSHandle);
414- Device->SetPixelShader (g_WaterPSHandle);
488+ Device->SetPixelShader ((roomID == R_FOREST_CEMETERY) ? g_WaterPondPSHandle : g_WaterPSHandle);
415489
416490 Device->SetTexture (WATER_TEXTURE_SLOT_REFRACTION, g_ScreenCopyTexture);
417491 Device->SetTexture (WATER_TEXTURE_SLOT_DUDV, g_DuDvTexture);
@@ -454,6 +528,14 @@ HRESULT DrawWaterEnhanced(bool needToGrabScreenForWater, LPDIRECT3DDEVICE8 Devic
454528 const float worldScale = 1 .0f / 3000 .0f ;
455529 D3DXVECTOR4 worldDiv = { worldScale, worldScale, worldScale, worldScale };
456530 Device->SetVertexShaderConstant (WATER_WORLD_VS_CB_SLOT, &worldDiv, 1 );
531+
532+ D3DXVECTOR4 waterColour = { 0 .32f , 0 .32f , 0 .32f , 0 .35f };
533+ Device->SetVertexShaderConstant (WATER_COLOUR_VS_CB_SLOT, &waterColour, 1 );
534+
535+ DWORD dwFogColour = 0u ;
536+ Device->GetRenderState (D3DRS_FOGCOLOR, &dwFogColour);
537+ D3DXVECTOR4 fogColour (float ((dwFogColour >> 16 ) & 0xFF ) / 255 .0f , float ((dwFogColour >> 8 ) & 0xFF ) / 255 .0f , float (dwFogColour & 0xFF ) / 255 .0f , 1 .0f );
538+ Device->SetPixelShaderConstant (WATER_FOG_COLOUR_PS_CB_SLOT, &fogColour, 1u );
457539 }
458540
459541 Device->SetPixelShaderConstant (WATER_DUDV_SCALE_PS_CB_SLOT, &dudvScale, 1u );
0 commit comments