Syrux Posted October 14, 2014 Share Posted October 14, 2014 Hi to all! I recently found this amazing resource to preview matcaps materials in the viewport. But unfortunately I cant make it work. https://www.sidefx.com/index.php?option=com_forum&Itemid=172&page=viewtopic&t=22724 This first problem is that the pow function is not recognized by Houdini, so what I did was to modify the code and delete everything related to the pow function. (some beautification too ): // vertex shader varying vec3 vPos, vN; void main() { vPos = vec3(gl_ModelViewMatrix * gl_Vertex); vN = normalize (gl_NormalMatrix * gl_Normal); gl_TexCoord[0] = gl_MultiTexCoord0; gl_Position = gl_ProjectionMatrix * vec4(vPos, 1.0); } // fragment shader uniform sampler2D g_smpTex; uniform int glH_MaterialPass; varying vec3 vPos; varying vec3 vN; void HOUassignOutputs(vec3 emit, vec3 amb, vec3 diff, vec3 spec, float shiny, vec3 P, vec3 N, float alpha); void main() { vec3 c; vec2 uv = normalize(vN) * 0.5 + 0.5; vec3 n = normalize(vN); if (glH_MaterialPass == 0) { c = texture2D(g_smpTex, uv).rgb; // lookup color from normal HOUassignOutputs( /* emit */ c, /* amb */ vec3(0.0), /* diff */ vec3(0.0), /* spec */ vec3(0.0), /* shin */ 0.0, /* P */ vPos, /* N */ vN, /* alpha */ 1.0 ); } else { HOUassignOutputs( /* emit */ vec3(0.0), /* amb */ vec3(0.0), /* diff */ vec3(0.0), /* spec */ vec3(0.0), /* shin */ 0.0, /* P */ vPos, /* N */ vec3(0.0), /* alpha */ 1.0 ); } } I created another parameter for glH_MaterialPass and embedded the otl to the hipnc, just in case But this doesn't even work for me it's just transparent. I tried to implement it again from scratch in Houdini 13 but not luck (now its Black ). I think that maybe the code its just compatible with the version they were using at that time. Also, the Houdini Console is reporting: Unknown operator type: Shop/GLSL_matcap So, how can I use this shader in Houdini 13? I'm using AMD by the way. Thanks for reading!! Here is the new file: glsl_matcap_170_new.hipnc Quote Link to comment Share on other sites More sharing options...
pezetko Posted October 15, 2014 Share Posted October 15, 2014 That pow function isn't problem but the version of GLSL is. (Without pow (gamma) function you get washed out shader if you are using 3D Viewport gamma correction). That shader was written for older OpenGL version. So to make it work just switch your viewport to OpenGL 2.1. Some function are depreciated in OpenGL 3.x: like varying( -> use in and out instead), gl_ProjectionMatrix, gl_ModelviewMatrix ( -> use uniform), as well as glVertex, glNormal) So to make it work in OpenGL 3.x you need to rewrite it for newer GLSL version. 1 Quote Link to comment Share on other sites More sharing options...
malexander Posted October 15, 2014 Share Posted October 15, 2014 A Houdini GL3 vertex shader would look like: #version 150 in vec3 P; // inputs are named after Houdini attributes in vec3 N; in vec2 uv; out vec3 vPos; out vec3 vN; out vec2 vUV; uniform mat4 glH_ObjectMatrix; // houdini built-in uniforms uniform mat4 glH_ViewMatrix; uniform mat4 glH_ProjectMatrix; uniform mat3 glH_NormalMatrix; void main() { vPos = vec3(glH_ViewMatrix * glH_ObjectMatrix * vec4(P, 1.0)); vN = normalize (glH_NormalMatrix * N); vUV = uv; gl_Position = glH_ProjectMatrix * vec4(vPos, 1.0); } The fragment shader is similar, taking 'in vec3 vPos' (etc) and writing to 'out vec4 color'. The texture2D() call is replaced by texture(). 1 Quote Link to comment Share on other sites More sharing options...
pezetko Posted October 16, 2014 Share Posted October 16, 2014 Mark: How could we make it work with Subdivision Surface display mode (when object parameter viewportlod (Display As) is set to Subdivision Surfaces)? With OpenGL 2.1 we get it for "free" but in 3.3 will not . Pedro: that Fragment Shader could look like this: #version 150 #line 1 uniform sampler2D g_smpTex; uniform float gamma; in vec3 vPos; in vec3 vN; out vec4 color; void main() { vec3 c; vec2 uv = vec2(normalize(vN) * 0.5 + 0.5); c = texture(g_smpTex, uv).rgb; // lookup color from normal c = pow(c, vec3(gamma)); // gamma correct color = vec4(c,1.0); } 1 Quote Link to comment Share on other sites More sharing options...
malexander Posted October 17, 2014 Share Posted October 17, 2014 Mark: How could we make it work with Subdivision Surface display mode (when object parameter viewportlod (Display As) is set to Subdivision Surfaces)? You'd just need to turn off adaptive subdivision in GL3. Pixar's opensubdiv shaders don't really lend themselves to alternative shading, unfortunately. 2 Quote Link to comment Share on other sites More sharing options...
Syrux Posted October 17, 2014 Author Share Posted October 17, 2014 Sorry very much for this embarrassing late response. Unfortunely, Gmail, is classifying OD|Forum responses as Spam. Thank very much malexander and pezetko. Your help is really invaluable, everything works perfectly now! Quote Link to comment Share on other sites More sharing options...
mestela Posted October 19, 2014 Share Posted October 19, 2014 Cool, great to hear you got it to work! I wouldn't have been any help, I barely qualify as a Houdini guy, I lucked out on that first glsl attempt, updating it for ogl3 would have been totally beyond me. Any chance you could post an updated otl here and on the sidefx forum? -matt 1 Quote Link to comment Share on other sites More sharing options...
Syrux Posted October 22, 2014 Author Share Posted October 22, 2014 Cool, great to hear you got it to work! I wouldn't have been any help, I barely qualify as a Houdini guy, I lucked out on that first glsl attempt, updating it for ogl3 would have been totally beyond me. Any chance you could post an updated otl here and on the sidefx forum? -matt I embedded the otl and the definitions to the hipnc. MaterialCap.hipnc 1 Quote Link to comment Share on other sites More sharing options...
mestela Posted October 25, 2014 Share Posted October 25, 2014 Nice, thanks! 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.