Jump to content

GLSL Pipeline in Houdini


monomind

Recommended Posts

Would love to know about how GLSL pipeline works inhoudini. I was not successful creating anything related to GLSL shaders in houdini yet, some help is very much appreciated!

How to create or load a shader?

looking at houdini/glsl directory, there is plenty of stuff to test, but I'm not sure how to load them into houdini.

Link to comment
Share on other sites

Add a GLSL Shader parameter to the material (Edit Rendering Parameters, Material Option > OpenGL) and put the path to glsl .prog file into the field.

GLSL shaders are responsible for a lot more than just surface shading, so you need to be careful what GL geometry types you apply the shader to. Any GLSL shader with a geometry shader stage will require a specific GL input type (triangles, lines, points), and be much more restricted as to what they can be applied to (polys, curves, particles). Others have more implicit targets, like a hair shader requiring lines or particle sprites requiring points, but not outright failing if you don't pass it the right geometry.

  • Like 1
Link to comment
Share on other sites

Not sure what you're trying to do, more details please. If what you need is simple enough, it could maybe be achieved by turning off the lights? (See picture, use the selected/orange icon under lock in top-right of viewport)

I've got a super simple GLSL shader working as well, can post an example later.

flat_point.thumb.png.198be4f513711678c256fc7ff84a0e4d.png

Edited by limeforce
Link to comment
Share on other sites

This should help you with the GLSL setup/boilerplate (point the material parm to the .prog file, vertex shader is basically a passtrough shader copied from somewhere in Houdini files). I've no answer for creating & rendering 100mil points on the GPU though, I haven't tried to create points in the vertex shader. Would be cool if Houdini had some intuitive ways of working with & displaying GPU data (something like a more wrangle-like OpenCL SOP with a direct hook/endpoint in the viewport so that the data doesn't have to come back to the CPU before being displayed).

I included a test file using instancing as well, that approach seems to start to break down around 1-10mil points here.

hou-glsl-instancing-example.zip

Edited by limeforce
  • Like 1
Link to comment
Share on other sites

  • 4 months later...

Thank you for your example files, Emil. Those are appreciated. :)

I did not promote and set the "ogl_glsl_shader" rendering property of the geometry's material to display my GLSL shader.
But instead, I created a new SHOP type (Network type: GLSL shader) via File > New Asset... and directly assigned an instance of said type to my geometry.
Seems to work.

I still have a couple of questions though:
- Which approach should be preferred ("ogl_glsl_shader" vs. new SHOP type) and why?
- And how are my GLSL shaders supposed to blend with Houdini's natural lighting computations?

The doc recommends the use of built-in functions such as HOUassignLitOutput() (cf. http://www.sidefx.com/docs/houdini/shade/glsl.html#houdini-built-in-functions), but I could not make it work properly. When creating a new SHOP type, Houdini provides me with a default implementation for the fragment shader which involves the HOUassignOutputs() function. However, no matter how I try to edit its call, my geometry always appears completely flat (and so does Houdini's default GLSL shader).

Any help is welcome.
Cheers.

Edited by PEL
my English is broken
Link to comment
Share on other sites

  • 2 months later...

Does anyone have an example for a volume glsl? i am trying to write a custom one but no matter i do i can't seem to get any effect.  i know it can be done (horizon zero down 2015 siggraph presentation   slide no:63)   

further questions.

and a couple more questions.

- how does sampler3D work in houdini?  

- i tried to color the volume (new operator method) by using HouAssignDiffuseOnly function but it gives me "call to undefined function" error. 

 

here are my vertex and frag code

 

vertex

 

#version 330


#line 1

#ifdef GL_ARB_explicit_attrib_location
#extension GL_ARB_explicit_attrib_location : require
layout(location=0) in vec3 P;
layout(location=1) in vec3 N;
layout(location=2) in vec3 uv;
#else
in vec3 P;
in vec3 N;
in vec3 uv;
#endif

layout(std140) uniform glH_Material
{
    vec3            ambient_color;
    vec3            diffuse_color;
    vec3            emission_color;
    vec3            specular_color;
    vec3            metallic_color;
    float           metal;
    float           material_alpha;
    float           material_alpha_parallel;
    float           roughness;
    float           diffuse_roughness;
    float           ior;
    float           reflection;
    float           coat_intensity;
    float           coat_roughness;
    int             specular_model;
    int             coat_spec_model;
    float           specular_tint;

    bool            use_geo_color;
    bool            use_packed_color;

    bool            has_textures;
    bool            has_diffuse_map;
    bool            has_spec_map;
    bool            has_opacity_map;
    bool            has_emission_map;
    bool            has_normal_map;
    bool            has_rough_map;
    bool            has_displace_map;
    bool            has_occlusion_map;
    bool            has_metallic_map;
    bool            has_coat_int_map;
    bool            has_coat_rough_map;
    bool            has_reflection_int_map;
    bool            has_reflect_map;
    
    ivec4           diffuse_udim_area;
    ivec4           spec_udim_area;
    ivec4           opacity_udim_area;
    ivec4           emission_udim_area;
    ivec4           normal_udim_area;
    ivec4           rough_udim_area; 
    ivec4           displace_udim_area;
    ivec4           occlusion_udim_area;
    ivec4           metallic_udim_area;
    ivec4           coat_int_udim_area;
    ivec4           coat_rough_udim_area;
    ivec4           reflection_udim_area;
    
    bool            has_env_map;
    vec3            envScale;
    mat3            envRotate;

    vec2            normalMapScaleShift;
    vec2            normalMapScale;
    vec3            normalMapXYZScale;
    int             normal_map_type; // space: 0=tangent, 1=world  
    int             normal_map_ncomps; // 2 or 3 component

    int             displace_space;
    float           displace_scale;
    float           displace_offset;
    bool            displace_y_up; // vs. z-up

    bool            invert_opacitymap;
    
    bool            invert_roughmap;
    vec4            rough_comp;
    
    vec4            occlusion_comp;
    vec4            metallic_comp;
    vec4            coat_int_comp;
    vec4            coat_rough_comp;

    bool            reflection_as_ior;
    vec4            reflection_comp;
};

out parms
{
    vec3  pos;
    vec3  nN;
    vec3  tex;
} vsOut;

uniform mat4    glH_ViewMatrix;
uniform mat4    glH_ProjectMatrix;
uniform mat4    glH_ObjectMatrix;
uniform mat4    volumeMatrix;


void main()
{
    vec4 my_p;
    vsOut.tex = uv; 
    vsOut.nN  = normalize( glH_ViewMatrix * (glH_ObjectMatrix * vec4(N, 0.0)) ).xyz;
    my_p = glH_ViewMatrix * (glH_ObjectMatrix * (volumeMatrix * vec4(P, 1.0)));
    vsOut.pos = my_p.xyz;

    gl_Position = glH_ProjectMatrix * my_p;
}

 

 

frag

 


#version 330


#line 1

in wparms
{
    vec3 pos;
    vec3 nN;
    vec3 tex;
    
} fsIn;

layout(std140) uniform glH_Material
{
    vec3            ambient_color;
    vec3            diffuse_color;
    vec3            emission_color;
    vec3            specular_color;
    vec3            metallic_color;
    float           metal;
    float           material_alpha;
    float           material_alpha_parallel;
    float           roughness;
    float           diffuse_roughness;
    float           ior;
    float           reflection;
    float           coat_intensity;
    float           coat_roughness;
    int             specular_model;
    int             coat_spec_model;
    float           specular_tint;

    bool            use_geo_color;
    bool            use_packed_color;

    bool            has_textures;
    bool            has_diffuse_map;
    bool            has_spec_map;
    bool            has_opacity_map;
    bool            has_emission_map;
    bool            has_normal_map;
    bool            has_rough_map;
    bool            has_displace_map;
    bool            has_occlusion_map;
    bool            has_metallic_map;
    bool            has_coat_int_map;
    bool            has_coat_rough_map;
    bool            has_reflection_int_map;
    bool            has_reflect_map;
    
    ivec4           diffuse_udim_area;
    ivec4           spec_udim_area;
    ivec4           opacity_udim_area;
    ivec4           emission_udim_area;
    ivec4           normal_udim_area;
    ivec4           rough_udim_area; 
    ivec4           displace_udim_area;
    ivec4           occlusion_udim_area;
    ivec4           metallic_udim_area;
    ivec4           coat_int_udim_area;
    ivec4           coat_rough_udim_area;
    ivec4           reflection_udim_area;
    
    bool            has_env_map;
    vec3            envScale;
    mat3            envRotate;

    vec2            normalMapScaleShift;
    vec2            normalMapScale;
    vec3            normalMapXYZScale;
    int             normal_map_type; // space: 0=tangent, 1=world  
    int             normal_map_ncomps; // 2 or 3 component

    int             displace_space;
    float           displace_scale;
    float           displace_offset;
    bool            displace_y_up; // vs. z-up

    bool            invert_opacitymap;
    
    bool            invert_roughmap;
    vec4            rough_comp;
    
    vec4            occlusion_comp;
    vec4            metallic_comp;
    vec4            coat_int_comp;
    vec4            coat_rough_comp;

    bool            reflection_as_ior;
    vec4            reflection_comp;
};

uniform sampler3D volumeMap;
uniform float step_scale;
uniform float depth_cutoff;

uniform mat4 glH_InvObjectMatrix;
uniform mat4 glH_InvViewMatrix;
uniform mat4 glH_ProjectMatrix;
uniform mat4 glH_ViewMatrix;
uniform mat4 glH_ObjectMatrix;
uniform mat4 iVolumeMatrix;
                       
void HOUassignDiffuseOnly(vec3 diff, vec3 P, vec3 N, float alpha);

void main()
{
    vec4 color; 
    int i; 
    vec3 dir;
    vec3 uv; 
    vec4 c, p, zp;
    float a;
    int count = 0;
    mat4 imat;
    
    imat = iVolumeMatrix * (glH_InvObjectMatrix * glH_InvViewMatrix);
    if(fsIn.nN.z <= 0.0)
        discard;
        
    dir = normalize(fsIn.pos.xyz);
    dir *= 0.1; //step_scale;
    color = vec4(0.0);
    gl_FragDepth = 1.0;
    
    p = vec4(fsIn.pos,1.0);
    uv = (imat * p).xyz * 0.5 + 0.5;
    do
    {
        c = texture(volumeMap, uv);

        a = 1 ; // * step_scale;
        if(a > 0.0)
        {
            if(color.a < depth_cutoff && color.a + a >= depth_cutoff)
            {
                zp = glH_ProjectMatrix * p;
                gl_FragDepth = zp.z / zp.w;
            }

            c.rgb *= a;
            color.rgb += (1.0 - color.a) * c.rgb;
            color.a += a;
        }

        p.xyz += dir;
        uv = (imat * p).xyz * 0.5 + 0.5;

        count++;
        if(any(lessThan(uv, vec3(0.0))) ||
           any(greaterThan(uv, vec3(1.0))) || count > 200)
            break;
    }
     
    while(color.a < 1.0);   
    HOUassignDiffuseOnly(color.xyz, fsIn.pos, fsIn.nN, a);
}

 

Edited by sergio
Link to comment
Share on other sites

  • 1 month later...
  • 3 years later...

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