RT GPU and OSLTex and Siger

Hi Guys

I’m switching to GPU, but my materials are mostly Siger reflections with it’s custom OSLTex ComplexFresnel.

I can use the n and k values I’m getting from Siger’s OSL and punch it into the V-Ray version as per here:

But the Siger one has additional values for example, gamma, hue shift and saturation. How can I translate those into the pure ChaosGroup version?

The point of all this is that my Siger Materials are useless in RT GPU and I need to convert ALL of them manually to be compatible with RT GPU

We do reimplement some 3rd party textures in the GPU code (f.e. ColorCorrect, MultiTexture and recently ForestColor), unfortunately the Siger textures are not among them right now.

It should be possible to write a GLSL shader that implements the functionality of the Siger textures exactly, but we will need to look into it.

Best regards,
Vlado

Hello Morne,

Here is the GLSL equivalent of complex_ior.osl that works with RT GPU:


#version 110

float fresnel(float n, float k, float c)
{
	float k2 = k*k;
	float rs_num = n*n + k2 - 2.0*n*c + c*c;
	float rs_den = n*n + k2 + 2.0*n*c + c*c;
	float rs = rs_num/rs_den;
	float rp_num = (n*n + k2)*c*c - 2.0*n*c + 1.0;
	float rp_den = (n*n + k2)*c*c + 2.0*n*c + 1.0;
	float rp = rp_num/rp_den;
	return clamp(0.5*(rs+rp), 0.0, 1.0);
}

uniform vec3 n = vec3(0.27105, 0.67693, 1.3164);
uniform vec3 k = vec3(3.6092, 2.6247, 2.2921);

void main()
{
	float thetaCos = abs(dot(vr_Direction, vr_Normal));
	float r = fresnel(n[0], k[0], thetaCos);
	float g = fresnel(n[1], k[1], thetaCos);
	float b = fresnel(n[2], k[2], thetaCos);
	gl_FragColor = vec4(r, g, b, 1.0);
}

Best regards,
Ivan

Siger basically just has a Color Correction node to the complex_ior.osl for gamma, hue shift and saturation.

Thanks Ivan. Is there a way to “click” the compile button in Maxscript?
All I see is this:

Showproperties(vrayglsltex())
  .shader_file : filename
  .material : material
  .shader_node : integer
  .refraction_ior : float
  .incident_ior : float
  .max_ray_depth : integer
  .animation_time : float
  .show_preview : boolean
  .clamp_shader_result : boolean
  .clamping_limit : float
  .use_quick_shader : boolean
  .shader_sourcecode : string
  .message_log : string
  .tweakCount : integer
  .isShaderLoaded : boolean
  .useQuickShader : boolean

If I’m coding a script to replace all the Siger custom OSL’s in the scene with this, I need to have a way to also compile each one with code…

Yes I’m hoping to stick the GLSL into a Color Correction and hopefully that works with RT GPU

Anybody with suggestions?

Hi Morne

Is it possible to share the script you’re using?
Also, I tested Ivans GLSL and it seems to work fine on CPU but not on GPU. Do you face the same issue in your case?
CPU

GPU

Best Regards,
LK


I think the shader will be auto-compiled when rendering, but I need to confirm.

Best regards,
Vlado

The script is still in my head. I’m just getting all the bits together to make sure it will work before I spend time coding it…
I’ll update here when I have all the info I need, and then share the script when it’s done

Thanks, Vlado. I should have just tested to see if it renders, before asking. Will get back to you, just on a project at the moment…

@idnok - That wrong render seems to not be working both in RT CPU and RT GPU.
I’ve reported that as a bug, thanks for the pointer !

Best,
Blago

Yes, you can compile shaders from MAX Script. If you invoke showinterfaces on your material instance, you’ll see that it implements the TweakAccessor interface which has a couple of shader-loading methods. The load method is used to load a new shader file and the reload one can be used to recompile the current shader.

showinterfaces m
  Interface: IMtlRender_Compability_MtlBase
   Properties:
   Methods:
   Actions:
  Interface: TweakAccessor
   Properties:
    .tweakCount : integer : Read
    .isShaderLoaded : boolean : Read
    .useQuickShader : boolean : Read|Write
   Methods:
    <fpvalue>getTweak <fpvalue>tweak
    <void>setTweak <fpvalue>tweak <fpvalue>value
    <void>load <TSTR>filePath
    <void>reload()
    <void>reset()
    <void>clear()
    <boolean>export <TSTR>filePath compress:<boolean>
       compress default value: true
   Actions:
OK
-- to compile
m.reload()

Alternatively, the shader_file property can be used to load shaders, e.g.

m.shader_file="X:\path\to\your\shader.frag"

Best regards,
Ivan

@idnok it seems there is a bug that prevents the ‘quick shader’ from being exported. I’ll fix that asap, but for now, I’d suggest loading the shader from an external file as a workaround.

Best regards,
Ivan

@ikomitov that way it recognize the shader in RT as a fixed parameter instead. In this specific occasion it prevents you from changing ‘n’ & ‘k’ values.

Thank you!
For now, let see how GLSL is gonna work on GPU! :slight_smile:

It didn’t auto-compile in my test.

It would be GREAT if you guys can implement this. In my test to convert a basic siger metal to a native one, didn’t work (not even on CPU Advanced)
In this pic, the left one is the siger metal, on the right is an attempt to convert it to native

And in RT, even worse:

The RT test also revealed ANOTHER problem, namely the Shadow Catcher. In the scene there is a VRay Plane set to shadow catcher. In Advanced it acts correctly, catching shadows and not visible in reflection. But in RT the shadows are very black and the green in the reflection is the green wireframe color of the plane

Here’s a max 2016 file if you want to check it out (V-Ray 3.50.04)


2balls.zip (30.3 KB)

We will be adding a “metalness” parameter to the VRayALSurfaceMtl shader first, so you will be able to use that. We will probably be adding it to the VRayMtl material at some point too. This option will do proper glossy metallic Fresnel without the need for the Siger shader.

Best regards,
Vlado

Any news here? I’m also using SIGER shader and have used them in lots of scenes. What is currently the best/easiest way to convert them for GPU?
Regards
Olaf

If SIGER shaders can be converted to MDL, they will work on V-Ray GPU.

Best,
Blago.