2
$\begingroup$

Sometimes I need to downgrade the resolution of the texture of a model to optimize it for web visualization. To do that i just take the texture in photoshop and export them with a lower resolution and jpeg format. When I import the texture into blender again I get white lines in the edges of the texture. Why does this happen and how can I avoid this problem?

before resize:

enter image description here

after resize (I changed also the curves, the brightness change was intended):

enter image description here

The settings I use in photoshop are these:

enter image description here

I just set the scale to 50% (starting pixels 4096px, target pixel 2048), and set the Resample mode to "Preserve details", the rest of the settings are the standard one. What do I need to change?

here the white line in the texture after resizing:

enter image description here

Edit: in most cases the solution could be to resize using the right resample mode in photoshop (like nearest). In this case this was not the solution, the border of the islands gets distorted too much in any case after the scaling, so the solution was to manually change the UV using pixel snapping.

$\endgroup$
2
  • 1
    $\begingroup$ Ar the brigther Pixels line in the Texture? ... I would guess this is a problem in your PS workflow. I think this happens wenn you have a fraction of a Pixels while resizing. $\endgroup$
    – J.Doe
    Commented Sep 21, 2021 at 10:19
  • $\begingroup$ Yes, the line is visible in the texture, i put a zoomed screenshot, It's a pixel size line. What could I change in my export settings to avoid this? $\endgroup$
    – Danzer
    Commented Sep 21, 2021 at 16:41

3 Answers 3

1
$\begingroup$

To fix the source of your problem, you should check your resizing workflow as @J.Doe suggested. Check your resizing mode/ interpolation and your source/target resolution in your external image editing tool.

To fix a resized texture, go into UV Editor and turn on snap to pixel. This way the UVs cannot cut Pixels in half and generate this sort of bleeding.

enter image description here

$\endgroup$
2
  • $\begingroup$ The solution to fix it manually works pretty well, but I want to avoid the problem directly in the resizing workflow, not after the error has already happened. What should I change in my export settings? I put a screen of my export settings (I just set the scale to 50% (starting pixels 4096px, target pixel 2048), and set the Resample mode to "Preserve details", the rest of the settings are the standard one) $\endgroup$
    – Danzer
    Commented Sep 21, 2021 at 16:43
  • 1
    $\begingroup$ As this Stack Exchange here is not about Photoshop this is Off Topic. You might find experts here: graphicdesign.stackexchange.com/questions/tagged/… $\endgroup$
    – J.Doe
    Commented Sep 23, 2021 at 11:03
5
$\begingroup$

Pixel snapping, or in more general, being exact is kind of your enemy here. Being exact makes you vulnerable to an off-by-one error. A safety margin is what protects you from such errors, hence my original one-word comment under your question (sorry! I consider my knowledge intermediate and happily give ground to true experts).

First part is simplifying the problem to an Image Texture node with Interpolation Mode set as Nearest. I believe you have it set, if you don't have the reported problem before scaling down your texture - but since we don't see your project, we can't say - perhaps you have a margin, but one too small (it becomes subpixel after scaling down), or maybe the original resolution is high enough that the artifact is not visible at the zoom level you test your setup in, etc...

1. Scaling down the texture

Create a plane, in Edit Mode S, X, ., 5, Enter to scale it to 50% width, ShiftD, Y to duplicate and move it "below" (in top view), as for shading, just use the 100x100 image texture shown in first row of the table below:

👈 Closest interpolation!

In UV Editing for one face S, X, ., 5, Enter to scale accordingly to mesh size, G, X, ., -, 2, 5, Enter to align to left border, likewise with the other face but without - so it's aligned to the right border...

Add Array modifier and we have our setup ready:

Starting with 100x100 texture, left and right halves with different colors:

zoom on center of texture:

When scaling 50% down to 50x50 in Photoshop, using Bilinear resampling, the effect is exactly the same, so just posting the texture:

and zoom:

With different resampling, there are some small artifacts already, but let's just jump to a case where it's much more visible, by scaling again 50% down, so now the size is 25x25:

texture algorithm zoom
bilinear
nearest

The antialiased region in bilinear version has been eaten by one of the regions (here: orange). What happened? First blue area had 50px width, then you divided it by 2 and it had 25px width, then you divided it by 2 and it had 12.5 px width. Because it's a raster image, the middle pixel could be either blue, orange, or an average (interpolation) of the two. Turning antialiasing off didn't help; using "nearest neighbor" algorithm in Photoshop makes the middle column orange; it means ${0.5 \over 12.5} = 4\%$ of the surface that's supposed to be blue, now becomes orange. In some cases it can be quite visible, for example if two regions connecting on UV map don't describe two regions connecting in geometry, or if it's a normal map in tangent space as in this question: How do I fix these normal map edges?

Since Hamed asked in comments, let's prove it by comparing the two:

25x25 bilinear ______________________ 25x25 nearest neighbor

The bottom plane works, because orange region became "greedy". However as mentioned above, blue color lost 4% of surface.

2. Interpolation inside of Blender

You probably want to have interpolation enabled, however, due to how it works, points with coordinates between center of a pixels on an edge and a pixel outside the edge of a region, will have their color calculated as an interpolation of those two (or more) pixels; for example, looking at the problem 1-dimensionally, using the 100 px wide texture, if color is calculated for a point at x = 99.8% of width, since it's beyond the last blue pixel's center (which is at 99.5% of width, as it defines color between 99% and 100% of width), the color will be an interpolation of nearest pixel, and the next pixel, which is outside the region defined in UV:

And so in linear interpolation, the resulting color will be ${a \over a+b} \times c_1 + {b \over a+b} \times c_2$.

You could wonder why software (not necessarily just Blender) doesn't clamp the value so it's not interpolated outside its UV region, but it wouldn't solve the problem, at least not entirely: for example if you had a gradient, clamping would mean that for a distance of 0.5 px (and then again for same distance on the other side) the color would be constant, which you would absolutely see in cases like zoom-ins or animation.

Solution

Finally! With 100x100 texture loaded, create another UV mapping:

U, U again to Unwrap, in UV Editor UV menu -> Pack Islands, expand the pop-up and set the margin. Now bake with standard settings:

Now switch the UV to the new one by clicking on the camera icon next to it. Save your baked image, open in a program of your choosing, scale down arbitrarily (you can still scale down too much depending on how small your margins are, save the texture, load back in Blender, everything should work even in linear interpolation mode, no artifacts - however, in my UV map above, one of the boundaries touches the edge, therefore extension mode has to be changed to Extend - in Repeat, you get the same orange/blue interpolation problem, and in Clip you're interpolating with black on the problematic edge.

$\endgroup$
3
  • $\begingroup$ your definitions were true , but i didn't get the final part , how baking texture with margins fixes this problem ? $\endgroup$ Commented Sep 25, 2021 at 11:18
  • $\begingroup$ Ok , i edited my previous answer with an example of what did you said , i'd be glad if you explain more why "turning antialiasing off" won't help ? $\endgroup$ Commented Sep 25, 2021 at 11:30
  • $\begingroup$ @hamed.design since the answer got some traction, I'll rework it and try to hit 2 birds with one stone (image texture node interpolation and how it causes color bleed + image texture scaling possibly outside of Blender and how it causes color bleed). $\endgroup$ Commented Sep 25, 2021 at 14:51
0
$\begingroup$
  • Your problem is "AntiAliasing" (AA) that happens due to resampling or when creating stuff in your application .

  1. so you should make sure that you don't have it in first hand , for example in the picture below you can see i disabled AA for creating text . enter image description here

and as the result i have a very sharp edge in my final saved picture

  1. as for resizing an already exist Sharp image I prefer to open it in PS and from menus choose "Image > image size..." and tweak the settings a little. enter image description here

I found these settings in resampling sharp enough for your purpose . enter image description here

And the you can "File > save as > jpg" thats it ....


Ok a simple Update , Just tested what our friend is talkin about "near neighbor" here is a simple Blue-Red colors (600X900pixs) reduced to 10% and nothing changes :enter image description here enter image description here And here is the final result as you can see a Clean (60X90pixs) final result : enter image description here

$\endgroup$
9
  • $\begingroup$ When saving this option does not appear, where can I enable it? I use "Export As" to save and resize a texture. $\endgroup$
    – Danzer
    Commented Sep 21, 2021 at 19:28
  • $\begingroup$ @Danzer i updated the answer please accept the answer that is correct since you dont have enough information about the problem $\endgroup$ Commented Sep 21, 2021 at 22:31
  • 4
    $\begingroup$ "Google it '' It's not an answer. This is not a photoshop forum, it's a Blender forum, and Blender is a software that can integrate many other softwares in its workflow, like photoshop. If you don't know the solution using that particular software you can suggest another practical solution (and no, "google it" is not a practical solution), even a solution that uses only Blender if you know one. If you think I didn't give enough information just ask what you think is missing, I gave all the details I could, even detailed screenshots and tried all the solutions you have proposed. $\endgroup$
    – Danzer
    Commented Sep 21, 2021 at 23:26
  • 1
    $\begingroup$ I don't want to reverse it, I want to prevent it from happening before it happens by using the right settings while resizing. I tried all the settings in photoshop without good results (there is no antialiasing option for resize or export, only "resample modes") so, if PS is not the right choice for the task, whic software is? Blender itself? Another one? $\endgroup$
    – Danzer
    Commented Sep 24, 2021 at 17:20
  • 1
    $\begingroup$ "reduced to 10% and nothing changes" - my guess is the coordinates of color region borders are divisible by the divisor you apply when scaling the image, that is, on your image if the red region has 50% height = 450 out of 900 pixels, if you scale the image down to 10%, 450/10 = 45 which still is a whole number. If you now scale down to 50%, 45/2 = 22.5, not a whole number, either AA kicks in, or one region is larger than the other (and so AA causes color bleed to both, "nearest" color bleed to one, but more significant). $\endgroup$ Commented Sep 25, 2021 at 14:49

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .