Simple Texture GLSL shader

   12264   7   3
User Avatar
Member
4 posts
Joined: Oct. 2009
Offline
This is my first foray into GLSL in Houdini and shading in general in Houdini.
I have a really simple example I am trying to get working to no avail.
I am trying to figure out how to hook up a texture with a sampler in a GLSL SHOP… I created a new type operator of type SHOP: GLSL and then entered my GLSL code Here is what I have:

Vertex Shader Code:


varying vec3 position;
varying vec2 diffuse_uv;

void main(void)
{
position = vec3(gl_ModelViewMatrix * gl_Vertex);
gl_Position = ftransform();
diffuse_uv = vec2(gl_MultiTexCoord0);
}


Fragment shader code:


varying vec3 position;
varying vec2 diffuse_uv;
uniform sampler2D diffuse_sampler;

void main(void)
{
gl_FragColor = texture2D(diffuse_sampler,diffuse_uv ) ;
gl_FragColor.a = 1.0;

}

Can anyone point me to an example of how to hook this up? I am not sure what is next.. I added a parameter to the type: OGL Texture layer… and got the sampler hooked up but the UVs are screwed-up… I added a TextureUV SOP to my geo but the Uvs are not getting through to the material…I am not sure what is the semantical sugar to hook all this up..?

-jm
User Avatar
Member
7726 posts
Joined: July 2005
Offline
The OGL2 Decal SHOP serves as the simplest example. You can just take a look at how it's hooked by creating a copy of the node, right-click on it > Type Properties. The important thing to note is to create an “File - Image” parameter that is named the same as your sampler2D variable.

As for texture coordinates, just use the regular Houdini tools to create some on your geometry for display (eg. UVTexture SOP).
User Avatar
Member
4 posts
Joined: Oct. 2009
Offline
So maybe I am having a graphics card issue then? I hooked up the OGL2 Decal shader and assigned it to a material suboutput and the material to a sphere with a UVTexture SOP on it. Then I chose a map for the textureidx param of the GLSL shader and ouila black is all I get! A beautiful black sphere..
I have an 8800 GTX. Would someone mind sending me a known working hip file with this setup… I have attached mine:

Attachments:
ogl2_decal_sample.hip (42.8 KB)

User Avatar
Member
7726 posts
Joined: July 2005
Offline
Here's what I changed in your .hip file to make things work on my machine:
- Changed update mode (lower-right corner on status bar) from Manual to Auto Update
- Sphere SOP -> changed Type from Primitive to Polygon Mesh. Sphere primitives only contain a single point and so can't be textured. You need polygon primitives.
- Changed the display (blue) flag from the Sphere SOP to the UVTexture SOP so that the viewer will actually see the uv coords.
- Changed the “Texture” parameter on your OGL2 Decal node to “default.pic” since I don't have the image from your Y: drive.

Attachments:
ogl2_decal_sample_189.hipnc (41.4 KB)

User Avatar
Member
4 posts
Joined: Oct. 2009
Offline
ahhh the polygon was the key! I like using manual updates as I typically have some big networks and Houdini likes to crash.. awesome great thanks
User Avatar
Member
1743 posts
Joined: May 2006
Offline
Hi,

was curious to try this in 11.1, but caught in a bind (pardon the pun).

If I try the initial simple example, and create a matching file-image parm named ‘diffuse_sampler’, I get several houdini console warnings, even with default.pic:

WARNING: Failed to bind variable ‘diffuse_sampler’


I went to look for the ogl_decal example, but it looks like its missing/removed from the latest houdini apprentice.

Is the otl/code for this still floating around somewhere? Also tried looking at the code in ogl2_default_material.frag, but can't get that to work either. hmm.

cheers,

-matt
http://www.tokeru.com/cgwiki [www.tokeru.com]
https://www.patreon.com/mattestela [www.patreon.com]
User Avatar
Member
51 posts
Joined: Oct. 2006
Offline
It hard to tell why the binding fails without the actual scene, but try the attached example see if it works for you.
Note that OGL renderer is a bit different in H11 instead of writing to gl_FragColor it's necessary to take render passes into account and use HOUassignOutputs - see the docs for more info.
(Also I posted a couple of simple GLSL examples here: http://www.sidefx.com/index.php?option=com_forum&Itemid=172&page=viewtopic&t=22491) [sidefx.com]

Attachments:
GLSL_tex.zip (8.5 KB)

User Avatar
Member
1743 posts
Joined: May 2006
Offline
wow that was fast, thanks! your examples give me lots to play with, brilliant.

interestingly, found 2 things that could break it:

-applying the shader via the shop_materialpath parm would cause the bind error to reappear. it only works if i assign it via a material SOP.

-trying other images would always appear black, unless i went into the display options->effects and disabled ‘mipmap textures’

obviously the default houdini glsl shader that gets automatically assigned to mantra shaders doesn't suffer the same issues… if i get time I might compare their default shader to yours, see if there's any obvious reason why the sidefx ones are more resilient.

thanks again!

(edit)

and here's the result, woo!
http://www.sidefx.com/index.php?option=com_forum&Itemid=172&page=viewtopic&p=107260#107260 [sidefx.com]



-matt
http://www.tokeru.com/cgwiki [www.tokeru.com]
https://www.patreon.com/mattestela [www.patreon.com]
  • Quick Links