trunk/hlsl/bloom.fx
| r253015 | r253016 | |
| 149 | 149 | { |
| 150 | 150 | float4 Position : POSITION; |
| 151 | 151 | 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; |
| 158 | 158 | }; |
| 159 | 159 | |
| 160 | 160 | struct VS_INPUT |
| 161 | 161 | { |
| 162 | | float3 Position : POSITION; |
| 162 | float4 Position : POSITION; |
| 163 | 163 | float4 Color : COLOR0; |
| 164 | 164 | float2 TexCoord : TEXCOORD0; |
| 165 | 165 | }; |
| r253015 | r253016 | |
| 167 | 167 | struct PS_INPUT |
| 168 | 168 | { |
| 169 | 169 | 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; |
| 176 | 176 | }; |
| 177 | 177 | |
| 178 | 178 | //----------------------------------------------------------------------------- |
| r253015 | r253016 | |
| 202 | 202 | |
| 203 | 203 | uniform float2 ScreenDims; |
| 204 | 204 | uniform float2 TargetDims; |
| 205 | uniform float2 SourceRect; |
| 205 | 206 | |
| 206 | | uniform float4 Level01Size; |
| 207 | | uniform float4 Level23Size; |
| 208 | | uniform float4 Level45Size; |
| 209 | | uniform float4 Level67Size; |
| 210 | | uniform float4 Level89Size; |
| 211 | | uniform float2 LevelASize; |
| 207 | uniform float2 Level0Size; |
| 208 | uniform float4 Level12Size; |
| 209 | uniform float4 Level34Size; |
| 210 | uniform float4 Level56Size; |
| 211 | uniform float4 Level78Size; |
| 212 | uniform float4 Level9ASize; |
| 212 | 213 | |
| 213 | 214 | VS_OUTPUT vs_main(VS_INPUT Input) |
| 214 | 215 | { |
| r253015 | r253016 | |
| 225 | 226 | float2 TexCoord = Input.Position.xy / ScreenDims; |
| 226 | 227 | TexCoord += 0.5f / TargetDims; // half texel offset correction (DX9) |
| 227 | 228 | |
| 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); |
| 235 | 235 | |
| 236 | 236 | return Output; |
| 237 | 237 | } |
| r253015 | r253016 | |
| 240 | 240 | // Bloom Pixel Shader |
| 241 | 241 | //----------------------------------------------------------------------------- |
| 242 | 242 | |
| 243 | | uniform float4 Level0123Weight; |
| 244 | | uniform float4 Level4567Weight; |
| 245 | | uniform float3 Level89AWeight; |
| 243 | uniform float Level0Weight; |
| 244 | uniform float2 Level12Weight; |
| 245 | uniform float2 Level34Weight; |
| 246 | uniform float2 Level56Weight; |
| 247 | uniform float2 Level78Weight; |
| 248 | uniform float2 Level9AWeight; |
| 246 | 249 | |
| 247 | | uniform int BloomBlendMode = 1; // 0 addition, 1 darken |
| 250 | uniform int BloomBlendMode = 0; // 0 addition, 1 darken |
| 248 | 251 | uniform float BloomScale; |
| 249 | 252 | uniform float3 BloomOverdrive; |
| 250 | 253 | |
| r253015 | r253016 | |
| 256 | 259 | |
| 257 | 260 | float4 ps_main(PS_INPUT Input) : COLOR |
| 258 | 261 | { |
| 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; |
| 270 | 273 | |
| 271 | 274 | float3 blend; |
| 272 | 275 | |
| 273 | 276 | // addition |
| 274 | 277 | if (BloomBlendMode == 0) |
| 275 | 278 | { |
| 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; |
| 287 | 290 | |
| 288 | 291 | float3 bloom = float3( |
| 289 | 292 | texel1 + |
| r253015 | r253016 | |
| 306 | 309 | bloom.b += bloomOverdrive.r * 0.5f; |
| 307 | 310 | bloom.b += bloomOverdrive.g * 0.5f; |
| 308 | 311 | |
| 309 | | float2 NoiseCoord = Input.TexCoord01.xy; |
| 312 | float2 NoiseCoord = Input.TexCoord0; |
| 310 | 313 | float3 NoiseFactor = GetNoiseFactor(bloom, random(NoiseCoord)); |
| 311 | 314 | |
| 312 | 315 | blend = texel0 + bloom * NoiseFactor; |
| r253015 | r253016 | |
| 326 | 329 | texel9 = min(texel0, texel9); |
| 327 | 330 | texelA = min(texel0, texelA); |
| 328 | 331 | |
| 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); |
| 340 | 343 | } |
| 341 | 344 | |
| 342 | 345 | return float4(blend, 1.0f); |
trunk/src/osd/modules/render/d3d/d3dhlsl.cpp
| r253015 | r253016 | |
| 1515 | 1515 | return next_index; |
| 1516 | 1516 | } |
| 1517 | 1517 | |
| 1518 | | curr_effect = bloom_effect; |
| 1519 | | curr_effect->update_uniforms(); |
| 1520 | | |
| 1521 | | float weight0123[4] = { |
| 1522 | | options->bloom_level0_weight, |
| 1518 | float weight12[2] = { |
| 1523 | 1519 | options->bloom_level1_weight, |
| 1524 | | options->bloom_level2_weight, |
| 1525 | | options->bloom_level3_weight |
| 1520 | options->bloom_level2_weight |
| 1526 | 1521 | }; |
| 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] = { |
| 1529 | 1527 | options->bloom_level5_weight, |
| 1530 | 1528 | options->bloom_level6_weight, |
| 1531 | | options->bloom_level7_weight |
| 1532 | 1529 | }; |
| 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] = { |
| 1535 | 1535 | options->bloom_level9_weight, |
| 1536 | 1536 | options->bloom_level10_weight |
| 1537 | 1537 | }; |
| 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]); |
| 1547 | 1538 | |
| 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 | |
| 1548 | 1556 | curr_effect->set_int("BloomBlendMode", options->bloom_blend_mode); |
| 1549 | 1557 | curr_effect->set_float("BloomScale", options->bloom_scale); |
| 1550 | 1558 | curr_effect->set_vector("BloomOverdrive", 3, options->bloom_overdrive); |
| r253015 | r253016 | |
| 3185 | 3193 | case CU_POST_FLOOR: |
| 3186 | 3194 | m_shader->set_vector("Floor", 3, options->floor); |
| 3187 | 3195 | 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 | | } |
| 3210 | 3196 | } |
| 3211 | 3197 | } |
| 3212 | 3198 | |