Pryme8 Posted July 20, 2018 Share Posted July 20, 2018 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 Quote Link to comment Share on other sites More sharing options...
brianzinn Posted July 20, 2018 Share Posted July 20, 2018 #ifdef VAR1 ... #endif #ifndef VAR1 #endif Not very pretty, but I haven't seen else... you can nest those as well. https://github.com/BabylonJS/Babylon.js/blob/master/src/Shaders/pbr.vertex.fx#L149 Quote Link to comment Share on other sites More sharing options...
brianzinn Posted July 20, 2018 Share Posted July 20, 2018 actually, I see that you have #elseif and then #else preprocessors. I think you need to use defined() function and boolean logic. Pryme8 1 Quote Link to comment Share on other sites More sharing options...
Pryme8 Posted July 20, 2018 Author Share Posted July 20, 2018 funny part is I just figured that out right before I read your post and was gonna try that. You just reinforced that I should give that a shot, THANKS! #if defined(BLAH) #elif defined(BLAH2) #endif right? brianzinn 1 Quote Link to comment Share on other sites More sharing options...
brianzinn Posted July 20, 2018 Share Posted July 20, 2018 Did you try elif? #if #ifdef #ifndef #else #elif #endif https://www.khronos.org/registry/OpenGL/specs/gl/GLSLangSpec.1.20.pdf think they just copied c (https://en.wikipedia.org/wiki/C_preprocessor) Quote Link to comment Share on other sites More sharing options...
Pryme8 Posted July 20, 2018 Author Share Posted July 20, 2018 ❤️ 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); brianzinn 1 Quote Link to comment Share on other sites More sharing options...
Nabroski Posted July 20, 2018 Share Posted July 20, 2018 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. Quote Link to comment Share on other sites More sharing options...
Pryme8 Posted July 20, 2018 Author Share Posted July 20, 2018 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 Nabroski 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.