hlsl/post.fx
| r11575 | r11576 | |
| 1 | 1 | //----------------------------------------------------------------------------- |
| 2 | | // Post-Processing Effect |
| 2 | // Scanline & Shadowmask Effect |
| 3 | 3 | //----------------------------------------------------------------------------- |
| 4 | 4 | |
| 5 | 5 | texture Diffuse; |
| r11575 | r11576 | |
| 38 | 38 | float4 Color : COLOR0; |
| 39 | 39 | float2 TexCoord : TEXCOORD0; |
| 40 | 40 | float2 ExtraInfo : TEXCOORD1; |
| 41 | | float3 CoordX : TEXCOORD2; |
| 42 | | float3 CoordY : TEXCOORD3; |
| 43 | | float2 ShadowCoord : TEXCOORD4; |
| 44 | 41 | }; |
| 45 | 42 | |
| 46 | 43 | struct VS_INPUT |
| r11575 | r11576 | |
| 56 | 53 | float4 Color : COLOR0; |
| 57 | 54 | float2 TexCoord : TEXCOORD0; |
| 58 | 55 | float2 ExtraInfo : TEXCOORD1; |
| 59 | | float3 CoordX : TEXCOORD2; |
| 60 | | float3 CoordY : TEXCOORD3; |
| 61 | | float2 ShadowCoord : TEXCOORD4; |
| 62 | 56 | }; |
| 63 | 57 | |
| 64 | 58 | //----------------------------------------------------------------------------- |
| 65 | | // Post-Processing Vertex Shader |
| 59 | // Scanline & Shadowmask Vertex Shader |
| 66 | 60 | //----------------------------------------------------------------------------- |
| 67 | 61 | |
| 68 | | uniform float RedConvergeX; |
| 69 | | uniform float RedConvergeY; |
| 70 | | uniform float GrnConvergeX; |
| 71 | | uniform float GrnConvergeY; |
| 72 | | uniform float BluConvergeX; |
| 73 | | uniform float BluConvergeY; |
| 74 | | |
| 75 | 62 | uniform float TargetWidth; |
| 76 | 63 | uniform float TargetHeight; |
| 77 | 64 | |
| r11575 | r11576 | |
| 81 | 68 | uniform float WidthRatio; |
| 82 | 69 | uniform float HeightRatio; |
| 83 | 70 | |
| 84 | | uniform float RedRadialConvergeX; |
| 85 | | uniform float RedRadialConvergeY; |
| 86 | | uniform float GrnRadialConvergeX; |
| 87 | | uniform float GrnRadialConvergeY; |
| 88 | | uniform float BluRadialConvergeX; |
| 89 | | uniform float BluRadialConvergeY; |
| 90 | | |
| 91 | 71 | VS_OUTPUT vs_main(VS_INPUT Input) |
| 92 | 72 | { |
| 93 | 73 | VS_OUTPUT Output = (VS_OUTPUT)0; |
| 94 | 74 | |
| 95 | | float2 invDims = float2(1.0f / RawWidth, 1.0f / RawHeight); |
| 96 | | float2 Ratios = float2(1.0f / WidthRatio, 1.0f / HeightRatio); |
| 97 | 75 | Output.Position = float4(Input.Position.xyz, 1.0f); |
| 98 | 76 | Output.Position.x /= TargetWidth; |
| 99 | 77 | Output.Position.y /= TargetHeight; |
| r11575 | r11576 | |
| 102 | 80 | Output.Position.y -= 0.5f; |
| 103 | 81 | Output.Position *= float4(2.0f, 2.0f, 1.0f, 1.0f); |
| 104 | 82 | Output.Color = Input.Color; |
| 105 | | Output.TexCoord = Input.TexCoord;//(Input.TexCoord - float2(0.5f, 0.5f)) / 8.0f + float2(0.25f, 0.25f); |
| 83 | float2 InvTexSize = float2(1.0f / TargetWidth, 1.0f / TargetHeight); |
| 84 | float2 TexCoord = (Input.Position.xy * InvTexSize) / float2(WidthRatio, HeightRatio); |
| 85 | Output.TexCoord = TexCoord;//(Input.TexCoord - float2(0.5f, 0.5f)) / 8.0f + float2(0.25f, 0.25f); |
| 106 | 86 | Output.ExtraInfo = Input.ExtraInfo; |
| 107 | 87 | |
| 108 | | Output.CoordX.x = ((((Output.TexCoord.x / Ratios.x) - 0.5f)) * (1.0f + RedRadialConvergeX / RawWidth) + 0.5f) * Ratios.x + RedConvergeX * invDims.x; |
| 109 | | Output.CoordX.y = ((((Output.TexCoord.x / Ratios.x) - 0.5f)) * (1.0f + GrnRadialConvergeX / RawWidth) + 0.5f) * Ratios.x + GrnConvergeX * invDims.x; |
| 110 | | Output.CoordX.z = ((((Output.TexCoord.x / Ratios.x) - 0.5f)) * (1.0f + BluRadialConvergeX / RawWidth) + 0.5f) * Ratios.x + GrnConvergeX * invDims.x; |
| 111 | | |
| 112 | | Output.CoordY.x = ((((Output.TexCoord.y / Ratios.y) - 0.5f)) * (1.0f + RedRadialConvergeY / RawHeight) + 0.5f) * Ratios.y + RedConvergeY * invDims.y; |
| 113 | | Output.CoordY.y = ((((Output.TexCoord.y / Ratios.y) - 0.5f)) * (1.0f + GrnRadialConvergeY / RawHeight) + 0.5f) * Ratios.y + BluConvergeY * invDims.y; |
| 114 | | Output.CoordY.z = ((((Output.TexCoord.y / Ratios.y) - 0.5f)) * (1.0f + BluRadialConvergeY / RawHeight) + 0.5f) * Ratios.y + BluConvergeY * invDims.y; |
| 115 | | |
| 116 | | Output.ShadowCoord = Output.TexCoord * float2(RawWidth, RawHeight); |
| 117 | 88 | return Output; |
| 118 | 89 | } |
| 119 | 90 | |
| r11575 | r11576 | |
| 123 | 94 | |
| 124 | 95 | uniform float PI = 3.14159265f; |
| 125 | 96 | |
| 126 | | uniform float PincushionAmountX = 0.1f; |
| 127 | | uniform float PincushionAmountY = 0.1f; |
| 97 | uniform float PincushionAmount = 0.00f; |
| 98 | uniform float CurvatureAmount = 0.08f; |
| 128 | 99 | |
| 129 | 100 | uniform float ScanlineAmount = 1.0f; |
| 130 | 101 | uniform float ScanlineScale = 1.0f; |
| r11575 | r11576 | |
| 132 | 103 | uniform float ScanlineBrightOffset = 1.0f; |
| 133 | 104 | uniform float ScanlineOffset = 1.0f; |
| 134 | 105 | |
| 135 | | uniform float RedFromRed = 1.0f; |
| 136 | | uniform float RedFromGrn = 0.0f; |
| 137 | | uniform float RedFromBlu = 0.0f; |
| 138 | | uniform float GrnFromRed = 0.0f; |
| 139 | | uniform float GrnFromGrn = 1.0f; |
| 140 | | uniform float GrnFromBlu = 0.0f; |
| 141 | | uniform float BluFromRed = 0.0f; |
| 142 | | uniform float BluFromGrn = 0.0f; |
| 143 | | uniform float BluFromBlu = 1.0f; |
| 144 | | |
| 145 | | uniform float YfromY = 1.0f; |
| 146 | | uniform float YfromI = 0.0f; |
| 147 | | uniform float YfromQ = 0.0f; |
| 148 | | uniform float IfromY = 0.0f; |
| 149 | | uniform float IfromI = 1.0f; |
| 150 | | uniform float IfromQ = 0.0f; |
| 151 | | uniform float QfromY = 0.0f; |
| 152 | | uniform float QfromI = 0.0f; |
| 153 | | uniform float QfromQ = 1.0f; |
| 154 | | |
| 155 | | uniform float RedOffset = 0.0f; |
| 156 | | uniform float GrnOffset = 0.0f; |
| 157 | | uniform float BluOffset = 0.0f; |
| 158 | | |
| 159 | | uniform float RedScale = 1.0f; |
| 160 | | uniform float GrnScale = 1.0f; |
| 161 | | uniform float BluScale = 1.0f; |
| 162 | | |
| 163 | | uniform float RedFloor = 0.0f; |
| 164 | | uniform float GrnFloor = 0.0f; |
| 165 | | uniform float BluFloor = 0.0f; |
| 166 | | |
| 167 | | uniform float Saturation = 1.0f; |
| 168 | | |
| 169 | | uniform float YScale = 1.0f; |
| 170 | | uniform float IScale = 1.0f; |
| 171 | | uniform float QScale = 1.0f; |
| 172 | | uniform float YOffset = 0.0f; |
| 173 | | uniform float IOffset = 0.0f; |
| 174 | | uniform float QOffset = 0.0f; |
| 175 | | |
| 176 | | uniform float RedPower = 2.2f; |
| 177 | | uniform float GrnPower = 2.2f; |
| 178 | | uniform float BluPower = 2.2f; |
| 179 | | |
| 180 | | uniform float EdgeDetectScale = 1.0f; |
| 181 | | uniform float EdgeToBaseRatio = 0.0f; |
| 182 | | |
| 183 | | uniform float SubsampleLength = 3.0f; |
| 184 | | |
| 185 | | uniform float CurrFrame = 0.0f; |
| 186 | | uniform float CrawlWidth = 3.0f; |
| 187 | | uniform float CrawlHeight = 3.0f; |
| 188 | | uniform float CrawlRate = 3.0f; |
| 189 | | |
| 190 | 106 | uniform float UseShadow = 0.0f; |
| 191 | 107 | uniform float ShadowBrightness = 1.0f; |
| 192 | 108 | uniform float ShadowPixelSizeX = 3.0f; |
| 193 | 109 | uniform float ShadowPixelSizeY = 3.0f; |
| 110 | uniform float ShadowMaskSizeX = 3.0f; |
| 111 | uniform float ShadowMaskSizeY = 3.0f; |
| 194 | 112 | uniform float ShadowU = 0.375f; |
| 195 | 113 | uniform float ShadowV = 0.375f; |
| 196 | 114 | uniform float ShadowWidth = 8.0f; |
| r11575 | r11576 | |
| 201 | 119 | float2 Ratios = float2(WidthRatio, HeightRatio); |
| 202 | 120 | |
| 203 | 121 | // -- Screen Pincushion Calculation -- |
| 204 | | float2 UnitCoord = Input.TexCoord * Ratios * 2.0f - 1.0f; |
| 122 | float2 PinViewpointOffset = float2(0.0f, 0.0f); |
| 123 | float2 PinUnitCoord = (Input.TexCoord + PinViewpointOffset) * Ratios * 2.0f - 1.0f; |
| 124 | float PincushionR2 = pow(length(PinUnitCoord), 2.0f) / pow(length(Ratios), 2.0f); |
| 125 | float2 PincushionCurve = PinUnitCoord * PincushionAmount * PincushionR2; |
| 126 | float2 BaseCoord = Input.TexCoord; |
| 127 | BaseCoord -= 0.5f / Ratios; |
| 128 | BaseCoord *= 1.0f - PincushionAmount * Ratios * 0.2f; // Warning: Magic constant |
| 129 | BaseCoord += 0.5f / Ratios; |
| 130 | BaseCoord += PincushionCurve; |
| 205 | 131 | |
| 206 | | float PincushionR2 = pow(length(UnitCoord),2.0f) / pow(length(Ratios), 2.0f); |
| 207 | | float2 PincushionCurve = UnitCoord * PincushionAmountX * PincushionR2; |
| 208 | | float2 BaseCoord = Input.TexCoord + PincushionCurve; |
| 132 | float2 CurveViewpointOffset = float2(0.2f, 0.0f); |
| 133 | float2 CurveUnitCoord = (Input.TexCoord + CurveViewpointOffset) * 2.0f - 1.0f; |
| 134 | float CurvatureR2 = pow(length(CurveUnitCoord),2.0f) / pow(length(Ratios), 2.0f); |
| 135 | float2 CurvatureCurve = CurveUnitCoord * CurvatureAmount * CurvatureR2; |
| 136 | float2 ScreenCurveCoord = Input.TexCoord + CurvatureCurve; |
| 209 | 137 | |
| 138 | float2 CurveClipUnitCoord = Input.TexCoord * Ratios * 2.0f - 1.0f; |
| 139 | float CurvatureClipR2 = pow(length(CurveClipUnitCoord),2.0f) / pow(length(Ratios), 2.0f); |
| 140 | float2 CurvatureClipCurve = CurveClipUnitCoord * CurvatureAmount * CurvatureClipR2; |
| 141 | float2 ScreenClipCoord = Input.TexCoord; |
| 142 | ScreenClipCoord -= 0.5f / Ratios; |
| 143 | ScreenClipCoord *= 1.0f - CurvatureAmount * Ratios * 0.2f; // Warning: Magic constant |
| 144 | ScreenClipCoord += 0.5f / Ratios; |
| 145 | ScreenClipCoord += CurvatureClipCurve; |
| 146 | |
| 210 | 147 | // RGB Pincushion Calculation |
| 211 | | float3 PincushionCurveX = UnitCoord.x * PincushionAmountX * PincushionR2; |
| 212 | | float3 PincushionCurveY = UnitCoord.y * PincushionAmountX * PincushionR2; |
| 148 | float3 PincushionCurveX = PinUnitCoord.x * PincushionAmount * PincushionR2; |
| 149 | float3 PincushionCurveY = PinUnitCoord.y * PincushionAmount * PincushionR2; |
| 213 | 150 | |
| 214 | | float4 BaseTexel = tex2D(DiffuseSampler, BaseCoord); |
| 151 | float4 BaseTexel = tex2D(DiffuseSampler, BaseCoord * Ratios); |
| 215 | 152 | |
| 216 | 153 | // -- Alpha Clipping (1px border in drawd3d does not work for some reason) -- |
| 217 | | clip((BaseCoord.x < 1.0f / TargetWidth) ? -1 : 1); |
| 218 | | clip((BaseCoord.y < 3.0f / TargetHeight) ? -1 : 1); |
| 219 | | clip((BaseCoord.x > 1.0f / WidthRatio) ? -1 : 1); |
| 220 | | clip((BaseCoord.y > 1.0f / HeightRatio) ? -1 : 1); |
| 154 | clip((ScreenClipCoord.x < 1.0f / TargetWidth) ? -1 : 1); |
| 155 | clip((ScreenClipCoord.y < 3.0f / TargetHeight) ? -1 : 1); |
| 156 | clip((ScreenClipCoord.x > 1.0f / WidthRatio) ? -1 : 1); |
| 157 | clip((ScreenClipCoord.y > 1.0f / HeightRatio) ? -1 : 1); |
| 221 | 158 | |
| 222 | | // -- Chroma Subsampling & RGB Deconvergence -- |
| 223 | | float3 CoordX = Input.CoordX + PincushionCurveX; |
| 224 | | float3 CoordY = Input.CoordY + PincushionCurveY; |
| 225 | | float RedTexel = tex2D(DiffuseSampler, float2(CoordX.x, CoordY.x)).r; |
| 226 | | float GrnTexel = tex2D(DiffuseSampler, float2(CoordX.y, CoordY.y)).g; |
| 227 | | float BluTexel = tex2D(DiffuseSampler, float2(CoordX.z, CoordY.z)).b; |
| 228 | | |
| 229 | | float ChromaSubsampleWidth = RawWidth / SubsampleLength; |
| 230 | | float LumaSubsampleWidth = RawWidth / SubsampleLength; // For now |
| 231 | | float3 YFrac = frac((CoordY * RawHeight) / CrawlHeight); |
| 232 | | float3 CrawlPercent = frac(CurrFrame / CrawlRate + (YFrac - frac(YFrac * CrawlWidth) / CrawlWidth)) * CrawlWidth; |
| 233 | | float3 ChromaCoordX = Input.CoordX + CrawlPercent / RawWidth; |
| 234 | | float3 ChannelFrac = frac((ChromaCoordX + PincushionCurveX) * ChromaSubsampleWidth); |
| 235 | | ChromaCoordX = ((ChromaCoordX + PincushionCurveX) * ChromaSubsampleWidth - ChannelFrac) / ChromaSubsampleWidth + ChannelFrac / (ChromaSubsampleWidth * 2.0f); |
| 236 | | float3 ChromaCoordY = Input.CoordY + PincushionCurveY; |
| 237 | | |
| 238 | | float3 BaseTexelRight = tex2D(DiffuseSampler, BaseCoord + float2(1.0f / TargetWidth, 0.0f)).rgb; |
| 239 | | float3 BaseTexelUpper = tex2D(DiffuseSampler, BaseCoord + float2(0.0f, 1.0f / TargetHeight)).rgb; |
| 240 | | |
| 241 | | float3 UpperDifference = abs(BaseTexel.rgb - BaseTexelUpper); |
| 242 | | float3 RightDifference = abs(BaseTexel.rgb - BaseTexelRight); |
| 243 | | float3 EdgeDifference = (UpperDifference + RightDifference) * EdgeDetectScale; |
| 244 | | |
| 245 | | float RedChromaTexel = tex2D(DiffuseSampler, float2(ChromaCoordX.x, ChromaCoordY.x)).r; |
| 246 | | float GrnChromaTexel = tex2D(DiffuseSampler, float2(ChromaCoordX.y, ChromaCoordY.y)).g; |
| 247 | | float BluChromaTexel = tex2D(DiffuseSampler, float2(ChromaCoordX.z, ChromaCoordY.z)).b; |
| 248 | | |
| 249 | | float3 LumaTexel = float3(RedTexel, GrnTexel, BluTexel); |
| 250 | | float3 ChromaTexel = lerp(float3(RedChromaTexel, GrnChromaTexel, BluChromaTexel), LumaTexel, ChannelFrac); |
| 251 | | |
| 252 | | // -- RGB Tint & Shift -- |
| 253 | | float ShiftedRed = dot(LumaTexel, float3(RedFromRed, RedFromGrn, RedFromBlu)); |
| 254 | | float ShiftedGrn = dot(LumaTexel, float3(GrnFromRed, GrnFromGrn, GrnFromBlu)); |
| 255 | | float ShiftedBlu = dot(LumaTexel, float3(BluFromRed, BluFromGrn, BluFromBlu)); |
| 256 | | float ShiftedRedChroma = dot(ChromaTexel, float3(RedFromRed, RedFromGrn, RedFromBlu)); |
| 257 | | float ShiftedGrnChroma = dot(ChromaTexel, float3(GrnFromRed, GrnFromGrn, GrnFromBlu)); |
| 258 | | float ShiftedBluChroma = dot(ChromaTexel, float3(BluFromRed, BluFromGrn, BluFromBlu)); |
| 259 | | float EdgeRed = dot(EdgeDifference, float3(RedFromRed, RedFromGrn, RedFromBlu)); |
| 260 | | float EdgeGrn = dot(EdgeDifference, float3(GrnFromRed, GrnFromGrn, GrnFromBlu)); |
| 261 | | float EdgeBlu = dot(EdgeDifference, float3(BluFromRed, BluFromGrn, BluFromBlu)); |
| 262 | | |
| 263 | | // -- RGB Offset & Scale -- |
| 264 | | float3 OutTexelLuma = float3(ShiftedRed, ShiftedGrn, ShiftedBlu) * float3(RedScale, GrnScale, BluScale) + float3(RedOffset, GrnOffset, BluOffset); |
| 265 | | float3 OutTexelChroma = float3(ShiftedRedChroma, ShiftedGrnChroma, ShiftedBluChroma) * float3(RedScale, GrnScale, BluScale) + float3(RedOffset, GrnOffset, BluOffset); |
| 266 | | |
| 267 | | // -- Saturation -- |
| 268 | | float OutLumaLuma = dot(OutTexelLuma, float3(0.3f, 0.59f, 0.11f)); |
| 269 | | float3 OutChromaLuma = OutTexelLuma - float3(OutLumaLuma, OutLumaLuma, OutLumaLuma); |
| 270 | | float3 SaturatedLuma = OutLumaLuma + OutChromaLuma * Saturation; |
| 271 | | |
| 272 | | float OutLumaChroma = dot(OutTexelChroma, float3(0.3f, 0.59f, 0.11f)); |
| 273 | | float3 OutChromaChroma = OutTexelChroma - float3(OutLumaChroma, OutLumaChroma, OutLumaChroma); |
| 274 | | float3 SaturatedChroma = OutLumaChroma + OutChromaChroma * Saturation; |
| 275 | | |
| 276 | | // -- YIQ Convolution -- |
| 277 | | float Y = dot(SaturatedLuma, float3(0.299f, 0.587f, 0.114f)); |
| 278 | | float I = dot(SaturatedChroma, float3(0.595716f, -0.274453f, -0.321263f)); |
| 279 | | float Q = dot(SaturatedChroma, float3(0.211456f, -0.522591f, 0.311135f)); |
| 280 | | Y = dot(float3(Y, I, Q), float3(YfromY, YfromI, YfromQ)); |
| 281 | | I = dot(float3(Y, I, Q), float3(IfromY, IfromI, IfromQ)); |
| 282 | | Q = dot(float3(Y, I, Q), float3(QfromY, QfromI, QfromQ)); |
| 283 | | float3 OutYIQ = float3(Y, I, Q) * float3(YScale, IScale, QScale) + float3(YOffset, IOffset, QOffset); |
| 284 | | float3 OutRGB = float3(dot(OutYIQ, float3(1.0f, 0.9563f, 0.6210f)), dot(OutYIQ, float3(1.0f, -0.2721f, -0.6474f)), dot(OutYIQ, float3(1.0f, -1.1070f, 1.7046f))); |
| 285 | | |
| 286 | | OutRGB = lerp(OutRGB, float3(EdgeRed, EdgeGrn, EdgeBlu), EdgeToBaseRatio); |
| 287 | | |
| 288 | | OutRGB.r = pow(OutRGB.r, RedPower); |
| 289 | | OutRGB.g = pow(OutRGB.g, GrnPower); |
| 290 | | OutRGB.b = pow(OutRGB.b, BluPower); |
| 291 | | |
| 292 | | // -- Color Compression (increasing the floor of the signal without affecting the ceiling) -- |
| 293 | | OutRGB = float3(RedFloor + (1.0f - RedFloor) * OutRGB.r, GrnFloor + (1.0f - GrnFloor) * OutRGB.g, BluFloor + (1.0f - BluFloor) * OutRGB.b); |
| 294 | | |
| 295 | 159 | // -- Scanline Simulation -- |
| 296 | | float3 ScanBrightness = lerp(1.0f, abs(sin(((CoordY * RawHeight * ScanlineScale) * PI + ScanlineOffset * RawHeight))) * ScanlineBrightScale + ScanlineBrightOffset, ScanlineAmount); |
| 297 | | float3 Scanned = OutRGB * ScanBrightness; |
| 160 | float3 ScanBrightness = lerp(1.0f, abs(sin(((BaseCoord.y * Ratios.y * RawHeight * ScanlineScale) * PI + ScanlineOffset * RawHeight))) * ScanlineBrightScale + ScanlineBrightOffset, ScanlineAmount); |
| 161 | float3 Scanned = BaseTexel.rgb * ScanBrightness; |
| 298 | 162 | |
| 299 | | float2 ShadowCoord = BaseCoord * float2(RawWidth, RawHeight); |
| 300 | | float ShadowCoordX = frac(ShadowCoord.x / ShadowPixelSizeX) * ShadowU + 0.5f / (ShadowWidth * ShadowU); |
| 301 | | float ShadowCoordY = frac(ShadowCoord.y / ShadowPixelSizeY) * ShadowV + 0.5f / (ShadowHeight * ShadowV); |
| 302 | | float3 ShadowTexel = lerp(1.0f, tex2D(ShadowSampler, float2(ShadowCoordX, ShadowCoordY)), UseShadow); |
| 163 | float2 ShadowDims = float2(ShadowWidth, ShadowHeight); |
| 164 | float2 ShadowUV = float2(ShadowU, ShadowV); |
| 165 | float2 ShadowMaskSize = float2(ShadowMaskSizeX, ShadowMaskSizeY); |
| 166 | float2 ShadowFrac = frac(ScreenCurveCoord * ShadowMaskSize * Ratios * 0.5f); |
| 167 | float2 ShadowCoord = ShadowFrac * ShadowUV + 2.5f / ShadowDims; |
| 168 | float3 ShadowTexel = lerp(1.0f, tex2D(ShadowSampler, ShadowCoord), UseShadow); |
| 303 | 169 | |
| 304 | 170 | // -- Final Pixel -- |
| 305 | 171 | float4 Output = lerp(Input.Color, float4(Scanned * lerp(1.0f, ShadowTexel * 1.25f, ShadowBrightness), BaseTexel.a) * Input.Color, Input.ExtraInfo.x); |
| r11575 | r11576 | |
| 308 | 174 | } |
| 309 | 175 | |
| 310 | 176 | //----------------------------------------------------------------------------- |
| 311 | | // Post-Processing Effect |
| 177 | // Scanline & Shadowmask Effect |
| 312 | 178 | //----------------------------------------------------------------------------- |
| 313 | 179 | |
| 314 | | technique TestTechnique |
| 180 | technique ScanMaskTechnique |
| 315 | 181 | { |
| 316 | 182 | pass Pass0 |
| 317 | 183 | { |
hlsl/color_heavy.fx
| r0 | r11576 | |
| 1 | //----------------------------------------------------------------------------- |
| 2 | // Color-Convolution Effect |
| 3 | //----------------------------------------------------------------------------- |
| 4 | |
| 5 | texture Diffuse; |
| 6 | |
| 7 | sampler DiffuseSampler = sampler_state |
| 8 | { |
| 9 | Texture = <Diffuse>; |
| 10 | MipFilter = LINEAR; |
| 11 | MinFilter = LINEAR; |
| 12 | MagFilter = LINEAR; |
| 13 | AddressU = CLAMP; |
| 14 | AddressV = CLAMP; |
| 15 | AddressW = CLAMP; |
| 16 | }; |
| 17 | |
| 18 | //----------------------------------------------------------------------------- |
| 19 | // Vertex Definitions |
| 20 | //----------------------------------------------------------------------------- |
| 21 | |
| 22 | struct VS_OUTPUT |
| 23 | { |
| 24 | float4 Position : POSITION; |
| 25 | float4 Color : COLOR0; |
| 26 | float2 TexCoord : TEXCOORD0; |
| 27 | float2 ExtraInfo : TEXCOORD1; |
| 28 | }; |
| 29 | |
| 30 | struct VS_INPUT |
| 31 | { |
| 32 | float4 Position : POSITION; |
| 33 | float4 Color : COLOR0; |
| 34 | float2 TexCoord : TEXCOORD0; |
| 35 | float2 ExtraInfo : TEXCOORD1; |
| 36 | }; |
| 37 | |
| 38 | struct PS_INPUT |
| 39 | { |
| 40 | float4 Color : COLOR0; |
| 41 | float2 TexCoord : TEXCOORD0; |
| 42 | float2 ExtraInfo : TEXCOORD1; |
| 43 | }; |
| 44 | |
| 45 | //----------------------------------------------------------------------------- |
| 46 | // Post-Processing Vertex Shader |
| 47 | //----------------------------------------------------------------------------- |
| 48 | |
| 49 | uniform float TargetWidth; |
| 50 | uniform float TargetHeight; |
| 51 | |
| 52 | uniform float RawWidth; |
| 53 | uniform float RawHeight; |
| 54 | |
| 55 | uniform float WidthRatio; |
| 56 | uniform float HeightRatio; |
| 57 | |
| 58 | VS_OUTPUT vs_main(VS_INPUT Input) |
| 59 | { |
| 60 | VS_OUTPUT Output = (VS_OUTPUT)0; |
| 61 | |
| 62 | Output.Position = float4(Input.Position.xyz, 1.0f); |
| 63 | Output.Position.x /= TargetWidth; |
| 64 | Output.Position.y /= TargetHeight; |
| 65 | Output.Position.y = 1.0f - Output.Position.y; |
| 66 | Output.Position.x -= 0.5f; |
| 67 | Output.Position.y -= 0.5f; |
| 68 | Output.Position *= float4(2.0f, 2.0f, 1.0f, 1.0f); |
| 69 | Output.Color = Input.Color; |
| 70 | Output.TexCoord = Input.TexCoord;//(Input.TexCoord - float2(0.5f, 0.5f)) / 8.0f + float2(0.25f, 0.25f); |
| 71 | Output.ExtraInfo = Input.ExtraInfo; |
| 72 | |
| 73 | return Output; |
| 74 | } |
| 75 | |
| 76 | //----------------------------------------------------------------------------- |
| 77 | // Post-Processing Pixel Shader |
| 78 | //----------------------------------------------------------------------------- |
| 79 | |
| 80 | uniform float RedFromRed = 1.0f; |
| 81 | uniform float RedFromGrn = 0.0f; |
| 82 | uniform float RedFromBlu = 0.0f; |
| 83 | uniform float GrnFromRed = 0.0f; |
| 84 | uniform float GrnFromGrn = 1.0f; |
| 85 | uniform float GrnFromBlu = 0.0f; |
| 86 | uniform float BluFromRed = 0.0f; |
| 87 | uniform float BluFromGrn = 0.0f; |
| 88 | uniform float BluFromBlu = 1.0f; |
| 89 | |
| 90 | uniform float YfromY = 1.0f; |
| 91 | uniform float YfromI = 0.0f; |
| 92 | uniform float YfromQ = 0.0f; |
| 93 | uniform float IfromY = 0.0f; |
| 94 | uniform float IfromI = 1.0f; |
| 95 | uniform float IfromQ = 0.0f; |
| 96 | uniform float QfromY = 0.0f; |
| 97 | uniform float QfromI = 0.0f; |
| 98 | uniform float QfromQ = 1.0f; |
| 99 | |
| 100 | uniform float RedOffset = 0.0f; |
| 101 | uniform float GrnOffset = 0.0f; |
| 102 | uniform float BluOffset = 0.0f; |
| 103 | |
| 104 | uniform float RedScale = 1.0f; |
| 105 | uniform float GrnScale = 1.0f; |
| 106 | uniform float BluScale = 1.0f; |
| 107 | |
| 108 | uniform float RedFloor = 0.0f; |
| 109 | uniform float GrnFloor = 0.0f; |
| 110 | uniform float BluFloor = 0.0f; |
| 111 | |
| 112 | uniform float Saturation = 1.0f; |
| 113 | |
| 114 | uniform float YScale = 1.0f; |
| 115 | uniform float IScale = 1.0f; |
| 116 | uniform float QScale = 1.0f; |
| 117 | uniform float YOffset = 0.0f; |
| 118 | uniform float IOffset = 0.0f; |
| 119 | uniform float QOffset = 0.0f; |
| 120 | |
| 121 | uniform float RedPower = 2.2f; |
| 122 | uniform float GrnPower = 2.2f; |
| 123 | uniform float BluPower = 2.2f; |
| 124 | |
| 125 | uniform float YSubsampleLength = 3.0f; |
| 126 | uniform float ISubsampleLength = 3.0f; |
| 127 | uniform float QSubsampleLength = 3.0f; |
| 128 | |
| 129 | float4 ps_main(PS_INPUT Input) : COLOR |
| 130 | { |
| 131 | // -- Bandwidth Subsampling -- |
| 132 | float YSubsampleWidth = (RawWidth * 2.0f) / YSubsampleLength; |
| 133 | float ISubsampleWidth = (RawWidth * 2.0f) / ISubsampleLength; |
| 134 | float QSubsampleWidth = (RawWidth * 2.0f) / QSubsampleLength; |
| 135 | float3 SubsampleWidth = float3(YSubsampleWidth, ISubsampleWidth, QSubsampleWidth); |
| 136 | float3 SubsampleFrac = frac(Input.TexCoord.x * SubsampleWidth); |
| 137 | float3 SubsampleCoord = (Input.TexCoord.x * SubsampleWidth - SubsampleFrac) / SubsampleWidth + SubsampleFrac / (SubsampleWidth * 2.0f); |
| 138 | |
| 139 | float4 BaseTexel = tex2D(DiffuseSampler, Input.TexCoord); |
| 140 | |
| 141 | float3 YTexel = tex2D(DiffuseSampler, float2(SubsampleCoord.x, Input.TexCoord.y)).rgb; |
| 142 | float3 ITexel = tex2D(DiffuseSampler, float2(SubsampleCoord.y, Input.TexCoord.y)).rgb; |
| 143 | float3 QTexel = tex2D(DiffuseSampler, float2(SubsampleCoord.z, Input.TexCoord.y)).rgb; |
| 144 | |
| 145 | float3 LastYTexel = tex2D(DiffuseSampler, float2(SubsampleCoord.x - SubsampleFrac.x / RawWidth, Input.TexCoord.y)).rgb; |
| 146 | float3 LastITexel = tex2D(DiffuseSampler, float2(SubsampleCoord.y - SubsampleFrac.y / RawWidth, Input.TexCoord.y)).rgb; |
| 147 | float3 LastQTexel = tex2D(DiffuseSampler, float2(SubsampleCoord.z - SubsampleFrac.z / RawWidth, Input.TexCoord.y)).rgb; |
| 148 | |
| 149 | YTexel = lerp(LastYTexel, YTexel, SubsampleFrac.x); |
| 150 | ITexel = lerp(LastITexel, ITexel, SubsampleFrac.y); |
| 151 | QTexel = lerp(LastQTexel, QTexel, SubsampleFrac.z); |
| 152 | |
| 153 | // -- RGB Tint & Shift -- |
| 154 | float ShiftedRedY = dot(YTexel, float3(RedFromRed, RedFromGrn, RedFromBlu)); |
| 155 | float ShiftedGrnY = dot(YTexel, float3(GrnFromRed, GrnFromGrn, GrnFromBlu)); |
| 156 | float ShiftedBluY = dot(YTexel, float3(BluFromRed, BluFromGrn, BluFromBlu)); |
| 157 | float ShiftedRedI = dot(ITexel, float3(RedFromRed, RedFromGrn, RedFromBlu)); |
| 158 | float ShiftedGrnI = dot(ITexel, float3(GrnFromRed, GrnFromGrn, GrnFromBlu)); |
| 159 | float ShiftedBluI = dot(ITexel, float3(BluFromRed, BluFromGrn, BluFromBlu)); |
| 160 | float ShiftedRedQ = dot(QTexel, float3(RedFromRed, RedFromGrn, RedFromBlu)); |
| 161 | float ShiftedGrnQ = dot(QTexel, float3(GrnFromRed, GrnFromGrn, GrnFromBlu)); |
| 162 | float ShiftedBluQ = dot(QTexel, float3(BluFromRed, BluFromGrn, BluFromBlu)); |
| 163 | |
| 164 | // -- RGB Offset & Scale -- |
| 165 | float3 RGBScale = float3(RedScale, GrnScale, BluScale); |
| 166 | float3 RGBShift = float3(RedOffset, GrnOffset, BluOffset); |
| 167 | float3 OutTexelY = float3(ShiftedRedY, ShiftedGrnY, ShiftedBluY) * RGBScale + RGBShift; |
| 168 | float3 OutTexelI = float3(ShiftedRedI, ShiftedGrnI, ShiftedBluI) * RGBScale + RGBShift; |
| 169 | float3 OutTexelQ = float3(ShiftedRedQ, ShiftedGrnQ, ShiftedBluQ) * RGBScale + RGBShift; |
| 170 | |
| 171 | // -- Saturation -- |
| 172 | float3 Gray = float3(0.3f, 0.59f, 0.11f); |
| 173 | float OutLumaY = dot(OutTexelY, Gray); |
| 174 | float OutLumaI = dot(OutTexelI, Gray); |
| 175 | float OutLumaQ = dot(OutTexelQ, Gray); |
| 176 | float3 OutChromaY = OutTexelY - OutLumaY; |
| 177 | float3 OutChromaI = OutTexelI - OutLumaI; |
| 178 | float3 OutChromaQ = OutTexelQ - OutLumaQ; |
| 179 | float3 SaturatedY = OutLumaY + OutChromaY * Saturation; |
| 180 | float3 SaturatedI = OutLumaI + OutChromaI * Saturation; |
| 181 | float3 SaturatedQ = OutLumaQ + OutChromaQ * Saturation; |
| 182 | |
| 183 | // -- YIQ Convolution -- |
| 184 | float Y = dot(SaturatedY, float3(0.299f, 0.587f, 0.114f)); |
| 185 | float I = dot(SaturatedI, float3(0.595716f, -0.274453f, -0.321263f)); |
| 186 | float Q = dot(SaturatedQ, float3(0.211456f, -0.522591f, 0.311135f)); |
| 187 | Y = dot(float3(Y, I, Q), float3(YfromY, YfromI, YfromQ)); |
| 188 | I = dot(float3(Y, I, Q), float3(IfromY, IfromI, IfromQ)); |
| 189 | Q = dot(float3(Y, I, Q), float3(QfromY, QfromI, QfromQ)); |
| 190 | float3 OutYIQ = float3(Y, I, Q) * float3(YScale, IScale, QScale) + float3(YOffset, IOffset, QOffset); |
| 191 | float3 OutRGB = float3(dot(OutYIQ, float3(1.0f, 0.9563f, 0.6210f)), dot(OutYIQ, float3(1.0f, -0.2721f, -0.6474f)), dot(OutYIQ, float3(1.0f, -1.1070f, 1.7046f))); |
| 192 | |
| 193 | OutRGB.r = pow(OutRGB.r, RedPower); |
| 194 | OutRGB.g = pow(OutRGB.g, GrnPower); |
| 195 | OutRGB.b = pow(OutRGB.b, BluPower); |
| 196 | |
| 197 | // -- Color Compression (increasing the floor of the signal without affecting the ceiling) -- |
| 198 | OutRGB = float3(RedFloor + (1.0f - RedFloor) * OutRGB.r, GrnFloor + (1.0f - GrnFloor) * OutRGB.g, BluFloor + (1.0f - BluFloor) * OutRGB.b); |
| 199 | |
| 200 | // -- Final Pixel -- |
| 201 | float4 Output = lerp(Input.Color, float4(OutRGB, BaseTexel.a) * Input.Color, Input.ExtraInfo.x); |
| 202 | |
| 203 | return BaseTexel; |
| 204 | } |
| 205 | |
| 206 | //----------------------------------------------------------------------------- |
| 207 | // Color-Convolution Technique |
| 208 | //----------------------------------------------------------------------------- |
| 209 | |
| 210 | technique ColorTechnique |
| 211 | { |
| 212 | pass Pass0 |
| 213 | { |
| 214 | Lighting = FALSE; |
| 215 | |
| 216 | VertexShader = compile vs_3_0 vs_main(); |
| 217 | PixelShader = compile ps_3_0 ps_main(); |
| 218 | } |
| 219 | } |
hlsl/color.fx
| r0 | r11576 | |
| 1 | //----------------------------------------------------------------------------- |
| 2 | // Color-Convolution Effect |
| 3 | //----------------------------------------------------------------------------- |
| 4 | |
| 5 | texture Diffuse; |
| 6 | |
| 7 | sampler DiffuseSampler = sampler_state |
| 8 | { |
| 9 | Texture = <Diffuse>; |
| 10 | MipFilter = LINEAR; |
| 11 | MinFilter = LINEAR; |
| 12 | MagFilter = LINEAR; |
| 13 | AddressU = CLAMP; |
| 14 | AddressV = CLAMP; |
| 15 | AddressW = CLAMP; |
| 16 | }; |
| 17 | |
| 18 | //----------------------------------------------------------------------------- |
| 19 | // Vertex Definitions |
| 20 | //----------------------------------------------------------------------------- |
| 21 | |
| 22 | struct VS_OUTPUT |
| 23 | { |
| 24 | float4 Position : POSITION; |
| 25 | float4 Color : COLOR0; |
| 26 | float2 TexCoord : TEXCOORD0; |
| 27 | float2 ExtraInfo : TEXCOORD1; |
| 28 | }; |
| 29 | |
| 30 | struct VS_INPUT |
| 31 | { |
| 32 | float4 Position : POSITION; |
| 33 | float4 Color : COLOR0; |
| 34 | float2 TexCoord : TEXCOORD0; |
| 35 | float2 ExtraInfo : TEXCOORD1; |
| 36 | }; |
| 37 | |
| 38 | struct PS_INPUT |
| 39 | { |
| 40 | float4 Color : COLOR0; |
| 41 | float2 TexCoord : TEXCOORD0; |
| 42 | float2 ExtraInfo : TEXCOORD1; |
| 43 | }; |
| 44 | |
| 45 | //----------------------------------------------------------------------------- |
| 46 | // Post-Processing Vertex Shader |
| 47 | //----------------------------------------------------------------------------- |
| 48 | |
| 49 | uniform float TargetWidth; |
| 50 | uniform float TargetHeight; |
| 51 | |
| 52 | uniform float RawWidth; |
| 53 | uniform float RawHeight; |
| 54 | |
| 55 | uniform float WidthRatio; |
| 56 | uniform float HeightRatio; |
| 57 | |
| 58 | VS_OUTPUT vs_main(VS_INPUT Input) |
| 59 | { |
| 60 | VS_OUTPUT Output = (VS_OUTPUT)0; |
| 61 | |
| 62 | Output.Position = float4(Input.Position.xyz, 1.0f); |
| 63 | Output.Position.x /= TargetWidth; |
| 64 | Output.Position.y /= TargetHeight; |
| 65 | Output.Position.y = 1.0f - Output.Position.y; |
| 66 | Output.Position.x -= 0.5f; |
| 67 | Output.Position.y -= 0.5f; |
| 68 | Output.Position *= float4(2.0f, 2.0f, 1.0f, 1.0f); |
| 69 | Output.Color = Input.Color; |
| 70 | Output.TexCoord = Input.TexCoord;//(Input.TexCoord - float2(0.5f, 0.5f)) / 8.0f + float2(0.25f, 0.25f); |
| 71 | Output.ExtraInfo = Input.ExtraInfo; |
| 72 | |
| 73 | return Output; |
| 74 | } |
| 75 | |
| 76 | //----------------------------------------------------------------------------- |
| 77 | // Post-Processing Pixel Shader |
| 78 | //----------------------------------------------------------------------------- |
| 79 | |
| 80 | uniform float RedFromRed = 1.0f; |
| 81 | uniform float RedFromGrn = 0.0f; |
| 82 | uniform float RedFromBlu = 0.0f; |
| 83 | uniform float GrnFromRed = 0.0f; |
| 84 | uniform float GrnFromGrn = 1.0f; |
| 85 | uniform float GrnFromBlu = 0.0f; |
| 86 | uniform float BluFromRed = 0.0f; |
| 87 | uniform float BluFromGrn = 0.0f; |
| 88 | uniform float BluFromBlu = 1.0f; |
| 89 | |
| 90 | uniform float YfromY = 1.0f; |
| 91 | uniform float YfromI = 0.0f; |
| 92 | uniform float YfromQ = 0.0f; |
| 93 | uniform float IfromY = 0.0f; |
| 94 | uniform float IfromI = 1.0f; |
| 95 | uniform float IfromQ = 0.0f; |
| 96 | uniform float QfromY = 0.0f; |
| 97 | uniform float QfromI = 0.0f; |
| 98 | uniform float QfromQ = 1.0f; |
| 99 | |
| 100 | uniform float RedOffset = 0.0f; |
| 101 | uniform float GrnOffset = 0.0f; |
| 102 | uniform float BluOffset = 0.0f; |
| 103 | |
| 104 | uniform float RedScale = 1.0f; |
| 105 | uniform float GrnScale = 1.0f; |
| 106 | uniform float BluScale = 1.0f; |
| 107 | |
| 108 | uniform float RedFloor = 0.0f; |
| 109 | uniform float GrnFloor = 0.0f; |
| 110 | uniform float BluFloor = 0.0f; |
| 111 | |
| 112 | uniform float Saturation = 1.0f; |
| 113 | |
| 114 | uniform float YScale = 1.0f; |
| 115 | uniform float IScale = 1.0f; |
| 116 | uniform float QScale = 1.0f; |
| 117 | uniform float YOffset = 0.0f; |
| 118 | uniform float IOffset = 0.0f; |
| 119 | uniform float QOffset = 0.0f; |
| 120 | |
| 121 | uniform float RedPower = 2.2f; |
| 122 | uniform float GrnPower = 2.2f; |
| 123 | uniform float BluPower = 2.2f; |
| 124 | |
| 125 | uniform float YSubsampleLength = 3.0f; |
| 126 | uniform float ISubsampleLength = 3.0f; |
| 127 | uniform float QSubsampleLength = 3.0f; |
| 128 | |
| 129 | float4 ps_main(PS_INPUT Input) : COLOR |
| 130 | { |
| 131 | // -- Bandwidth Subsampling -- |
| 132 | float3 SubsampleWidth = float3(YSubsampleLength, ISubsampleLength, QSubsampleLength); |
| 133 | SubsampleWidth = (RawWidth * 2.0f) / SubsampleWidth; |
| 134 | float3 SubsampleCoord = Input.TexCoord.x; |
| 135 | float3 SubsampleFrac = frac(SubsampleCoord * SubsampleWidth); // Fraction is in subsample width units! |
| 136 | SubsampleCoord = (SubsampleCoord * SubsampleWidth - SubsampleFrac) / SubsampleWidth; |
| 137 | |
| 138 | float4 BaseTexel = tex2D(DiffuseSampler, Input.TexCoord); |
| 139 | |
| 140 | float3 YTexel = tex2D(DiffuseSampler, float2(SubsampleCoord.x, Input.TexCoord.y)).rgb; |
| 141 | float3 ITexel = tex2D(DiffuseSampler, float2(SubsampleCoord.y, Input.TexCoord.y)).rgb; |
| 142 | float3 QTexel = tex2D(DiffuseSampler, float2(SubsampleCoord.z, Input.TexCoord.y)).rgb; |
| 143 | |
| 144 | float3 LastYTexel = tex2D(DiffuseSampler, float2(SubsampleCoord.x + YSubsampleLength / (RawWidth * 2.0f), Input.TexCoord.y)).rgb; |
| 145 | float3 LastITexel = tex2D(DiffuseSampler, float2(SubsampleCoord.y + ISubsampleLength / (RawWidth * 2.0f), Input.TexCoord.y)).rgb; |
| 146 | float3 LastQTexel = tex2D(DiffuseSampler, float2(SubsampleCoord.z + QSubsampleLength / (RawWidth * 2.0f), Input.TexCoord.y)).rgb; |
| 147 | |
| 148 | YTexel = lerp(YTexel, LastYTexel, SubsampleFrac.x); |
| 149 | ITexel = lerp(ITexel, LastITexel, SubsampleFrac.y); |
| 150 | QTexel = lerp(QTexel, LastQTexel, SubsampleFrac.z); |
| 151 | |
| 152 | // -- RGB Tint & Shift -- |
| 153 | float ShiftedRedY = dot(YTexel, float3(RedFromRed, RedFromGrn, RedFromBlu)); |
| 154 | float ShiftedGrnY = dot(YTexel, float3(GrnFromRed, GrnFromGrn, GrnFromBlu)); |
| 155 | float ShiftedBluY = dot(YTexel, float3(BluFromRed, BluFromGrn, BluFromBlu)); |
| 156 | float ShiftedRedI = dot(ITexel, float3(RedFromRed, RedFromGrn, RedFromBlu)); |
| 157 | float ShiftedGrnI = dot(ITexel, float3(GrnFromRed, GrnFromGrn, GrnFromBlu)); |
| 158 | float ShiftedBluI = dot(ITexel, float3(BluFromRed, BluFromGrn, BluFromBlu)); |
| 159 | float ShiftedRedQ = dot(QTexel, float3(RedFromRed, RedFromGrn, RedFromBlu)); |
| 160 | float ShiftedGrnQ = dot(QTexel, float3(GrnFromRed, GrnFromGrn, GrnFromBlu)); |
| 161 | float ShiftedBluQ = dot(QTexel, float3(BluFromRed, BluFromGrn, BluFromBlu)); |
| 162 | |
| 163 | // -- RGB Offset & Scale -- |
| 164 | float3 RGBScale = float3(RedScale, GrnScale, BluScale); |
| 165 | float3 RGBShift = float3(RedOffset, GrnOffset, BluOffset); |
| 166 | float3 OutTexelY = float3(ShiftedRedY, ShiftedGrnY, ShiftedBluY) * RGBScale + RGBShift; |
| 167 | float3 OutTexelI = float3(ShiftedRedI, ShiftedGrnI, ShiftedBluI) * RGBScale + RGBShift; |
| 168 | float3 OutTexelQ = float3(ShiftedRedQ, ShiftedGrnQ, ShiftedBluQ) * RGBScale + RGBShift; |
| 169 | |
| 170 | // -- Saturation -- |
| 171 | float3 Gray = float3(0.3f, 0.59f, 0.11f); |
| 172 | float OutLumaY = dot(OutTexelY, Gray); |
| 173 | float OutLumaI = dot(OutTexelI, Gray); |
| 174 | float OutLumaQ = dot(OutTexelQ, Gray); |
| 175 | float3 OutChromaY = OutTexelY - OutLumaY; |
| 176 | float3 OutChromaI = OutTexelI - OutLumaI; |
| 177 | float3 OutChromaQ = OutTexelQ - OutLumaQ; |
| 178 | float3 SaturatedY = OutLumaY + OutChromaY * Saturation; |
| 179 | float3 SaturatedI = OutLumaI + OutChromaI * Saturation; |
| 180 | float3 SaturatedQ = OutLumaQ + OutChromaQ * Saturation; |
| 181 | |
| 182 | // -- YIQ Convolution -- |
| 183 | float Y = dot(SaturatedY, float3(0.299f, 0.587f, 0.114f)); |
| 184 | float I = dot(SaturatedI, float3(0.595716f, -0.274453f, -0.321263f)); |
| 185 | float Q = dot(SaturatedQ, float3(0.211456f, -0.522591f, 0.311135f)); |
| 186 | Y = dot(float3(Y, I, Q), float3(YfromY, YfromI, YfromQ)); |
| 187 | I = dot(float3(Y, I, Q), float3(IfromY, IfromI, IfromQ)); |
| 188 | Q = dot(float3(Y, I, Q), float3(QfromY, QfromI, QfromQ)); |
| 189 | float3 OutYIQ = float3(Y, I, Q) * float3(YScale, IScale, QScale) + float3(YOffset, IOffset, QOffset); |
| 190 | float3 OutRGB = float3(dot(OutYIQ, float3(1.0f, 0.9563f, 0.6210f)), dot(OutYIQ, float3(1.0f, -0.2721f, -0.6474f)), dot(OutYIQ, float3(1.0f, -1.1070f, 1.7046f))); |
| 191 | |
| 192 | OutRGB.r = pow(OutRGB.r, RedPower); |
| 193 | OutRGB.g = pow(OutRGB.g, GrnPower); |
| 194 | OutRGB.b = pow(OutRGB.b, BluPower); |
| 195 | |
| 196 | // -- Color Compression (increasing the floor of the signal without affecting the ceiling) -- |
| 197 | OutRGB = float3(RedFloor + (1.0f - RedFloor) * OutRGB.r, GrnFloor + (1.0f - GrnFloor) * OutRGB.g, BluFloor + (1.0f - BluFloor) * OutRGB.b); |
| 198 | |
| 199 | // -- Final Pixel -- |
| 200 | float4 Output = lerp(Input.Color, float4(OutRGB, BaseTexel.a) * Input.Color, Input.ExtraInfo.x); |
| 201 | |
| 202 | return Output; |
| 203 | } |
| 204 | |
| 205 | //----------------------------------------------------------------------------- |
| 206 | // Color-Convolution Technique |
| 207 | //----------------------------------------------------------------------------- |
| 208 | |
| 209 | technique ColorTechnique |
| 210 | { |
| 211 | pass Pass0 |
| 212 | { |
| 213 | Lighting = FALSE; |
| 214 | |
| 215 | VertexShader = compile vs_3_0 vs_main(); |
| 216 | PixelShader = compile ps_3_0 ps_main(); |
| 217 | } |
| 218 | } |
src/osd/windows/drawd3d.c
| r11575 | r11576 | |
| 130 | 130 | d3d_texture * d3dtex; // Direct3D texture pointer |
| 131 | 131 | d3d_surface * d3dsurface; // Direct3D offscreen plain surface pointer |
| 132 | 132 | d3d_surface * d3dtarget0; // Direct3D render target surface pointer (pass 0, if necessary) |
| 133 | | d3d_surface * d3dtarget1; // Direct3D render target surface pointer (pass 2, if necessary) |
| 134 | | d3d_surface * d3dtarget2; // Direct3D render target surface pointer (pass 3, if necessary) |
| 133 | d3d_surface * d3dtarget1; // Direct3D render target surface pointer (pass 1, if necessary) |
| 134 | d3d_surface * d3dtarget2; // Direct3D render target surface pointer (pass 2, if necessary) |
| 135 | d3d_surface * d3dsmalltarget0; // Direct3D render target surface pointer (small pass 0, if necessary) |
| 136 | d3d_surface * d3dsmalltarget1; // Direct3D render target surface pointer (small pass 1, if necessary) |
| 135 | 137 | d3d_texture * d3dtexture0; // Direct3D render target texture pointer (pass 0, if necessary) |
| 136 | | d3d_texture * d3dtexture1; // Direct3D render target texture pointer (pass 2, if necessary) |
| 137 | | d3d_texture * d3dtexture2; // Direct3D render target texture pointer (pass 3, if necessary) |
| 138 | d3d_texture * d3dtexture1; // Direct3D render target texture pointer (pass 1, if necessary) |
| 139 | d3d_texture * d3dtexture2; // Direct3D render target texture pointer (pass 2, if necessary) |
| 140 | d3d_texture * d3dsmalltexture0; // Direct3D render target texture pointer (small pass 0, if necessary) |
| 141 | d3d_texture * d3dsmalltexture1; // Direct3D render target texture pointer (small pass 1, if necessary) |
| 138 | 142 | d3d_texture * d3dfinaltex; // Direct3D final (post-scaled) texture |
| 139 | 143 | }; |
| 140 | 144 | |
| r11575 | r11576 | |
| 190 | 194 | d3d_effect * pincushion_effect; // pointer to the current pincushion-effect object |
| 191 | 195 | d3d_effect * focus_effect; // pointer to the current focus-effect object |
| 192 | 196 | d3d_effect * phosphor_effect; // pointer to the current phosphor-effect object |
| 197 | d3d_effect * deconverge_effect; // pointer to the current deconvergence-effect object |
| 198 | d3d_effect * color_effect; // pointer to the current color-effect object |
| 193 | 199 | |
| 194 | 200 | poly_info poly[VERTEX_BUFFER_SIZE / 3];// array to hold polygons as they are created |
| 195 | 201 | int numpolys; // number of accumulated polygons |
| r11575 | r11576 | |
| 357 | 363 | if(d3d->hlsl_enable && d3d->effect != NULL) |
| 358 | 364 | { |
| 359 | 365 | (*d3dintf->effect.set_texture)(d3d->effect, "Diffuse", (texture == NULL) ? NULL : texture->d3dfinaltex); |
| 360 | | (*d3dintf->effect.set_texture)(d3d->post_effect, "Diffuse", (texture == NULL) ? NULL : texture->d3dfinaltex); |
| 366 | (*d3dintf->effect.set_texture)(d3d->color_effect, "Diffuse", (texture == NULL) ? NULL : texture->d3dfinaltex); |
| 361 | 367 | (*d3dintf->effect.set_texture)(d3d->pincushion_effect, "Diffuse", (texture == NULL) ? NULL : texture->d3dfinaltex); |
| 362 | 368 | } |
| 363 | 369 | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device set_texture call\n", (int)result); |
| r11575 | r11576 | |
| 636 | 642 | d3d->vector_bitmap = NULL; |
| 637 | 643 | |
| 638 | 644 | // experimental: free the shadow PNG |
| 639 | | if(d3d->hlsl_enable) |
| 645 | if(d3d->hlsl_enable && d3d->shadow_bitmap != NULL) |
| 640 | 646 | { |
| 641 | 647 | global_free(d3d->shadow_bitmap); |
| 642 | 648 | d3d->shadow_bitmap = NULL; |
| r11575 | r11576 | |
| 850 | 856 | |
| 851 | 857 | // create the D3D device |
| 852 | 858 | result = (*d3dintf->d3d.create_device)(d3dintf, d3d->adapter, D3DDEVTYPE_HAL, win_window_list->hwnd, |
| 853 | | D3DCREATE_SOFTWARE_VERTEXPROCESSING | D3DCREATE_FPU_PRESERVE, &d3d->presentation, &d3d->device); |
| 859 | D3DCREATE_HARDWARE_VERTEXPROCESSING | D3DCREATE_FPU_PRESERVE, &d3d->presentation, &d3d->device); |
| 854 | 860 | if (result != D3D_OK) |
| 855 | 861 | { |
| 856 | 862 | // if we got a "DEVICELOST" error, it may be transitory; count it and only fail if |
| r11575 | r11576 | |
| 900 | 906 | } |
| 901 | 907 | |
| 902 | 908 | // experimental: initialize some more things if we're using HLSL |
| 903 | | if(d3d->hlsl_enable) |
| 909 | if(d3d->hlsl_enable && d3dintf->post_fx_available) |
| 904 | 910 | { |
| 905 | 911 | const char *fx_dir = downcast<windows_options &>(window->machine().options()).screen_post_fx_dir(); |
| 906 | 912 | char primary_name_cstr[1024]; |
| r11575 | r11576 | |
| 908 | 914 | char pincushion_name_cstr[1024]; |
| 909 | 915 | char phosphor_name_cstr[1024]; |
| 910 | 916 | char focus_name_cstr[1024]; |
| 917 | char deconverge_name_cstr[1024]; |
| 918 | char color_name_cstr[1024]; |
| 911 | 919 | |
| 912 | 920 | sprintf(primary_name_cstr, "%s\\primary.fx", fx_dir); |
| 913 | 921 | TCHAR *primary_name = tstring_from_utf8(primary_name_cstr); |
| r11575 | r11576 | |
| 924 | 932 | sprintf(focus_name_cstr, "%s\\focus.fx", fx_dir); |
| 925 | 933 | TCHAR *focus_name = tstring_from_utf8(focus_name_cstr); |
| 926 | 934 | |
| 935 | sprintf(deconverge_name_cstr, "%s\\deconverge.fx", fx_dir); |
| 936 | TCHAR *deconverge_name = tstring_from_utf8(deconverge_name_cstr); |
| 937 | |
| 938 | sprintf(color_name_cstr, "%s\\color.fx", fx_dir); |
| 939 | TCHAR *color_name = tstring_from_utf8(color_name_cstr); |
| 940 | |
| 927 | 941 | // create the regular shader |
| 928 | 942 | result = (*d3dintf->device.create_effect)(d3d->device, primary_name, &d3d->effect); |
| 929 | 943 | |
| r11575 | r11576 | |
| 939 | 953 | // create the focus shader |
| 940 | 954 | result = (*d3dintf->device.create_effect)(d3d->device, focus_name, &d3d->focus_effect); |
| 941 | 955 | |
| 956 | // create the deconvergence shader |
| 957 | result = (*d3dintf->device.create_effect)(d3d->device, deconverge_name, &d3d->deconverge_effect); |
| 958 | |
| 959 | // create the color convolution shader |
| 960 | result = (*d3dintf->device.create_effect)(d3d->device, color_name, &d3d->color_effect); |
| 961 | |
| 942 | 962 | if (primary_name) |
| 943 | 963 | osd_free(primary_name); |
| 944 | 964 | if (post_name) |
| r11575 | r11576 | |
| 949 | 969 | osd_free(phosphor_name); |
| 950 | 970 | if (focus_name) |
| 951 | 971 | osd_free(focus_name); |
| 972 | if (deconverge_name) |
| 973 | osd_free(deconverge_name); |
| 974 | if (color_name) |
| 975 | osd_free(color_name); |
| 952 | 976 | } |
| 953 | 977 | |
| 954 | 978 | return device_create_resources(d3d); |
| r11575 | r11576 | |
| 967 | 991 | // allocate a vertex buffer to use |
| 968 | 992 | result = (*d3dintf->device.create_vertex_buffer)(d3d->device, |
| 969 | 993 | sizeof(d3d_vertex) * VERTEX_BUFFER_SIZE, |
| 970 | | D3DUSAGE_DYNAMIC | D3DUSAGE_SOFTWAREPROCESSING | D3DUSAGE_WRITEONLY, |
| 971 | | VERTEX_BASE_FORMAT | (d3d->hlsl_enable ? D3DFVF_XYZW : D3DFVF_XYZRHW), D3DPOOL_DEFAULT, &d3d->vertexbuf); |
| 994 | D3DUSAGE_DYNAMIC | D3DUSAGE_WRITEONLY, |
| 995 | VERTEX_BASE_FORMAT | ((d3d->hlsl_enable && d3dintf->post_fx_available) ? D3DFVF_XYZW : D3DFVF_XYZRHW), D3DPOOL_DEFAULT, &d3d->vertexbuf); |
| 972 | 996 | if (result != D3D_OK) |
| 973 | 997 | { |
| 974 | 998 | mame_printf_error("Error creating vertex buffer (%08X)", (UINT32)result); |
| r11575 | r11576 | |
| 976 | 1000 | } |
| 977 | 1001 | |
| 978 | 1002 | // set the vertex format |
| 979 | | result = (*d3dintf->device.set_vertex_format)(d3d->device, (D3DFORMAT)(VERTEX_BASE_FORMAT | (d3d->hlsl_enable ? D3DFVF_XYZW : D3DFVF_XYZRHW))); |
| 1003 | result = (*d3dintf->device.set_vertex_format)(d3d->device, (D3DFORMAT)(VERTEX_BASE_FORMAT | ((d3d->hlsl_enable && d3dintf->post_fx_available) ? D3DFVF_XYZW : D3DFVF_XYZRHW))); |
| 980 | 1004 | if (result != D3D_OK) |
| 981 | 1005 | { |
| 982 | 1006 | mame_printf_error("Error setting vertex format (%08X)", (UINT32)result); |
| r11575 | r11576 | |
| 1033 | 1057 | } |
| 1034 | 1058 | |
| 1035 | 1059 | // experimental: initialize some more things if we're using HLSL |
| 1036 | | if(d3d->hlsl_enable) |
| 1060 | if(d3d->hlsl_enable && d3dintf->post_fx_available) |
| 1037 | 1061 | { |
| 1038 | 1062 | // experimental: create a default bitmap for our shader |
| 1039 | 1063 | if (d3d->default_bitmap != NULL) |
| r11575 | r11576 | |
| 1120 | 1144 | (*d3dintf->texture.release)(tex->d3dtexture1); |
| 1121 | 1145 | if (tex->d3dtexture2 != NULL) |
| 1122 | 1146 | (*d3dintf->texture.release)(tex->d3dtexture2); |
| 1147 | if (tex->d3dsmalltexture0 != NULL) |
| 1148 | (*d3dintf->texture.release)(tex->d3dsmalltexture0); |
| 1149 | if (tex->d3dsmalltexture1 != NULL) |
| 1150 | (*d3dintf->texture.release)(tex->d3dsmalltexture1); |
| 1123 | 1151 | if (tex->d3dtarget0 != NULL) |
| 1124 | 1152 | (*d3dintf->surface.release)(tex->d3dtarget0); |
| 1125 | 1153 | if (tex->d3dtarget1 != NULL) |
| 1126 | 1154 | (*d3dintf->surface.release)(tex->d3dtarget1); |
| 1127 | 1155 | if (tex->d3dtarget2 != NULL) |
| 1128 | 1156 | (*d3dintf->surface.release)(tex->d3dtarget2); |
| 1157 | if (tex->d3dsmalltarget0 != NULL) |
| 1158 | (*d3dintf->surface.release)(tex->d3dsmalltarget0); |
| 1159 | if (tex->d3dsmalltarget1 != NULL) |
| 1160 | (*d3dintf->surface.release)(tex->d3dsmalltarget1); |
| 1129 | 1161 | global_free(tex); |
| 1130 | 1162 | } |
| 1131 | 1163 | |
| r11575 | r11576 | |
| 1162 | 1194 | (*d3dintf->effect.release)(d3d->focus_effect); |
| 1163 | 1195 | d3d->focus_effect = NULL; |
| 1164 | 1196 | } |
| 1197 | if(d3d->deconverge_effect != NULL) |
| 1198 | { |
| 1199 | (*d3dintf->effect.release)(d3d->deconverge_effect); |
| 1200 | d3d->deconverge_effect = NULL; |
| 1201 | } |
| 1202 | if(d3d->color_effect != NULL) |
| 1203 | { |
| 1204 | (*d3dintf->effect.release)(d3d->color_effect); |
| 1205 | d3d->color_effect = NULL; |
| 1206 | } |
| 1165 | 1207 | |
| 1166 | 1208 | for(int index = 0; index < 9; index++) |
| 1167 | 1209 | { |
| r11575 | r11576 | |
| 1943 | 1985 | |
| 1944 | 1986 | d3d_effect *curr_effect = d3d->effect; |
| 1945 | 1987 | |
| 1946 | | if(d3d->hlsl_enable) |
| 1988 | if(d3d->hlsl_enable && d3dintf->post_fx_available) |
| 1947 | 1989 | { |
| 1948 | 1990 | (*d3dintf->effect.set_technique)(d3d->effect, "TestTechnique"); |
| 1949 | | (*d3dintf->effect.set_technique)(d3d->post_effect, "TestTechnique"); |
| 1991 | (*d3dintf->effect.set_technique)(d3d->post_effect, "ScanMaskTechnique"); |
| 1950 | 1992 | (*d3dintf->effect.set_technique)(d3d->pincushion_effect, "TestTechnique"); |
| 1951 | 1993 | (*d3dintf->effect.set_technique)(d3d->phosphor_effect, "TestTechnique"); |
| 1952 | 1994 | (*d3dintf->effect.set_technique)(d3d->focus_effect, "TestTechnique"); |
| 1995 | (*d3dintf->effect.set_technique)(d3d->deconverge_effect, "DeconvergeTechnique"); |
| 1996 | (*d3dintf->effect.set_technique)(d3d->color_effect, "ColorTechnique"); |
| 1953 | 1997 | } |
| 1954 | 1998 | |
| 1955 | 1999 | d3d_surface *backbuffer; |
| 1956 | 2000 | |
| 1957 | 2001 | // first remember the original render target in case we need to set a new one |
| 1958 | | result = (*d3dintf->device.get_render_target)(d3d->device, 0, &backbuffer); |
| 1959 | | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device get_render_target call\n", (int)result); |
| 2002 | if(d3d->hlsl_enable && d3dintf->post_fx_available) |
| 2003 | { |
| 2004 | result = (*d3dintf->device.get_render_target)(d3d->device, 0, &backbuffer); |
| 2005 | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device get_render_target call\n", (int)result); |
| 2006 | } |
| 1960 | 2007 | |
| 1961 | 2008 | windows_options &options = downcast<windows_options &>(d3d->window->machine().options()); |
| 1962 | 2009 | |
| r11575 | r11576 | |
| 1980 | 2027 | set_wrap(d3d, PRIMFLAG_GET_TEXWRAP(poly->flags)); |
| 1981 | 2028 | set_modmode(d3d, poly->modmode); |
| 1982 | 2029 | |
| 1983 | | if(d3d->hlsl_enable) |
| 2030 | if(d3d->hlsl_enable && d3dintf->post_fx_available) |
| 1984 | 2031 | { |
| 1985 | 2032 | if(PRIMFLAG_GET_TEXSHADE(d3d->last_texture_flags)) |
| 1986 | 2033 | { |
| r11575 | r11576 | |
| 1988 | 2035 | } |
| 1989 | 2036 | else if(PRIMFLAG_GET_SCREENTEX(d3d->last_texture_flags)) |
| 1990 | 2037 | { |
| 2038 | // Plug in all of the shader settings we're going to need |
| 2039 | // This is extremely slow, but we're not rendering models here, |
| 2040 | // just post-processing. |
| 1991 | 2041 | curr_effect = d3d->post_effect; |
| 1992 | 2042 | |
| 2043 | (*d3dintf->effect.set_float)(curr_effect, "RawWidth", poly->texture != NULL ? (float)poly->texture->rawwidth : 8.0f); |
| 2044 | (*d3dintf->effect.set_float)(curr_effect, "RawHeight", poly->texture != NULL ? (float)poly->texture->rawheight : 8.0f); |
| 2045 | (*d3dintf->effect.set_float)(curr_effect, "WidthRatio", poly->texture != NULL ? (1.0f / (poly->texture->ustop - poly->texture->ustart)) : 0.0f); |
| 2046 | (*d3dintf->effect.set_float)(curr_effect, "HeightRatio", poly->texture != NULL ? (1.0f / (poly->texture->vstop - poly->texture->vstart)) : 0.0f); |
| 2047 | (*d3dintf->effect.set_float)(curr_effect, "TargetWidth", (float)d3d->width); |
| 2048 | (*d3dintf->effect.set_float)(curr_effect, "TargetHeight", (float)d3d->height); |
| 2049 | (*d3dintf->effect.set_float)(curr_effect, "PincushionAmount", (float)options.screen_pincushion()); |
| 2050 | (*d3dintf->effect.set_float)(curr_effect, "CurvatureAmount", (float)options.screen_curvature()); |
| 2051 | (*d3dintf->effect.set_float)(curr_effect, "UseShadow", d3d->shadow_texture == NULL ? 0.0f : 1.0f); |
| 1993 | 2052 | (*d3dintf->effect.set_texture)(curr_effect, "Shadow", d3d->shadow_texture == NULL ? NULL : d3d->shadow_texture->d3dfinaltex); |
| 1994 | | (*d3dintf->effect.set_float)(curr_effect, "UseShadow", d3d->shadow_texture == NULL ? 0.0f : 1.0f); |
| 1995 | 2053 | (*d3dintf->effect.set_float)(curr_effect, "ShadowBrightness", (float)options.screen_shadow_mask_alpha()); |
| 1996 | | (*d3dintf->effect.set_float)(curr_effect, "ShadowPixelSizeX", (float)options.screen_shadow_mask_width()); |
| 1997 | | (*d3dintf->effect.set_float)(curr_effect, "ShadowPixelSizeY", (float)options.screen_shadow_mask_height()); |
| 2054 | (*d3dintf->effect.set_float)(curr_effect, "ShadowPixelSizeX", (float)options.screen_shadow_mask_ratio_x()); |
| 2055 | (*d3dintf->effect.set_float)(curr_effect, "ShadowPixelSizeY", (float)options.screen_shadow_mask_ratio_y()); |
| 2056 | (*d3dintf->effect.set_float)(curr_effect, "ShadowMaskSizeX", (float)options.screen_shadow_mask_count_x()); |
| 2057 | (*d3dintf->effect.set_float)(curr_effect, "ShadowMaskSizeY", (float)options.screen_shadow_mask_count_y()); |
| 1998 | 2058 | (*d3dintf->effect.set_float)(curr_effect, "ShadowU", (float)options.screen_shadow_mask_u_size()); |
| 1999 | 2059 | (*d3dintf->effect.set_float)(curr_effect, "ShadowV", (float)options.screen_shadow_mask_v_size()); |
| 2000 | 2060 | (*d3dintf->effect.set_float)(curr_effect, "ShadowWidth", d3d->shadow_texture == NULL ? 1.0f : (float)d3d->shadow_texture->rawwidth); |
| 2001 | 2061 | (*d3dintf->effect.set_float)(curr_effect, "ShadowHeight", d3d->shadow_texture == NULL ? 1.0f : (float)d3d->shadow_texture->rawheight); |
| 2002 | | (*d3dintf->effect.set_float)(curr_effect, "RawWidth", poly->texture != NULL ? (float)poly->texture->rawwidth : 8.0f); |
| 2003 | | (*d3dintf->effect.set_float)(curr_effect, "RawHeight", poly->texture != NULL ? (float)poly->texture->rawheight : 8.0f); |
| 2004 | | (*d3dintf->effect.set_float)(curr_effect, "WidthRatio", poly->texture != NULL ? (1.0f / (poly->texture->ustop - poly->texture->ustart)) : 0.0f); |
| 2005 | | (*d3dintf->effect.set_float)(curr_effect, "HeightRatio", poly->texture != NULL ? (1.0f / (poly->texture->vstop - poly->texture->vstart)) : 0.0f); |
| 2006 | | (*d3dintf->effect.set_float)(curr_effect, "TargetWidth", (float)d3d->width); |
| 2007 | | (*d3dintf->effect.set_float)(curr_effect, "TargetHeight", (float)d3d->height); |
| 2008 | | (*d3dintf->effect.set_float)(curr_effect, "PostPass", 0.0f); |
| 2009 | | (*d3dintf->effect.set_float)(curr_effect, "PincushionAmountX", (float)options.screen_pincushion_x()); |
| 2010 | | (*d3dintf->effect.set_float)(curr_effect, "PincushionAmountY", (float)options.screen_pincushion_y()); |
| 2011 | 2062 | (*d3dintf->effect.set_float)(curr_effect, "ScanlineAmount", (float)options.screen_scanline_amount()); |
| 2012 | 2063 | (*d3dintf->effect.set_float)(curr_effect, "ScanlineScale", (float)options.screen_scanline_scale()); |
| 2013 | 2064 | (*d3dintf->effect.set_float)(curr_effect, "ScanlineBrightScale", (float)options.screen_scanline_bright_scale()); |
| 2014 | 2065 | (*d3dintf->effect.set_float)(curr_effect, "ScanlineBrightOffset", (float)options.screen_scanline_bright_offset()); |
| 2015 | 2066 | (*d3dintf->effect.set_float)(curr_effect, "ScanlineOffset", (poly->texture != NULL && poly->texture->cur_frame == 0) ? 0.0f : (float)options.screen_scanline_offset()); |
| 2016 | | (*d3dintf->effect.set_float)(curr_effect, "RedConvergeX", (float)options.screen_red_converge_x()); |
| 2017 | | (*d3dintf->effect.set_float)(curr_effect, "RedConvergeY", (float)options.screen_red_converge_y()); |
| 2018 | | (*d3dintf->effect.set_float)(curr_effect, "GrnConvergeX", (float)options.screen_green_converge_x()); |
| 2019 | | (*d3dintf->effect.set_float)(curr_effect, "GrnConvergeY", (float)options.screen_green_converge_y()); |
| 2020 | | (*d3dintf->effect.set_float)(curr_effect, "BluConvergeX", (float)options.screen_blue_converge_x()); |
| 2021 | | (*d3dintf->effect.set_float)(curr_effect, "BluConvergeY", (float)options.screen_blue_converge_y()); |
| 2022 | | (*d3dintf->effect.set_float)(curr_effect, "RedRadialConvergeX", (float)options.screen_red_radial_converge_x()); |
| 2023 | | (*d3dintf->effect.set_float)(curr_effect, "RedRadialConvergeY", (float)options.screen_red_radial_converge_y()); |
| 2024 | | (*d3dintf->effect.set_float)(curr_effect, "GrnRadialConvergeX", (float)options.screen_green_radial_converge_x()); |
| 2025 | | (*d3dintf->effect.set_float)(curr_effect, "GrnRadialConvergeY", (float)options.screen_green_radial_converge_y()); |
| 2026 | | (*d3dintf->effect.set_float)(curr_effect, "BluRadialConvergeX", (float)options.screen_blue_radial_converge_x()); |
| 2027 | | (*d3dintf->effect.set_float)(curr_effect, "BluRadialConvergeY", (float)options.screen_blue_radial_converge_y()); |
| 2028 | | (*d3dintf->effect.set_float)(curr_effect, "RedFromRed", (float)options.screen_red_from_red()); |
| 2029 | | (*d3dintf->effect.set_float)(curr_effect, "RedFromGrn", (float)options.screen_red_from_green()); |
| 2030 | | (*d3dintf->effect.set_float)(curr_effect, "RedFromBlu", (float)options.screen_red_from_blue()); |
| 2031 | | (*d3dintf->effect.set_float)(curr_effect, "GrnFromRed", (float)options.screen_green_from_red()); |
| 2032 | | (*d3dintf->effect.set_float)(curr_effect, "GrnFromGrn", (float)options.screen_green_from_green()); |
| 2033 | | (*d3dintf->effect.set_float)(curr_effect, "GrnFromBlu", (float)options.screen_green_from_blue()); |
| 2034 | | (*d3dintf->effect.set_float)(curr_effect, "BluFromRed", (float)options.screen_blue_from_red()); |
| 2035 | | (*d3dintf->effect.set_float)(curr_effect, "BluFromGrn", (float)options.screen_blue_from_green()); |
| 2036 | | (*d3dintf->effect.set_float)(curr_effect, "BluFromBlu", (float)options.screen_blue_from_blue()); |
| 2037 | | (*d3dintf->effect.set_float)(curr_effect, "YfromY", (float)options.screen_y_from_y()); |
| 2038 | | (*d3dintf->effect.set_float)(curr_effect, "YfromI", (float)options.screen_y_from_i()); |
| 2039 | | (*d3dintf->effect.set_float)(curr_effect, "YfromQ", (float)options.screen_y_from_q()); |
| 2040 | | (*d3dintf->effect.set_float)(curr_effect, "IfromY", (float)options.screen_i_from_y()); |
| 2041 | | (*d3dintf->effect.set_float)(curr_effect, "IfromI", (float)options.screen_i_from_i()); |
| 2042 | | (*d3dintf->effect.set_float)(curr_effect, "IfromQ", (float)options.screen_i_from_q()); |
| 2043 | | (*d3dintf->effect.set_float)(curr_effect, "QfromY", (float)options.screen_q_from_y()); |
| 2044 | | (*d3dintf->effect.set_float)(curr_effect, "QfromI", (float)options.screen_q_from_i()); |
| 2045 | | (*d3dintf->effect.set_float)(curr_effect, "QfromQ", (float)options.screen_q_from_q()); |
| 2046 | | (*d3dintf->effect.set_float)(curr_effect, "RedOffset", (float)options.screen_red_offset()); |
| 2047 | | (*d3dintf->effect.set_float)(curr_effect, "GrnOffset", (float)options.screen_green_offset()); |
| 2048 | | (*d3dintf->effect.set_float)(curr_effect, "BluOffset", (float)options.screen_blue_offset()); |
| 2049 | | (*d3dintf->effect.set_float)(curr_effect, "RedScale", (float)options.screen_red_scale()); |
| 2050 | | (*d3dintf->effect.set_float)(curr_effect, "GrnScale", (float)options.screen_green_scale()); |
| 2051 | | (*d3dintf->effect.set_float)(curr_effect, "BluScale", (float)options.screen_blue_scale()); |
| 2052 | | (*d3dintf->effect.set_float)(curr_effect, "RedPower", (float)options.screen_red_power()); |
| 2053 | | (*d3dintf->effect.set_float)(curr_effect, "GrnPower", (float)options.screen_green_power()); |
| 2054 | | (*d3dintf->effect.set_float)(curr_effect, "BluPower", (float)options.screen_blue_power()); |
| 2055 | | (*d3dintf->effect.set_float)(curr_effect, "RedFloor", (float)options.screen_red_floor()); |
| 2056 | | (*d3dintf->effect.set_float)(curr_effect, "GrnFloor", (float)options.screen_green_floor()); |
| 2057 | | (*d3dintf->effect.set_float)(curr_effect, "BluFloor", (float)options.screen_blue_floor()); |
| 2058 | | (*d3dintf->effect.set_float)(curr_effect, "Saturation", (float)options.screen_saturation()); |
| 2059 | | (*d3dintf->effect.set_float)(curr_effect, "YScale", (float)options.screen_y_scale()); |
| 2060 | | (*d3dintf->effect.set_float)(curr_effect, "IScale", (float)options.screen_i_scale()); |
| 2061 | | (*d3dintf->effect.set_float)(curr_effect, "QScale", (float)options.screen_q_scale()); |
| 2062 | | (*d3dintf->effect.set_float)(curr_effect, "YOffset", (float)options.screen_y_offset()); |
| 2063 | | (*d3dintf->effect.set_float)(curr_effect, "IOffset", (float)options.screen_i_offset()); |
| 2064 | | (*d3dintf->effect.set_float)(curr_effect, "QOffset", (float)options.screen_q_offset()); |
| 2065 | | (*d3dintf->effect.set_float)(curr_effect, "EdgeDetectScale", (float)options.screen_edge_amount()); |
| 2066 | | (*d3dintf->effect.set_float)(curr_effect, "EdgeToBaseRatio", (float)options.screen_edge_ratio()); |
| 2067 | | (*d3dintf->effect.set_float)(curr_effect, "SubsampleLength", (float)options.screen_chroma_subsample_length()); |
| 2068 | | int frame = (poly->texture != NULL && poly->texture->cur_frame) ? (float)poly->texture->cur_frame : 0; |
| 2069 | | frame = (frame == options.screen_dot_crawl_skip()) ? 0 : frame; |
| 2070 | | (*d3dintf->effect.set_float)(curr_effect, "CurrFrame", (float)frame); |
| 2071 | | (*d3dintf->effect.set_float)(curr_effect, "CrawlWidth", (float)options.screen_dot_crawl_width()); |
| 2072 | | (*d3dintf->effect.set_float)(curr_effect, "CrawlHeight", (float)options.screen_dot_crawl_height()); |
| 2073 | | (*d3dintf->effect.set_float)(curr_effect, "CrawlRate", (float)options.screen_dot_crawl_rate()); |
| 2074 | | (*d3dintf->effect.set_float)(curr_effect, "CrawlSkip", (float)options.screen_dot_crawl_skip()); |
| 2075 | 2067 | } |
| 2076 | 2068 | else |
| 2077 | 2069 | { |
| r11575 | r11576 | |
| 2085 | 2077 | // set the blendmode if different |
| 2086 | 2078 | set_blendmode(d3d, PRIMFLAG_GET_BLENDMODE(poly->flags)); |
| 2087 | 2079 | |
| 2088 | | if(d3d->hlsl_enable) |
| 2080 | if(d3d->hlsl_enable && d3dintf->post_fx_available) |
| 2089 | 2081 | { |
| 2090 | 2082 | assert(vertnum + poly->numverts <= d3d->numverts); |
| 2091 | 2083 | |
| r11575 | r11576 | |
| 2093 | 2085 | |
| 2094 | 2086 | if(PRIMFLAG_GET_SCREENTEX(d3d->last_texture_flags) && poly->texture != NULL) |
| 2095 | 2087 | { |
| 2096 | | /* Render the initial screen pass */ |
| 2097 | | (*d3dintf->effect.set_float)(curr_effect, "FixedAlpha", 1.0f); |
| 2088 | curr_effect = d3d->color_effect; |
| 2098 | 2089 | |
| 2099 | | result = (*d3dintf->device.set_render_target)(d3d->device, 0, poly->texture->d3dtarget0); |
| 2090 | /* Render the initial color-convolution pass */ |
| 2091 | (*d3dintf->effect.set_float)(curr_effect, "RawWidth", poly->texture != NULL ? (float)poly->texture->rawwidth : 8.0f); |
| 2092 | (*d3dintf->effect.set_float)(curr_effect, "RawHeight", poly->texture != NULL ? (float)poly->texture->rawheight : 8.0f); |
| 2093 | (*d3dintf->effect.set_float)(curr_effect, "WidthRatio", poly->texture != NULL ? (1.0f / (poly->texture->ustop - poly->texture->ustart)) : 0.0f); |
| 2094 | (*d3dintf->effect.set_float)(curr_effect, "HeightRatio", poly->texture != NULL ? (1.0f / (poly->texture->vstop - poly->texture->vstart)) : 0.0f); |
| 2095 | (*d3dintf->effect.set_float)(curr_effect, "TargetWidth", (float)d3d->width); |
| 2096 | (*d3dintf->effect.set_float)(curr_effect, "TargetHeight", (float)d3d->height); |
| 2097 | (*d3dintf->effect.set_float)(curr_effect, "RedFromRed", (float)options.screen_red_from_red()); |
| 2098 | (*d3dintf->effect.set_float)(curr_effect, "RedFromGrn", (float)options.screen_red_from_green()); |
| 2099 | (*d3dintf->effect.set_float)(curr_effect, "RedFromBlu", (float)options.screen_red_from_blue()); |
| 2100 | (*d3dintf->effect.set_float)(curr_effect, "GrnFromRed", (float)options.screen_green_from_red()); |
| 2101 | (*d3dintf->effect.set_float)(curr_effect, "GrnFromGrn", (float)options.screen_green_from_green()); |
| 2102 | (*d3dintf->effect.set_float)(curr_effect, "GrnFromBlu", (float)options.screen_green_from_blue()); |
| 2103 | (*d3dintf->effect.set_float)(curr_effect, "BluFromRed", (float)options.screen_blue_from_red()); |
| 2104 | (*d3dintf->effect.set_float)(curr_effect, "BluFromGrn", (float)options.screen_blue_from_green()); |
| 2105 | (*d3dintf->effect.set_float)(curr_effect, "BluFromBlu", (float)options.screen_blue_from_blue()); |
| 2106 | (*d3dintf->effect.set_float)(curr_effect, "YfromY", (float)options.screen_y_from_y()); |
| 2107 | (*d3dintf->effect.set_float)(curr_effect, "YfromI", (float)options.screen_y_from_i()); |
| 2108 | (*d3dintf->effect.set_float)(curr_effect, "YfromQ", (float)options.screen_y_from_q()); |
| 2109 | (*d3dintf->effect.set_float)(curr_effect, "IfromY", (float)options.screen_i_from_y()); |
| 2110 | (*d3dintf->effect.set_float)(curr_effect, "IfromI", (float)options.screen_i_from_i()); |
| 2111 | (*d3dintf->effect.set_float)(curr_effect, "IfromQ", (float)options.screen_i_from_q()); |
| 2112 | (*d3dintf->effect.set_float)(curr_effect, "QfromY", (float)options.screen_q_from_y()); |
| 2113 | (*d3dintf->effect.set_float)(curr_effect, "QfromI", (float)options.screen_q_from_i()); |
| 2114 | (*d3dintf->effect.set_float)(curr_effect, "QfromQ", (float)options.screen_q_from_q()); |
| 2115 | (*d3dintf->effect.set_float)(curr_effect, "RedOffset", (float)options.screen_red_offset()); |
| 2116 | (*d3dintf->effect.set_float)(curr_effect, "GrnOffset", (float)options.screen_green_offset()); |
| 2117 | (*d3dintf->effect.set_float)(curr_effect, "BluOffset", (float)options.screen_blue_offset()); |
| 2118 | (*d3dintf->effect.set_float)(curr_effect, "RedScale", (float)options.screen_red_scale()); |
| 2119 | (*d3dintf->effect.set_float)(curr_effect, "GrnScale", (float)options.screen_green_scale()); |
| 2120 | (*d3dintf->effect.set_float)(curr_effect, "BluScale", (float)options.screen_blue_scale()); |
| 2121 | (*d3dintf->effect.set_float)(curr_effect, "RedPower", (float)options.screen_red_power()); |
| 2122 | (*d3dintf->effect.set_float)(curr_effect, "GrnPower", (float)options.screen_green_power()); |
| 2123 | (*d3dintf->effect.set_float)(curr_effect, "BluPower", (float)options.screen_blue_power()); |
| 2124 | (*d3dintf->effect.set_float)(curr_effect, "RedFloor", (float)options.screen_red_floor()); |
| 2125 | (*d3dintf->effect.set_float)(curr_effect, "GrnFloor", (float)options.screen_green_floor()); |
| 2126 | (*d3dintf->effect.set_float)(curr_effect, "BluFloor", (float)options.screen_blue_floor()); |
| 2127 | (*d3dintf->effect.set_float)(curr_effect, "Saturation", (float)options.screen_saturation()); |
| 2128 | (*d3dintf->effect.set_float)(curr_effect, "YScale", (float)options.screen_y_scale()); |
| 2129 | (*d3dintf->effect.set_float)(curr_effect, "IScale", (float)options.screen_i_scale()); |
| 2130 | (*d3dintf->effect.set_float)(curr_effect, "QScale", (float)options.screen_q_scale()); |
| 2131 | (*d3dintf->effect.set_float)(curr_effect, "YOffset", (float)options.screen_y_offset()); |
| 2132 | (*d3dintf->effect.set_float)(curr_effect, "IOffset", (float)options.screen_i_offset()); |
| 2133 | (*d3dintf->effect.set_float)(curr_effect, "QOffset", (float)options.screen_q_offset()); |
| 2134 | (*d3dintf->effect.set_float)(curr_effect, "YSubsampleLength", (float)options.screen_y_subsample_length()); |
| 2135 | (*d3dintf->effect.set_float)(curr_effect, "ISubsampleLength", (float)options.screen_i_subsample_length()); |
| 2136 | (*d3dintf->effect.set_float)(curr_effect, "QSubsampleLength", (float)options.screen_q_subsample_length()); |
| 2100 | 2137 | |
| 2101 | | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device set_render_target call 3\n", (int)result); |
| 2102 | | result = (*d3dintf->device.clear)(d3d->device, 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_ARGB(0,0,0,0), 0, 0); |
| 2138 | result = (*d3dintf->device.set_render_target)(d3d->device, 0, poly->texture->d3dsmalltarget0); |
| 2139 | |
| 2140 | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device set_render_target call\n", (int)result); |
| 2141 | result = (*d3dintf->device.clear)(d3d->device, 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_ARGB(255,0,0,0), 0, 0); |
| 2103 | 2142 | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device clear call\n", (int)result); |
| 2104 | 2143 | |
| 2105 | 2144 | (*d3dintf->effect.begin)(curr_effect, &num_passes, 0); |
| r11575 | r11576 | |
| 2115 | 2154 | |
| 2116 | 2155 | (*d3dintf->effect.end)(curr_effect); |
| 2117 | 2156 | |
| 2118 | | // max() the two previous frames |
| 2119 | | curr_effect = d3d->phosphor_effect; |
| 2157 | /* Deconverge pass */ |
| 2158 | curr_effect = d3d->deconverge_effect; |
| 2159 | (*d3dintf->effect.set_texture)(curr_effect, "Diffuse", poly->texture->d3dsmalltexture0); |
| 2120 | 2160 | |
| 2121 | 2161 | (*d3dintf->effect.set_float)(curr_effect, "TargetWidth", (float)d3d->width); |
| 2122 | 2162 | (*d3dintf->effect.set_float)(curr_effect, "TargetHeight", (float)d3d->height); |
| 2123 | 2163 | (*d3dintf->effect.set_float)(curr_effect, "RawWidth", (float)poly->texture->rawwidth); |
| 2124 | 2164 | (*d3dintf->effect.set_float)(curr_effect, "RawHeight", (float)poly->texture->rawheight); |
| 2125 | | (*d3dintf->effect.set_float)(curr_effect, "RedPhosphor", (float)options.screen_red_phosphor()); |
| 2126 | | (*d3dintf->effect.set_float)(curr_effect, "GreenPhosphor", (float)options.screen_green_phosphor()); |
| 2127 | | (*d3dintf->effect.set_float)(curr_effect, "BluePhosphor", (float)options.screen_blue_phosphor()); |
| 2165 | (*d3dintf->effect.set_float)(curr_effect, "WidthRatio", poly->texture != NULL ? (1.0f / (poly->texture->ustop - poly->texture->ustart)) : 0.0f); |
| 2166 | (*d3dintf->effect.set_float)(curr_effect, "HeightRatio", poly->texture != NULL ? (1.0f / (poly->texture->vstop - poly->texture->vstart)) : 0.0f); |
| 2167 | (*d3dintf->effect.set_float)(curr_effect, "RedConvergeX", (float)options.screen_red_converge_x()); |
| 2168 | (*d3dintf->effect.set_float)(curr_effect, "RedConvergeY", (float)options.screen_red_converge_y()); |
| 2169 | (*d3dintf->effect.set_float)(curr_effect, "GrnConvergeX", (float)options.screen_green_converge_x()); |
| 2170 | (*d3dintf->effect.set_float)(curr_effect, "GrnConvergeY", (float)options.screen_green_converge_y()); |
| 2171 | (*d3dintf->effect.set_float)(curr_effect, "BluConvergeX", (float)options.screen_blue_converge_x()); |
| 2172 | (*d3dintf->effect.set_float)(curr_effect, "BluConvergeY", (float)options.screen_blue_converge_y()); |
| 2173 | (*d3dintf->effect.set_float)(curr_effect, "RedRadialConvergeX", (float)options.screen_red_radial_converge_x()); |
| 2174 | (*d3dintf->effect.set_float)(curr_effect, "RedRadialConvergeY", (float)options.screen_red_radial_converge_y()); |
| 2175 | (*d3dintf->effect.set_float)(curr_effect, "GrnRadialConvergeX", (float)options.screen_green_radial_converge_x()); |
| 2176 | (*d3dintf->effect.set_float)(curr_effect, "GrnRadialConvergeY", (float)options.screen_green_radial_converge_y()); |
| 2177 | (*d3dintf->effect.set_float)(curr_effect, "BluRadialConvergeX", (float)options.screen_blue_radial_converge_x()); |
| 2178 | (*d3dintf->effect.set_float)(curr_effect, "BluRadialConvergeY", (float)options.screen_blue_radial_converge_y()); |
| 2128 | 2179 | |
| 2129 | | (*d3dintf->effect.set_texture)(curr_effect, "Diffuse", poly->texture->d3dtexture0); |
| 2130 | | (*d3dintf->effect.set_texture)(curr_effect, "LastPass", d3d->last_d3dtexture[cur_render_screen]); |
| 2180 | (*d3dintf->effect.begin)(curr_effect, &num_passes, 0); |
| 2131 | 2181 | |
| 2132 | | result = (*d3dintf->device.set_render_target)(d3d->device, 0, poly->texture->d3dtarget1); |
| 2133 | | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device set_render_target call 4\n", (int)result); |
| 2182 | result = (*d3dintf->device.set_render_target)(d3d->device, 0, poly->texture->d3dtarget2); |
| 2183 | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device set_render_target call 6\n", (int)result); |
| 2134 | 2184 | result = (*d3dintf->device.clear)(d3d->device, 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_ARGB(0,0,0,0), 0, 0); |
| 2135 | 2185 | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device clear call\n", (int)result); |
| 2136 | 2186 | |
| 2137 | | (*d3dintf->effect.begin)(curr_effect, &num_passes, 0); |
| 2138 | | |
| 2139 | 2187 | for (UINT pass = 0; pass < num_passes; pass++) |
| 2140 | 2188 | { |
| 2141 | 2189 | (*d3dintf->effect.begin_pass)(curr_effect, pass); |
| r11575 | r11576 | |
| 2147 | 2195 | |
| 2148 | 2196 | (*d3dintf->effect.end)(curr_effect); |
| 2149 | 2197 | |
| 2150 | | /* Pass along our phosphor'd screen */ |
| 2151 | | curr_effect = d3d->phosphor_effect; |
| 2198 | /* Defocus pass 1 */ |
| 2199 | curr_effect = d3d->focus_effect; |
| 2152 | 2200 | |
| 2153 | | (*d3dintf->effect.set_float)(curr_effect, "FixedAlpha", 1.0f); |
| 2201 | (*d3dintf->effect.set_texture)(curr_effect, "Diffuse", poly->texture->d3dtexture2); |
| 2154 | 2202 | |
| 2155 | | (*d3dintf->effect.set_texture)(curr_effect, "Diffuse", poly->texture->d3dtexture1); |
| 2156 | | (*d3dintf->effect.set_texture)(curr_effect, "LastPass", poly->texture->d3dtexture1); |
| 2203 | float defocus_x = (float)options.screen_defocus_x(); |
| 2204 | float defocus_y = (float)options.screen_defocus_y(); |
| 2205 | (*d3dintf->effect.set_float)(curr_effect, "TargetWidth", (float)d3d->width); |
| 2206 | (*d3dintf->effect.set_float)(curr_effect, "TargetHeight", (float)d3d->height); |
| 2207 | (*d3dintf->effect.set_float)(curr_effect, "RawWidth", (float)poly->texture->rawwidth); |
| 2208 | (*d3dintf->effect.set_float)(curr_effect, "RawHeight", (float)poly->texture->rawheight); |
| 2209 | (*d3dintf->effect.set_float)(curr_effect, "WidthRatio", poly->texture != NULL ? (1.0f / (poly->texture->ustop - poly->texture->ustart)) : 0.0f); |
| 2210 | (*d3dintf->effect.set_float)(curr_effect, "HeightRatio", poly->texture != NULL ? (1.0f / (poly->texture->vstop - poly->texture->vstart)) : 0.0f); |
| 2211 | (*d3dintf->effect.set_float)(curr_effect, "DefocusX", defocus_x); |
| 2212 | (*d3dintf->effect.set_float)(curr_effect, "DefocusY", defocus_y); |
| 2213 | (*d3dintf->effect.set_float)(curr_effect, "FocusEnable", (defocus_x == 0.0f && defocus_y == 0.0f) ? 0.0f : 1.0f); |
| 2157 | 2214 | |
| 2158 | | result = (*d3dintf->device.set_render_target)(d3d->device, 0, d3d->last_d3dtarget[cur_render_screen++]); |
| 2159 | | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device set_render_target call 5\n", (int)result); |
| 2215 | (*d3dintf->effect.begin)(curr_effect, &num_passes, 0); |
| 2216 | |
| 2217 | result = (*d3dintf->device.set_render_target)(d3d->device, 0, poly->texture->d3dtarget0); |
| 2218 | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device set_render_target call 6\n", (int)result); |
| 2160 | 2219 | result = (*d3dintf->device.clear)(d3d->device, 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_ARGB(0,0,0,0), 0, 0); |
| 2161 | 2220 | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device clear call\n", (int)result); |
| 2162 | 2221 | |
| 2163 | | (*d3dintf->effect.begin)(curr_effect, &num_passes, 0); |
| 2164 | | |
| 2165 | 2222 | for (UINT pass = 0; pass < num_passes; pass++) |
| 2166 | 2223 | { |
| 2167 | 2224 | (*d3dintf->effect.begin_pass)(curr_effect, pass); |
| r11575 | r11576 | |
| 2173 | 2230 | |
| 2174 | 2231 | (*d3dintf->effect.end)(curr_effect); |
| 2175 | 2232 | |
| 2176 | | /* Next, defocus pass 1 */ |
| 2177 | | curr_effect = d3d->focus_effect; |
| 2233 | /* Defocus pass 2 */ |
| 2178 | 2234 | |
| 2179 | | (*d3dintf->effect.set_texture)(curr_effect, "Diffuse", poly->texture->d3dtexture1); |
| 2235 | (*d3dintf->effect.set_texture)(curr_effect, "Diffuse", poly->texture->d3dtexture0); |
| 2180 | 2236 | |
| 2181 | | float defocus_x = (float)options.screen_defocus_x(); |
| 2182 | | float defocus_y = (float)options.screen_defocus_y(); |
| 2183 | 2237 | (*d3dintf->effect.set_float)(curr_effect, "TargetWidth", (float)d3d->width); |
| 2184 | 2238 | (*d3dintf->effect.set_float)(curr_effect, "TargetHeight", (float)d3d->height); |
| 2185 | 2239 | (*d3dintf->effect.set_float)(curr_effect, "RawWidth", (float)poly->texture->rawwidth); |
| 2186 | 2240 | (*d3dintf->effect.set_float)(curr_effect, "RawHeight", (float)poly->texture->rawheight); |
| 2241 | (*d3dintf->effect.set_float)(curr_effect, "WidthRatio", 1.0f); |
| 2242 | (*d3dintf->effect.set_float)(curr_effect, "HeightRatio", 1.0f); |
| 2187 | 2243 | (*d3dintf->effect.set_float)(curr_effect, "DefocusX", defocus_x); |
| 2188 | 2244 | (*d3dintf->effect.set_float)(curr_effect, "DefocusY", defocus_y); |
| 2189 | 2245 | (*d3dintf->effect.set_float)(curr_effect, "FocusEnable", (defocus_x == 0.0f && defocus_y == 0.0f) ? 0.0f : 1.0f); |
| 2190 | 2246 | |
| 2191 | 2247 | (*d3dintf->effect.begin)(curr_effect, &num_passes, 0); |
| 2192 | 2248 | |
| 2193 | | result = (*d3dintf->device.set_render_target)(d3d->device, 0, poly->texture->d3dtarget2); |
| 2194 | | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device set_render_target call 6\n", (int)result); |
| 2195 | | result = (*d3dintf->device.clear)(d3d->device, 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_ARGB(0,0,0,0), 0, 0); |
| 2196 | | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device clear call\n", (int)result); |
| 2249 | result = (*d3dintf->device.set_render_target)(d3d->device, 0, poly->texture->d3dtarget1); |
| 2250 | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device set_render_target call 7\n", (int)result); |
| 2197 | 2251 | |
| 2198 | 2252 | for (UINT pass = 0; pass < num_passes; pass++) |
| 2199 | 2253 | { |
| r11575 | r11576 | |
| 2206 | 2260 | |
| 2207 | 2261 | (*d3dintf->effect.end)(curr_effect); |
| 2208 | 2262 | |
| 2209 | | /* Lastly, defocus pass 1 */ |
| 2210 | | (*d3dintf->effect.set_texture)(curr_effect, "Diffuse", poly->texture->d3dtexture2); |
| 2263 | // Simulate phosphorescence. This should happen after the shadow/scanline pass, but since |
| 2264 | // the phosphors are a direct result of the incoming texture, might as well just change the |
| 2265 | // input texture. |
| 2266 | curr_effect = d3d->phosphor_effect; |
| 2211 | 2267 | |
| 2212 | 2268 | (*d3dintf->effect.set_float)(curr_effect, "TargetWidth", (float)d3d->width); |
| 2213 | 2269 | (*d3dintf->effect.set_float)(curr_effect, "TargetHeight", (float)d3d->height); |
| 2214 | 2270 | (*d3dintf->effect.set_float)(curr_effect, "RawWidth", (float)poly->texture->rawwidth); |
| 2215 | 2271 | (*d3dintf->effect.set_float)(curr_effect, "RawHeight", (float)poly->texture->rawheight); |
| 2216 | | (*d3dintf->effect.set_float)(curr_effect, "DefocusX", defocus_x); |
| 2217 | | (*d3dintf->effect.set_float)(curr_effect, "DefocusY", defocus_y); |
| 2218 | | (*d3dintf->effect.set_float)(curr_effect, "FocusEnable", (defocus_x == 0.0f && defocus_y == 0.0f) ? 0.0f : 1.0f); |
| 2272 | (*d3dintf->effect.set_float)(curr_effect, "RedPhosphor", (float)options.screen_red_phosphor()); |
| 2273 | (*d3dintf->effect.set_float)(curr_effect, "GreenPhosphor", (float)options.screen_green_phosphor()); |
| 2274 | (*d3dintf->effect.set_float)(curr_effect, "BluePhosphor", (float)options.screen_blue_phosphor()); |
| 2219 | 2275 | |
| 2276 | (*d3dintf->effect.set_texture)(curr_effect, "Diffuse", poly->texture->d3dtexture1); |
| 2277 | (*d3dintf->effect.set_texture)(curr_effect, "LastPass", d3d->last_d3dtexture[cur_render_screen]); |
| 2278 | |
| 2279 | result = (*d3dintf->device.set_render_target)(d3d->device, 0, poly->texture->d3dtarget0); |
| 2280 | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device set_render_target call 4\n", (int)result); |
| 2281 | result = (*d3dintf->device.clear)(d3d->device, 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_ARGB(0,0,0,0), 0, 0); |
| 2282 | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device clear call\n", (int)result); |
| 2283 | |
| 2220 | 2284 | (*d3dintf->effect.begin)(curr_effect, &num_passes, 0); |
| 2221 | 2285 | |
| 2286 | for (UINT pass = 0; pass < num_passes; pass++) |
| 2287 | { |
| 2288 | (*d3dintf->effect.begin_pass)(curr_effect, pass); |
| 2289 | // add the primitives |
| 2290 | result = (*d3dintf->device.draw_primitive)(d3d->device, poly->type, vertnum, poly->count); |
| 2291 | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device draw_primitive call\n", (int)result); |
| 2292 | (*d3dintf->effect.end_pass)(curr_effect); |
| 2293 | } |
| 2294 | |
| 2295 | (*d3dintf->effect.end)(curr_effect); |
| 2296 | |
| 2297 | /* Pass along our phosphor'd screen */ |
| 2298 | curr_effect = d3d->phosphor_effect; |
| 2299 | |
| 2300 | (*d3dintf->effect.set_float)(curr_effect, "FixedAlpha", 1.0f); |
| 2301 | |
| 2302 | (*d3dintf->effect.set_texture)(curr_effect, "Diffuse", poly->texture->d3dtexture1); |
| 2303 | (*d3dintf->effect.set_texture)(curr_effect, "LastPass", poly->texture->d3dtexture1); |
| 2304 | |
| 2305 | result = (*d3dintf->device.set_render_target)(d3d->device, 0, d3d->last_d3dtarget[cur_render_screen++]); |
| 2306 | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device set_render_target call 5\n", (int)result); |
| 2307 | result = (*d3dintf->device.clear)(d3d->device, 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_ARGB(0,0,0,0), 0, 0); |
| 2308 | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device clear call\n", (int)result); |
| 2309 | |
| 2310 | (*d3dintf->effect.begin)(curr_effect, &num_passes, 0); |
| 2311 | |
| 2312 | for (UINT pass = 0; pass < num_passes; pass++) |
| 2313 | { |
| 2314 | (*d3dintf->effect.begin_pass)(curr_effect, pass); |
| 2315 | // add the primitives |
| 2316 | result = (*d3dintf->device.draw_primitive)(d3d->device, poly->type, vertnum, poly->count); |
| 2317 | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device draw_primitive call\n", (int)result); |
| 2318 | (*d3dintf->effect.end_pass)(curr_effect); |
| 2319 | } |
| 2320 | |
| 2321 | (*d3dintf->effect.end)(curr_effect); |
| 2322 | |
| 2323 | /* Scanlines and shadow mask */ |
| 2324 | curr_effect = d3d->post_effect; |
| 2325 | |
| 2326 | (*d3dintf->effect.set_texture)(curr_effect, "Diffuse", poly->texture->d3dtexture0); |
| 2327 | |
| 2222 | 2328 | result = (*d3dintf->device.set_render_target)(d3d->device, 0, backbuffer); |
| 2223 | | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device set_render_target call 7\n", (int)result); |
| 2329 | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device set_render_target call 5\n", (int)result); |
| 2330 | result = (*d3dintf->device.clear)(d3d->device, 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_ARGB(0,0,0,0), 0, 0); |
| 2331 | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device clear call\n", (int)result); |
| 2224 | 2332 | |
| 2333 | (*d3dintf->effect.begin)(curr_effect, &num_passes, 0); |
| 2334 | |
| 2225 | 2335 | for (UINT pass = 0; pass < num_passes; pass++) |
| 2226 | 2336 | { |
| 2227 | 2337 | (*d3dintf->effect.begin_pass)(curr_effect, pass); |
| r11575 | r11576 | |
| 2234 | 2344 | (*d3dintf->effect.end)(curr_effect); |
| 2235 | 2345 | |
| 2236 | 2346 | poly->texture->cur_frame++; |
| 2237 | | poly->texture->cur_frame %= options.screen_dot_crawl_rate(); |
| 2347 | poly->texture->cur_frame %= 2; |
| 2238 | 2348 | } |
| 2239 | 2349 | else |
| 2240 | 2350 | { |
| r11575 | r11576 | |
| 2245 | 2355 | (*d3dintf->effect.set_float)(curr_effect, "TargetWidth", (float)d3d->width); |
| 2246 | 2356 | (*d3dintf->effect.set_float)(curr_effect, "TargetHeight", (float)d3d->height); |
| 2247 | 2357 | (*d3dintf->effect.set_float)(curr_effect, "PostPass", 0.0f); |
| 2248 | | (*d3dintf->effect.set_float)(curr_effect, "PincushionAmountX", (float)options.screen_pincushion_x()); |
| 2249 | | (*d3dintf->effect.set_float)(curr_effect, "PincushionAmountY", (float)options.screen_pincushion_y()); |
| 2358 | (*d3dintf->effect.set_float)(curr_effect, "PincushionAmountX", (float)options.screen_pincushion()); |
| 2359 | (*d3dintf->effect.set_float)(curr_effect, "PincushionAmountY", (float)options.screen_pincushion()); |
| 2250 | 2360 | |
| 2251 | 2361 | (*d3dintf->effect.begin)(curr_effect, &num_passes, 0); |
| 2252 | 2362 | |
| r11575 | r11576 | |
| 2274 | 2384 | vertnum += poly->numverts; |
| 2275 | 2385 | } |
| 2276 | 2386 | |
| 2277 | | (*d3dintf->surface.release)(backbuffer); |
| 2387 | if(d3d->hlsl_enable && d3dintf->post_fx_available) |
| 2388 | { |
| 2389 | (*d3dintf->surface.release)(backbuffer); |
| 2390 | } |
| 2278 | 2391 | |
| 2279 | 2392 | // reset the vertex count |
| 2280 | 2393 | d3d->numverts = 0; |
| r11575 | r11576 | |
| 2372 | 2485 | if (result != D3D_OK) |
| 2373 | 2486 | goto error; |
| 2374 | 2487 | (*d3dintf->texture.get_surface_level)(d3d->last_d3dtexture[d3d->registered_targets], 0, &d3d->last_d3dtarget[d3d->registered_targets]); |
| 2375 | | d3d->registered_targets++; |
| 2376 | 2488 | |
| 2377 | 2489 | result = (*d3dintf->device.create_texture)(d3d->device, (int)(d3d->width * d3d->oversample_x), (int)(d3d->height * d3d->oversample_y), 1, D3DUSAGE_RENDERTARGET, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &texture->d3dtexture1); |
| 2378 | 2490 | if (result != D3D_OK) |
| r11575 | r11576 | |
| 2383 | 2495 | if (result != D3D_OK) |
| 2384 | 2496 | goto error; |
| 2385 | 2497 | (*d3dintf->texture.get_surface_level)(texture->d3dtexture2, 0, &texture->d3dtarget2); |
| 2498 | |
| 2499 | result = (*d3dintf->device.create_texture)(d3d->device, texture->rawwidth, texture->rawheight, 1, D3DUSAGE_RENDERTARGET, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &texture->d3dsmalltexture0); |
| 2500 | if (result != D3D_OK) |
| 2501 | goto error; |
| 2502 | (*d3dintf->texture.get_surface_level)(texture->d3dsmalltexture0, 0, &texture->d3dsmalltarget0); |
| 2503 | |
| 2504 | result = (*d3dintf->device.create_texture)(d3d->device, texture->rawwidth, texture->rawheight, 1, D3DUSAGE_RENDERTARGET, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &texture->d3dsmalltexture1); |
| 2505 | if (result != D3D_OK) |
| 2506 | goto error; |
| 2507 | (*d3dintf->texture.get_surface_level)(texture->d3dsmalltexture1, 0, &texture->d3dsmalltarget1); |
| 2508 | |
| 2509 | d3d->registered_targets++; |
| 2510 | |
| 2386 | 2511 | break; |
| 2387 | 2512 | } |
| 2388 | 2513 | } |
| r11575 | r11576 | |
| 2442 | 2567 | goto error; |
| 2443 | 2568 | (*d3dintf->texture.get_surface_level)(texture->d3dtexture2, 0, &texture->d3dtarget2); |
| 2444 | 2569 | |
| 2570 | result = (*d3dintf->device.create_texture)(d3d->device, scwidth, scheight, 1, D3DUSAGE_RENDERTARGET, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &texture->d3dsmalltexture0); |
| 2571 | if (result != D3D_OK) |
| 2572 | goto error; |
| 2573 | (*d3dintf->texture.get_surface_level)(texture->d3dsmalltexture0, 0, &texture->d3dsmalltarget0); |
| 2574 | |
| 2575 | result = (*d3dintf->device.create_texture)(d3d->device, scwidth, scheight, 1, D3DUSAGE_RENDERTARGET, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &texture->d3dsmalltexture1); |
| 2576 | if (result != D3D_OK) |
| 2577 | goto error; |
| 2578 | (*d3dintf->texture.get_surface_level)(texture->d3dsmalltexture0, 1, &texture->d3dsmalltarget1); |
| 2579 | |
| 2445 | 2580 | break; |
| 2446 | 2581 | } |
| 2447 | 2582 | (*d3dintf->texture.release)(texture->d3dtex); |