Previous 199869 Revisions Next

r44503 Thursday 31st December, 2015 at 15:59:23 UTC by Jezze
Refactoring

- replaced shader parameters OrientationSwapXY xor RotationSwapXY by
SwapXY
- made shader parameters SourceDims, SourceRect, TargetDims, ScreenDims,
QuadDims and SwapXY available for all shaders
- color convolution, defocus and phosphor pass will now be skipped if
all influencing parameters are 0
- removed unused bloom_texture and bloom_target arrays from cache_target
class
- fixed half texel offset in prescale.fx
[hlsl]distortion.fx focus.fx post.fx prescale.fx
[hlsl/artwork_support]post.fx
[src/osd/modules/render]drawd3d.cpp drawd3d.h
[src/osd/modules/render/d3d]d3dhlsl.cpp d3dhlsl.h

trunk/hlsl/artwork_support/post.fx
r253014r253015
7474// Functions
7575//-----------------------------------------------------------------------------
7676
77bool xor(bool a, bool b)
78{
79   return (a || b) && !(a && b);
80}
81
8277// www.stackoverflow.com/questions/5149544/can-i-generate-a-random-number-inside-a-pixel-shader/
8378float random(float2 seed)
8479{
r253014r253015
114109uniform float2 ShadowDims = float2(32.0f, 32.0f); // size of the shadow texture (extended to power-of-two size)
115110uniform float2 ShadowUVOffset = float2(0.0f, 0.0f);
116111
117uniform bool OrientationSwapXY = false; // false landscape, true portrait for default screen orientation
118uniform bool RotationSwapXY = false; // swapped default screen orientation due to screen rotation
112uniform bool SwapXY = false;
113
119114uniform int RotationType = 0; // 0 = 0°, 1 = 90°, 2 = 180°, 3 = 270°
120115
121116uniform bool PrepareBloom = false; // disables some effects for rendering bloom textures
r253014r253015
126121   VS_OUTPUT Output = (VS_OUTPUT)0;
127122
128123   float2 shadowUVOffset = ShadowUVOffset;
129   shadowUVOffset = xor(OrientationSwapXY, RotationSwapXY)
124   shadowUVOffset = SwapXY
130125      ? shadowUVOffset.yx
131126      : shadowUVOffset.xy;
132127
r253014r253015
227222   // normalized screen canvas ratio
228223   float2 CanvasRatio = PrepareVector
229224      ? float2(1.0f, QuadDims.y / QuadDims.x)
230      : float2(1.0f, xor(OrientationSwapXY, RotationSwapXY)
225      : float2(1.0f, SwapXY
231226         ? QuadDims.x / QuadDims.y
232227         : QuadDims.y / QuadDims.x);
233228
r253014r253015
240235            : RotationType == 3 // 270°
241236               ? float2(0.25f, 0.25f)
242237               : float2(-0.25f, 0.25f)
243      : OrientationSwapXY
238      : SwapXY
244239         ? float2(0.25f, 0.25f)
245240         : float2(-0.25f, 0.25f);
246241
r253014r253015
272267
273268   float2 CanvasDims = PrepareVector
274269      ? ScreenDims
275      : xor(OrientationSwapXY, RotationSwapXY)
270      : SwapXY
276271         ? QuadDims.yx / SourceRect
277272         : QuadDims.xy / SourceRect;
278273
r253014r253015
375370   float2 ScreenTexelDims = 1.0f / ScreenDims;
376371   float2 SourceTexelDims = 1.0f / SourceDims;
377372
378   float2 HalfSourceRect = PrepareVector
379      ? float2(0.5f, 0.5f)
380      : SourceRect * 0.5f;
373   float2 HalfSourceRect = SourceRect * 0.5f;
381374
382375   float2 ScreenCoord = Input.ScreenCoord / ScreenDims;
383376   ScreenCoord = GetCoords(ScreenCoord, float2(0.5f, 0.5f), CurvatureAmount * 0.25f); // reduced amount
r253014r253015
406399   if (!PrepareBloom)
407400   {
408401      float2 shadowDims = ShadowDims;
409      shadowDims = xor(OrientationSwapXY, RotationSwapXY)
402      shadowDims = SwapXY
410403         ? shadowDims.yx
411404         : shadowDims.xy;
412405
413406      float2 shadowUV = ShadowUV;
414      // shadowUV = xor(OrientationSwapXY, RotationSwapXY)
407      // shadowUV = SwapXY
415408         // ? shadowUV.yx
416409         // : shadowUV.xy;
417410
418411      float2 screenCoord = ShadowTileMode == 0 ? ScreenCoord : BaseCoord;
419      screenCoord = xor(OrientationSwapXY, RotationSwapXY)
412      screenCoord = SwapXY
420413         ? screenCoord.yx
421414         : screenCoord.xy;
422415
423416      float2 shadowCount = ShadowCount;
424      shadowCount = xor(OrientationSwapXY, RotationSwapXY)
417      shadowCount = SwapXY
425418         ? shadowCount.yx
426419         : shadowCount.xy;
427420
428421      float2 shadowTile = ((ShadowTileMode == 0 ? ScreenTexelDims : SourceTexelDims) * shadowCount);
429      shadowTile = xor(OrientationSwapXY, RotationSwapXY)
422      shadowTile = SwapXY
430423         ? shadowTile.yx
431424         : shadowTile.xy;
432425
433426      float2 ShadowFrac = frac(screenCoord / shadowTile);
434427      float2 ShadowCoord = (ShadowFrac * shadowUV);
435428      ShadowCoord += 0.5f / shadowDims; // half texel offset
436      // ShadowCoord = xor(OrientationSwapXY, RotationSwapXY)
429      // ShadowCoord = SwapXY
437430         // ? ShadowCoord.yx
438431         // : ShadowCoord.xy;
439432
trunk/hlsl/distortion.fx
r253014r253015
5959// Functions
6060//-----------------------------------------------------------------------------
6161
62bool xor(bool a, bool b)
63{
64   return (a || b) && !(a && b);
65}
66
6762// www.stackoverflow.com/questions/5149544/can-i-generate-a-random-number-inside-a-pixel-shader/
6863float random(float2 seed)
6964{
r253014r253015
122117uniform float VignettingAmount = 0.0f;
123118uniform float ReflectionAmount = 0.0f;
124119
125uniform bool OrientationSwapXY = false; // false landscape, true portrait for default screen orientation
126uniform bool RotationSwapXY = false; // swapped default screen orientation due to screen rotation
127120uniform int RotationType = 0; // 0 = 0°, 1 = 90°, 2 = 180°, 3 = 270°
128121
129122float2 GetRatioCorrection()
trunk/hlsl/focus.fx
r253014r253015
4646};
4747
4848//-----------------------------------------------------------------------------
49// Functions
50//-----------------------------------------------------------------------------
51
52bool xor(bool a, bool b)
53{
54   return (a || b) && !(a && b);
55}
56
57//-----------------------------------------------------------------------------
5849// Defocus Vertex Shader
5950//-----------------------------------------------------------------------------
6051
r253014r253015
9889
9990uniform float2 Defocus = float2(0.0f, 0.0f);
10091
101uniform bool OrientationSwapXY = false; // false landscape, true portrait for default screen orientation
102uniform bool RotationSwapXY = false; // swapped default screen orientation due to screen rotation
92uniform bool SwapXY = false;
10393
10494float4 ps_main(PS_INPUT Input) : COLOR
10595{
10696   float2 QuadRatio =
107      float2(1.0f, xor(OrientationSwapXY, RotationSwapXY)
97      float2(1.0f, SwapXY
10898         ? QuadDims.y / QuadDims.x
10999         : QuadDims.x / QuadDims.y);
110100
111101   // imaginary texel dimensions independed from quad dimensions, but dependend on quad ratio
112   float2 DefocusTexelDims = (1.0f / 1024.0) * SourceRect * QuadRatio * Defocus;
102   float2 TexelDims = (1.0f / 1024.0) * SourceRect * QuadRatio;
113103
104   float2 DefocusTexelDims = Defocus * TexelDims;
105
114106   float4 d = tex2D(DiffuseSampler, Input.TexCoord);
115107   float3 d1 = tex2D(DiffuseSampler, Input.TexCoord + Coord1Offset * DefocusTexelDims).rgb;
116108   float3 d2 = tex2D(DiffuseSampler, Input.TexCoord + Coord2Offset * DefocusTexelDims).rgb;
trunk/hlsl/post.fx
r253014r253015
6767static const float PI = 3.1415927f;
6868
6969//-----------------------------------------------------------------------------
70// Functions
71//-----------------------------------------------------------------------------
72
73bool xor(bool a, bool b)
74{
75   return (a || b) && !(a && b);
76}
77
78//-----------------------------------------------------------------------------
7970// Scanline & Shadowmask Vertex Shader
8071//-----------------------------------------------------------------------------
8172
r253014r253015
8778uniform float2 ShadowDims = float2(32.0f, 32.0f); // size of the shadow texture (extended to power-of-two size)
8879uniform float2 ShadowUVOffset = float2(0.0f, 0.0f);
8980
90uniform bool OrientationSwapXY = false; // false landscape, true portrait for default screen orientation
91uniform bool RotationSwapXY = false; // swapped default screen orientation due to screen rotation
81uniform bool SwapXY = false;
9282
9383uniform bool PrepareBloom = false; // disables some effects for rendering bloom textures
9484uniform bool PrepareVector = false;
r253014r253015
9888   VS_OUTPUT Output = (VS_OUTPUT)0;
9989
10090   float2 shadowUVOffset = ShadowUVOffset;
101   shadowUVOffset = xor(OrientationSwapXY, RotationSwapXY)
91   shadowUVOffset = SwapXY
10292      ? shadowUVOffset.yx
10393      : shadowUVOffset.xy;
10494
r253014r253015
170160   float2 ScreenTexelDims = 1.0f / ScreenDims;
171161   float2 SourceTexelDims = 1.0f / SourceDims;
172162
173   float2 HalfSourceRect = PrepareVector
174      ? float2(0.5f, 0.5f)
175      : SourceRect * 0.5f;
163   float2 HalfSourceRect = SourceRect * 0.5f;
176164
177165   float2 ScreenCoord = Input.ScreenCoord / ScreenDims;
178166   float2 BaseCoord = GetAdjustedCoords(Input.TexCoord, HalfSourceRect);
r253014r253015
190178   if (!PrepareBloom)
191179   {
192180      float2 shadowDims = ShadowDims;
193      shadowDims = xor(OrientationSwapXY, RotationSwapXY)
181      shadowDims = SwapXY
194182         ? shadowDims.yx
195183         : shadowDims.xy;
196184
197185      float2 shadowUV = ShadowUV;
198      // shadowUV = xor(OrientationSwapXY, RotationSwapXY)
186      // shadowUV = SwapXY
199187         // ? shadowUV.yx
200188         // : shadowUV.xy;
201189
202190      float2 screenCoord = ShadowTileMode == 0 ? ScreenCoord : BaseCoord;
203      screenCoord = xor(OrientationSwapXY, RotationSwapXY)
191      screenCoord = SwapXY
204192         ? screenCoord.yx
205193         : screenCoord.xy;
206194
207195      float2 shadowCount = ShadowCount;
208      shadowCount = xor(OrientationSwapXY, RotationSwapXY)
196      shadowCount = SwapXY
209197         ? shadowCount.yx
210198         : shadowCount.xy;
211199
212200      float2 shadowTile = ((ShadowTileMode == 0 ? ScreenTexelDims : SourceTexelDims) * shadowCount);
213      shadowTile = xor(OrientationSwapXY, RotationSwapXY)
201      shadowTile = SwapXY
214202         ? shadowTile.yx
215203         : shadowTile.xy;
216204
217205      float2 ShadowFrac = frac(screenCoord / shadowTile);
218206      float2 ShadowCoord = (ShadowFrac * shadowUV);
219207      ShadowCoord += 0.5f / shadowDims; // half texel offset
220      // ShadowCoord = xor(OrientationSwapXY, RotationSwapXY)
208      // ShadowCoord = SwapXY
221209         // ? ShadowCoord.yx
222210         // : ShadowCoord.xy;
223211
trunk/hlsl/prescale.fx
r253014r253015
4949//-----------------------------------------------------------------------------
5050
5151uniform float2 ScreenDims;
52uniform float2 TargetDims;
5253
5354VS_OUTPUT vs_main(VS_INPUT Input)
5455{
r253014r253015
5657   
5758   Output.Position = float4(Input.Position.xyz, 1.0f);
5859   Output.Position.xy /= ScreenDims;
59   Output.Position.y = 1.0f - Output.Position.y;
60   Output.Position.xy -= 0.5f;
61   Output.Position *= float4(2.0f, 2.0f, 1.0f, 1.0f);
60   Output.Position.y = 1.0f - Output.Position.y; // flip y
61   Output.Position.xy -= 0.5f; // center
62   Output.Position.xy *= 2.0f; // zoom
6263   
63   Output.TexCoord = Input.TexCoord + 0.5f / ScreenDims;
64   Output.TexCoord = Input.TexCoord;
65   Output.TexCoord += 0.5f / TargetDims; // half texel offset correction (DX9)
6466
6567   return Output;
6668}
trunk/src/osd/modules/render/d3d/d3dhlsl.cpp
r253014r253015
940940      return 1;
941941   }
942942
943   yiq_encode_effect->add_uniform("ScreenDims", uniform::UT_VEC2, uniform::CU_SCREEN_DIMS);
944   yiq_encode_effect->add_uniform("SourceDims", uniform::UT_VEC2, uniform::CU_SOURCE_DIMS);
945   yiq_encode_effect->add_uniform("SourceRect", uniform::UT_VEC2, uniform::CU_SOURCE_RECT);
943   effect *effects[14] = {
944      default_effect,
945      post_effect,
946      distortion_effect,
947      prescale_effect,
948      phosphor_effect,
949      focus_effect,
950      deconverge_effect,
951      color_effect,
952      yiq_encode_effect,
953      yiq_decode_effect,
954      color_effect,
955      bloom_effect,
956      downsample_effect,
957      vector_effect
958   };
959
960   for (int i = 0; i < 14; i++)
961   {
962      effects[i]->add_uniform("SourceDims", uniform::UT_VEC2, uniform::CU_SOURCE_DIMS);
963      effects[i]->add_uniform("SourceRect", uniform::UT_VEC2, uniform::CU_SOURCE_RECT);
964      effects[i]->add_uniform("TargetDims", uniform::UT_VEC2, uniform::CU_TARGET_DIMS);
965      effects[i]->add_uniform("ScreenDims", uniform::UT_VEC2, uniform::CU_SCREEN_DIMS);
966      effects[i]->add_uniform("QuadDims", uniform::UT_VEC2, uniform::CU_QUAD_DIMS);
967      effects[i]->add_uniform("SwapXY", uniform::UT_BOOL, uniform::CU_SWAP_XY);
968   }
969
946970   yiq_encode_effect->add_uniform("CCValue", uniform::UT_FLOAT, uniform::CU_NTSC_CCFREQ);
947971   yiq_encode_effect->add_uniform("AValue", uniform::UT_FLOAT, uniform::CU_NTSC_A);
948972   yiq_encode_effect->add_uniform("BValue", uniform::UT_FLOAT, uniform::CU_NTSC_B);
r253014r253015
952976   yiq_encode_effect->add_uniform("IFreqResponse", uniform::UT_FLOAT, uniform::CU_NTSC_IFREQ);
953977   yiq_encode_effect->add_uniform("QFreqResponse", uniform::UT_FLOAT, uniform::CU_NTSC_QFREQ);
954978   yiq_encode_effect->add_uniform("ScanTime", uniform::UT_FLOAT, uniform::CU_NTSC_HTIME);
955
956   yiq_decode_effect->add_uniform("ScreenDims", uniform::UT_VEC2, uniform::CU_SCREEN_DIMS);
957   yiq_decode_effect->add_uniform("SourceDims", uniform::UT_VEC2, uniform::CU_SOURCE_DIMS);
958   yiq_decode_effect->add_uniform("SourceRect", uniform::UT_VEC2, uniform::CU_SOURCE_RECT);
979   
959980   yiq_decode_effect->add_uniform("CCValue", uniform::UT_FLOAT, uniform::CU_NTSC_CCFREQ);
960981   yiq_decode_effect->add_uniform("AValue", uniform::UT_FLOAT, uniform::CU_NTSC_A);
961982   yiq_decode_effect->add_uniform("BValue", uniform::UT_FLOAT, uniform::CU_NTSC_B);
r253014r253015
967988   yiq_decode_effect->add_uniform("QFreqResponse", uniform::UT_FLOAT, uniform::CU_NTSC_QFREQ);
968989   yiq_decode_effect->add_uniform("ScanTime", uniform::UT_FLOAT, uniform::CU_NTSC_HTIME);
969990
970   color_effect->add_uniform("ScreenDims", uniform::UT_VEC2, uniform::CU_SCREEN_DIMS);
971   color_effect->add_uniform("SourceDims", uniform::UT_VEC2, uniform::CU_SOURCE_DIMS);
972
973991   color_effect->add_uniform("RedRatios", uniform::UT_VEC3, uniform::CU_COLOR_RED_RATIOS);
974992   color_effect->add_uniform("GrnRatios", uniform::UT_VEC3, uniform::CU_COLOR_GRN_RATIOS);
975993   color_effect->add_uniform("BluRatios", uniform::UT_VEC3, uniform::CU_COLOR_BLU_RATIOS);
r253014r253015
977995   color_effect->add_uniform("Scale", uniform::UT_VEC3, uniform::CU_COLOR_SCALE);
978996   color_effect->add_uniform("Saturation", uniform::UT_FLOAT, uniform::CU_COLOR_SATURATION);
979997
980   prescale_effect->add_uniform("ScreenDims", uniform::UT_VEC2, uniform::CU_SCREEN_DIMS);
981
982   deconverge_effect->add_uniform("ScreenDims", uniform::UT_VEC2, uniform::CU_SCREEN_DIMS);
983   deconverge_effect->add_uniform("SourceDims", uniform::UT_VEC2, uniform::CU_SOURCE_DIMS);
984   deconverge_effect->add_uniform("SourceRect", uniform::UT_VEC2, uniform::CU_SOURCE_RECT);
985998   deconverge_effect->add_uniform("ConvergeX", uniform::UT_VEC3, uniform::CU_CONVERGE_LINEAR_X);
986999   deconverge_effect->add_uniform("ConvergeY", uniform::UT_VEC3, uniform::CU_CONVERGE_LINEAR_Y);
9871000   deconverge_effect->add_uniform("RadialConvergeX", uniform::UT_VEC3, uniform::CU_CONVERGE_RADIAL_X);
9881001   deconverge_effect->add_uniform("RadialConvergeY", uniform::UT_VEC3, uniform::CU_CONVERGE_RADIAL_Y);
9891002
990   focus_effect->add_uniform("ScreenDims", uniform::UT_VEC2, uniform::CU_SCREEN_DIMS);
991   focus_effect->add_uniform("TargetDims", uniform::UT_VEC2, uniform::CU_TARGET_DIMS);
992   focus_effect->add_uniform("SourceRect", uniform::UT_VEC2, uniform::CU_SOURCE_RECT);
993   focus_effect->add_uniform("QuadDims", uniform::UT_VEC2, uniform::CU_QUAD_DIMS);
9941003   focus_effect->add_uniform("Defocus", uniform::UT_VEC2, uniform::CU_FOCUS_SIZE);
995   focus_effect->add_uniform("OrientationSwapXY", uniform::UT_BOOL, uniform::CU_ORIENTATION_SWAP);
996   focus_effect->add_uniform("RotationSwapXY", uniform::UT_BOOL, uniform::CU_ROTATION_SWAP);
997
998   phosphor_effect->add_uniform("ScreenDims", uniform::UT_VEC2, uniform::CU_SCREEN_DIMS);
999   phosphor_effect->add_uniform("TargetDims", uniform::UT_VEC2, uniform::CU_TARGET_DIMS);
1004   
10001005   phosphor_effect->add_uniform("Phosphor", uniform::UT_VEC3, uniform::CU_PHOSPHOR_LIFE);
10011006
1002   downsample_effect->add_uniform("ScreenDims", uniform::UT_VEC2, uniform::CU_SCREEN_DIMS);
1003
1004   bloom_effect->add_uniform("ScreenDims", uniform::UT_VEC2, uniform::CU_SCREEN_DIMS);
1005   bloom_effect->add_uniform("TargetDims", uniform::UT_VEC2, uniform::CU_TARGET_DIMS);
1006
1007   post_effect->add_uniform("SourceDims", uniform::UT_VEC2, uniform::CU_SOURCE_DIMS);
1008   post_effect->add_uniform("SourceRect", uniform::UT_VEC2, uniform::CU_SOURCE_RECT);
1009   post_effect->add_uniform("ScreenDims", uniform::UT_VEC2, uniform::CU_SCREEN_DIMS);
1010   post_effect->add_uniform("TargetDims", uniform::UT_VEC2, uniform::CU_TARGET_DIMS);
1011   post_effect->add_uniform("QuadDims", uniform::UT_VEC2, uniform::CU_QUAD_DIMS); // backward compatibility
1012
10131007   post_effect->add_uniform("VignettingAmount", uniform::UT_FLOAT, uniform::CU_POST_VIGNETTING); // backward compatibility
10141008   post_effect->add_uniform("CurvatureAmount", uniform::UT_FLOAT, uniform::CU_POST_CURVATURE); // backward compatibility
10151009   post_effect->add_uniform("RoundCornerAmount", uniform::UT_FLOAT, uniform::CU_POST_ROUND_CORNER); // backward compatibility
r253014r253015
10301024   post_effect->add_uniform("Power", uniform::UT_VEC3, uniform::CU_POST_POWER);
10311025   post_effect->add_uniform("Floor", uniform::UT_VEC3, uniform::CU_POST_FLOOR);
10321026
1033   post_effect->add_uniform("OrientationSwapXY", uniform::UT_BOOL, uniform::CU_ORIENTATION_SWAP);
1034   post_effect->add_uniform("RotationSwapXY", uniform::UT_BOOL, uniform::CU_ROTATION_SWAP);
10351027   post_effect->add_uniform("RotationType", uniform::UT_INT, uniform::CU_ROTATION_TYPE);
10361028
1037   distortion_effect->add_uniform("ScreenDims", uniform::UT_VEC2, uniform::CU_SCREEN_DIMS);
1038   distortion_effect->add_uniform("TargetDims", uniform::UT_VEC2, uniform::CU_TARGET_DIMS);
1039   distortion_effect->add_uniform("QuadDims", uniform::UT_VEC2, uniform::CU_QUAD_DIMS);
1040
10411029   distortion_effect->add_uniform("VignettingAmount", uniform::UT_FLOAT, uniform::CU_POST_VIGNETTING);
10421030   distortion_effect->add_uniform("CurvatureAmount", uniform::UT_FLOAT, uniform::CU_POST_CURVATURE);
10431031   distortion_effect->add_uniform("RoundCornerAmount", uniform::UT_FLOAT, uniform::CU_POST_ROUND_CORNER);
10441032   distortion_effect->add_uniform("SmoothBorderAmount", uniform::UT_FLOAT, uniform::CU_POST_SMOOTH_BORDER);
10451033   distortion_effect->add_uniform("ReflectionAmount", uniform::UT_FLOAT, uniform::CU_POST_REFLECTION);
10461034
1047   distortion_effect->add_uniform("OrientationSwapXY", uniform::UT_BOOL, uniform::CU_ORIENTATION_SWAP);
1048   distortion_effect->add_uniform("RotationSwapXY", uniform::UT_BOOL, uniform::CU_ROTATION_SWAP);
10491035   distortion_effect->add_uniform("RotationType", uniform::UT_INT, uniform::CU_ROTATION_TYPE);
10501036
1051   vector_effect->add_uniform("ScreenDims", uniform::UT_VEC2, uniform::CU_SCREEN_DIMS);
1052
1053   default_effect->add_uniform("ScreenDims", uniform::UT_VEC2, uniform::CU_SCREEN_DIMS);
1054   default_effect->add_uniform("TargetDims", uniform::UT_VEC2, uniform::CU_TARGET_DIMS);
1055
10561037   initialized = true;
10571038
10581039   return 0;
r253014r253015
13591340{
13601341   int next_index = source_index;
13611342
1343   // skip deconverge if no influencing settings
1344   if (options->converge_x[0] == 0.0f && options->converge_x[1] == 0.0f && options->converge_x[2] == 0.0f &&
1345      options->converge_y[0] == 0.0f && options->converge_y[1] == 0.0f && options->converge_y[2] == 0.0f &&
1346      options->radial_converge_x[0] == 0.0f && options->radial_converge_x[1] == 0.0f && options->radial_converge_x[2] == 0.0f &&
1347      options->radial_converge_y[0] == 0.0f && options->radial_converge_y[1] == 0.0f && options->radial_converge_y[2] == 0.0f)
1348   {
1349      return next_index;
1350   }
1351
13621352   curr_effect = deconverge_effect;
13631353   curr_effect->update_uniforms();
13641354   curr_effect->set_texture("Diffuse", rt->prescale_texture[next_index]);
r253014r253015
13731363{
13741364   int next_index = source_index;
13751365
1376   float defocus_x = options->defocus[0];
1377   float defocus_y = options->defocus[1];
1378
13791366   // skip defocus if no influencing settings
1380   if (defocus_x == 0.0f && defocus_y == 0.0f)
1367   if (options->defocus[0] == 0.0f && options->defocus[1] == 0.0f)
13811368   {
13821369      return next_index;
13831370   }
r253014r253015
13961383{
13971384   int next_index = source_index;
13981385
1386   // skip phosphor if no influencing settings
1387   if (options->phosphor[0] == 0.0f && options->defocus[1] == 0.0f && options->defocus[2] == 0.0f)
1388   {
1389      return next_index;
1390   }
1391
13991392   curr_effect = phosphor_effect;
14001393   curr_effect->update_uniforms();
14011394   curr_effect->set_texture("Diffuse", rt->prescale_texture[next_index]);
r253014r253015
14211414{
14221415   int next_index = source_index;
14231416
1424   texture_info *texture = poly->get_texture();
1425
14261417   bool prepare_vector =
14271418      machine->first_screen()->screen_type() == SCREEN_TYPE_VECTOR;
14281419
r253014r253015
14591450   curr_effect->set_vector("BackColor", 3, back_color);
14601451   curr_effect->set_vector("ScreenScale", 2, screen_scale);
14611452   curr_effect->set_vector("ScreenOffset", 2, screen_offset);
1462   curr_effect->set_float("ScanlineOffset", texture->get_cur_frame() == 0 ? 0.0f : options->scanline_offset);
1453   curr_effect->set_float("ScanlineOffset", curr_texture->get_cur_frame() == 0 ? 0.0f : options->scanline_offset);
14631454   curr_effect->set_bool("PrepareBloom", prepare_bloom);
14641455   curr_effect->set_bool("PrepareVector", prepare_vector);
14651456
r253014r253015
14731464{
14741465   int next_index = source_index;
14751466
1476   bool prepare_vector =
1477      machine->first_screen()->screen_type() == SCREEN_TYPE_VECTOR;
1478   float bloom_rescale = options->bloom_scale;
1479
14801467   // skip downsample if no influencing settings
1481   if (bloom_rescale == 0.0f)
1468   if (options->bloom_scale == 0.0f)
14821469   {
14831470      return next_index;
14841471   }
14851472
1473   bool prepare_vector =
1474      machine->first_screen()->screen_type() == SCREEN_TYPE_VECTOR;
1475
14861476   curr_effect = downsample_effect;
14871477   curr_effect->update_uniforms();
14881478   curr_effect->set_bool("PrepareVector", prepare_vector);
r253014r253015
15191509{
15201510   int next_index = source_index;
15211511
1522   float bloom_rescale = options->bloom_scale;
1523
15241512   // skip bloom if no influencing settings
1525   if (bloom_rescale == 0.0f)
1513   if (options->bloom_scale == 0.0f)
15261514   {
15271515      return next_index;
15281516   }
r253014r253015
15581546   curr_effect->set_vector("LevelASize", 2, bloom_dims[10]);
15591547
15601548   curr_effect->set_int("BloomBlendMode", options->bloom_blend_mode);
1561   curr_effect->set_float("BloomScale", bloom_rescale);
1549   curr_effect->set_float("BloomScale", options->bloom_scale);
15621550   curr_effect->set_vector("BloomOverdrive", 3, options->bloom_overdrive);
15631551
15641552   curr_effect->set_texture("DiffuseA", rt->prescale_texture[next_index]);
r253014r253015
17551743      // render on screen
17561744      d3d->set_wrap(D3DTADDRESS_MIRROR);
17571745      next_index = screen_pass(rt, next_index, poly, vertnum);
1758      d3d->set_wrap(PRIMFLAG_GET_TEXWRAP(poly->get_texture()->get_flags()) ? D3DTADDRESS_WRAP : D3DTADDRESS_CLAMP);
1746      d3d->set_wrap(PRIMFLAG_GET_TEXWRAP(curr_texture->get_flags()) ? D3DTADDRESS_WRAP : D3DTADDRESS_CLAMP);
17591747
17601748      curr_texture->increment_frame_count();
17611749      curr_texture->mask_frame_count(options->yiq_phase_count);
r253014r253015
29612949      }
29622950      case CU_SOURCE_DIMS:
29632951      {
2964         vec2f sourcedims = shadersys->curr_texture->get_rawdims();
2965         m_shader->set_vector("SourceDims", 2, &sourcedims.c.x);
2952         if (shadersys->curr_texture != NULL)
2953         {
2954            vec2f sourcedims = shadersys->curr_texture->get_rawdims();
2955            m_shader->set_vector("SourceDims", 2, &sourcedims.c.x);
2956         }
2957
29662958         break;
29672959      }
29682960      case CU_SOURCE_RECT:
2969      {
2970         vec2f delta = shadersys->curr_texture->get_uvstop() - shadersys->curr_texture->get_uvstart();
2971         m_shader->set_vector("SourceRect", 2, &delta.c.x);
2961      {         
2962         bool prepare_vector =
2963            d3d->window().machine().first_screen()->screen_type() == SCREEN_TYPE_VECTOR;
2964
2965         if (prepare_vector)
2966         {
2967            float delta[2] = { 1.0f, 1.0f };
2968            m_shader->set_vector("SourceRect", 2, delta);
2969            break;
2970         }
2971         
2972         if (shadersys->curr_texture != NULL)
2973         {
2974            vec2f delta = shadersys->curr_texture->get_uvstop() - shadersys->curr_texture->get_uvstart();
2975            m_shader->set_vector("SourceRect", 2, &delta.c.x);
2976            break;
2977         }
2978
29722979         break;
29732980      }
29742981      case CU_TARGET_DIMS:
29752982      {
2976         if (shadersys->curr_render_target == NULL)
2983         if (shadersys->curr_render_target != NULL)
29772984         {
2978            float targetdims[2] = { 0.0f, 0.0f };
2985            float targetdims[2] = {
2986               static_cast<float>(shadersys->curr_render_target->target_width),
2987               static_cast<float>(shadersys->curr_render_target->target_height) };
29792988            m_shader->set_vector("TargetDims", 2, targetdims);
29802989         }
2981         else
2982         {
2983            float targetdims[2] = { static_cast<float>(shadersys->curr_render_target->target_width), static_cast<float>(shadersys->curr_render_target->target_height) };
2984            m_shader->set_vector("TargetDims", 2, targetdims);
2985         }
29862990         break;
29872991      }
29882992      case CU_QUAD_DIMS:
29892993      {
2990         float quaddims[2] = { shadersys->curr_poly->get_prim_width(), shadersys->curr_poly->get_prim_height() };
2991         m_shader->set_vector("QuadDims", 2, quaddims);
2994         if (shadersys->curr_poly != NULL)
2995         {
2996            float quaddims[2] = {
2997               shadersys->curr_poly->get_prim_width(),
2998               shadersys->curr_poly->get_prim_height() };
2999            m_shader->set_vector("QuadDims", 2, quaddims);
3000         }
29923001         break;
29933002      }
29943003
3004      case CU_SWAP_XY:
3005      {
3006         bool orientation_swap_xy =
3007            (d3d->window().machine().system().flags & ORIENTATION_SWAP_XY) == ORIENTATION_SWAP_XY;
3008         bool rotation_swap_xy =
3009            (d3d->window().target()->orientation() & ROT90) == ROT90 ||
3010            (d3d->window().target()->orientation() & ROT270) == ROT270;
3011         m_shader->set_bool("SwapXY", orientation_swap_xy ^ rotation_swap_xy);
3012      }
29953013      case CU_ORIENTATION_SWAP:
29963014      {
29973015         bool orientation_swap_xy =
trunk/src/osd/modules/render/d3d/d3dhlsl.h
r253014r253015
5050      CU_TARGET_DIMS,
5151      CU_QUAD_DIMS,
5252
53      CU_SWAP_XY,
5354      CU_ORIENTATION_SWAP,
5455      CU_ROTATION_SWAP,
5556      CU_ROTATION_TYPE,
trunk/src/osd/modules/render/drawd3d.cpp
r253014r253015
27342734
27352735cache_target::~cache_target()
27362736{
2737   for (int index = 0; index < 11; index++)
2738   {
2739      if (bloom_texture[index] != NULL)
2740      {
2741         (*d3dintf->texture.release)(bloom_texture[index]);
2742         bloom_texture[index] = NULL;
2743      }
2744      if (bloom_target[index] != NULL)
2745      {
2746         (*d3dintf->surface.release)(bloom_target[index]);
2747         bloom_target[index] = NULL;
2748      }
2749   }
2750
27512737   if (last_texture != NULL)
27522738   {
27532739      (*d3dintf->texture.release)(last_texture);
r253014r253015
27672753
27682754bool cache_target::init(renderer *d3d, base *d3dintf, int width, int height, int prescale_x, int prescale_y)
27692755{
2770   int bloom_index = 0;
2771   int bloom_size = (width < height) ? width : height;
2772   int bloom_width = width;
2773   int bloom_height = height;
2774   for (; bloom_size >= 2 && bloom_index < 11; bloom_size >>= 1)
2775   {
2776      bloom_width >>= 1;
2777      bloom_height >>= 1;
2778
2779      HRESULT result = (*d3dintf->device.create_texture)(d3d->get_device(), bloom_width, bloom_height, 1, D3DUSAGE_RENDERTARGET, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &bloom_texture[bloom_index]);
2780      if (result != D3D_OK)
2781      {
2782         return false;
2783      }
2784      (*d3dintf->texture.get_surface_level)(bloom_texture[bloom_index], 0, &bloom_target[bloom_index]);
2785
2786      bloom_index++;
2787   }
2788
27892756   HRESULT result = (*d3dintf->device.create_texture)(d3d->get_device(), width * prescale_x, height * prescale_y, 1, D3DUSAGE_RENDERTARGET, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &last_texture);
27902757   if (result != D3D_OK)
27912758   {
trunk/src/osd/modules/render/drawd3d.h
r253014r253015
5353
5454   cache_target *next;
5555   cache_target *prev;
56
57   surface *bloom_target[11];
58   texture *bloom_texture[11];
5956};
6057
6158/* render_target is the information about a Direct3D render target chain */


Previous 199869 Revisions Next


© 1997-2024 The MAME Team