[SOLVED] Is it possible to do what I'm trying to do here?
- Ioxa
- Topic Author
Less
More
9 years 2 months ago #1
by Ioxa
Is it possible to do what I'm trying to do here? was created by Ioxa
I'm trying to scale a texture down by half and then apply a blur to it. The way I have it set up now it blurs and then scales the image but when I try to apply another blur pass it returns a black screen. Can I only apply effects to the buffer image or am I doing something wrong?
Ultimately I'd like to pass the already scaled image to the first blur pass or maybe pass the image to another scaled texture. Also, is it possible to upscale an image? When I tried using values < 1 it would cause an error.
Warning: Spoiler!
//GaussEffect
//0 = off, 1 = Blur, 2 = effects image
#define GaussEffect 2
//GaussStrength
//[0.000 to 1.000] Amount of effect blended into the final image.
#define GaussStrength 0.500
//GaussQuality [0,1]
#define GaussQuality 0
#define HW 1.00
#define VW 1.00
#define SCALE 2
#define GAUSS_TOGGLE 0x2D
//TEXTURES
texture2D origframeTex2D : COLOR;
texture frameTex2D{Width = BUFFER_WIDTH/SCALE;Height = BUFFER_HEIGHT/SCALE;Format = R8G8B8A8;};
//SAMPLERS
sampler2D origframeSampler { Texture = origframeTex2D; };
sampler2D frameSampler { Texture = frameTex2D;SRGBTexture = FALSE;};
void Triangle(in uint id : SV_VertexID, out float4 pos : SV_Position, out float2 texcoord : TEXCOORD)
{
texcoord.x = (id == 2) ? 2.0 : 0.0;
texcoord.y = (id == 1) ? 2.0 : 0.0;
pos = float4(texcoord * float2(2.0, -2.0) + float2(-1.0, 1.0), 0.0, 1.0);
}
/*
float4 PassThrough(in float4 pos : SV_Position, in float2 texcoord : TEXCOORD) : COLOR
{
return tex2D(origframeSampler, texcoord);
}
*/
#define PIXEL_SIZE float2(BUFFER_RCP_WIDTH,BUFFER_RCP_HEIGHT)
//First blur pass using original image (origframeSampler).
float4 GaussianBlurPS(in float4 pos : SV_Position, in float2 texcoord : TEXCOORD) : COLOR
{
float sampleOffsets[5] = { 0.0, 1.4347826, 3.3478260, 5.2608695, 7.1739130 };
float sampleWeights[5] = { 0.16818994, 0.27276957, 0.11690125, 0.024067905, 0.0021112196 };
float4 color;
float4 color1 = tex2D(origframeSampler, texcoord) * sampleWeights[0];
for(int i = 1; i < 5; ++i) {
color1 += tex2D(origframeSampler, texcoord + float2(sampleOffsets[i]*HW * PIXEL_SIZE.x, 0.0)) * sampleWeights[i];
color1 += tex2D(origframeSampler, texcoord - float2(sampleOffsets[i]*HW * PIXEL_SIZE.x, 0.0)) * sampleWeights[i];
}
float4 color2 = tex2D(origframeSampler, texcoord) * sampleWeights[0];
for(int j = 1; j < 5; ++j) {
color2 += tex2D(origframeSampler, texcoord + float2(0.0, sampleOffsets[j]*VW * PIXEL_SIZE.y)) * sampleWeights[j];
color2 += tex2D(origframeSampler, texcoord - float2(0.0, sampleOffsets[j]*VW * PIXEL_SIZE.y)) * sampleWeights[j];
}
return color = (color1 + color2)*0.5;
}
//Second pass using already blurred image.
float4 GaussianBlurPS2(in float4 pos : SV_Position, in float2 texcoord : TEXCOORD) : COLOR
{
float sampleOffsets[5] = { 0.0, 1.4347826, 3.3478260, 5.2608695, 7.1739130 };
float sampleWeights[5] = { 0.16818994, 0.27276957, 0.11690125, 0.024067905, 0.0021112196 };
float4 color;
float4 color1 = tex2D(frameSampler, texcoord) * sampleWeights[0];
for(int i = 1; i < 5; ++i) {
color1 += tex2D(frameSampler, texcoord + float2(sampleOffsets[i]*HW * PIXEL_SIZE.x, 0.0)) * sampleWeights[i];
color1 += tex2D(frameSampler, texcoord - float2(sampleOffsets[i]*HW * PIXEL_SIZE.x, 0.0)) * sampleWeights[i];
}
float4 color2 = tex2D(origframeSampler, texcoord) * sampleWeights[0];
for(int j = 1; j < 5; ++j) {
color2 += tex2D(frameSampler, texcoord + float2(0.0, sampleOffsets[j]*VW * PIXEL_SIZE.y)) * sampleWeights[j];
color2 += tex2D(frameSampler, texcoord - float2(0.0, sampleOffsets[j]*VW * PIXEL_SIZE.y)) * sampleWeights[j];
}
return color = (color1 + color2)*0.5;
}
float4 CombinePS(in float4 pos : SV_Position, in float2 texcoord : TEXCOORD) : COLOR
{
float4 orig = tex2D(origframeSampler, texcoord);
float4 blur = tex2D(frameSampler, texcoord);
float3 sharp;
#if (GaussEffect == 0)
orig = orig;
#elif (GaussEffect == 1)
// Blur...
orig = lerp(orig, blur, GaussStrength);
#else
orig = blur;
#endif
return saturate(orig);
}
technique GAUSS < bool enabled = true; toggle = GAUSS_TOGGLE; >
{
/*
pass
{
VertexShader = Triangle;
PixelShader = PassThrough;
RenderTarget = frameTex2D;
}
*/
pass Q0
{
VertexShader = Triangle;
PixelShader = GaussianBlurPS;
RenderTarget = frameTex2D;
}
#if GaussQuality == 1
pass Q1
{
VertexShader = Triangle;
PixelShader = GaussianBlurPS2;
RenderTarget1 = frameTex2D;
}
#endif
pass CB
{
VertexShader = Triangle;
PixelShader = CombinePS;
}
}
Ultimately I'd like to pass the already scaled image to the first blur pass or maybe pass the image to another scaled texture. Also, is it possible to upscale an image? When I tried using values < 1 it would cause an error.
Please Log in or Create an account to join the conversation.
- crosire
Less
More
9 years 2 months ago #2
by crosire
Replied by crosire on topic Is it possible to do what I'm trying to do here?
Pass Q1 writes to frameTex2D, but at the same time samples from that texture (in GaussianBlurPS2). That's impossible, you can only read or write from/to a texture, but not both at the same time.
A way around would be to create two textures and switch between them (first write to the first, then read from that one while writing to the second, etc.).
A way around would be to create two textures and switch between them (first write to the first, then read from that one while writing to the second, etc.).
The following user(s) said Thank You: Ioxa
Please Log in or Create an account to join the conversation.
- Ioxa
- Topic Author
Less
More
9 years 2 months ago #3
by Ioxa
Replied by Ioxa on topic Is it possible to do what I'm trying to do here?
Sweet, it worked! Thanks Crosire, you da man!
Please Log in or Create an account to join the conversation.