6
$\begingroup$

I made shader that calculates RGB based on height. Height -> Map Range to 0-16777216 and result pixel based on where C is input number based on height:

B = C % 256
G = ((C-B)/256) % 256
R = ((C-B)/256**2) - G/256

Render result looks bad. Res: 5000x2900, tried cycles, evee, tga, openexr and all possible combinations i could think of. I'm not expecting render to look good, i just want file with correctly calculated pixels. Is there any way to achieve this with Blender? Any settings? Plugins?Shader

Context: I'm working on isometric rpg. Need solution for hiding objects behind parts of pre-rendered background. Depth map is not good enough (greyscale) for big maps so I'm going with height map based on full rgb - similar to Pillars of Eternity. The problem is they did it in Maya (using mental ray) - am not familiar with this soft and I don't have it.

$\endgroup$

1 Answer 1

7
$\begingroup$

Your calculation looks incorrect. Also, are you expecting RGB values in the range 0-255 or in the range 0.0-1.0? Blender shader nodes expect values in the range 0.0 -> 1.0.

I suspect you actually require something like the folllowing :

B = C % 256
G = ( (C - B) / 256 ) % 256
R = ( ( (C - B) / 256 - G ) / 256 )

This will produce a colour with each channel in the range 0-255

Then, produce a shader colour (ranged 0.0-1.0) using :

Color = (R/255 , G/255, B/255)
$\endgroup$
2
  • $\begingroup$ Dividing helped, thank you. I'll test formula tomorrow - I took current one from -math.stackexchange.com/questions/1635999/… $\endgroup$
    – krabicz
    Commented Mar 30, 2021 at 21:45
  • 2
    $\begingroup$ I've just re-worked through the maths in your equations and I think they are actually equivalent - although dividing by 256**2 then subtracting G/256 is more likely to hit floating point innaccuracies - better to divide just by 256 (which should produce an integer, then subtract, then divide by the second 256 as rounding less likely to be a problem. $\endgroup$ Commented Mar 30, 2021 at 22:00

You must log in to answer this question.

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