Pretty Parameter Lines Shader

From JReality Wiki
Jump to: navigation, search

22Apr13.png

This tutorial explains how to draw parameter lines, that are only shown if the faces face roughly towards the camera.

We can display the parameter lines by applying a suitable texture if we already have a parameter aware triangulation. See Intro07 for details. Then, what is left, is to slightly modify the GLSL polygon shader: We want it to only draw the texture, if the angle between the surface normal and the direction to the camera is small enough.

The following code has to be in your jReality application. See how to use Appearances in this section.

   Appearance a = new Appearance();
   String[] source = new String[2];
   source[0] = "polygon.v";
   source[1] = "polygonParameterLines.f";
   a.setAttribute("polygonShader.glsl330-source", source);

Then in the package de.jreality.jogl3.glsl.nontransp you copy polygon.f to polygonParameterLines.f in the package de.jreality.jogl3.glsl and add the following at the right place (this is not Java, but GLSL, code to be executed not on the CPU but on the graphics card):

   float Product = dot(normalize(camSpaceCoord.xyz), camSpaceNormal);
       if(has_vertex_texturecoordinates==1 && has_Tex == 1 && Product < -0.5){