Using custom GLSL shader in nodes

Hi!
Is it possible to use custom GLSL shader in nodes and if so than how? This may allow me to access different mipmap levels through nodes.

Why not I have seen something like that but where in this website??? I didn’t know…

Contact Eduardo here:


He is a big Chief in Nodes!

Good Luck!
Spirou4D

This is meant as question. I don’t know if it is possible, but it may come very useful for me.

This is actually not possible.

Sad, really sad… Even this node won’t work?



And so how do I make the roughness look good in nodes?

As I told you earlier by PM, roughness in not possible in nodes if you render a real time video texture image. Because you can’t effectively blur the rendered image.
If you use a static environment map you can use a blurred image and blend between between the sharp and blurred one and reduce slightly the brightness of the material is more rough.

Well, if you look at my PBR node, I do it already, but it looks pretty wrong. It is not even half of that good appearance that Unity/Unreal achieves.

I have taken a quick look looked into PBR_Equirectangular_0_07.blend and I can’t see that you reduced the brightness of the material.
Also you can use can us Oren-Nayar instead of Lambert defuse shading.

Can I edit Oren-Nayer through the nodes? In this case I can note that Wardiso is also much more physically accurate, but I cannot edit Oren-Nayar roughness or Wardiso slope through nodes and that means no texture support and no user friendly interface. However, my problem more tends to be reflections which diffusion is not right and doesn’t look strong enaugh on high values…

Can I edit Oren-Nayer through the nodes?

No. That does not work.
But you can use it as base rough material.

There is roughness input texture and I cannot edit it’s roughness with it. So if material uses a texture of roughness that is very contrastful, that it will look all through the same roughness:( But what about the reflections? How to gain very good effect with them, not like now? I can use 3 textures if needed, but I still need the equation.

I am sorry, I don’t understand what you mean.

I mean that the blending between smooth and rough reflection textures doesn’t look good at all and at .5 roughness you can still see quite sharp edges and shapes in reflections. I need a solution for this. Aswell as I need an input for roughness in material(inside of nodes) if I use Oren-Nayar. Otherwise it won’t adapt the roughness value/texture and won’t look good.

Instead of working in blender nodes, it is probably a good idea to learn pure GLSL and just write it in that. This will allow you the level of control you want and probably run faster as well (the default shader code isn’t very optimized.

The first thing to do would probably be to build a shader framework that … allows lights to work.
Yeah, you’d have to program that in.

Fortunately, GLSL is very well understood and there are plenty of resources out there.

Well, I tried that before nodes, I could do most of it, but NOT THE LIGHTING. I have no idea how to get lamp data(type, energy, color etc.) from scene by reading all the lights, not even talking about theese calculations and more - about shadows. I could do most of other things(except normalmaps, I don’t know anything of tangent space calculations), but lighting - that is too much…
If someone codes me a lighting shader which reads all the lamp data in scene(including hemis and area lights) and applies shader, aswell as normalmap calculation, I can do the rest. Shadows can be implemented later…

Nodes are faster, they’re executed through pure C++ while GLSL shaders are executed through python which is slower than C++.
You can check it by searching for HG1’s real-time cubemap and comparing the first download node vs first download shader(both 1.0). You will see a difference that node is 60 FPS while shader about 45 FPS.

Edit:
If you have better GPU, you won’t see it.

That’s the reason why I’d like to have patched blender with node improvements rather than using custom GLSL shaders.

except normalmaps, I don’t know anything of tangent space calculations

https://en.wikibooks.org/wiki/GLSL_Programming/Blender/Lighting_of_Bumpy_Surfaces

If someone codes me a lighting shader which reads all the lamp data in scene

You’ll have to generate the shaders on startup. This is exactly what blender does. When you press ‘P,’ it takes all the lights in the scene and puts them in every shader you see. One part of this is the shader side:
https://en.wikibooks.org/wiki/GLSL_Programming/Blender#Basic_Lighting

The other part is making the scripts to compile the shader and pass in the light data. This should be done once in python at startup.
So you may have something like:


shader = 'Some string containing a shader'
getPointLightCode(location, brightness)

for light in lights:
    if light['type'] == point:
        shader += getPointLightCode(location, brightness)

Obviously this is far simpler than what would be needed. This is a good opportunity to implement a proper dynamic light LOD system as well (something like: each shader has a maximum of three lights - the three closest)

Nodes are faster, they’re executed through pure C++ while GLSL shaders are executed through python which is slower than C++.

Eh, no. Both are executed by the graphics card in GLSL (GLSL is it’s own language). The nodes are converted to GLSL before being used. From memory the code used to do this is pretty hideous. (Darn it, my link to a sump someone put on pastebin no longer works).


But, please implement it as a blender node. I’d love to see the extension of the nodes. They are a powerful tool, and blender is open source, so you can go and have a peek inside…

Why does HG1 cubemap shader work much slower than his cubemap node?
About lights - what type of data can I get? I will need also shadows there. I need a lot of data…

I still need somebody to more help me out, this is much closer to it, but not all of the needed stuff yet.

I mean that the blending between smooth and rough reflection textures doesn’t look good at all and at .5 roughness you can still see quite sharp edges and shapes in reflections. I need a solution for this.

Sounds like that you only need to adapt your blending value. You can use the math, vector curve or the color ramp node to adapt the blending value.

Aswell as I need an input for roughness in material(inside of nodes) if I use Oren-Nayar. Otherwise it won’t adapt the roughness value/texture and won’t look good.

You can blend between two materials with the MixRGB node.

Why does HG1 cubemap shader work much slower than his cubemap node?

Read the description it is about the plot function which is used to stitch the six images into one.
Formerly it was custom shades are limited to 4 textures if you are have a Nvidia card.
I have fixed this issue, now Nvidia card users can also use 8 textures for custom shades.
But 8 textures are also not much, because you need 6 images only for the cube map.
For nodes the Blender code is used to bind the textures which can use all image texture units of the graphic card (my graphic card has 56 texture units).

The second problem with custom shaders is that it fully replace the original material shader. So you loose the original shader material with the lighting, shadows and so on.
Lights are basically not the problem for a custom shader. You can get all 8 OpenGL lights. So it is only a problem if you want to use more then 8 lights. If you want to use more then 8 lights, you have to use properties to define your light color, position for your lights.
But the main problem are the shadows. Actually there is no way to get the original rendered shadow map, except you grab it with some OpenGL functions. But the problem with it is that you don’t know the image buffer number(s) that is used for the shadow map(s).
So the only way for now is to render a own shadow texture by using the video texture.

That are the reasons why I have done it with Nodes.

OK! Blending between 2 materials - possible.
Blending reflections what you said - needs at least 8 textures for good effect, bad for performance, hard to do in nodes.

If I wanna continue this node, I need a “Get Mipmap Levels” node…