0

I created a simple graphics program using DirectX 12 for learning purpose. I heard that using If statements in the shader code is not good for performance. However i couldn't wrap my head around how to achieve the effect on the attached image without using if statements.

Here is my code:

float4 WaterPixelShader(PixelInput _in) : SV_Target
{    
    float heigth = _in.worldPosition.y / 10;
    float white;

    if (heigth > 0.7)
    {
        white = 1;
    }
    else
    {
        white = 0;
    }
    return float4(white, white, heigth, 1);
}

This is the effect I am trying to achieve:

Icy mountain

dbc
  • 104,963
  • 20
  • 228
  • 340
funtar
  • 1
  • Does your code currently work? If so this question might be more appropriate for https://codereview.stackexchange.com/ – dbc Jul 18 '20 at 20:47
  • This may help you, though it is in wegbl. https://2pha.com/demos/threejs/shaders/perlin_noise_3d_vertex.html – 2pha Jul 18 '20 at 23:01

0 Answers0