-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathmilkdropfs.cpp
4713 lines (4112 loc) · 178 KB
/
milkdropfs.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
LICENSE
-------
Copyright 2005-2013 Nullsoft, Inc.
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* Neither the name of Nullsoft nor the names of its contributors may be used to
endorse or promote products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "plugin.h"
#include "resource.h"
#include "support.h"
//#include "evallib\eval.h" // for math. expr. eval - thanks Francis! (in SourceOffSite, it's the 'vis_avs\evallib' project.)
//#include "evallib\compiler.h"
#include "../ns-eel2/ns-eel.h"
#include "utility.h"
#include <assert.h>
#include <math.h>
#define D3DCOLOR_RGBA_01(r,g,b,a) D3DCOLOR_RGBA(((int)(r*255)),((int)(g*255)),((int)(b*255)),((int)(a*255)))
#define FRAND ((rand() % 7381)/7380.0f)
#define VERT_CLIP 0.75f // warning: top/bottom can get clipped if you go < 0.65!
int g_title_font_sizes[] =
{
// NOTE: DO NOT EXCEED 64 FONTS HERE.
6, 8, 10, 12, 14, 16,
20, 26, 32, 38, 44, 50, 56,
64, 72, 80, 88, 96, 104, 112, 120, 128, 136, 144,
160, 192, 224, 256, 288, 320, 352, 384, 416, 448,
480, 512 /**/
};
//#define COMPILE_MULTIMON_STUBS 1
//#include <multimon.h>
// This function evaluates whether the floating-point
// control Word is set to single precision/round to nearest/
// exceptions disabled. If not, the
// function changes the control Word to set them and returns
// TRUE, putting the old control Word value in the passback
// location pointed to by pwOldCW.
static void MungeFPCW( WORD *pwOldCW )
{
#if 0
BOOL ret = FALSE;
WORD wTemp, wSave;
__asm fstcw wSave
if (wSave & 0x300 || // Not single mode
0x3f != (wSave & 0x3f) || // Exceptions enabled
wSave & 0xC00) // Not round to nearest mode
{
__asm
{
mov ax, wSave
and ax, not 300h ;; single mode
or ax, 3fh ;; disable all exceptions
and ax, not 0xC00 ;; round to nearest mode
mov wTemp, ax
fldcw wTemp
}
ret = TRUE;
}
if (pwOldCW) *pwOldCW = wSave;
// return ret;
#else
_controlfp(_PC_24, _MCW_PC); // single precision
_controlfp(_RC_NEAR, _MCW_RC); // round to nearest mode
_controlfp(_EM_ZERODIVIDE, _EM_ZERODIVIDE); // disable divide-by-zero
#endif
}
void RestoreFPCW(WORD wSave)
{
__asm fldcw wSave
}
int GetNumToSpawn(float fTime, float fDeltaT, float fRate, float fRegularity, int iNumSpawnedSoFar)
{
// PARAMETERS
// ------------
// fTime: sum of all fDeltaT's so far (excluding this one)
// fDeltaT: time window for this frame
// fRate: avg. rate (spawns per second) of generation
// fRegularity: regularity of generation
// 0.0: totally chaotic
// 0.2: getting chaotic / very jittered
// 0.4: nicely jittered
// 0.6: slightly jittered
// 0.8: almost perfectly regular
// 1.0: perfectly regular
// iNumSpawnedSoFar: the total number of spawnings so far
//
// RETURN VALUE
// ------------
// The number to spawn for this frame (add this to your net count!).
//
// COMMENTS
// ------------
// The spawn values returned will, over time, match
// (within 1%) the theoretical totals expected based on the
// amount of time passed and the average generation rate.
//
// UNRESOLVED ISSUES
// -----------------
// actual results of mixed gen. (0 < reg < 1) are about 1% too low
// in the long run (vs. analytical expectations). Decided not
// to bother fixing it since it's only 1% (and VERY consistent).
float fNumToSpawnReg;
float fNumToSpawnIrreg;
float fNumToSpawn;
// compute # spawned based on regular generation
fNumToSpawnReg = ((fTime + fDeltaT) * fRate) - iNumSpawnedSoFar;
// compute # spawned based on irregular (random) generation
if (fDeltaT <= 1.0f / fRate)
{
// case 1: avg. less than 1 spawn per frame
if ((rand() % 16384)/16384.0f < fDeltaT * fRate)
fNumToSpawnIrreg = 1.0f;
else
fNumToSpawnIrreg = 0.0f;
}
else
{
// case 2: avg. more than 1 spawn per frame
fNumToSpawnIrreg = fDeltaT * fRate;
fNumToSpawnIrreg *= 2.0f*(rand() % 16384)/16384.0f;
}
// get linear combo. of regular & irregular
fNumToSpawn = fNumToSpawnReg*fRegularity + fNumToSpawnIrreg*(1.0f - fRegularity);
// round to nearest integer for result
return (int)(fNumToSpawn + 0.49f);
}
bool CPlugin::OnResizeTextWindow()
{
/*
if (!m_hTextWnd)
return false;
RECT rect;
GetClientRect(m_hTextWnd, &rect);
if (rect.right - rect.left != m_nTextWndWidth ||
rect.bottom - rect.top != m_nTextWndHeight)
{
m_nTextWndWidth = rect.right - rect.left;
m_nTextWndHeight = rect.bottom - rect.top;
// first, resize fonts if necessary
//if (!InitFont())
//return false;
// then resize the memory bitmap used for double buffering
if (m_memDC)
{
SelectObject(m_memDC, m_oldBM); // delete our doublebuffer
DeleteObject(m_memDC);
DeleteObject(m_memBM);
m_memDC = NULL;
m_memBM = NULL;
m_oldBM = NULL;
}
HDC hdc = GetDC(m_hTextWnd);
if (!hdc) return false;
m_memDC = CreateCompatibleDC(hdc);
m_memBM = CreateCompatibleBitmap(hdc, rect.right - rect.left, rect.bottom - rect.top);
m_oldBM = (HBITMAP)SelectObject(m_memDC,m_memBM);
ReleaseDC(m_hTextWnd, hdc);
// save new window pos
WriteRealtimeConfig();
}*/
return true;
}
void CPlugin::ClearGraphicsWindow()
{
// clear the window contents, to avoid a 1-pixel-thick border of noise that sometimes sticks around
/*
RECT rect;
GetClientRect(GetPluginWindow(), &rect);
HDC hdc = GetDC(GetPluginWindow());
FillRect(hdc, &rect, m_hBlackBrush);
ReleaseDC(GetPluginWindow(), hdc);
*/
}
/*
bool CPlugin::OnResizeGraphicsWindow()
{
// NO LONGER NEEDED, SINCE PLUGIN SHELL CREATES A NEW DIRECTX
// OBJECT WHENEVER WINDOW IS RESIZED.
}
*/
bool CPlugin::RenderStringToTitleTexture() // m_szSongMessage
{
if (!m_lpDDSTitle) // this *can* be NULL, if not much video mem!
return false;
if (m_supertext.szTextW[0]==0)
return false;
LPDIRECT3DDEVICE9 lpDevice = GetDevice();
if (!lpDevice)
return false;
wchar_t szTextToDraw[512];
swprintf(szTextToDraw, L" %s ", m_supertext.szTextW); //add a space @ end for italicized fonts; and at start, too, because it's centered!
// Remember the original backbuffer and zbuffer
LPDIRECT3DSURFACE9 pBackBuffer=NULL;//, pZBuffer=NULL;
lpDevice->GetRenderTarget( 0, &pBackBuffer );
//lpDevice->GetDepthStencilSurface( &pZBuffer );
// set render target to m_lpDDSTitle
{
lpDevice->SetTexture(0, NULL);
IDirect3DSurface9* pNewTarget = NULL;
if (m_lpDDSTitle->GetSurfaceLevel(0, &pNewTarget) != D3D_OK)
{
SafeRelease(pBackBuffer);
//SafeRelease(pZBuffer);
return false;
}
lpDevice->SetRenderTarget(0, pNewTarget);
//lpDevice->SetDepthStencilSurface( NULL );
pNewTarget->Release();
lpDevice->SetTexture(0, NULL);
}
// clear the texture to black
{
lpDevice->SetVertexShader( NULL );
lpDevice->SetFVF( WFVERTEX_FORMAT );
lpDevice->SetTexture(0, NULL);
lpDevice->SetRenderState( D3DRS_ALPHABLENDENABLE, FALSE );
// set up a quad
WFVERTEX verts[4];
for (int i=0; i<4; i++)
{
verts[i].x = (i%2==0) ? -1.f : 1.f;
verts[i].y = (i/2==0) ? -1.f : 1.f;
verts[i].z = 0;
verts[i].Diffuse = 0xFF000000;
}
lpDevice->DrawPrimitiveUP(D3DPT_TRIANGLESTRIP, 2, verts, sizeof(WFVERTEX));
}
/*// 1. clip title if too many chars
if (m_supertext.bIsSongTitle)
{
// truncate song title if too long; don't clip custom messages, though!
int clip_chars = 32;
int user_title_size = GetFontHeight(SONGTITLE_FONT);
#define MIN_CHARS 8 // max clip_chars *for BIG FONTS*
#define MAX_CHARS 64 // max clip chars *for tiny fonts*
float t = (user_title_size-10)/(float)(128-10);
t = min(1,max(0,t));
clip_chars = (int)(MAX_CHARS - (MAX_CHARS-MIN_CHARS)*t);
if ((int)strlen(szTextToDraw) > clip_chars+3)
lstrcpy(&szTextToDraw[clip_chars], "...");
}*/
bool ret = true;
// use 2 lines; must leave room for bottom of 'g' characters and such!
RECT rect;
rect.left = 0;
rect.right = m_nTitleTexSizeX;
rect.top = m_nTitleTexSizeY* 1/21; // otherwise, top of '%' could be cut off (1/21 seems safe)
rect.bottom = m_nTitleTexSizeY*17/21; // otherwise, bottom of 'g' could be cut off (18/21 seems safe, but we want some leeway)
if (!m_supertext.bIsSongTitle)
{
// custom msg -> pick font to use that will best fill the texture
HFONT gdi_font = NULL;
LPD3DXFONT d3dx_font = NULL;
int lo = 0;
int hi = sizeof(g_title_font_sizes)/sizeof(int) - 1;
// limit the size of the font used:
//int user_title_size = GetFontHeight(SONGTITLE_FONT);
//while (g_title_font_sizes[hi] > user_title_size*2 && hi>4)
// hi--;
RECT temp;
while (1)//(lo < hi-1)
{
int mid = (lo+hi)/2;
// create new gdi font at 'mid' size:
gdi_font = CreateFontW( g_title_font_sizes[mid], 0, 0, 0, m_supertext.bBold ? 900 : 400, m_supertext.bItal, FALSE, FALSE, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS,
m_fontinfo[SONGTITLE_FONT].bAntiAliased ? ANTIALIASED_QUALITY : DEFAULT_QUALITY,
DEFAULT_PITCH, m_supertext.nFontFace );
if (gdi_font)
{
// create new d3dx font at 'mid' size:
if (D3DXCreateFontW(
lpDevice,
g_title_font_sizes[mid],
0,
m_supertext.bBold ? 900 : 400,
1,
m_supertext.bItal,
DEFAULT_CHARSET,
OUT_DEFAULT_PRECIS,
ANTIALIASED_QUALITY,//m_fontinfo[SONGTITLE_FONT].bAntiAliased ? ANTIALIASED_QUALITY : DEFAULT_QUALITY,
DEFAULT_PITCH,
m_supertext.nFontFace,
&d3dx_font
) == D3D_OK)
{
if (lo == hi-1)
break; // DONE; but the 'lo'-size font is ready for use!
// compute size of text if drawn w/font of THIS size:
temp = rect;
int h = d3dx_font->DrawTextW(NULL, szTextToDraw, -1, &temp, DT_SINGLELINE | DT_CALCRECT /*| DT_NOPREFIX*/, 0xFFFFFFFF);
// adjust & prepare to reiterate:
if (temp.right >= rect.right || h > rect.bottom-rect.top)
hi = mid;
else
lo = mid;
SafeRelease(d3dx_font);
}
DeleteObject(gdi_font); gdi_font=NULL;
}
}
if (gdi_font && d3dx_font)
{
// do actual drawing + set m_supertext.nFontSizeUsed; use 'lo' size
int h = d3dx_font->DrawTextW(NULL, szTextToDraw, -1, &temp, DT_SINGLELINE | DT_CALCRECT /*| DT_NOPREFIX*/ | DT_CENTER, 0xFFFFFFFF);
temp.left = 0;
temp.right = m_nTitleTexSizeX; // now allow text to go all the way over, since we're actually drawing!
temp.top = m_nTitleTexSizeY/2 - h/2;
temp.bottom = m_nTitleTexSizeY/2 + h/2;
m_supertext.nFontSizeUsed = d3dx_font->DrawTextW(NULL, szTextToDraw, -1, &temp, DT_SINGLELINE /*| DT_NOPREFIX*/ | DT_CENTER, 0xFFFFFFFF);
ret = true;
}
else
{
ret = false;
}
// clean up font:
SafeRelease(d3dx_font);
if (gdi_font) DeleteObject(gdi_font); gdi_font=NULL;
}
else // song title
{
wchar_t* str = m_supertext.szTextW;
// clip the text manually...
// NOTE: DT_END_ELLIPSIS CAUSES NOTHING TO DRAW, IF YOU USE W/D3DX9!
int h;
int max_its = 6;
int it = 0;
while (it < max_its)
{
it++;
if (!str[0])
break;
RECT temp = rect;
h = m_d3dx_title_font_doublesize->DrawTextW(NULL, str, -1, &temp, DT_SINGLELINE | DT_CALCRECT /*| DT_NOPREFIX | DT_END_ELLIPSIS*/, 0xFFFFFFFF);
if (temp.right-temp.left <= m_nTitleTexSizeX)
break;
// 11/01/2009 DO - disabled as it was causing to users 'random' titles against
// what is expected so we now just work on the ellipse at the end approach which
// manually clip the text... chop segments off the front
/*wchar_t* p = wcsstr(str, L" - ");
if (p)
{
str = p+3;
continue;
}*/
// no more stuff to chop off the front; chop off the end w/ ...
int len = wcslen(str);
float fPercentToKeep = 0.91f * m_nTitleTexSizeX / (float)(temp.right-temp.left);
if (len > 8)
lstrcpyW( &str[ (int)(len*fPercentToKeep) ], L"...");
break;
}
// now actually draw it
RECT temp;
temp.left = 0;
temp.right = m_nTitleTexSizeX; // now allow text to go all the way over, since we're actually drawing!
temp.top = m_nTitleTexSizeY/2 - h/2;
temp.bottom = m_nTitleTexSizeY/2 + h/2;
// NOTE: DT_END_ELLIPSIS CAUSES NOTHING TO DRAW, IF YOU USE W/D3DX9!
m_supertext.nFontSizeUsed = m_d3dx_title_font_doublesize->DrawTextW(NULL, str, -1, &temp, DT_SINGLELINE /*| DT_NOPREFIX | DT_END_ELLIPSIS*/ | DT_CENTER , 0xFFFFFFFF);
}
// Change the rendertarget back to the original setup
lpDevice->SetTexture(0, NULL);
lpDevice->SetRenderTarget( 0, pBackBuffer );
//lpDevice->SetDepthStencilSurface( pZBuffer );
SafeRelease(pBackBuffer);
//SafeRelease(pZBuffer);
return ret;
}
void CPlugin::LoadPerFrameEvallibVars(CState* pState)
{
// load the 'var_pf_*' variables in this CState object with the correct values.
// for vars that affect pixel motion, that means evaluating them at time==-1,
// (i.e. no blending w/blendto value); the blending of the file dx/dy
// will be done *after* execution of the per-vertex code.
// for vars that do NOT affect pixel motion, evaluate them at the current time,
// so that if they're blending, both states see the blended value.
// 1. vars that affect pixel motion: (eval at time==-1)
*pState->var_pf_zoom = (double)pState->m_fZoom.eval(-1);//GetTime());
*pState->var_pf_zoomexp = (double)pState->m_fZoomExponent.eval(-1);//GetTime());
*pState->var_pf_rot = (double)pState->m_fRot.eval(-1);//GetTime());
*pState->var_pf_warp = (double)pState->m_fWarpAmount.eval(-1);//GetTime());
*pState->var_pf_cx = (double)pState->m_fRotCX.eval(-1);//GetTime());
*pState->var_pf_cy = (double)pState->m_fRotCY.eval(-1);//GetTime());
*pState->var_pf_dx = (double)pState->m_fXPush.eval(-1);//GetTime());
*pState->var_pf_dy = (double)pState->m_fYPush.eval(-1);//GetTime());
*pState->var_pf_sx = (double)pState->m_fStretchX.eval(-1);//GetTime());
*pState->var_pf_sy = (double)pState->m_fStretchY.eval(-1);//GetTime());
// read-only:
*pState->var_pf_time = (double)(GetTime() - m_fStartTime);
*pState->var_pf_fps = (double)GetFps();
*pState->var_pf_bass = (double)mysound.imm_rel[0];
*pState->var_pf_mid = (double)mysound.imm_rel[1];
*pState->var_pf_treb = (double)mysound.imm_rel[2];
*pState->var_pf_bass_att = (double)mysound.avg_rel[0];
*pState->var_pf_mid_att = (double)mysound.avg_rel[1];
*pState->var_pf_treb_att = (double)mysound.avg_rel[2];
*pState->var_pf_frame = (double)GetFrame();
//*pState->var_pf_monitor = 0; -leave this as it was set in the per-frame INIT code!
for (int vi=0; vi<NUM_Q_VAR; vi++)
*pState->var_pf_q[vi] = pState->q_values_after_init_code[vi];//0.0f;
*pState->var_pf_monitor = pState->monitor_after_init_code;
*pState->var_pf_progress = (GetTime() - m_fPresetStartTime) / (m_fNextPresetTime - m_fPresetStartTime);
// 2. vars that do NOT affect pixel motion: (eval at time==now)
*pState->var_pf_decay = (double)pState->m_fDecay.eval(GetTime());
*pState->var_pf_wave_a = (double)pState->m_fWaveAlpha.eval(GetTime());
*pState->var_pf_wave_r = (double)pState->m_fWaveR.eval(GetTime());
*pState->var_pf_wave_g = (double)pState->m_fWaveG.eval(GetTime());
*pState->var_pf_wave_b = (double)pState->m_fWaveB.eval(GetTime());
*pState->var_pf_wave_x = (double)pState->m_fWaveX.eval(GetTime());
*pState->var_pf_wave_y = (double)pState->m_fWaveY.eval(GetTime());
*pState->var_pf_wave_mystery= (double)pState->m_fWaveParam.eval(GetTime());
*pState->var_pf_wave_mode = (double)pState->m_nWaveMode; //?!?! -why won't it work if set to pState->m_nWaveMode???
*pState->var_pf_ob_size = (double)pState->m_fOuterBorderSize.eval(GetTime());
*pState->var_pf_ob_r = (double)pState->m_fOuterBorderR.eval(GetTime());
*pState->var_pf_ob_g = (double)pState->m_fOuterBorderG.eval(GetTime());
*pState->var_pf_ob_b = (double)pState->m_fOuterBorderB.eval(GetTime());
*pState->var_pf_ob_a = (double)pState->m_fOuterBorderA.eval(GetTime());
*pState->var_pf_ib_size = (double)pState->m_fInnerBorderSize.eval(GetTime());
*pState->var_pf_ib_r = (double)pState->m_fInnerBorderR.eval(GetTime());
*pState->var_pf_ib_g = (double)pState->m_fInnerBorderG.eval(GetTime());
*pState->var_pf_ib_b = (double)pState->m_fInnerBorderB.eval(GetTime());
*pState->var_pf_ib_a = (double)pState->m_fInnerBorderA.eval(GetTime());
*pState->var_pf_mv_x = (double)pState->m_fMvX.eval(GetTime());
*pState->var_pf_mv_y = (double)pState->m_fMvY.eval(GetTime());
*pState->var_pf_mv_dx = (double)pState->m_fMvDX.eval(GetTime());
*pState->var_pf_mv_dy = (double)pState->m_fMvDY.eval(GetTime());
*pState->var_pf_mv_l = (double)pState->m_fMvL.eval(GetTime());
*pState->var_pf_mv_r = (double)pState->m_fMvR.eval(GetTime());
*pState->var_pf_mv_g = (double)pState->m_fMvG.eval(GetTime());
*pState->var_pf_mv_b = (double)pState->m_fMvB.eval(GetTime());
*pState->var_pf_mv_a = (double)pState->m_fMvA.eval(GetTime());
*pState->var_pf_echo_zoom = (double)pState->m_fVideoEchoZoom.eval(GetTime());
*pState->var_pf_echo_alpha = (double)pState->m_fVideoEchoAlpha.eval(GetTime());
*pState->var_pf_echo_orient = (double)pState->m_nVideoEchoOrientation;
// new in v1.04:
*pState->var_pf_wave_usedots = (double)pState->m_bWaveDots;
*pState->var_pf_wave_thick = (double)pState->m_bWaveThick;
*pState->var_pf_wave_additive = (double)pState->m_bAdditiveWaves;
*pState->var_pf_wave_brighten = (double)pState->m_bMaximizeWaveColor;
*pState->var_pf_darken_center = (double)pState->m_bDarkenCenter;
*pState->var_pf_gamma = (double)pState->m_fGammaAdj.eval(GetTime());
*pState->var_pf_wrap = (double)pState->m_bTexWrap;
*pState->var_pf_invert = (double)pState->m_bInvert;
*pState->var_pf_brighten = (double)pState->m_bBrighten;
*pState->var_pf_darken = (double)pState->m_bDarken;
*pState->var_pf_solarize = (double)pState->m_bSolarize;
*pState->var_pf_meshx = (double)m_nGridX;
*pState->var_pf_meshy = (double)m_nGridY;
*pState->var_pf_pixelsx = (double)GetWidth();
*pState->var_pf_pixelsy = (double)GetHeight();
*pState->var_pf_aspectx = (double)m_fInvAspectX;
*pState->var_pf_aspecty = (double)m_fInvAspectY;
// new in v2.0:
*pState->var_pf_blur1min = (double)pState->m_fBlur1Min.eval(GetTime());
*pState->var_pf_blur2min = (double)pState->m_fBlur2Min.eval(GetTime());
*pState->var_pf_blur3min = (double)pState->m_fBlur3Min.eval(GetTime());
*pState->var_pf_blur1max = (double)pState->m_fBlur1Max.eval(GetTime());
*pState->var_pf_blur2max = (double)pState->m_fBlur2Max.eval(GetTime());
*pState->var_pf_blur3max = (double)pState->m_fBlur3Max.eval(GetTime());
*pState->var_pf_blur1_edge_darken = (double)pState->m_fBlur1EdgeDarken.eval(GetTime());
}
void CPlugin::RunPerFrameEquations(int code)
{
// run per-frame calculations
/*
code is only valid when blending.
OLDcomp ~ blend-from preset has a composite shader;
NEWwarp ~ blend-to preset has a warp shader; etc.
code OLDcomp NEWcomp OLDwarp NEWwarp
0
1 1
2 1
3 1 1
4 1
5 1 1
6 1 1
7 1 1 1
8 1
9 1 1
10 1 1
11 1 1 1
12 1 1
13 1 1 1
14 1 1 1
15 1 1 1 1
*/
// when blending booleans (like darken, invert, etc) for pre-shader presets,
// if blending to/from a pixel-shader preset, we can tune the snap point
// (when it changes during the blend) for a less jumpy transition:
m_fSnapPoint = 0.5f;
if (m_pState->m_bBlending)
{
switch(code)
{
case 4:
case 6:
case 12:
case 14:
// old preset (only) had a comp shader
m_fSnapPoint = -0.01f;
break;
case 1:
case 3:
case 9:
case 11:
// new preset (only) has a comp shader
m_fSnapPoint = 1.01f;
break;
case 0:
case 2:
case 8:
case 10:
// neither old or new preset had a comp shader
m_fSnapPoint = 0.5f;
break;
case 5:
case 7:
case 13:
case 15:
// both old and new presets use a comp shader - so it won't matter
m_fSnapPoint = 0.5f;
break;
}
}
int num_reps = (m_pState->m_bBlending) ? 2 : 1;
for (int rep=0; rep<num_reps; rep++)
{
CState *pState;
if (rep==0)
pState = m_pState;
else
pState = m_pOldState;
// values that will affect the pixel motion (and will be automatically blended
// LATER, when the results of 2 sets of these params creates 2 different U/V
// meshes that get blended together.)
LoadPerFrameEvallibVars(pState);
// also do just a once-per-frame init for the *per-**VERTEX*** *READ-ONLY* variables
// (the non-read-only ones will be reset/restored at the start of each vertex)
*pState->var_pv_time = *pState->var_pf_time;
*pState->var_pv_fps = *pState->var_pf_fps;
*pState->var_pv_frame = *pState->var_pf_frame;
*pState->var_pv_progress = *pState->var_pf_progress;
*pState->var_pv_bass = *pState->var_pf_bass;
*pState->var_pv_mid = *pState->var_pf_mid;
*pState->var_pv_treb = *pState->var_pf_treb;
*pState->var_pv_bass_att = *pState->var_pf_bass_att;
*pState->var_pv_mid_att = *pState->var_pf_mid_att;
*pState->var_pv_treb_att = *pState->var_pf_treb_att;
*pState->var_pv_meshx = (double)m_nGridX;
*pState->var_pv_meshy = (double)m_nGridY;
*pState->var_pv_pixelsx = (double)GetWidth();
*pState->var_pv_pixelsy = (double)GetHeight();
*pState->var_pv_aspectx = (double)m_fInvAspectX;
*pState->var_pv_aspecty = (double)m_fInvAspectY;
//*pState->var_pv_monitor = *pState->var_pf_monitor;
// execute once-per-frame expressions:
#ifndef _NO_EXPR_
if (pState->m_pf_codehandle)
{
if (pState->m_pf_codehandle)
{
NSEEL_code_execute(pState->m_pf_codehandle);
}
}
#endif
// save some things for next frame:
pState->monitor_after_init_code = *pState->var_pf_monitor;
// save some things for per-vertex code:
for (int vi=0; vi<NUM_Q_VAR; vi++)
*pState->var_pv_q[vi] = *pState->var_pf_q[vi];
// (a few range checks:)
*pState->var_pf_gamma = max(0 , min( 8, *pState->var_pf_gamma ));
*pState->var_pf_echo_zoom = max(0.001, min( 1000, *pState->var_pf_echo_zoom));
/*
if (m_pState->m_bRedBlueStereo || m_bAlways3D)
{
// override wave colors
*pState->var_pf_wave_r = 0.35f*(*pState->var_pf_wave_r) + 0.65f;
*pState->var_pf_wave_g = 0.35f*(*pState->var_pf_wave_g) + 0.65f;
*pState->var_pf_wave_b = 0.35f*(*pState->var_pf_wave_b) + 0.65f;
}
*/
}
if (m_pState->m_bBlending)
{
// For all variables that do NOT affect pixel motion, blend them NOW,
// so later the user can just access m_pState->m_pf_whatever.
double mix = (double)CosineInterp(m_pState->m_fBlendProgress);
double mix2 = 1.0 - mix;
*m_pState->var_pf_decay = mix*(*m_pState->var_pf_decay ) + mix2*(*m_pOldState->var_pf_decay );
*m_pState->var_pf_wave_a = mix*(*m_pState->var_pf_wave_a ) + mix2*(*m_pOldState->var_pf_wave_a );
*m_pState->var_pf_wave_r = mix*(*m_pState->var_pf_wave_r ) + mix2*(*m_pOldState->var_pf_wave_r );
*m_pState->var_pf_wave_g = mix*(*m_pState->var_pf_wave_g ) + mix2*(*m_pOldState->var_pf_wave_g );
*m_pState->var_pf_wave_b = mix*(*m_pState->var_pf_wave_b ) + mix2*(*m_pOldState->var_pf_wave_b );
*m_pState->var_pf_wave_x = mix*(*m_pState->var_pf_wave_x ) + mix2*(*m_pOldState->var_pf_wave_x );
*m_pState->var_pf_wave_y = mix*(*m_pState->var_pf_wave_y ) + mix2*(*m_pOldState->var_pf_wave_y );
*m_pState->var_pf_wave_mystery = mix*(*m_pState->var_pf_wave_mystery) + mix2*(*m_pOldState->var_pf_wave_mystery);
// wave_mode: exempt (integer)
*m_pState->var_pf_ob_size = mix*(*m_pState->var_pf_ob_size ) + mix2*(*m_pOldState->var_pf_ob_size );
*m_pState->var_pf_ob_r = mix*(*m_pState->var_pf_ob_r ) + mix2*(*m_pOldState->var_pf_ob_r );
*m_pState->var_pf_ob_g = mix*(*m_pState->var_pf_ob_g ) + mix2*(*m_pOldState->var_pf_ob_g );
*m_pState->var_pf_ob_b = mix*(*m_pState->var_pf_ob_b ) + mix2*(*m_pOldState->var_pf_ob_b );
*m_pState->var_pf_ob_a = mix*(*m_pState->var_pf_ob_a ) + mix2*(*m_pOldState->var_pf_ob_a );
*m_pState->var_pf_ib_size = mix*(*m_pState->var_pf_ib_size ) + mix2*(*m_pOldState->var_pf_ib_size );
*m_pState->var_pf_ib_r = mix*(*m_pState->var_pf_ib_r ) + mix2*(*m_pOldState->var_pf_ib_r );
*m_pState->var_pf_ib_g = mix*(*m_pState->var_pf_ib_g ) + mix2*(*m_pOldState->var_pf_ib_g );
*m_pState->var_pf_ib_b = mix*(*m_pState->var_pf_ib_b ) + mix2*(*m_pOldState->var_pf_ib_b );
*m_pState->var_pf_ib_a = mix*(*m_pState->var_pf_ib_a ) + mix2*(*m_pOldState->var_pf_ib_a );
*m_pState->var_pf_mv_x = mix*(*m_pState->var_pf_mv_x ) + mix2*(*m_pOldState->var_pf_mv_x );
*m_pState->var_pf_mv_y = mix*(*m_pState->var_pf_mv_y ) + mix2*(*m_pOldState->var_pf_mv_y );
*m_pState->var_pf_mv_dx = mix*(*m_pState->var_pf_mv_dx ) + mix2*(*m_pOldState->var_pf_mv_dx );
*m_pState->var_pf_mv_dy = mix*(*m_pState->var_pf_mv_dy ) + mix2*(*m_pOldState->var_pf_mv_dy );
*m_pState->var_pf_mv_l = mix*(*m_pState->var_pf_mv_l ) + mix2*(*m_pOldState->var_pf_mv_l );
*m_pState->var_pf_mv_r = mix*(*m_pState->var_pf_mv_r ) + mix2*(*m_pOldState->var_pf_mv_r );
*m_pState->var_pf_mv_g = mix*(*m_pState->var_pf_mv_g ) + mix2*(*m_pOldState->var_pf_mv_g );
*m_pState->var_pf_mv_b = mix*(*m_pState->var_pf_mv_b ) + mix2*(*m_pOldState->var_pf_mv_b );
*m_pState->var_pf_mv_a = mix*(*m_pState->var_pf_mv_a ) + mix2*(*m_pOldState->var_pf_mv_a );
*m_pState->var_pf_echo_zoom = mix*(*m_pState->var_pf_echo_zoom ) + mix2*(*m_pOldState->var_pf_echo_zoom );
*m_pState->var_pf_echo_alpha = mix*(*m_pState->var_pf_echo_alpha ) + mix2*(*m_pOldState->var_pf_echo_alpha );
*m_pState->var_pf_echo_orient = (mix < m_fSnapPoint) ? *m_pOldState->var_pf_echo_orient : *m_pState->var_pf_echo_orient;
// added in v1.04:
*m_pState->var_pf_wave_usedots = (mix < m_fSnapPoint) ? *m_pOldState->var_pf_wave_usedots : *m_pState->var_pf_wave_usedots ;
*m_pState->var_pf_wave_thick = (mix < m_fSnapPoint) ? *m_pOldState->var_pf_wave_thick : *m_pState->var_pf_wave_thick ;
*m_pState->var_pf_wave_additive= (mix < m_fSnapPoint) ? *m_pOldState->var_pf_wave_additive : *m_pState->var_pf_wave_additive;
*m_pState->var_pf_wave_brighten= (mix < m_fSnapPoint) ? *m_pOldState->var_pf_wave_brighten : *m_pState->var_pf_wave_brighten;
*m_pState->var_pf_darken_center= (mix < m_fSnapPoint) ? *m_pOldState->var_pf_darken_center : *m_pState->var_pf_darken_center;
*m_pState->var_pf_gamma = mix*(*m_pState->var_pf_gamma ) + mix2*(*m_pOldState->var_pf_gamma );
*m_pState->var_pf_wrap = (mix < m_fSnapPoint) ? *m_pOldState->var_pf_wrap : *m_pState->var_pf_wrap ;
*m_pState->var_pf_invert = (mix < m_fSnapPoint) ? *m_pOldState->var_pf_invert : *m_pState->var_pf_invert ;
*m_pState->var_pf_brighten = (mix < m_fSnapPoint) ? *m_pOldState->var_pf_brighten : *m_pState->var_pf_brighten ;
*m_pState->var_pf_darken = (mix < m_fSnapPoint) ? *m_pOldState->var_pf_darken : *m_pState->var_pf_darken ;
*m_pState->var_pf_solarize = (mix < m_fSnapPoint) ? *m_pOldState->var_pf_solarize : *m_pState->var_pf_solarize ;
// added in v2.0:
*m_pState->var_pf_blur1min = mix*(*m_pState->var_pf_blur1min ) + mix2*(*m_pOldState->var_pf_blur1min );
*m_pState->var_pf_blur2min = mix*(*m_pState->var_pf_blur2min ) + mix2*(*m_pOldState->var_pf_blur2min );
*m_pState->var_pf_blur3min = mix*(*m_pState->var_pf_blur3min ) + mix2*(*m_pOldState->var_pf_blur3min );
*m_pState->var_pf_blur1max = mix*(*m_pState->var_pf_blur1max ) + mix2*(*m_pOldState->var_pf_blur1max );
*m_pState->var_pf_blur2max = mix*(*m_pState->var_pf_blur2max ) + mix2*(*m_pOldState->var_pf_blur2max );
*m_pState->var_pf_blur3max = mix*(*m_pState->var_pf_blur3max ) + mix2*(*m_pOldState->var_pf_blur3max );
*m_pState->var_pf_blur1_edge_darken = mix*(*m_pState->var_pf_blur1_edge_darken) + mix2*(*m_pOldState->var_pf_blur1_edge_darken);
}
}
void CPlugin::RenderFrame(int bRedraw)
{
int i;
float fDeltaT = 1.0f/GetFps();
if (bRedraw)
{
// pre-un-flip buffers, so we are redoing the same work as we did last frame...
IDirect3DTexture9* pTemp = m_lpVS[0];
m_lpVS[0] = m_lpVS[1];
m_lpVS[1] = pTemp;
}
if (GetFrame()==0)
{
m_fStartTime = GetTime();
m_fPresetStartTime = GetTime();
}
if (m_fNextPresetTime < 0)
{
float dt = m_fTimeBetweenPresetsRand * (rand()%1000)*0.001f;
m_fNextPresetTime = GetTime() + m_fBlendTimeAuto + m_fTimeBetweenPresets + dt;
}
if (!bRedraw)
{
m_rand_frame = D3DXVECTOR4(FRAND, FRAND, FRAND, FRAND);
// randomly change the preset, if it's time
if (m_fNextPresetTime < GetTime())
{
if (m_nLoadingPreset==0) // don't start a load if one is already underway!
LoadRandomPreset(m_fBlendTimeAuto);
}
// randomly spawn Song Title, if time
if (m_fTimeBetweenRandomSongTitles > 0 &&
!m_supertext.bRedrawSuperText &&
GetTime() >= m_supertext.fStartTime + m_supertext.fDuration + 1.0f/GetFps())
{
int n = GetNumToSpawn(GetTime(), fDeltaT, 1.0f/m_fTimeBetweenRandomSongTitles, 0.5f, m_nSongTitlesSpawned);
if (n > 0)
{
LaunchSongTitleAnim();
m_nSongTitlesSpawned += n;
}
}
// randomly spawn Custom Message, if time
if (m_fTimeBetweenRandomCustomMsgs > 0 &&
!m_supertext.bRedrawSuperText &&
GetTime() >= m_supertext.fStartTime + m_supertext.fDuration + 1.0f/GetFps())
{
int n = GetNumToSpawn(GetTime(), fDeltaT, 1.0f/m_fTimeBetweenRandomCustomMsgs, 0.5f, m_nCustMsgsSpawned);
if (n > 0)
{
LaunchCustomMessage(-1);
m_nCustMsgsSpawned += n;
}
}
// update m_fBlendProgress;
if (m_pState->m_bBlending)
{
m_pState->m_fBlendProgress = (GetTime() - m_pState->m_fBlendStartTime) / m_pState->m_fBlendDuration;
if (m_pState->m_fBlendProgress > 1.0f)
{
m_pState->m_bBlending = false;
}
}
// handle hard cuts here (just after new sound analysis)
static float m_fHardCutThresh;
if (GetFrame() == 0)
m_fHardCutThresh = m_fHardCutLoudnessThresh*2.0f;
if (GetFps() > 1.0f && !m_bHardCutsDisabled && !m_bPresetLockedByUser && !m_bPresetLockedByCode)
{
if (mysound.imm_rel[0] + mysound.imm_rel[1] + mysound.imm_rel[2] > m_fHardCutThresh*3.0f)
{
if (m_nLoadingPreset==0) // don't start a load if one is already underway!
LoadRandomPreset(0.0f);
m_fHardCutThresh *= 2.0f;
}
else
{
/*
float halflife_modified = m_fHardCutHalflife*0.5f;
//thresh = (thresh - 1.5f)*0.99f + 1.5f;
float k = -0.69315f / halflife_modified;*/
float k = -1.3863f / (m_fHardCutHalflife*GetFps());
//float single_frame_multiplier = powf(2.7183f, k / GetFps());
float single_frame_multiplier = expf(k);
m_fHardCutThresh = (m_fHardCutThresh - m_fHardCutLoudnessThresh)*single_frame_multiplier + m_fHardCutLoudnessThresh;
}
}
// smooth & scale the audio data, according to m_state, for display purposes
float scale = m_pState->m_fWaveScale.eval(GetTime()) / 128.0f;
mysound.fWave[0][0] *= scale;
mysound.fWave[1][0] *= scale;
float mix2 = m_pState->m_fWaveSmoothing.eval(GetTime());
float mix1 = scale*(1.0f - mix2);
for (i=1; i<576; i++)
{
mysound.fWave[0][i] = mysound.fWave[0][i]*mix1 + mysound.fWave[0][i-1]*mix2;
mysound.fWave[1][i] = mysound.fWave[1][i]*mix1 + mysound.fWave[1][i-1]*mix2;
}
}
bool bOldPresetUsesWarpShader = (m_pOldState->m_nWarpPSVersion > 0);
bool bNewPresetUsesWarpShader = (m_pState->m_nWarpPSVersion > 0);
bool bOldPresetUsesCompShader = (m_pOldState->m_nCompPSVersion > 0);
bool bNewPresetUsesCompShader = (m_pState->m_nCompPSVersion > 0);
// note: 'code' is only meaningful if we are BLENDING.
int code = (bOldPresetUsesWarpShader ? 8 : 0) |
(bOldPresetUsesCompShader ? 4 : 0) |
(bNewPresetUsesWarpShader ? 2 : 0) |
(bNewPresetUsesCompShader ? 1 : 0);
RunPerFrameEquations(code);
// restore any lost surfaces
//m_lpDD->RestoreAllSurfaces();
LPDIRECT3DDEVICE9 lpDevice = GetDevice();
if (!lpDevice)
return;
// Remember the original backbuffer and zbuffer
LPDIRECT3DSURFACE9 pBackBuffer=NULL;//, pZBuffer=NULL;
lpDevice->GetRenderTarget( 0, &pBackBuffer );
//lpDevice->GetDepthStencilSurface( &pZBuffer );
// set up render state
{
DWORD texaddr = (*m_pState->var_pf_wrap > m_fSnapPoint) ? D3DTADDRESS_WRAP : D3DTADDRESS_CLAMP;
lpDevice->SetRenderState(D3DRS_WRAP0, 0);//D3DWRAPCOORD_0|D3DWRAPCOORD_1|D3DWRAPCOORD_2|D3DWRAPCOORD_3);
//lpDevice->SetRenderState(D3DRS_WRAP0, (*m_pState->var_pf_wrap) ? D3DWRAP_U|D3DWRAP_V|D3DWRAP_W : 0);
//lpDevice->SetRenderState(D3DRS_WRAP1, (*m_pState->var_pf_wrap) ? D3DWRAP_U|D3DWRAP_V|D3DWRAP_W : 0);
lpDevice->SetSamplerState(0, D3DSAMP_ADDRESSU, D3DTADDRESS_WRAP);//texaddr);
lpDevice->SetSamplerState(0, D3DSAMP_ADDRESSV, D3DTADDRESS_WRAP);//texaddr);
lpDevice->SetSamplerState(0, D3DSAMP_ADDRESSW, D3DTADDRESS_WRAP);//texaddr);
lpDevice->SetSamplerState(1, D3DSAMP_ADDRESSU, D3DTADDRESS_WRAP);
lpDevice->SetSamplerState(1, D3DSAMP_ADDRESSV, D3DTADDRESS_WRAP);
lpDevice->SetSamplerState(1, D3DSAMP_ADDRESSW, D3DTADDRESS_WRAP);
lpDevice->SetRenderState( D3DRS_SHADEMODE, D3DSHADE_GOURAUD );
lpDevice->SetRenderState( D3DRS_SPECULARENABLE, FALSE );
lpDevice->SetRenderState( D3DRS_CULLMODE, D3DCULL_NONE );
lpDevice->SetRenderState( D3DRS_ZENABLE, FALSE );
lpDevice->SetRenderState( D3DRS_ZWRITEENABLE, FALSE );
lpDevice->SetRenderState( D3DRS_LIGHTING, FALSE );
lpDevice->SetRenderState( D3DRS_COLORVERTEX, TRUE );
lpDevice->SetRenderState( D3DRS_FILLMODE, D3DFILL_SOLID );
lpDevice->SetRenderState( D3DRS_ALPHABLENDENABLE, FALSE );
lpDevice->SetRenderState( D3DRS_AMBIENT, 0xFFFFFFFF ); //?
lpDevice->SetRenderState( D3DRS_CLIPPING, TRUE );
// stages 0 and 1 always just use bilinear filtering.
lpDevice->SetSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR);
lpDevice->SetSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR);
lpDevice->SetSamplerState(0, D3DSAMP_MIPFILTER, D3DTEXF_LINEAR);
lpDevice->SetSamplerState(1, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR);
lpDevice->SetSamplerState(1, D3DSAMP_MINFILTER, D3DTEXF_LINEAR);
lpDevice->SetSamplerState(1, D3DSAMP_MIPFILTER, D3DTEXF_LINEAR);
// note: this texture stage state setup works for 0 or 1 texture.
// if you set a texture, it will be modulated with the current diffuse color.
// if you don't set a texture, it will just use the current diffuse color.
lpDevice->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_MODULATE);
lpDevice->SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_DIFFUSE);
lpDevice->SetTextureStageState(0, D3DTSS_COLORARG2, D3DTA_TEXTURE);
lpDevice->SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_DISABLE);
lpDevice->SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1 );
lpDevice->SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_DIFFUSE );
lpDevice->SetTextureStageState(1, D3DTSS_ALPHAOP, D3DTOP_DISABLE);
// NOTE: don't forget to call SetTexture and SetVertexShader before drawing!
// Examples:
// SPRITEVERTEX verts[4]; // has texcoords
// lpDevice->SetTexture(0, m_sprite_tex);
// lpDevice->SetVertexShader( SPRITEVERTEX_FORMAT );
//
// WFVERTEX verts[4]; // no texcoords
// lpDevice->SetTexture(0, NULL);
// lpDevice->SetVertexShader( WFVERTEX_FORMAT );
}
// render string to m_lpDDSTitle, if necessary
if (m_supertext.bRedrawSuperText)
{
if (!RenderStringToTitleTexture())
m_supertext.fStartTime = -1.0f;
m_supertext.bRedrawSuperText = false;
}
// set up to render [from NULL] to VS0 (for motion vectors).
{
lpDevice->SetTexture(0, NULL);
IDirect3DSurface9* pNewTarget = NULL;
if (m_lpVS[0]->GetSurfaceLevel(0, &pNewTarget) != D3D_OK)
return;
lpDevice->SetRenderTarget(0, pNewTarget );
//lpDevice->SetDepthStencilSurface( NULL );
pNewTarget->Release();
lpDevice->SetTexture(0, NULL);
}
// draw motion vectors to VS0
DrawMotionVectors();
lpDevice->SetTexture(0, NULL);
lpDevice->SetTexture(1, NULL);
// on first frame, clear OLD VS.
if (m_nFramesSinceResize == 0)
{
IDirect3DSurface9* pNewTarget = NULL;
if (m_lpVS[0]->GetSurfaceLevel(0, &pNewTarget) != D3D_OK)
return;
lpDevice->SetRenderTarget(0, pNewTarget );
//lpDevice->SetDepthStencilSurface( NULL );
pNewTarget->Release();
lpDevice->Clear(0, NULL, D3DCLEAR_TARGET, 0x00000000, 1.0f, 0);
}
// set up to render [from VS0] to VS1.
{
IDirect3DSurface9* pNewTarget = NULL;
if (m_lpVS[1]->GetSurfaceLevel(0, &pNewTarget) != D3D_OK)
return;
lpDevice->SetRenderTarget(0, pNewTarget );
//lpDevice->SetDepthStencilSurface( NULL );
pNewTarget->Release();
}
if (m_bAutoGamma && GetFrame()==0)
{
if (strstr(GetDriverDescription(), "nvidia") ||
strstr(GetDriverDescription(), "nVidia") ||
strstr(GetDriverDescription(), "NVidia") ||
strstr(GetDriverDescription(), "NVIDIA"))
m_n16BitGamma = 2;
else if (strstr(GetDriverDescription(), "ATI RAGE MOBILITY M"))