Announcement

Collapse
No announcement yet.

GLSL And Caustics

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • GLSL And Caustics

    Hello,

    I have been working on some VRay tests to replicate the Unity Shaders into VRay, most of this is working by using the vrayGLSLmtl.

    However I am running into some issues when using the vr_trace function (to add reflections to the objects) combined with enabling caustics. The reflections work as expected, but when enabling the caustics in the global render settings the caustics are extremely bright.

    When I disable the vr_trace function the caustics disappear, but the objects do not have any reflections(obviously). It appears that anything that has the vr_trace(even if the result from the function is not used) function on the shader will write very bright caustics to the caustics buffer(Render elements caustics showed me this). When I compare the caustics from the render elements to a normal vray material, with the same setup the caustics are alot more dim. Is there any control in the glsl side to tone down the caustics, or is this a bug?.

    I can specify more info/screenshots if required.

    Thanks.

  • #2
    Can you post the shader, or the part of it that is causing issues, just so we can reproduce it here? I would generally advise you to use BRDF calls rather than tracing rays directly or looping through the lights.

    Best regards,
    Vlado
    I only act like I know everything, Rogers.

    Comment


    • #3
      Thanks for your quick reply.

      I have had another play with VRay and may have found another solution to the problem I was going to solve. However the GLSL part is interesting and it might be handy to be able to write my own shaders in it. Yet it seems to be missing some functionality/documentation.

      Here is a simplified version of the shader that I used, It's based on the shaders from http://docs.chaosgroup.com/display/V...X/GLSL+Support . The idea of the shader is to simulate a IBL effect using the vr_trace functions, so if something is full metallic/glossy it will be a perfect mirror, or it can be a a very rough surface that disperses alot of the specular light while using the same shader/textures.

      The culprit of the caustics becoming very bright is due to the vr_trace function at line 31, when disabling this function call the caustics disappear(because it doesn't trace anymore which makes sense). But the caustics that it causes are very bright. They are a lot brighter than the caustics from a regular vraymtl, even though the objects look similar without caustics. When calling, but not using the result from the vr_trace the caustics are still there.

      Code:
      #version 110
       
      uniform float amount = 0.1;
      uniform float diffuse_scalar = 0.7;
      __color uniform vec4 diffuse_color = vec4(0.9, 0.2, 0.8, 1.0);
      uniform float specular_scalar = 0.06;
      uniform float specular_shininess = 20.0;
       
      const int requiredSamples = 16;
       
      float phong_specular(vec3 light_dir, vec3 direction, vec3 normal) {
          vec3 reflection = reflect(direction, normal);
          float cos_rl = clamp(dot(reflection, light_dir), 0.0, 1.0);
          return (pow(cos_rl, specular_shininess) * (specular_shininess + 2.0));
      }
      
      
      vec4 SampleSpecularGI(vec3 tangent, vec3 binormal, vec3 normal)
      {
      	int numSuperSamples = vr_NumSuperSamples;
      	int superSampleIndex = vr_SuperSampleIndex;
       
      	vec4 specularGI = vec4(0.0);
       
      	vr_TraceOptions options;
      	options.rayType = VR_TRACE_REFLECT;
      	options.rayGroup = VR_GLOSSY_DISPERSAL;
      
      	options.normal = normalize(normal);
      	options.rayType = VR_TRACE_REFLECT;
      	vec4 reflection = vr_trace(options);
       
      	return reflection;
      }
      
       
      void main() {
          bool isGIRay = ((vr_RayFlags & VR_INDIRECT_FLAG) != 0);
          vec3 normal = (gl_FrontFacing) ? vr_Normal : -vr_Normal;
          vec3 direction = vr_Direction;
          vec3 position = vr_Position;
       
          vec4 raw_diffuse = vec4(vec3(diffuse_color) * diffuse_scalar, 1.0);
        
          vec4 diffuse_contrib = vec4(0.0, 0.0, 0.0, 1.0);
          vec4 specular_contrib = vec4(0.0, 0.0, 0.0, 1.0);
       
          if(isGIRay) {
              vr_LightIterator light;
              for(int j = 0; j < vr_NumLights; ++j) {
                  vr_evalLight(j, position, normal, light);
       
                  float cos_nl = clamp(light.dot_nl, 0.0, 1.0);
                  if (cos_nl > 0.0) {
                      diffuse_contrib += vec4(cos_nl * light.contribution, 0.0);
                      float specular_coeff = phong_specular(light.direction, direction, normal);
                      specular_contrib += vec4(specular_coeff * cos_nl * light.contribution, 0.0);
                  }
              }
          } else {
              vec3 tangent = vr_TexTangent;
              vec3 binormal = vr_TexBinormal;
              vr_LightIterator light;
              for(int j = 0; j < vr_NumLights; ++j) {
                  vr_evalLight(j, position, normal, light);
                  float cos_nl = clamp(light.dot_nl, 0.0, 1.0);
                  if(cos_nl > 0.0) {
                      diffuse_contrib += vec4(cos_nl * light.contribution, 0.0);
                  }
              }
       
      		specular_contrib += SampleSpecularGI(tangent,binormal,normal);
          }
       
          diffuse_contrib += vec4(vr_irradiance(normal, 1.0), 0.0);
          diffuse_contrib *= raw_diffuse;
          specular_contrib *= specular_scalar;
       
          gl_FragColor = diffuse_contrib + specular_contrib;
      }
      I tried using the built in BRDF functions but these do not seem to receive any caustics(I might be missing something here). I also noticed that when I used a GLSL function to try and recreate glass, I can get the result looking very good. But the vr_trace (refract flag) function/built in BRDF glass function do not apply any colored shadows when a light casts through them while the vraymtl does.
      Objects inside the glass also seemed to be incorrect when trying to light them, they required their normal to be flipped for the diffuse light calculation to be correct.
      So there seem to be some limitations with the GLSL pipeline to be using it properly(They might also be missuses by me).

      As mentioned above I may have found a better way of achievement my goal by just using the VRayMTL shader, which should give me the desired result and be fully functiona.l However, I am still interested in the GLSL part as it is a powerful tool to have in a pipeline in case I want to have some special effect or try to achieve something more complicated. Is there any more documentation on the GLSL pipeline of vray other than http://docs.chaosgroup.com/display/V...X/GLSL+Support ?

      Thanks for your help.

      Comment

      Working...
      X