[X3D-Public] Can I create a colored shape without any light effects?

John A. Stewart alex.stewart at crc.ca
Fri Jul 31 11:42:37 PDT 2009


Tomas;

I thought a little bit more about your issue; here is a potential  
solution. It does use Shaders; FreeWRL on OSX should work 100% of the  
time, FreeWRL on Linux - depends on the graphics drivers as to whether  
shaders are available or not.

Tell me what you think about it.

----

1) take the simpleShader.zip file, from http://freewrl.sourceforge/net/simpleShader.zip

2) Add in a DirectionalLight, and a ProximitySensor; I did this before  
the "DEF BOX... line in the simpleShader.x3dv file.

...
DEF MYLIGHT Transform { translation 0 0 10 children DirectionalLight {}}
DEF MYPROX ProximitySensor {size 100 100 100}
ROUTE MYPROX.position_changed TO MYLIGHT.set_translation
...

3) remove any other DirectionalLights

4) remove all other ROUTES. You can also remove the TimeSensor and  
Interpolator, too.

5) the toon.vs:

varying vec3 normal;
void main() {
normal = gl_NormalMatrix * gl_Normal;
gl_Position = ftransform();
}


6) the toon.fs:

         varying vec3 normal;
         uniform vec3 decis;

         void main()
         {
                 float intensity;
                 vec4 color;
                 vec3 n = normalize(normal);

                 intensity =  
dot(vec3(gl_LightSource[0].position),normal);

                 if (intensity > 0.9)
                         color = vec4(0.0,0.5,0.5,1.0);
                 else if (intensity > 0.8)
                         color = vec4(0.0,0.5,0.5,0.60);
                 else if (intensity > 0.6)
                         color = vec4(0.0,0.5,0.5,0.30);
                 else
                         color = vec4(0.0,0.5,0.5,0.0);

                 gl_FragColor = color;
         }


7) run the .x3dv file in that directory. Notes:
	- what happens is that the surfaces of the Spheres that point towards  
the light source (ie, the viewer, via the ProximitySensor) are of a  
high intensity; the closer to the sides, the lower the intensity.
	- so, if the intensity is high, the colour created is (RGBA) 0.0,  
0.5, 0.5, 1.0.
	- as the intensity drops off, the alpha (transparency) goes from  
solid to totally transparent.
	- you can change the colour of the "Spheres" - take the x3dv program,  
and note the "decis" variable. You can change this into an RGB colour,  
and, in the toon.fs, change the vec4 to

		color=vec4(decis,1.0);  (or decis,0.30, or decis 0.00...)

	  and that will change the "decis" variable into an RGBA.
	- this test has 4 "Spheres" make as many as you wish. I think the  
more you have, the better it will look.

Hope this helps;


-----------------------------------------------------------
John A. Stewart
Team Leader: Networked Virtual Reality
alex.stewart at crc.ca

Network Systems and Technologies -
         Systemes et technologies des reseaux
Communications Research Centre Canada  |
          Centre de recherches sur les communications Canada

3701 Carling Ave.  |  3701, avenue Carling
PO Box 11490, Station H  |  CP 11490, succursale H
          Ottawa ON K2H 8S2   |  Ottawa (Ontario) K2H 8S2

http://www.crc.ca








More information about the X3D-Public mailing list