Previous topicNext topic

Displacement Shader - Blocky/Pixilated

Questions, comments, feedback, etc.
Post Reply
vedev
Posts: 8
Joined: Thu May 03, 2018 2:55 pm

Displacement Shader - Blocky/Pixilated

Post by vedev »

Not sure if this is the right place to post this but I'm trying to figure out how to get a displacement module working properly in Magic. I've converted and imported the fs shader into Magic, and it's mostly working, but the resulting displacement is blocky/pixilated/banding. (See image link)
https://imgur.com/a/sFjzKJk
Below is the code for the shader, is there anything that can be done?

Code: Select all

/*
{
  "CATEGORIES" : [
    "Distortion Effect"
  ],
  "DESCRIPTION" : "Simple Displace",
  "ISFVSN" : "2",
  "INPUTS" : [
    {
      "NAME" : "inputImage",
      "TYPE" : "image"
    },
    {
      "NAME" : "displaceImage",
      "TYPE" : "image",
      "LABEL" : "displace image"
    },
    {
      "NAME" : "uDisplaceAmt",
      "TYPE" : "float",
      "MAX" : 2,
      "DEFAULT" : 0,
      "MIN" : -2
    },
    {
      "LABELS" : [
        "Luma",
        "R",
        "G",
        "B",
        "A"
      ],
      "NAME" : "xComponent",
      "TYPE" : "long",
      "DEFAULT" : 1,
      "VALUES" : [
        0,
        1,
        2,
        3,
        4
      ]
    },
    {
      "LABELS" : [
        "Luma",
        "R",
        "G",
        "B",
        "A"
      ],
      "NAME" : "yComponent",
      "TYPE" : "long",
      "DEFAULT" : 2,
      "VALUES" : [
        0,
        1,
        2,
        3,
        4
      ]
    },
    {
      "NAME" : "relativeShift",
      "TYPE" : "bool",
      "DEFAULT" : 0
    }
  ],
  "CREDIT" : "by @colin_movecraft"
}
*/



void main(){
	vec2 p=isf_FragNormCoord.xy;
	vec4	displacePixel = IMG_NORM_PIXEL(displaceImage, p);
    
    float	r = (displacePixel.r);
    float	g = (displacePixel.g);
    float	b = (displacePixel.b);
    float	a = (displacePixel.a);
    float	avg = (r+g+b)/3.0;
    
    vec2	displace = vec2(avg,avg);
    if (xComponent==1)
    	displace.x = r;
	else if (xComponent==2)
    	displace.x = g;
    else if (xComponent==3)
    	displace.x = b;
	else if (xComponent==4)
    	displace.x = a;

    if (yComponent==1)
    	displace.y = r;
	else if (yComponent==2)
    	displace.y = g;
    else if (yComponent==3)
    	displace.y = b;
	else if (yComponent==4)
    	displace.y = a;
    
    displace = (relativeShift) ? displace - vec2(0.5) : displace;
    displace *= uDisplaceAmt;
    
	gl_FragColor = IMG_NORM_PIXEL(inputImage,p+displace);
}
Sadler
Posts: 1139
Joined: Sat Aug 02, 2014 7:10 pm
Location: London, UK

Re: Displacement Shader - Blocky/Pixilated

Post by Sadler »

Try blurring your displacement map a little (or a lot). It might be easier if your displacement map is greyscale or normal map.
vedev
Posts: 8
Joined: Thu May 03, 2018 2:55 pm

Re: Displacement Shader - Blocky/Pixilated

Post by vedev »

Sadler wrote:Try blurring your displacement map a little (or a lot). It might be easier if your displacement map is greyscale or normal map.
Ahh I'm an idiot. The banding was coming from the shader I was using as the displacement map. No pixilation on other maps. I could have sworn I checked that out. Thanks for the reply!
Post Reply