Previous 199869 Revisions Next

r44504 Sunday 3rd January, 2016 at 15:20:27 UTC by Jezze
Refactoring (nw)

- restructured bloom level size and weight uniforms
[hlsl]bloom.fx downsample.fx
[src/osd/modules/render/d3d]d3dhlsl.cpp d3dhlsl.h

trunk/hlsl/bloom.fx
r253015r253016
149149{
150150   float4 Position : POSITION;
151151   float4 Color : COLOR0;
152   float4 TexCoord01 : TEXCOORD0;
153   float4 TexCoord23 : TEXCOORD1;
154   float4 TexCoord45 : TEXCOORD2;
155   float4 TexCoord67 : TEXCOORD3;
156   float4 TexCoord89 : TEXCOORD4;
157   float2 TexCoordA : TEXCOORD5;
152   float2 TexCoord0 : TEXCOORD0;
153   float4 TexCoord12 : TEXCOORD1;
154   float4 TexCoord34 : TEXCOORD2;
155   float4 TexCoord56 : TEXCOORD3;
156   float4 TexCoord78 : TEXCOORD4;
157   float4 TexCoord9A : TEXCOORD5;
158158};
159159
160160struct VS_INPUT
161161{
162   float3 Position : POSITION;
162   float4 Position : POSITION;
163163   float4 Color : COLOR0;
164164   float2 TexCoord : TEXCOORD0;
165165};
r253015r253016
167167struct PS_INPUT
168168{
169169   float4 Color : COLOR0;
170   float4 TexCoord01 : TEXCOORD0;
171   float4 TexCoord23 : TEXCOORD1;
172   float4 TexCoord45 : TEXCOORD2;
173   float4 TexCoord67 : TEXCOORD3;
174   float4 TexCoord89 : TEXCOORD4;
175   float2 TexCoordA : TEXCOORD5;
170   float2 TexCoord0 : TEXCOORD0;
171   float4 TexCoord12 : TEXCOORD1;
172   float4 TexCoord34 : TEXCOORD2;
173   float4 TexCoord56 : TEXCOORD3;
174   float4 TexCoord78 : TEXCOORD4;
175   float4 TexCoord9A : TEXCOORD5;
176176};
177177
178178//-----------------------------------------------------------------------------
r253015r253016
202202
203203uniform float2 ScreenDims;
204204uniform float2 TargetDims;
205uniform float2 SourceRect;
205206
206uniform float4 Level01Size;
207uniform float4 Level23Size;
208uniform float4 Level45Size;
209uniform float4 Level67Size;
210uniform float4 Level89Size;
211uniform float2 LevelASize;
207uniform float2 Level0Size;
208uniform float4 Level12Size;
209uniform float4 Level34Size;
210uniform float4 Level56Size;
211uniform float4 Level78Size;
212uniform float4 Level9ASize;
212213
213214VS_OUTPUT vs_main(VS_INPUT Input)
214215{
r253015r253016
225226   float2 TexCoord = Input.Position.xy / ScreenDims;
226227   TexCoord += 0.5f / TargetDims; // half texel offset correction (DX9)
227228
228   Output.TexCoord01.xy = TexCoord.xy;
229   Output.TexCoord01.zw = TexCoord.xy + 0.5f / Level01Size.zw;
230   Output.TexCoord23 = TexCoord.xyxy + 0.5f / Level23Size;
231   Output.TexCoord45 = TexCoord.xyxy + 0.5f / Level45Size;
232   Output.TexCoord67 = TexCoord.xyxy + 0.5f / Level67Size;
233   Output.TexCoord89 = TexCoord.xyxy + 0.5f / Level89Size;
234   Output.TexCoordA = TexCoord.xy + 0.5f / LevelASize;
229   Output.TexCoord0 = TexCoord;
230   Output.TexCoord12 = TexCoord.xyxy + (0.5f / Level12Size);
231   Output.TexCoord34 = TexCoord.xyxy + (0.5f / Level34Size);
232   Output.TexCoord56 = TexCoord.xyxy + (0.5f / Level56Size);
233   Output.TexCoord78 = TexCoord.xyxy + (0.5f / Level78Size);
234   Output.TexCoord9A = TexCoord.xyxy + (0.5f / Level9ASize);
235235
236236   return Output;
237237}
r253015r253016
240240// Bloom Pixel Shader
241241//-----------------------------------------------------------------------------
242242
243uniform float4 Level0123Weight;
244uniform float4 Level4567Weight;
245uniform float3 Level89AWeight;
243uniform float Level0Weight;
244uniform float2 Level12Weight;
245uniform float2 Level34Weight;
246uniform float2 Level56Weight;
247uniform float2 Level78Weight;
248uniform float2 Level9AWeight;
246249
247uniform int BloomBlendMode = 1; // 0 addition, 1 darken
250uniform int BloomBlendMode = 0; // 0 addition, 1 darken
248251uniform float BloomScale;
249252uniform float3 BloomOverdrive;
250253
r253015r253016
256259
257260float4 ps_main(PS_INPUT Input) : COLOR
258261{
259   float3 texel0 = tex2D(DiffuseSampler0, Input.TexCoord01.xy).rgb;
260   float3 texel1 = tex2D(DiffuseSampler1, Input.TexCoord01.zw).rgb;
261   float3 texel2 = tex2D(DiffuseSampler2, Input.TexCoord23.xy).rgb;
262   float3 texel3 = tex2D(DiffuseSampler3, Input.TexCoord23.zw).rgb;
263   float3 texel4 = tex2D(DiffuseSampler4, Input.TexCoord45.xy).rgb;
264   float3 texel5 = tex2D(DiffuseSampler5, Input.TexCoord45.zw).rgb;
265   float3 texel6 = tex2D(DiffuseSampler6, Input.TexCoord67.xy).rgb;
266   float3 texel7 = tex2D(DiffuseSampler7, Input.TexCoord67.zw).rgb;
267   float3 texel8 = tex2D(DiffuseSampler8, Input.TexCoord89.xy).rgb;
268   float3 texel9 = tex2D(DiffuseSampler9, Input.TexCoord89.zw).rgb;
269   float3 texelA = tex2D(DiffuseSamplerA, Input.TexCoordA).rgb;
262   float3 texel0 = tex2D(DiffuseSampler0, Input.TexCoord0).rgb;
263   float3 texel1 = tex2D(DiffuseSampler1, Input.TexCoord12.xy).rgb;
264   float3 texel2 = tex2D(DiffuseSampler2, Input.TexCoord12.zw).rgb;
265   float3 texel3 = tex2D(DiffuseSampler3, Input.TexCoord34.xy).rgb;
266   float3 texel4 = tex2D(DiffuseSampler4, Input.TexCoord34.zw).rgb;
267   float3 texel5 = tex2D(DiffuseSampler5, Input.TexCoord56.xy).rgb;
268   float3 texel6 = tex2D(DiffuseSampler6, Input.TexCoord56.zw).rgb;
269   float3 texel7 = tex2D(DiffuseSampler7, Input.TexCoord78.xy).rgb;
270   float3 texel8 = tex2D(DiffuseSampler8, Input.TexCoord78.zw).rgb;
271   float3 texel9 = tex2D(DiffuseSampler9, Input.TexCoord9A.xy).rgb;
272   float3 texelA = tex2D(DiffuseSamplerA, Input.TexCoord9A.zw).rgb;
270273
271274   float3 blend;
272275
273276   // addition
274277   if (BloomBlendMode == 0)
275278   {
276      texel0 *= Level0123Weight.x;
277      texel1 *= Level0123Weight.y;
278      texel2 *= Level0123Weight.z;
279      texel3 *= Level0123Weight.w;
280      texel4 *= Level4567Weight.x;
281      texel5 *= Level4567Weight.y;
282      texel6 *= Level4567Weight.z;
283      texel7 *= Level4567Weight.w;
284      texel8 *= Level89AWeight.x;
285      texel9 *= Level89AWeight.y;
286      texelA *= Level89AWeight.z;
279      texel0 *= Level0Weight;
280      texel1 *= Level12Weight.x;
281      texel2 *= Level12Weight.y;
282      texel3 *= Level34Weight.x;
283      texel4 *= Level34Weight.y;
284      texel5 *= Level56Weight.x;
285      texel6 *= Level56Weight.y;
286      texel7 *= Level78Weight.x;
287      texel8 *= Level78Weight.y;
288      texel9 *= Level9AWeight.x;
289      texelA *= Level9AWeight.y;
287290
288291      float3 bloom = float3(
289292         texel1 +
r253015r253016
306309      bloom.b += bloomOverdrive.r * 0.5f;
307310      bloom.b += bloomOverdrive.g * 0.5f;
308311
309      float2 NoiseCoord = Input.TexCoord01.xy;
312      float2 NoiseCoord = Input.TexCoord0;
310313      float3 NoiseFactor = GetNoiseFactor(bloom, random(NoiseCoord));
311314
312315      blend = texel0 + bloom * NoiseFactor;
r253015r253016
326329      texel9 = min(texel0, texel9);
327330      texelA = min(texel0, texelA);
328331
329      blend = texel0 * Level0123Weight.x;
330      blend = lerp(blend, texel1, Level0123Weight.y * BloomScale);
331      blend = lerp(blend, texel2, Level0123Weight.z * BloomScale);
332      blend = lerp(blend, texel3, Level0123Weight.w * BloomScale);
333      blend = lerp(blend, texel4, Level4567Weight.x * BloomScale);
334      blend = lerp(blend, texel5, Level4567Weight.y * BloomScale);
335      blend = lerp(blend, texel6, Level4567Weight.z * BloomScale);
336      blend = lerp(blend, texel7, Level4567Weight.w * BloomScale);
337      blend = lerp(blend, texel8, Level89AWeight.x * BloomScale);
338      blend = lerp(blend, texel9, Level89AWeight.y * BloomScale);
339      blend = lerp(blend, texelA, Level89AWeight.z * BloomScale);
332      blend = texel0 * Level0Weight;
333      blend = lerp(blend, texel1, Level12Weight.x * BloomScale);
334      blend = lerp(blend, texel2, Level12Weight.y * BloomScale);
335      blend = lerp(blend, texel3, Level34Weight.x * BloomScale);
336      blend = lerp(blend, texel4, Level34Weight.y * BloomScale);
337      blend = lerp(blend, texel5, Level56Weight.x * BloomScale);
338      blend = lerp(blend, texel6, Level56Weight.y * BloomScale);
339      blend = lerp(blend, texel7, Level78Weight.x * BloomScale);
340      blend = lerp(blend, texel8, Level78Weight.y * BloomScale);
341      blend = lerp(blend, texel9, Level9AWeight.x * BloomScale);
342      blend = lerp(blend, texelA, Level9AWeight.y * BloomScale);
340343   }
341344
342345   return float4(blend, 1.0f);
trunk/hlsl/downsample.fx
r253015r253016
3535
3636struct VS_INPUT
3737{
38   float3 Position : POSITION;
38   float4 Position : POSITION;
3939   float4 Color : COLOR0;
4040   float2 TexCoord : TEXCOORD0;
4141};
r253015r253016
5353
5454uniform float2 ScreenDims;
5555uniform float2 TargetDims;
56uniform float2 SourceRect;
5657
5758uniform bool PrepareVector;
5859
r253015r253016
7273
7374   float2 TexCoord = Input.Position.xy / ScreenDims;
7475   TexCoord += PrepareVector
75      ? 0.5f / TargetDims // half texel offset correction (DX9)
76      ? 0.5f / TargetDims // half texel offset correction (DX9) - only for vector grpahics
7677      : 0.0f;
7778
7879   Output.TexCoord01.xy = TexCoord + float2(-0.5f, -0.5f) * TargetTexelDims;
r253015r253016
8990
9091float4 ps_main(PS_INPUT Input) : COLOR
9192{
92   float4 texel0 = tex2D(DiffuseSampler, Input.TexCoord01.xy);
93   float4 texel1 = tex2D(DiffuseSampler, Input.TexCoord01.zw);
94   float4 texel2 = tex2D(DiffuseSampler, Input.TexCoord23.xy);
95   float4 texel3 = tex2D(DiffuseSampler, Input.TexCoord23.zw);
93   float3 texel0 = tex2D(DiffuseSampler, Input.TexCoord01.xy).rgb;
94   float3 texel1 = tex2D(DiffuseSampler, Input.TexCoord01.zw).rgb;
95   float3 texel2 = tex2D(DiffuseSampler, Input.TexCoord23.xy).rgb;
96   float3 texel3 = tex2D(DiffuseSampler, Input.TexCoord23.zw).rgb;
9697
97   float4 outTexel = (texel0 + texel1 + texel2 + texel3) / 4.0;
98   float3 outTexel = (texel0 + texel1 + texel2 + texel3) / 4.0;
9899
99   return float4(outTexel.rgb, 1.0f);
100   return float4(outTexel, 1.0f);
100101}
101102
102103//-----------------------------------------------------------------------------
trunk/src/osd/modules/render/d3d/d3dhlsl.cpp
r253015r253016
15151515      return next_index;
15161516   }
15171517
1518   curr_effect = bloom_effect;
1519   curr_effect->update_uniforms();
1520
1521   float weight0123[4] = {
1522      options->bloom_level0_weight,
1518   float weight12[2] = {
15231519      options->bloom_level1_weight,
1524      options->bloom_level2_weight,
1525      options->bloom_level3_weight
1520      options->bloom_level2_weight
15261521   };
1527   float weight4567[4] = {
1528      options->bloom_level4_weight,
1522   float weight34[2] = {
1523      options->bloom_level3_weight,
1524      options->bloom_level4_weight
1525   };
1526   float weight56[2] = {
15291527      options->bloom_level5_weight,
15301528      options->bloom_level6_weight,
1531      options->bloom_level7_weight
15321529   };
1533   float weight89A[3]  = {
1534      options->bloom_level8_weight,
1530   float weight78[2] = {
1531      options->bloom_level7_weight,
1532      options->bloom_level8_weight
1533   };
1534   float weight9A[2]  = {
15351535      options->bloom_level9_weight,
15361536      options->bloom_level10_weight
15371537   };
1538   curr_effect->set_vector("Level0123Weight", 4, weight0123);
1539   curr_effect->set_vector("Level4567Weight", 4, weight4567);
1540   curr_effect->set_vector("Level89AWeight", 3, weight89A);
1541   curr_effect->set_vector("Level01Size", 4, bloom_dims[0]);
1542   curr_effect->set_vector("Level23Size", 4, bloom_dims[2]);
1543   curr_effect->set_vector("Level45Size", 4, bloom_dims[4]);
1544   curr_effect->set_vector("Level67Size", 4, bloom_dims[6]);
1545   curr_effect->set_vector("Level89Size", 4, bloom_dims[8]);
1546   curr_effect->set_vector("LevelASize", 2, bloom_dims[10]);
15471538
1539   curr_effect = bloom_effect;
1540   curr_effect->update_uniforms();
1541
1542   curr_effect->set_float ("Level0Weight", options->bloom_level0_weight);
1543   curr_effect->set_vector("Level12Weight", 2, weight12);
1544   curr_effect->set_vector("Level34Weight", 2, weight34);
1545   curr_effect->set_vector("Level56Weight", 2, weight56);
1546   curr_effect->set_vector("Level78Weight", 2, weight78);
1547   curr_effect->set_vector("Level9AWeight", 2, weight9A);
1548
1549   curr_effect->set_vector("Level0Size", 2, bloom_dims[0]);
1550   curr_effect->set_vector("Level12Size", 4, bloom_dims[1]);
1551   curr_effect->set_vector("Level34Size", 4, bloom_dims[3]);
1552   curr_effect->set_vector("Level56Size", 4, bloom_dims[5]);
1553   curr_effect->set_vector("Level78Size", 4, bloom_dims[7]);
1554   curr_effect->set_vector("Level9ASize", 4, bloom_dims[9]);
1555
15481556   curr_effect->set_int("BloomBlendMode", options->bloom_blend_mode);
15491557   curr_effect->set_float("BloomScale", options->bloom_scale);
15501558   curr_effect->set_vector("BloomOverdrive", 3, options->bloom_overdrive);
r253015r253016
31853193      case CU_POST_FLOOR:
31863194         m_shader->set_vector("Floor", 3, options->floor);
31873195         break;
3188
3189      case CU_BLOOM_RESCALE:
3190         m_shader->set_float("BloomRescale", options->bloom_scale);
3191         break;
3192      case CU_BLOOM_LVL0123_WEIGHTS:
3193      {
3194         float weight0123[4] = { options->bloom_level0_weight, options->bloom_level1_weight, options->bloom_level2_weight, options->bloom_level3_weight };
3195         m_shader->set_vector("Level0123Weight", 4, weight0123);
3196         break;
3197      }
3198      case CU_BLOOM_LVL4567_WEIGHTS:
3199      {
3200         float weight4567[4] = { options->bloom_level4_weight, options->bloom_level5_weight, options->bloom_level6_weight, options->bloom_level7_weight };
3201         m_shader->set_vector("Level4567Weight", 4, weight4567);
3202         break;
3203      }
3204      case CU_BLOOM_LVL89A_WEIGHTS:
3205      {
3206         float weight89A[3]  = { options->bloom_level8_weight, options->bloom_level9_weight, options->bloom_level10_weight };
3207         m_shader->set_vector("Level89AWeight", 3, weight89A);
3208         break;
3209      }
32103196   }
32113197}
32123198
trunk/src/osd/modules/render/d3d/d3dhlsl.h
r253015r253016
102102      CU_POST_POWER,
103103      CU_POST_FLOOR,
104104
105      CU_BLOOM_RESCALE,
106      CU_BLOOM_LVL0123_WEIGHTS,
107      CU_BLOOM_LVL4567_WEIGHTS,
108      CU_BLOOM_LVL89A_WEIGHTS,
109
110105      CU_COUNT
111106   };
112107


Previous 199869 Revisions Next


© 1997-2024 The MAME Team