Jump to content

preprocessor ifdef elseifdef?


Pryme8
 Share

Recommended Posts

How would one go about completing this logic:
I need to do elseif statments for the defines.

float n0;
    #ifdef STONEFLOOR
        n0 = 1.0;
    #elseif WOOD

    #else
        //Base Stone
        n0 = abs(noise2((nUV*16.0)+fbm2((vUV-vec2(23333.222,3333.22))*32.0)*2.0-1.0));
    #endif


    vec3 color;

    #ifdef SPECULAR
        color = mix(vec3(0.1), vec3(0.72), n0);
    #elseif BUMP
        color = mix(vec3(0.0), vec3(0.7), n0);  
    #else
        #ifdef STONEFLOOR
            color = vec3(1.0);
        #elseif WOOD

        #else
            //Base Stone
            color = mix(vec3(0.4, 0.4, 0.42), vec3(0.6, 0.65, 0.65), n0);
        #endif        
    #endif

    gl_FragColor = vec4(color, 1.0);

I was going off of :http://www.people.vcu.edu/~jsiebers/mcnpinfo/dcomment/manual/node9.html
https://www.khronos.org/registry/OpenGL/specs/gl/GLSLangSpec.4.50.pdf

Link to comment
Share on other sites

❤️

 

float n0;
#if defined(STONEFLOOR)
n0 = 1.0;
#elif defined(WOOD)
n0 = 1.0;
#else
//Base Stone
n0 = abs(noise2((nUV*16.0)+fbm2((vUV-vec2(23333.222,3333.22))*32.0)*2.0-1.0));
#endif
 
vec3 color = vec3(0.);
#if defined(SPECULAR)
color = mix(vec3(0.1), vec3(0.72), n0);
#elif defined(BUMP)
color = mix(vec3(0.0), vec3(0.7), n0);
#else
#if defined(STONEFLOOR)
color = vec3(1.0);
#elif defined(WOOD)
color = vec3(1.0);
#else
//Base Stone
color = mix(vec3(0.4, 0.4, 0.42), vec3(0.6, 0.65, 0.65), n0);
#endif
#endif
 
gl_FragColor = vec4(color, 1.0);
Link to comment
Share on other sites

This is called a shader permutation hell. Babylonjs is master of this technique and it has understandable reasons (more or less), that's not the point. Think over it. Are you really winning something ? The compiler still needs to hold the hole damn thing in his register in order to throw and error exception. In worst case you end with something like this, scroll down, yes a bit longer, do you notice something. It's 2018 we not in C/C++ DX Engine, WebGL relies on Javascript, when you look closer at you shader, it is just a simple string, - manipulate the s t r i n g not the shader. 

Link to comment
Share on other sites

that is an interesting concept @Nabroski I like where your head is going.

I had a similar concept as what you are talking about that was trying to make a raymarching engine that edited the shader string like you are mentioning.  

I see pro's and con's to both and definitively see each as a valid method givin certain problems

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...