[X3D-Public] Shaders examples errors
Michalis Kamburelis
michalis.kambi at gmail.com
Fri May 3 03:52:57 PDT 2013
Hi,
I reported some problems with web3d.org shader examples some time ago
(http://web3d.org/pipermail/x3d-public_web3d.org/2012-November/002230.html
), I see that they are still not fixed. So, here I'm reporting them again :)
This applies to two shader example scenes linked from "Shaders" section
on http://www.web3d.org/x3d/content/examples/Basic/index.html :
http://www.web3d.org/x3d/content/examples/Basic/Shaders/Flutter.x3d
http://www.web3d.org/x3d/content/examples/Basic/Shaders/SimpleShader.x3d
I tested these two scenes, and found a couple of errors in Flutter.x3d
at inlined ShaderPart contents. Problems 1. and 2. below are commonly
found in other X3D scenes, so some browsers (like my view3dscene)
tolerate and only warn about them, but they really should be fixed IMHO
as these are official X3D examples and should show "the right way".
Problem 3. prevents the shader from working at all.
1. The MFString url values are not surrounded by quotes as necessary.
You have
<ShaderPart type='VERTEX' url='data:...'/>
while there should be
<ShaderPart type='VERTEX' url='"data:..."'/>
2. The data: URI are not used correctly. Header, that is
"data:text/plain" should be *always* followed by a comma, never by a
space. For example, vertex shader contents should not be
data:text/plain varying float...
They should be
data:text/plain,varying float
See http://en.wikipedia.org/wiki/Data_URI_scheme and
http://tools.ietf.org/html/rfc2397 .
3. Inside GLSL fragment code, many commas are missing and the shader
fails to compile at all... It seems that somewhere along the line
something removed all the commas, causing this (and previous) problem.
3.1. Instead of
float thisXY2=dot(vec2(TPO.xy) vec2(TPO.xy))*ticker;
there should be
float thisXY2=dot(vec2(TPO.xy), vec2(TPO.xy))*ticker;
3.2. Instead of
vec3 LightPos=vec3(0. 10. 0.);
there should be
vec3 LightPos=vec3(0., 10., 0.);
3.3. Instead of
LTI=dot(normalize(LightPos-ECpos) myNorml);
there should be
LTI=dot(normalize(LightPos-ECpos), myNorml);
3.4. Instead of
LTI=clamp(LTI 0. 1.);
there should be
LTI=clamp(LTI, 0., 1.);
I uploaded a fixed version of Flutter.x3d to
http://michalis.ii.uni.wroc.pl/~michalis/tmp/Flutter.x3d , with
modifications as listed above, and the shader code split into multiple
lines for easier editing. With these fixes, it works with view3dscene,
and without raising any warnings.
This example seems to be based on a flutter.x3d example available also
on FreeWRL website, from http://freewrl.sourceforge.net/examples.html
link to http://freewrl.sourceforge.net/images/flutter.x3d . Some of the
above problems (2. and 3., but not 1.) are fixed there already.
For
http://www.web3d.org/x3d/content/examples/Basic/Shaders/SimpleShader.x3d: everything
seems correct, although the example could be improved by placing
<ProtoInstance name='myP' />
near the end (before </Scene>). Otherwise, the current file only defines
a prototype without ever instantiating it, so the scene is simply empty.
So it doesn't seem a useful example at the 1st sight :)
I uploaded a modified version to
http://michalis.ii.uni.wroc.pl/~michalis/tmp/SimpleShader.x3d .
Regards,
Michalis
More information about the X3D-Public
mailing list