michael@0: // We store vertex coordinates and the quad shape in a constant buffer, this is michael@0: // easy to update and allows us to use a single call to set the x, y, w, h of michael@0: // the quad. michael@0: // The QuadDesc and TexCoords both work as follows: michael@0: // The x component is the quad left point, the y component is the top point michael@0: // the z component is the width, and the w component is the height. The quad michael@0: // are specified in viewport coordinates, i.e. { -1.0f, 1.0f, 2.0f, -2.0f } michael@0: // would cover the entire viewport (which runs from <-1.0f, 1.0f> left to right michael@0: // and <-1.0f, 1.0f> -bottom- to top. The TexCoords desc is specified in texture michael@0: // space <0, 1.0f> left to right and top to bottom. The input vertices of the michael@0: // shader stage always form a rectangle from {0, 0} - {1, 1} michael@0: cbuffer cb0 michael@0: { michael@0: float4 QuadDesc; michael@0: float4 TexCoords; michael@0: float4 MaskTexCoords; michael@0: float4 TextColor; michael@0: } michael@0: michael@0: cbuffer cb1 michael@0: { michael@0: float4 BlurOffsetsH[3]; michael@0: float4 BlurOffsetsV[3]; michael@0: float4 BlurWeights[3]; michael@0: float4 ShadowColor; michael@0: } michael@0: michael@0: cbuffer cb2 michael@0: { michael@0: float3x3 DeviceSpaceToUserSpace; michael@0: float2 dimensions; michael@0: // Precalculate as much as we can! michael@0: float3 diff; michael@0: float2 center1; michael@0: float A; michael@0: float radius1; michael@0: float sq_radius1; michael@0: } michael@0: michael@0: struct VS_OUTPUT michael@0: { michael@0: float4 Position : SV_Position; michael@0: float2 TexCoord : TEXCOORD0; michael@0: float2 MaskTexCoord : TEXCOORD1; michael@0: }; michael@0: michael@0: struct VS_RADIAL_OUTPUT michael@0: { michael@0: float4 Position : SV_Position; michael@0: float2 MaskTexCoord : TEXCOORD0; michael@0: float2 PixelCoord : TEXCOORD1; michael@0: }; michael@0: michael@0: struct PS_TEXT_OUTPUT michael@0: { michael@0: float4 color; michael@0: float4 alpha; michael@0: }; michael@0: michael@0: Texture2D tex; michael@0: Texture2D bcktex; michael@0: Texture2D mask; michael@0: uint blendop; michael@0: michael@0: sampler sSampler = sampler_state { michael@0: Filter = MIN_MAG_MIP_LINEAR; michael@0: Texture = tex; michael@0: AddressU = Clamp; michael@0: AddressV = Clamp; michael@0: }; michael@0: michael@0: sampler sBckSampler = sampler_state { michael@0: Filter = MIN_MAG_MIP_LINEAR; michael@0: Texture = bcktex; michael@0: AddressU = Clamp; michael@0: AddressV = Clamp; michael@0: }; michael@0: michael@0: sampler sWrapSampler = sampler_state { michael@0: Filter = MIN_MAG_MIP_LINEAR; michael@0: Texture = tex; michael@0: AddressU = Wrap; michael@0: AddressV = Wrap; michael@0: }; michael@0: michael@0: sampler sMirrorSampler = sampler_state { michael@0: Filter = MIN_MAG_MIP_LINEAR; michael@0: Texture = tex; michael@0: AddressU = Mirror; michael@0: AddressV = Mirror; michael@0: }; michael@0: michael@0: sampler sMaskSampler = sampler_state { michael@0: Filter = MIN_MAG_MIP_LINEAR; michael@0: Texture = mask; michael@0: AddressU = Clamp; michael@0: AddressV = Clamp; michael@0: }; michael@0: michael@0: sampler sShadowSampler = sampler_state { michael@0: Filter = MIN_MAG_MIP_LINEAR; michael@0: Texture = tex; michael@0: AddressU = Border; michael@0: AddressV = Border; michael@0: BorderColor = float4(0, 0, 0, 0); michael@0: }; michael@0: michael@0: RasterizerState TextureRast michael@0: { michael@0: ScissorEnable = True; michael@0: CullMode = None; michael@0: }; michael@0: michael@0: BlendState ShadowBlendH michael@0: { michael@0: BlendEnable[0] = False; michael@0: RenderTargetWriteMask[0] = 0xF; michael@0: }; michael@0: michael@0: BlendState ShadowBlendV michael@0: { michael@0: BlendEnable[0] = True; michael@0: SrcBlend = One; michael@0: DestBlend = Inv_Src_Alpha; michael@0: BlendOp = Add; michael@0: SrcBlendAlpha = One; michael@0: DestBlendAlpha = Inv_Src_Alpha; michael@0: BlendOpAlpha = Add; michael@0: RenderTargetWriteMask[0] = 0xF; michael@0: }; michael@0: michael@0: BlendState bTextBlend michael@0: { michael@0: AlphaToCoverageEnable = FALSE; michael@0: BlendEnable[0] = TRUE; michael@0: SrcBlend = Src1_Color; michael@0: DestBlend = Inv_Src1_Color; michael@0: BlendOp = Add; michael@0: SrcBlendAlpha = Src1_Alpha; michael@0: DestBlendAlpha = Inv_Src1_Alpha; michael@0: BlendOpAlpha = Add; michael@0: RenderTargetWriteMask[0] = 0x0F; // All michael@0: }; michael@0: michael@0: VS_OUTPUT SampleTextureVS(float3 pos : POSITION) michael@0: { michael@0: VS_OUTPUT Output; michael@0: Output.Position.w = 1.0f; michael@0: Output.Position.x = pos.x * QuadDesc.z + QuadDesc.x; michael@0: Output.Position.y = pos.y * QuadDesc.w + QuadDesc.y; michael@0: Output.Position.z = 0; michael@0: Output.TexCoord.x = pos.x * TexCoords.z + TexCoords.x; michael@0: Output.TexCoord.y = pos.y * TexCoords.w + TexCoords.y; michael@0: Output.MaskTexCoord.x = pos.x * MaskTexCoords.z + MaskTexCoords.x; michael@0: Output.MaskTexCoord.y = pos.y * MaskTexCoords.w + MaskTexCoords.y; michael@0: return Output; michael@0: } michael@0: michael@0: VS_RADIAL_OUTPUT SampleRadialVS(float3 pos : POSITION) michael@0: { michael@0: VS_RADIAL_OUTPUT Output; michael@0: Output.Position.w = 1.0f; michael@0: Output.Position.x = pos.x * QuadDesc.z + QuadDesc.x; michael@0: Output.Position.y = pos.y * QuadDesc.w + QuadDesc.y; michael@0: Output.Position.z = 0; michael@0: Output.MaskTexCoord.x = pos.x * MaskTexCoords.z + MaskTexCoords.x; michael@0: Output.MaskTexCoord.y = pos.y * MaskTexCoords.w + MaskTexCoords.y; michael@0: michael@0: // For the radial gradient pixel shader we need to pass in the pixel's michael@0: // coordinates in user space for the color to be correctly determined. michael@0: michael@0: Output.PixelCoord.x = ((Output.Position.x + 1.0f) / 2.0f) * dimensions.x; michael@0: Output.PixelCoord.y = ((1.0f - Output.Position.y) / 2.0f) * dimensions.y; michael@0: Output.PixelCoord.xy = mul(float3(Output.PixelCoord.x, Output.PixelCoord.y, 1.0f), DeviceSpaceToUserSpace).xy; michael@0: return Output; michael@0: } michael@0: michael@0: float Screen(float a, float b) michael@0: { michael@0: return 1 - ((1 - a)*(1 - b)); michael@0: } michael@0: michael@0: static float RedLuminance = 0.3f; michael@0: static float GreenLuminance = 0.59f; michael@0: static float BlueLuminance = 0.11f; michael@0: michael@0: float Lum(float3 C) michael@0: { michael@0: return RedLuminance * C.r + GreenLuminance * C.g + BlueLuminance * C.b; michael@0: } michael@0: michael@0: float3 ClipColor(float3 C) michael@0: { michael@0: float L = Lum(C); michael@0: float n = min(min(C.r, C.g), C.b); michael@0: float x = max(max(C.r, C.g), C.b); michael@0: michael@0: if(n < 0) michael@0: C = L + (((C - L) * L) / (L - n)); michael@0: michael@0: if(x > 1) michael@0: C = L + ((C - L) * (1 - L) / (x - L)); michael@0: michael@0: return C; michael@0: } michael@0: michael@0: float3 SetLum(float3 C, float l) michael@0: { michael@0: float d = l - Lum(C); michael@0: C = C + d; michael@0: return ClipColor(C); michael@0: } michael@0: michael@0: float Sat(float3 C) michael@0: { michael@0: return max(C.r, max(C.g, C.b)) - min(C.r, min(C.g, C.b)); michael@0: } michael@0: michael@0: void SetSatComponents(inout float minComp, inout float midComp, inout float maxComp, in float satVal) michael@0: { michael@0: midComp -= minComp; michael@0: maxComp -= minComp; michael@0: minComp = 0.0; michael@0: if (maxComp > 0.0) michael@0: { michael@0: midComp *= satVal/maxComp; michael@0: maxComp = satVal; michael@0: } michael@0: } michael@0: michael@0: float3 SetSat(float3 color, in float satVal) michael@0: { michael@0: if (color.x <= color.y) { michael@0: if (color.y <= color.z) { michael@0: // x <= y <= z michael@0: SetSatComponents(color.x, color.y, color.z, satVal); michael@0: } michael@0: else { michael@0: if (color.x <= color.z) { michael@0: // x <= z <= y michael@0: SetSatComponents(color.x, color.z, color.y, satVal); michael@0: } michael@0: else { michael@0: // z <= x <= y michael@0: SetSatComponents(color.z, color.x, color.y, satVal); michael@0: } michael@0: } michael@0: } michael@0: else { michael@0: if (color.x <= color.z) { michael@0: // y <= x <= z michael@0: SetSatComponents(color.y, color.x, color.z, satVal); michael@0: } michael@0: else { michael@0: if (color.y <= color.z) { michael@0: // y <= z <= x michael@0: SetSatComponents(color.y, color.z, color.x, satVal); michael@0: } michael@0: else { michael@0: // z <= y <= x michael@0: SetSatComponents(color.z, color.y, color.x, satVal); michael@0: } michael@0: } michael@0: } michael@0: michael@0: return color; michael@0: } michael@0: michael@0: float4 SampleBlendTextureSeparablePS_1( VS_OUTPUT In) : SV_Target michael@0: { michael@0: float4 output = tex.Sample(sSampler, In.TexCoord); michael@0: float4 background = bcktex.Sample(sBckSampler, In.TexCoord); michael@0: if((output.a == 0) || (background.a == 0)) michael@0: return output; michael@0: michael@0: output.rgb /= output.a; michael@0: background.rgb /= background.a; michael@0: michael@0: float4 retval = output; michael@0: michael@0: if(blendop == 1) { // multiply michael@0: retval.rgb = output.rgb * background.rgb; michael@0: } else if(blendop == 2) { michael@0: retval.rgb = output.rgb + background.rgb - output.rgb * background.rgb; michael@0: } else if(blendop == 3) { michael@0: if(background.r <= 0.5) michael@0: retval.r = 2*background.r * output.r; michael@0: else michael@0: retval.r = Screen(output.r, 2 * background.r - 1); michael@0: if(background.g <= 0.5) michael@0: retval.g = 2 * background.g * output.g; michael@0: else michael@0: retval.g = Screen(output.g, 2 * background.g - 1); michael@0: if(background.b <= 0.5) michael@0: retval.b = 2 * background.b * output.b; michael@0: else michael@0: retval.b = Screen(output.b, 2 * background.b - 1); michael@0: } else if(blendop == 4) { michael@0: retval.rgb = min(output.rgb, background.rgb); michael@0: } else if(blendop == 5) { michael@0: retval.rgb = max(output.rgb, background.rgb); michael@0: } else { michael@0: if(background.r == 0) michael@0: retval.r = 0; michael@0: else michael@0: if(output.r == 1) michael@0: retval.r = 1; michael@0: else michael@0: retval.r = min(1, background.r / (1 - output.r)); michael@0: if(background.g == 0) michael@0: retval.g = 0; michael@0: else michael@0: if(output.g == 1) michael@0: retval.g = 1; michael@0: else michael@0: retval.g = min(1, background.g / (1 - output.g)); michael@0: if(background.b == 0) michael@0: retval.b = 0; michael@0: else michael@0: if(output.b == 1) michael@0: retval.b = 1; michael@0: else michael@0: retval.b = min(1, background.b / (1 - output.b)); michael@0: } michael@0: michael@0: output.rgb = ((1 - background.a) * output.rgb + background.a * retval.rgb) * output.a; michael@0: return output; michael@0: } michael@0: michael@0: float4 SampleBlendTextureSeparablePS_2( VS_OUTPUT In) : SV_Target michael@0: { michael@0: float4 output = tex.Sample(sSampler, In.TexCoord); michael@0: float4 background = bcktex.Sample(sBckSampler, In.TexCoord); michael@0: if((output.a == 0) || (background.a == 0)) michael@0: return output; michael@0: michael@0: output.rgb /= output.a; michael@0: background.rgb /= background.a; michael@0: michael@0: float4 retval = output; michael@0: michael@0: if(blendop == 7) { michael@0: if(background.r == 1) michael@0: retval.r = 1; michael@0: else michael@0: if(output.r == 0) michael@0: retval.r = 0; michael@0: else michael@0: retval.r = 1 - min(1, (1 - background.r) / output.r); michael@0: if(background.g == 1) michael@0: retval.g = 1; michael@0: else michael@0: if(output.g == 0) michael@0: retval.g = 0; michael@0: else michael@0: retval.g = 1 - min(1, (1 - background.g) / output.g); michael@0: if(background.b == 1) michael@0: retval.b = 1; michael@0: else michael@0: if(output.b == 0) michael@0: retval.b = 0; michael@0: else michael@0: retval.b = 1 - min(1, (1 - background.b) / output.b); michael@0: } else if(blendop == 8) { michael@0: if(output.r <= 0.5) michael@0: retval.r = 2 * output.r * background.r; michael@0: else michael@0: retval.r = Screen(background.r, 2 * output.r -1); michael@0: if(output.g <= 0.5) michael@0: retval.g = 2 * output.g * background.g; michael@0: else michael@0: retval.g = Screen(background.g, 2 * output.g -1); michael@0: if(output.b <= 0.5) michael@0: retval.b = 2 * output.b * background.b; michael@0: else michael@0: retval.b = Screen(background.b, 2 * output.b -1); michael@0: } else if(blendop == 9){ michael@0: float D; michael@0: if(background.r <= 0.25) michael@0: D = ((16 * background.r - 12) * background.r + 4) * background.r; michael@0: else michael@0: D = sqrt(background.r); michael@0: if(output.r <= 0.5) michael@0: retval.r = background.r - (1 - 2 * output.r) * background.r * (1 - background.r); michael@0: else michael@0: retval.r = background.r + (2 * output.r - 1) * (D - background.r); michael@0: michael@0: if(background.g <= 0.25) michael@0: D = ((16 * background.g - 12) * background.g + 4) * background.g; michael@0: else michael@0: D = sqrt(background.g); michael@0: if(output.g <= 0.5) michael@0: retval.g = background.g - (1 - 2 * output.g) * background.g * (1 - background.g); michael@0: else michael@0: retval.g = background.g + (2 * output.g - 1) * (D - background.g); michael@0: michael@0: if(background.b <= 0.25) michael@0: D = ((16 * background.b - 12) * background.b + 4) * background.b; michael@0: else michael@0: D = sqrt(background.b); michael@0: michael@0: if(output.b <= 0.5) michael@0: retval.b = background.b - (1 - 2 * output.b) * background.b * (1 - background.b); michael@0: else michael@0: retval.b = background.b + (2 * output.b - 1) * (D - background.b); michael@0: } else if(blendop == 10) { michael@0: retval.rgb = abs(output.rgb - background.rgb); michael@0: } else { michael@0: retval.rgb = output.rgb + background.rgb - 2 * output.rgb * background.rgb; michael@0: } michael@0: michael@0: output.rgb = ((1 - background.a) * output.rgb + background.a * retval.rgb) * output.a; michael@0: return output; michael@0: } michael@0: michael@0: float4 SampleBlendTextureNonSeparablePS( VS_OUTPUT In) : SV_Target michael@0: { michael@0: float4 output = tex.Sample(sSampler, In.TexCoord); michael@0: float4 background = bcktex.Sample(sBckSampler, In.TexCoord); michael@0: if((output.a == 0) || (background.a == 0)) michael@0: return output; michael@0: michael@0: output.rgb /= output.a; michael@0: background.rgb /= background.a; michael@0: michael@0: float4 retval = output; michael@0: michael@0: if(blendop == 12) { michael@0: retval.rgb = SetLum(SetSat(output.rgb, Sat(background.rgb)), Lum(background.rgb)); michael@0: } else if(blendop == 13) { michael@0: retval.rgb = SetLum(SetSat(background.rgb, Sat(output.rgb)), Lum(background.rgb)); michael@0: } else if(blendop == 14) { michael@0: retval.rgb = SetLum(output.rgb, Lum(background.rgb)); michael@0: } else { michael@0: retval.rgb = SetLum(background.rgb, Lum(output.rgb)); michael@0: } michael@0: michael@0: output.rgb = ((1 - background.a) * output.rgb + background.a * retval.rgb) * output.a; michael@0: return output; michael@0: } michael@0: michael@0: michael@0: float4 SampleTexturePS( VS_OUTPUT In) : SV_Target michael@0: { michael@0: return tex.Sample(sSampler, In.TexCoord); michael@0: } michael@0: michael@0: float4 SampleMaskTexturePS( VS_OUTPUT In) : SV_Target michael@0: { michael@0: return tex.Sample(sSampler, In.TexCoord) * mask.Sample(sMaskSampler, In.MaskTexCoord).a; michael@0: } michael@0: michael@0: float4 SampleRadialGradientPS(VS_RADIAL_OUTPUT In, uniform sampler aSampler) : SV_Target michael@0: { michael@0: // Radial gradient painting is defined as the set of circles whose centers michael@0: // are described by C(t) = (C2 - C1) * t + C1; with radii michael@0: // R(t) = (R2 - R1) * t + R1; for R(t) > 0. This shader solves the michael@0: // quadratic equation that arises when calculating t for pixel (x, y). michael@0: // michael@0: // A more extensive derrivation can be found in the pixman radial gradient michael@0: // code. michael@0: michael@0: float2 p = In.PixelCoord; michael@0: float3 dp = float3(p - center1, radius1); michael@0: michael@0: // dpx * dcx + dpy * dcy + r * dr michael@0: float B = dot(dp, diff); michael@0: michael@0: float C = pow(dp.x, 2) + pow(dp.y, 2) - sq_radius1; michael@0: michael@0: float det = pow(B, 2) - A * C; michael@0: michael@0: if (det < 0) { michael@0: return float4(0, 0, 0, 0); michael@0: } michael@0: michael@0: float sqrt_det = sqrt(abs(det)); michael@0: michael@0: float2 t = (B + float2(sqrt_det, -sqrt_det)) / A; michael@0: michael@0: float2 isValid = step(float2(-radius1, -radius1), t * diff.z); michael@0: michael@0: if (max(isValid.x, isValid.y) <= 0) { michael@0: return float4(0, 0, 0, 0); michael@0: } michael@0: michael@0: float upper_t = lerp(t.y, t.x, isValid.x); michael@0: michael@0: float4 output = tex.Sample(aSampler, float2(upper_t, 0.5)); michael@0: // Premultiply michael@0: output.rgb *= output.a; michael@0: // Multiply the output color by the input mask for the operation. michael@0: output *= mask.Sample(sMaskSampler, In.MaskTexCoord).a; michael@0: return output; michael@0: }; michael@0: michael@0: float4 SampleRadialGradientA0PS( VS_RADIAL_OUTPUT In, uniform sampler aSampler ) : SV_Target michael@0: { michael@0: // This simpler shader is used for the degenerate case where A is 0, michael@0: // i.e. we're actually solving a linear equation. michael@0: michael@0: float2 p = In.PixelCoord; michael@0: float3 dp = float3(p - center1, radius1); michael@0: michael@0: // dpx * dcx + dpy * dcy + r * dr michael@0: float B = dot(dp, diff); michael@0: michael@0: float C = pow(dp.x, 2) + pow(dp.y, 2) - pow(radius1, 2); michael@0: michael@0: float t = 0.5 * C / B; michael@0: michael@0: if (-radius1 >= t * diff.z) { michael@0: return float4(0, 0, 0, 0); michael@0: } michael@0: michael@0: float4 output = tex.Sample(aSampler, float2(t, 0.5)); michael@0: // Premultiply michael@0: output.rgb *= output.a; michael@0: // Multiply the output color by the input mask for the operation. michael@0: output *= mask.Sample(sMaskSampler, In.MaskTexCoord).a; michael@0: return output; michael@0: }; michael@0: michael@0: float4 SampleShadowHPS( VS_OUTPUT In) : SV_Target michael@0: { michael@0: float outputStrength = 0; michael@0: michael@0: outputStrength += BlurWeights[0].x * tex.Sample(sShadowSampler, float2(In.TexCoord.x + BlurOffsetsH[0].x, In.TexCoord.y)).a; michael@0: outputStrength += BlurWeights[0].y * tex.Sample(sShadowSampler, float2(In.TexCoord.x + BlurOffsetsH[0].y, In.TexCoord.y)).a; michael@0: outputStrength += BlurWeights[0].z * tex.Sample(sShadowSampler, float2(In.TexCoord.x + BlurOffsetsH[0].z, In.TexCoord.y)).a; michael@0: outputStrength += BlurWeights[0].w * tex.Sample(sShadowSampler, float2(In.TexCoord.x + BlurOffsetsH[0].w, In.TexCoord.y)).a; michael@0: outputStrength += BlurWeights[1].x * tex.Sample(sShadowSampler, float2(In.TexCoord.x + BlurOffsetsH[1].x, In.TexCoord.y)).a; michael@0: outputStrength += BlurWeights[1].y * tex.Sample(sShadowSampler, float2(In.TexCoord.x + BlurOffsetsH[1].y, In.TexCoord.y)).a; michael@0: outputStrength += BlurWeights[1].z * tex.Sample(sShadowSampler, float2(In.TexCoord.x + BlurOffsetsH[1].z, In.TexCoord.y)).a; michael@0: outputStrength += BlurWeights[1].w * tex.Sample(sShadowSampler, float2(In.TexCoord.x + BlurOffsetsH[1].w, In.TexCoord.y)).a; michael@0: outputStrength += BlurWeights[2].x * tex.Sample(sShadowSampler, float2(In.TexCoord.x + BlurOffsetsH[2].x, In.TexCoord.y)).a; michael@0: michael@0: return ShadowColor * outputStrength; michael@0: }; michael@0: michael@0: float4 SampleShadowVPS( VS_OUTPUT In) : SV_Target michael@0: { michael@0: float4 outputColor = float4(0, 0, 0, 0); michael@0: michael@0: outputColor += BlurWeights[0].x * tex.Sample(sShadowSampler, float2(In.TexCoord.x, In.TexCoord.y + BlurOffsetsV[0].x)); michael@0: outputColor += BlurWeights[0].y * tex.Sample(sShadowSampler, float2(In.TexCoord.x, In.TexCoord.y + BlurOffsetsV[0].y)); michael@0: outputColor += BlurWeights[0].z * tex.Sample(sShadowSampler, float2(In.TexCoord.x, In.TexCoord.y + BlurOffsetsV[0].z)); michael@0: outputColor += BlurWeights[0].w * tex.Sample(sShadowSampler, float2(In.TexCoord.x, In.TexCoord.y + BlurOffsetsV[0].w)); michael@0: outputColor += BlurWeights[1].x * tex.Sample(sShadowSampler, float2(In.TexCoord.x, In.TexCoord.y + BlurOffsetsV[1].x)); michael@0: outputColor += BlurWeights[1].y * tex.Sample(sShadowSampler, float2(In.TexCoord.x, In.TexCoord.y + BlurOffsetsV[1].y)); michael@0: outputColor += BlurWeights[1].z * tex.Sample(sShadowSampler, float2(In.TexCoord.x, In.TexCoord.y + BlurOffsetsV[1].z)); michael@0: outputColor += BlurWeights[1].w * tex.Sample(sShadowSampler, float2(In.TexCoord.x, In.TexCoord.y + BlurOffsetsV[1].w)); michael@0: outputColor += BlurWeights[2].x * tex.Sample(sShadowSampler, float2(In.TexCoord.x, In.TexCoord.y + BlurOffsetsV[2].x)); michael@0: michael@0: return outputColor; michael@0: }; michael@0: michael@0: float4 SampleMaskShadowVPS( VS_OUTPUT In) : SV_Target michael@0: { michael@0: float4 outputColor = float4(0, 0, 0, 0); michael@0: michael@0: outputColor += BlurWeights[0].x * tex.Sample(sShadowSampler, float2(In.TexCoord.x, In.TexCoord.y + BlurOffsetsV[0].x)); michael@0: outputColor += BlurWeights[0].y * tex.Sample(sShadowSampler, float2(In.TexCoord.x, In.TexCoord.y + BlurOffsetsV[0].y)); michael@0: outputColor += BlurWeights[0].z * tex.Sample(sShadowSampler, float2(In.TexCoord.x, In.TexCoord.y + BlurOffsetsV[0].z)); michael@0: outputColor += BlurWeights[0].w * tex.Sample(sShadowSampler, float2(In.TexCoord.x, In.TexCoord.y + BlurOffsetsV[0].w)); michael@0: outputColor += BlurWeights[1].x * tex.Sample(sShadowSampler, float2(In.TexCoord.x, In.TexCoord.y + BlurOffsetsV[1].x)); michael@0: outputColor += BlurWeights[1].y * tex.Sample(sShadowSampler, float2(In.TexCoord.x, In.TexCoord.y + BlurOffsetsV[1].y)); michael@0: outputColor += BlurWeights[1].z * tex.Sample(sShadowSampler, float2(In.TexCoord.x, In.TexCoord.y + BlurOffsetsV[1].z)); michael@0: outputColor += BlurWeights[1].w * tex.Sample(sShadowSampler, float2(In.TexCoord.x, In.TexCoord.y + BlurOffsetsV[1].w)); michael@0: outputColor += BlurWeights[2].x * tex.Sample(sShadowSampler, float2(In.TexCoord.x, In.TexCoord.y + BlurOffsetsV[2].x)); michael@0: michael@0: return outputColor * mask.Sample(sMaskSampler, In.MaskTexCoord).a; michael@0: }; michael@0: michael@0: PS_TEXT_OUTPUT SampleTextTexturePS( VS_OUTPUT In) : SV_Target michael@0: { michael@0: PS_TEXT_OUTPUT output; michael@0: output.color = float4(TextColor.r, TextColor.g, TextColor.b, 1.0); michael@0: output.alpha.rgba = tex.Sample(sSampler, In.TexCoord).bgrg * TextColor.a; michael@0: return output; michael@0: }; michael@0: michael@0: PS_TEXT_OUTPUT SampleTextTexturePSMasked( VS_OUTPUT In) : SV_Target michael@0: { michael@0: PS_TEXT_OUTPUT output; michael@0: michael@0: float maskValue = mask.Sample(sMaskSampler, In.MaskTexCoord).a; michael@0: michael@0: output.color = float4(TextColor.r, TextColor.g, TextColor.b, 1.0); michael@0: output.alpha.rgba = tex.Sample(sSampler, In.TexCoord).bgrg * TextColor.a * maskValue; michael@0: michael@0: return output; michael@0: }; michael@0: michael@0: technique10 SampleTexture michael@0: { michael@0: pass P0 michael@0: { michael@0: SetRasterizerState(TextureRast); michael@0: SetVertexShader(CompileShader(vs_4_0_level_9_3, SampleTextureVS())); michael@0: SetGeometryShader(NULL); michael@0: SetPixelShader(CompileShader(ps_4_0_level_9_3, SampleTexturePS())); michael@0: } michael@0: } michael@0: michael@0: technique10 SampleTextureForSeparableBlending_1 michael@0: { michael@0: pass P0 michael@0: { michael@0: SetRasterizerState(TextureRast); michael@0: SetVertexShader(CompileShader(vs_4_0_level_9_3, SampleTextureVS())); michael@0: SetGeometryShader(NULL); michael@0: SetPixelShader(CompileShader(ps_4_0_level_9_3, SampleBlendTextureSeparablePS_1())); michael@0: } michael@0: } michael@0: michael@0: technique10 SampleTextureForSeparableBlending_2 michael@0: { michael@0: pass P0 michael@0: { michael@0: SetRasterizerState(TextureRast); michael@0: SetVertexShader(CompileShader(vs_4_0_level_9_3, SampleTextureVS())); michael@0: SetGeometryShader(NULL); michael@0: SetPixelShader(CompileShader(ps_4_0_level_9_3, SampleBlendTextureSeparablePS_2())); michael@0: } michael@0: } michael@0: michael@0: technique10 SampleTextureForNonSeparableBlending michael@0: { michael@0: pass P0 michael@0: { michael@0: SetRasterizerState(TextureRast); michael@0: SetVertexShader(CompileShader(vs_4_0_level_9_3, SampleTextureVS())); michael@0: SetGeometryShader(NULL); michael@0: SetPixelShader(CompileShader(ps_4_0_level_9_3, SampleBlendTextureNonSeparablePS())); michael@0: } michael@0: } michael@0: michael@0: technique10 SampleRadialGradient michael@0: { michael@0: pass APos michael@0: { michael@0: SetRasterizerState(TextureRast); michael@0: SetVertexShader(CompileShader(vs_4_0_level_9_3, SampleRadialVS())); michael@0: SetGeometryShader(NULL); michael@0: SetPixelShader(CompileShader(ps_4_0_level_9_3, SampleRadialGradientPS( sSampler ))); michael@0: } michael@0: pass A0 michael@0: { michael@0: SetRasterizerState(TextureRast); michael@0: SetVertexShader(CompileShader(vs_4_0_level_9_3, SampleRadialVS())); michael@0: SetGeometryShader(NULL); michael@0: SetPixelShader(CompileShader(ps_4_0_level_9_3, SampleRadialGradientA0PS( sSampler ))); michael@0: } michael@0: pass APosWrap michael@0: { michael@0: SetRasterizerState(TextureRast); michael@0: SetVertexShader(CompileShader(vs_4_0_level_9_3, SampleRadialVS())); michael@0: SetGeometryShader(NULL); michael@0: SetPixelShader(CompileShader(ps_4_0_level_9_3, SampleRadialGradientPS( sWrapSampler ))); michael@0: } michael@0: pass A0Wrap michael@0: { michael@0: SetRasterizerState(TextureRast); michael@0: SetVertexShader(CompileShader(vs_4_0_level_9_3, SampleRadialVS())); michael@0: SetGeometryShader(NULL); michael@0: SetPixelShader(CompileShader(ps_4_0_level_9_3, SampleRadialGradientA0PS( sWrapSampler ))); michael@0: } michael@0: pass APosMirror michael@0: { michael@0: SetRasterizerState(TextureRast); michael@0: SetVertexShader(CompileShader(vs_4_0_level_9_3, SampleRadialVS())); michael@0: SetGeometryShader(NULL); michael@0: SetPixelShader(CompileShader(ps_4_0_level_9_3, SampleRadialGradientPS( sMirrorSampler ))); michael@0: } michael@0: pass A0Mirror michael@0: { michael@0: SetRasterizerState(TextureRast); michael@0: SetVertexShader(CompileShader(vs_4_0_level_9_3, SampleRadialVS())); michael@0: SetGeometryShader(NULL); michael@0: SetPixelShader(CompileShader(ps_4_0_level_9_3, SampleRadialGradientA0PS( sMirrorSampler ))); michael@0: } michael@0: } michael@0: michael@0: technique10 SampleMaskedTexture michael@0: { michael@0: pass P0 michael@0: { michael@0: SetRasterizerState(TextureRast); michael@0: SetVertexShader(CompileShader(vs_4_0_level_9_3, SampleTextureVS())); michael@0: SetGeometryShader(NULL); michael@0: SetPixelShader(CompileShader(ps_4_0_level_9_3, SampleMaskTexturePS())); michael@0: } michael@0: } michael@0: michael@0: technique10 SampleTextureWithShadow michael@0: { michael@0: // Horizontal pass michael@0: pass P0 michael@0: { michael@0: SetRasterizerState(TextureRast); michael@0: SetBlendState(ShadowBlendH, float4(1.0f, 1.0f, 1.0f, 1.0f), 0xffffffff); michael@0: SetVertexShader(CompileShader(vs_4_0_level_9_3, SampleTextureVS())); michael@0: SetGeometryShader(NULL); michael@0: SetPixelShader(CompileShader(ps_4_0_level_9_3, SampleShadowHPS())); michael@0: } michael@0: // Vertical pass michael@0: pass P1 michael@0: { michael@0: SetRasterizerState(TextureRast); michael@0: SetBlendState(ShadowBlendV, float4(1.0f, 1.0f, 1.0f, 1.0f), 0xffffffff); michael@0: SetVertexShader(CompileShader(vs_4_0_level_9_3, SampleTextureVS())); michael@0: SetGeometryShader(NULL); michael@0: SetPixelShader(CompileShader(ps_4_0_level_9_3, SampleShadowVPS())); michael@0: } michael@0: // Vertical pass - used when using a mask michael@0: pass P2 michael@0: { michael@0: SetRasterizerState(TextureRast); michael@0: SetBlendState(ShadowBlendV, float4(1.0f, 1.0f, 1.0f, 1.0f), 0xffffffff); michael@0: SetVertexShader(CompileShader(vs_4_0_level_9_3, SampleTextureVS())); michael@0: SetGeometryShader(NULL); michael@0: SetPixelShader(CompileShader(ps_4_0_level_9_3, SampleMaskShadowVPS())); michael@0: } michael@0: } michael@0: michael@0: technique10 SampleTextTexture michael@0: { michael@0: pass Unmasked michael@0: { michael@0: SetRasterizerState(TextureRast); michael@0: SetBlendState(bTextBlend, float4( 0.0f, 0.0f, 0.0f, 0.0f ), 0xFFFFFFFF ); michael@0: SetVertexShader(CompileShader(vs_4_0_level_9_3, SampleTextureVS())); michael@0: SetGeometryShader(NULL); michael@0: SetPixelShader(CompileShader(ps_4_0_level_9_3, SampleTextTexturePS())); michael@0: } michael@0: pass Masked michael@0: { michael@0: SetRasterizerState(TextureRast); michael@0: SetBlendState(bTextBlend, float4( 0.0f, 0.0f, 0.0f, 0.0f ), 0xFFFFFFFF ); michael@0: SetVertexShader(CompileShader(vs_4_0_level_9_3, SampleTextureVS())); michael@0: SetGeometryShader(NULL); michael@0: SetPixelShader(CompileShader(ps_4_0_level_9_3, SampleTextTexturePSMasked())); michael@0: } michael@0: } michael@0: