Confirming 32bit color output via jPCT

Started by K24A3, October 05, 2012, 05:15:44 PM

Previous topic - Next topic

K24A3

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.

K24A3

#16
...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]

EgonOlsen

...that's all on MALI crapset, i assume?

K24A3

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]

K24A3

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;
}

EgonOlsen

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.

EgonOlsen

Quote from: K24A3 on October 11, 2012, 11:29:13 AM
Just to confirm I'm adjusting the ambient light correctly in the fragment shader,
Looks ok to me.

K24A3

Quote from: EgonOlsen 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.

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

K24A3

Still the same on the Mali crapset minus the bolts.

K24A3

Quote from: EgonOlsen on October 10, 2012, 09:07:42 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.

EgonOlsen

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.

K24A3


EgonOlsen

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:

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:

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));
}

K24A3

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;

EgonOlsen

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?