Author Topic: Confirming 32bit color output via jPCT  (Read 6530 times)

Offline K24A3

  • long
  • ***
  • Posts: 231
    • View Profile
Re: Confirming 32bit color output via jPCT
« Reply #15 on: October 11, 2012, 10:45:20 am »
Ok I moved obj.setShader(shader) into updateFrame() calling it 5 seconds later, the standard texture looks normal at the beginning then after 5 seconds it goes black with white bolts.

Offline K24A3

  • long
  • ***
  • Posts: 231
    • View Profile
Re: Confirming 32bit color output via jPCT
« Reply #16 on: October 11, 2012, 10:57:41 am »
...update

rotating the screen causes the whole sphere to be textured as if it had no directional lighting, just ambient light all around.

(and yes I am calling calcTangentVectors() at the beginning)


Edit: Attached log of starting with default shader, 5 seconds later it sets the user shader, then rotate the screen a second later. Also attached an image showing all three stages.

[attachment deleted by admin]
« Last Edit: October 11, 2012, 11:16:36 am by K24A3 »

Online EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11745
    • View Profile
    • http://www.jpct.net
Re: Confirming 32bit color output via jPCT
« Reply #17 on: October 11, 2012, 11:20:38 am »
...that's all on MALI crapset, i assume?

Offline K24A3

  • long
  • ***
  • Posts: 231
    • View Profile
Re: Confirming 32bit color output via jPCT
« Reply #18 on: October 11, 2012, 11:25:09 am »
Yes.

The shader works fine on the Tegra3.

I'm using a 3DS file now and that too has the lighning bolt effect, also visible on the Tegra3 but it's barely visible.

[attachment deleted by admin]

Offline K24A3

  • long
  • ***
  • Posts: 231
    • View Profile
Re: Confirming 32bit color output via jPCT
« Reply #19 on: October 11, 2012, 11:29:13 am »
Just to confirm I'm adjusting the ambient light correctly in the fragment shader, I've added the below lines


   float specular = pow(clamp(dot(reflect(-lVec, bump), vVec), 0.0, 1.0), 0.85);
   vec4 vSpecular = vec4(specularColors[0],0) * specular;   
   
   vAmbient.x += 0.3; // ADDED
   vAmbient.y += 0.3; // ADDED
   vAmbient.z += 0.3; // ADDED
   
   gl_FragColor = (vAmbient*base + vDiffuse*base + vSpecular) * att*2.0;
}

Online EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11745
    • View Profile
    • http://www.jpct.net
Re: Confirming 32bit color output via jPCT
« Reply #20 on: October 11, 2012, 11:29:45 am »
Are you still use calcTextureWrapXXX to apply the texture? The tangent vectors are calculated based on the u/v-mapping. Try to find and use a model with proper spherical uv-mapping.

Online EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11745
    • View Profile
    • http://www.jpct.net
Re: Confirming 32bit color output via jPCT
« Reply #21 on: October 11, 2012, 11:30:06 am »
Just to confirm I'm adjusting the ambient light correctly in the fragment shader,
Looks ok to me.

Offline K24A3

  • long
  • ***
  • Posts: 231
    • View Profile
Re: Confirming 32bit color output via jPCT
« Reply #22 on: October 11, 2012, 11:33:09 am »
Are you still use calcTextureWrapXXX to apply the texture? The tangent vectors are calculated based on the u/v-mapping. Try to find and use a model with proper spherical uv-mapping.

Oops yes you are spot on. Looks perfect now on the Tegra3

Offline K24A3

  • long
  • ***
  • Posts: 231
    • View Profile
Re: Confirming 32bit color output via jPCT
« Reply #23 on: October 11, 2012, 11:38:29 am »
Still the same on the Mali crapset minus the bolts.

Offline K24A3

  • long
  • ***
  • Posts: 231
    • View Profile
Re: Confirming 32bit color output via jPCT
« Reply #24 on: October 11, 2012, 02:49:12 pm »
I can also post a version that combines offset mapping for the first with normal gouraud shading for all other light sources, if that helps.

If you wouldn't mind posting that version I'll give it a try. As far as I can tell it looks like the problem may be related to shader lighting.

Online EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11745
    • View Profile
    • http://www.jpct.net
Re: Confirming 32bit color output via jPCT
« Reply #25 on: October 11, 2012, 02:54:16 pm »
I'll post them later. I'm still not sure what causes this...as said, i got similar reports from other shaders on other MALI based devices and saw the exact same problem in another engine, so i tend to think that it's a driver bug of some kind. The question is what triggers this bug and if we can somehow work around it. I have some ideas to try...i'll post them later too.

Offline K24A3

  • long
  • ***
  • Posts: 231
    • View Profile
Re: Confirming 32bit color output via jPCT
« Reply #26 on: October 11, 2012, 02:58:59 pm »
Ok thanks, no rush.

Online EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11745
    • View Profile
    • http://www.jpct.net
Re: Confirming 32bit color output via jPCT
« Reply #27 on: October 11, 2012, 05:47:18 pm »
The shader code. It assumes that the first light is the one you want to use for offset mapping. To ensure that this is always the case, you most likely have to enforce this by using http://www.jpct.net/jpct-ae/doc/com/threed/jpct/Light.html#setDistanceOverride(float)

vertex:
Code: [Select]
uniform mat4 modelViewMatrix;
uniform mat4 modelViewProjectionMatrix;

uniform vec4 additionalColor;
uniform vec4 ambientColor;

uniform int lightCount;

uniform vec3 lightPositions[8];
uniform vec3 diffuseColors[8];

uniform float fader;
uniform float fogDistance;

uniform float invRadius;

attribute vec4 position;
attribute vec3 normal;
attribute vec4 tangent;
attribute vec2 texture0;

varying vec3 eyeVec;
varying vec2 texCoord;
varying vec4 vertexColor;
varying vec4 diffuseColor;
varying vec3 lVec;
varying float fogWeight;
varying float att;

void main(void)
{
texCoord = texture0.xy;

vec3 n = normalize(modelViewMatrix * vec4(normal,0.0)).xyz;
vec3 t = normalize(modelViewMatrix * vec4(tangent.xyz, 0.0)).xyz;

vec3 b = tangent.w*cross(n, t);

vec3 vVertex = vec3(modelViewMatrix * position);
vec3 tmpVec = lightPositions[0].xyz - vVertex;

vec3 lv;
vec3 ev;

lv.x = dot(tmpVec, t);
lv.y = dot(tmpVec, b);
lv.z = dot(tmpVec, n);

tmpVec = vVertex*-1.0;
eyeVec.x = dot(tmpVec, t);
eyeVec.y = dot(tmpVec, b);
eyeVec.z = dot(tmpVec, n);

eyeVec=normalize(eyeVec);
vertexColor=vec4(0,0,0,0);
diffuseColor=vec4(diffuseColors[0],0);

float distSqr = dot(lv, lv);
att = clamp(1.0 - invRadius * sqrt(distSqr), 0.0, 1.0);
lVec = lv * inversesqrt(distSqr);

if (lightCount>1) {
vec3 normalEye   = normalize(modelViewMatrix * vec4(normal, 0.0)).xyz;
tmpVec = lightPositions[1] - vVertex;

float angle = dot(normalEye, normalize(tmpVec));

if (angle > 0.0) {
vertexColor += vec4(diffuseColors[1] * (angle * (1.0- (min(fader, length(tmpVec)+0.1)/fader))), 0);
}

if (lightCount>2) {
tmpVec = lightPositions[2] - vVertex;
angle = dot(normalEye, normalize(tmpVec));

if (angle > 0.0) {
vertexColor += vec4(diffuseColors[2] * (angle * (1.0- (min(fader, length(tmpVec)+0.1)/fader))), 0);
}

if (lightCount>3) {
tmpVec = lightPositions[3] - vVertex;
angle = dot(normalEye, normalize(tmpVec));

if (angle > 0.0) {
vertexColor += vec4(diffuseColors[3] * (angle * (1.0- (min(fader, length(tmpVec)+0.1)/fader))), 0);
}

if (lightCount>4) {
tmpVec = lightPositions[4] - vVertex;
angle = dot(normalEye, normalize(tmpVec));

if (angle > 0.0) {
vertexColor += vec4(diffuseColors[4] * (angle * (1.0- (min(fader, length(tmpVec)+0.1)/fader))), 0);
}

if (lightCount>5) {
tmpVec = lightPositions[5] - vVertex;
angle = dot(normalEye, normalize(tmpVec));

if (angle > 0.0) {
vertexColor += vec4(diffuseColors[5] * (angle * (1.0- (min(fader, length(tmpVec)+0.1)/fader))), 0);
}

if (lightCount>6) {
tmpVec = lightPositions[6] - vVertex;
angle = dot(normalEye, normalize(tmpVec));

if (angle > 0.0) {
vertexColor += vec4(diffuseColors[6] * (angle * (1.0- (min(fader, length(tmpVec)+0.1)/fader))), 0);
}

if (lightCount>7) {
tmpVec = lightPositions[7] - vVertex;
angle = dot(normalEye, normalize(tmpVec));

if (angle > 0.0) {
vertexColor += vec4(diffuseColors[7] * (angle * (1.0- (min(fader, length(tmpVec)+0.1)/fader))), 0);
}
}
}
}
}
}
}
}

fogWeight = 1.0-clamp((-vVertex.z - (fogDistance-280.0)) / (280.0), 0.0, 1.0);
gl_Position = modelViewProjectionMatrix * position;
}

fragment:
Code: [Select]
precision highp float;

varying vec3 eyeVec;
varying vec2 texCoord;
varying vec4 vertexColor;
varying vec4 diffuseColor;
varying vec3 lVec;
varying float fogWeight;
varying float att;

uniform sampler2D textureUnit0;
uniform sampler2D textureUnit1;

uniform vec4 ambientColor;
uniform float heightScale;

void main ()
{
float height = texture2D(textureUnit1, texCoord).a;
vec2 offset = eyeVec.xy * ((height * 2.0 - 1.0) * heightScale);
vec2 newTexCoord = texCoord + offset;

vec4 base = texture2D(textureUnit0, newTexCoord) * fogWeight;
vec3 bump = normalize(texture2D(textureUnit1, newTexCoord).xyz * 2.0 - 1.0);

float diffuse = max(dot(lVec, bump), 0.0);
vec4 vDiffuse = diffuseColor * diffuse;

gl_FragColor = ((ambientColor + vDiffuse)*base * att*2.0 + vertexColor*(base*2.0));
}

Offline K24A3

  • long
  • ***
  • Posts: 231
    • View Profile
Re: Confirming 32bit color output via jPCT
« Reply #28 on: October 12, 2012, 10:42:13 am »
I can't seem to find setDistanceOverride in v1.26 beta, was it removed?

Also adding the below lines to the fragment shader causes a shader load error

   ambientColor.x += 0.3;
   ambientColor.y += 0.3;
   ambientColor.z += 0.3;

Online EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11745
    • View Profile
    • http://www.jpct.net
Re: Confirming 32bit color output via jPCT
« Reply #29 on: October 12, 2012, 11:13:05 am »
No, it's still in the Light class. I'm using it myself, so it has to be...

Which error do you get for the ambientColor-code?