xeolabs / xeogl

A WebGL-based 3D engine for technical visualization. Not actively maintained.
http://xeogl.org
Other
1.15k stars 264 forks source link

Billboard demo fail #5

Closed Deamon87 closed 9 years ago

Deamon87 commented 9 years ago

Links: http://xeoengine.org/examples/billboards_spherical_clouds.html and http://xeoengine.org/examples/billboards_spherical_clouds.html Browsers: Chrome and Firefox GPU: Intel® HD Graphics 4600 Console text :

[ERROR] [XEO.GameObject 2510]: Draw program failed to validate

Vertex shader:

uniform mat4 xeo_uModelMatrix;
uniform mat4 xeo_uViewMatrix;
uniform mat4 xeo_uProjMatrix;
uniform vec3 xeo_uEye;

attribute vec3 xeo_aPosition;

varying vec4 xeo_vViewPosition;
varying vec3 xeo_vViewEyeVec;

attribute vec3 xeo_aNormal;
uniform mat4 xeo_uModelNormalMatrix;
uniform mat4 xeo_uViewNormalMatrix;
varying vec3 xeo_vViewNormal;

attribute vec2 xeo_aUV;
varying vec2 xeo_vUV;
void billboard(inout mat4 mat) {
   mat[0][0] = 1.0;
   mat[0][1] = 0.0;
   mat[0][2] = 0.0;
   mat[1][0] = 0.0;
   mat[1][1] = 1.0;
   mat[1][2] = 0.0;
   mat[2][0] = 0.0;
   mat[2][1] = 0.0;
   mat[2][2] = 1.0;
}

void main(void) {

   vec4 modelPosition = vec4(xeo_aPosition, 1.0); 
   vec4 modelNormal = vec4(xeo_aNormal, 0.0); 
   mat4 modelMatrix = xeo_uModelMatrix;
   mat4 viewMatrix = xeo_uViewMatrix;
   mat4 modelNormalMatrix = xeo_uModelNormalMatrix;
   mat4 viewNormalMatrix = xeo_uViewNormalMatrix;
   vec4 worldPosition;
   mat4 modelView =  xeo_uViewMatrix * xeo_uModelMatrix ;
   mat4 modelViewNormal =  xeo_uViewNormalMatrix * xeo_uModelNormalMatrix ;
   billboard(modelMatrix);
   billboard(viewMatrix);
   billboard(modelView);
   billboard(modelNormalMatrix);
   billboard(viewNormalMatrix);
   billboard(modelViewNormal);
   worldPosition = modelMatrix * modelPosition;
   vec4 viewPosition = modelView * modelPosition;
   vec3 worldNormal = (modelNormalMatrix * modelNormal).xyz; 
   xeo_vViewNormal = (viewNormalMatrix * vec4(worldNormal, 1.0)).xyz;
   xeo_vViewPosition = viewPosition;
  vec3 tmpVec3;
   xeo_vViewEyeVec = ((viewMatrix * vec4(xeo_uEye, 0.0)).xyz  - viewPosition.xyz);
   xeo_vUV = xeo_aUV;
   gl_Position = xeo_uProjMatrix * viewPosition;
}

Fragment shader:

precision highp float;

varying vec4 xeo_vViewPosition;

uniform vec3 xeo_uDiffuse;
uniform vec3 xeo_uSpecular;
uniform vec3 xeo_uEmissive;
uniform float xeo_uOpacity;
uniform float xeo_uShininess;
uniform float xeo_uReflectivity;

varying vec2 xeo_vUV;
uniform sampler2D xeo_uOpacityMap;
uniform vec3 xeo_uLightAmbientColor;
uniform float xeo_uLightAmbientIntensity;
varying vec3 xeo_vViewEyeVec;
varying vec3 xeo_vViewNormal;

void main(void) {

   vec3 ambient = xeo_uLightAmbientColor;
   vec3 diffuse = xeo_uDiffuse;
   vec3 specular = xeo_uSpecular;
   vec3 emissive = xeo_uEmissive;
   float opacity = xeo_uOpacity;
   float shininess = xeo_uShininess;
   float reflectivity = xeo_uReflectivity;
   vec3 viewNormalVec = normalize(xeo_vViewNormal);

   vec4 texturePos = vec4(xeo_vUV.s, xeo_vUV.t, 1.0, 1.0);
   vec2 textureCoord;

   textureCoord = texturePos.xy;
   textureCoord.y = -texturePos.y;
   opacity = texture2D(xeo_uOpacityMap, textureCoord).b;

   vec3  diffuseLight = vec3(0.0, 0.0, 0.0);
   vec3  specularLight = vec3(0.0, 0.0, 0.0);

   vec3  viewLightVec;
   float dotN;
   float lightDist;
   float attenuation;

   gl_FragColor = vec4( (specularLight * specular) + (diffuse * (diffuseLight + ambient * xeo_uLightAmbientIntensity)) + emissive, opacity);
}
Deamon87 commented 9 years ago

Mindblow. If I manually set this.validated to true, the application runs as it should. So for some reason gl.getProgramParameter(this.handle, gl.VALIDATE_STATUS) returns false even though the shader program is legal and can be used

xeolabs commented 9 years ago

Aha good catch. It's possibly that the program needs values set on all the variables when it's validated, in order to validate properly. I'll temporarily disable validation, but I do want to catch validation errors, so I might defer validation until render-time.

xeolabs commented 9 years ago

Just pushed a new snapshot build with your change - see if you get the validation error now...

Deamon87 commented 9 years ago

Yes, now it works.