Jump to content

Problem with old GLSL Shader.


Syrux

Recommended Posts

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 icon_wink.gif ): 

// 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 icon_sad.gif ). 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

Link to comment
Share on other sites

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.

  • Like 1
Link to comment
Share on other sites

 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().

  • Like 1
Link to comment
Share on other sites

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);  
}
  • Like 1
Link to comment
Share on other sites

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.

  • Like 2
Link to comment
Share on other sites

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

  • Like 1
Link to comment
Share on other sites

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.

post-11904-0-68679500-1413947485.jpg

MaterialCap.hipnc

  • Like 1
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.

×
×
  • Create New...