[X3D-Public] Can I create a colored shape without any light effects?
Tomas Mikula
tomas.mikula at gmail.com
Mon Aug 3 15:01:39 PDT 2009
Thank you for your ideas.
John, spheres do look a bit better and maybe a little more better with
Sergey's suggestion of using emissiveColor instead of diffuseColor.
On Tue, Jul 28, 2009 at 5:33 PM, Bederov, Sergey<bederov at cortona3d.com> wrote:
> To make the demonstration more visually appealing, you will have to use
> some tricks. For example, if the user is always looking from the same
> side,
He/she is not.
> then you can replace boxes by squares. To accommodate for moving
> camera, you can divide each box into six squares and change their
> transparency based on the viewer position. Though, this can be very
> slow...
This seems too complicated to me, as I'm new to X3D.
Miriam, I didn't know about billboards, I googled them, but I and
don't see how they would help me. (If I understood, billboard is a
plane that rotates to always face the user.) Anyway, I get the
specefication of the concentrations in the liquid as an XML output
from a program and am using XSLT to create the visualization in X3D.
This would mean that I would have to also generate the png textures by
some tool.
On Fri, Jul 31, 2009 at 8:42 PM, John A. Stewart<alex.stewart at crc.ca> wrote:
> 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;
This seems like I could achieve better results with, but I'm
experiencing some problems.
First, here is my simplified simpleShader.x3dv file (I inlined the shaders):
PROFILE Interactive
COMPONENT Shaders:1
PROTO myP [initializeOnly SFVec3f myColor 0 1 1 ] {
DEF TR Transform { children Shape {
geometry Sphere {radius 1.75 }
appearance Appearance {
shaders [
ComposedShader {
field SFVec3f decis IS myColor
language "GLSL" parts [
ShaderPart {
type "VERTEX"
url "data:text/plain,varying vec3 normal;void
main(){normal=gl_NormalMatrix*gl_Normal;gl_Position=ftransform();}"
}
ShaderPart {
type "FRAGMENT"
url "data:text/plain,
varying vec3 normal;
uniform vec3 decis;
void main(){
vec3 n = normalize(normal);
float intensity = dot(vec3(gl_LightSource[0].position),n);
intensity = intensity * intensity * intensity;
gl_FragColor = vec4(decis,intensity);
}"
}
]
}
]
}
}
}
}
DEF MYLIGHT Transform { translation 0 0 10 children DirectionalLight {}}
DEF MYPROX ProximitySensor {size 100 100 100}
ROUTE MYPROX.position_changed TO MYLIGHT.set_translation
DEF BOX Transform {
children Transform {
children [
Transform {translation -2 -2 0 children [
myP {}
]}
Transform {translation 2 -2 0 children [
myP{}
]}
Transform {translation -2 2 0 children [
myP {}
]}
Transform {translation 2 2 0 children [
myP{}
]}
]
}}
Problem 1: The light source is rotating with the scene, so if I use my
mouse to rotate the scene 90 degrees up, I see caps, if I rotate by
180 degrees, I see nothing.
Problem 2: I don't notice any change if I delete these two lines:
DEF MYPROX ProximitySensor {size 100 100 100}
ROUTE MYPROX.position_changed TO MYLIGHT.set_translation
(May this be the cause of Problem 1??)
If I further delete also the line
DEF MYLIGHT Transform { translation 0 0 10 children DirectionalLight {}}
it almost looks good, but there's still Problem 3 (which occurs
regardless of the presence of this line)
Problem 3: The decreased alpha "sometimes" renders as black instead of
transparent. I observed that this "sometimes" depends on the order in
which the spheres are defined in the x3dv file. The first sphere
(positioned at -2 -2 0) is never transparent. Through the second one
(2 -2 0) I can see the first one, but is opaque if the third or fourth
are behind it. So forth, only the last sphere handles transparency
correctly. Is this a bug in FreeWRL? I use FreeWRL 1.22.3 under Linux.
Tomas
More information about the X3D-Public
mailing list