www.jpct.net

jPCT-AE - a 3d engine for Android => Support => Topic started by: MichaelJPCT on August 29, 2016, 04:13:03 am

Title: default shader lighting problem
Post by: MichaelJPCT on August 29, 2016, 04:13:03 am
i have a JPCT app ported to JPCT-AE. i see a grey object with default shader has color problem. its faces are either grey or total black according to light direction, look like very much overbrighted.
my device has PowerVR540 GPU and Android 4.2.2.
what could be the cause?
Title: Re: default shader lighting problem
Post by: EgonOlsen on August 29, 2016, 07:46:34 am
Do you have screenshots of both version that you can show?
Title: Re: default shader lighting problem
Post by: MichaelJPCT on August 29, 2016, 09:44:43 am
i found it was setSpecularLighting(true) that cause the problem.
but even if specpow=0 specterm=0 , the problem is still there.
here is a screenshot without specular.
Title: Re: default shader lighting problem
Post by: EgonOlsen on August 29, 2016, 09:56:33 am
Yes, looks like a bug in the GL20 support. I'm not actually setting the shininess in the shader, like it's supposed to be. I'll fix that and upload a fixed version later today.
Title: Re: default shader lighting problem
Post by: MichaelJPCT on August 29, 2016, 10:02:12 am
great! thanks!
will you fix it based on the version with correct camera nearclip/farclip/fov settings?
Title: Re: default shader lighting problem
Post by: EgonOlsen on August 29, 2016, 10:03:05 am
Yes, sure. I only have that one. I don't really work with branches for jPCT(-AE).
Title: Re: default shader lighting problem
Post by: MichaelJPCT on August 29, 2016, 10:10:14 am
also , i found a problem with blitting.
if before blitting, the fov is very small (say 0.05 rad), the blit result is inaccurate - text distorted/biased.
can you reset the fov to a normal figure before blitting?
i use an empty world to reset the fov as a temperary solution for now.
Title: Re: default shader lighting problem
Post by: EgonOlsen on August 29, 2016, 10:49:53 am
Not sure...I would rather try to increase precision of the calculations. Maybe that helps. I'll look into it.
Title: Re: default shader lighting problem
Post by: EgonOlsen on August 29, 2016, 07:12:20 pm
This version should fix the specular issue: http://jpct.de/download/beta/jpct_ae.jar (http://jpct.de/download/beta/jpct_ae.jar)...at least it fixes the shader uniform not being initialized correctly. That should actually make it work, but I haven't fully tested it.
About the blitting: I can't verify that. Blitting works fine for me even with extremely low fov values. Can you create a simple test case that shows the problem?
Title: Re: default shader lighting problem
Post by: MichaelJPCT on August 30, 2016, 06:06:42 am
this is test code, you'll see a white square on top left corner and it moves a little.
if your screen has high resolution, maybe it's less noticeable, test screen is 1024x600.

package abc.def;
import com.threed.jpct.*;
import javax.microedition.khronos.egl.EGLConfig;
import javax.microedition.khronos.egl.EGLDisplay;
import javax.microedition.khronos.opengles.GL10;
import android.opengl.GLSurfaceView;
import android.os.Bundle;
import android.app.Activity;

public class Sim extends Activity {
   static GLSurfaceView GLview;
   static MyRenderer renderer;
   static FrameBuffer fb;
   static World world=new World();
   static Camera cam=world.getCamera();
   static Texture tex;
   static float fov=0.1f;

   protected void onCreate(Bundle a) {
      super.onCreate(a);
      renderer=new MyRenderer();
      GLview=new GLSurfaceView(getApplication());
      GLview.setEGLContextClientVersion(2);
      GLview.setRenderer(renderer);
      setContentView(GLview); }
   @Override
   protected void onPause() { super.onPause(); GLview.onPause(); }
   @Override
   protected void onResume() { super.onResume(); GLview.onResume(); }
   @Override
   protected void onStop() { super.onStop(); }

   class MyRenderer implements GLSurfaceView.Renderer {
      public void onSurfaceCreated(GL10 g,EGLConfig c) {}
      public void onSurfaceChanged(GL10 g,int w,int h) {
         if (fb!=null) fb.dispose();
         fb=new FrameBuffer(w,h);
         cam.setFOVLimits(0.0001f,10f);
         cam.setClippingPlanes(0.1f,100f);
         tex=new Texture(1,1,new RGBColor(200,200,200));
         TextureManager.getInstance().addTexture("tex",tex);
      }
      public void onDrawFrame(GL10 g) {
         fb.clear(); cam.setFOV(fov);
         fov-=0.001f; if (fov<0.01) fov=0.1f;
         world.renderScene(fb); world.draw(fb);
         fb.blit(tex,0,0,10,10,0,0,80,80,-1,false);
         fb.display(); }
   }
}
Title: Re: default shader lighting problem
Post by: MichaelJPCT on August 30, 2016, 11:00:37 am
i tested the newer version of jar, but i didn't see any specular effect.
my settings specterm=20 specpow=90.
Title: Re: default shader lighting problem
Post by: EgonOlsen on August 30, 2016, 11:09:44 am
Do you see something in the desktop application? And if you do, does this still apply if you set Config.lightMul=1 (in the desktop app)?
Title: Re: default shader lighting problem
Post by: MichaelJPCT on August 30, 2016, 12:27:10 pm
my desktop app has noticeable specular effect.
my desktop app uses hardware GL, so max lightmul is 1 , right?
i didn't set lightmul in it.
Title: Re: default shader lighting problem
Post by: EgonOlsen on August 30, 2016, 01:04:10 pm
my desktop app uses hardware GL, so max lightmul is 1 , right?
No, default is 10. It's only 1 for compiled objects, i.e. objects on which you've called compile(...);
Title: Re: default shader lighting problem
Post by: MichaelJPCT on August 30, 2016, 04:33:48 pm
ok, my objects are all compiled, so that i didn't change lightmul in desktop app.
Title: Re: default shader lighting problem
Post by: EgonOlsen on August 30, 2016, 05:53:58 pm
I'll look into it...
Title: Re: default shader lighting problem
Post by: EgonOlsen on August 30, 2016, 11:37:38 pm
I gave the blitting issue a shot...I couldn't fix it with increased accuracy. It didn't change one little bit, which makes me think that it's actually caused by inaccuracies in the GPU's view frustum and not so much in the generated coordinates. But I can't reset the fov in all cases, I should rather rework the blitting code as a whole. Anyway, that's not going to happen too soon, so...if you have a workaround, I suggest that you simply use it for now. These very low fov values are a very unusual use case anyway.
I'll look into the specular thing once my toothache is gone...can't really concentrate on it ATM... ;)
Title: Re: default shader lighting problem
Post by: MichaelJPCT on August 31, 2016, 06:11:13 am
i think using an empty world to reset fov is good enough. just that more operations are done than simply changing the frustum. if cpu speed is high enough, it's ok.
Title: Re: default shader lighting problem
Post by: EgonOlsen on August 31, 2016, 06:54:18 am
There's no real overhead in that workaround, so it's just fine.
Title: Re: default shader lighting problem
Post by: EgonOlsen on August 31, 2016, 10:02:52 pm
About the specular lighting: I made myself a test case and it looks in OpenGL ES 2.0 mode exactly the same way as it looks in 1.x mode (which can't be wrong, because specular is done by the fixed function pipeline in that one). So...I'm not sure what the actual issue is... ???
Title: Re: default shader lighting problem
Post by: MichaelJPCT on September 01, 2016, 12:14:35 pm
do you mean you see specular effect with the new jar?
i tested my app on another device with powervr 544 and IPS(better color) screen, i still don't see the effect similar to desktop version.
settings are the same as desktop.
Title: Re: default shader lighting problem
Post by: EgonOlsen on September 01, 2016, 12:24:17 pm
At least I'm seeing the same outcome in OpenGL ES 1.x as I do in 2.0 and it does look different from not having specular enabled, so I would say "yes, I'm seeing a specular highlight". I'm not sure if it's equal to what the desktop version provides, because I haven't checked that. I'll do later and report back.
Title: Re: default shader lighting problem
Post by: MichaelJPCT on September 01, 2016, 01:30:30 pm
the way i judge specular effect is that when viewed from different angles, a polygon has different light intensity. that is what "diffuse" lighting can't have.
Title: Re: default shader lighting problem
Post by: EgonOlsen on September 03, 2016, 10:13:28 pm
Yes, that should actually happen. You can look into the default shader's code. They do take the angle into account just like the fixed function pipeline should...!?
Title: Re: default shader lighting problem
Post by: MichaelJPCT on September 05, 2016, 06:41:55 pm
today i tested gl es 1.1 with my app on a mali400 device and i see the specular effect. with es 2.0 still no effect.
my app has something special in graphics - camera is always positioned at (0,0,0), objects move instead of the camera.
can this affect the specular effect?
Title: Re: default shader lighting problem
Post by: EgonOlsen on September 05, 2016, 06:50:06 pm
No, I don't think so. It should work. Can you provide me with a test case that shows the difference between the two modes?
Title: Re: default shader lighting problem
Post by: MichaelJPCT on September 07, 2016, 08:17:39 am
i made a test case.
if gl2=false, you can see the color of a box changes a bit, while with gl2=true, color doesn't change.

package abc.def;
import com.threed.jpct.*;
import javax.microedition.khronos.egl.EGL10;
import javax.microedition.khronos.egl.EGLConfig;
import javax.microedition.khronos.egl.EGLDisplay;
import javax.microedition.khronos.opengles.GL10;
import android.opengl.GLSurfaceView;
import android.os.Bundle; import android.app.Activity;
import java.lang.reflect.Field;

public class Sim extends Activity {
   static GLSurfaceView GLview; static MyRenderer renderer;
   static FrameBuffer fb;
   static World world=new World();
   static Camera cam=world.getCamera();
   static Object3D box=Primitives.getBox(5,1),gnd=Primitives.getPlane(1,500);
   static float yaw;
   static SimpleVector vec=new SimpleVector();
   static Light sun;
   static Texture tex=new Texture(1,1,new RGBColor(200,200,200));
   static boolean gl2=false;

   void init() { sun=new Light(world); sun.setAttenuation(-1f);
      sun.setDiscardDistance(-1f); vec.set(0,2000,10000);
      sun.setPosition(vec); TextureManager.getInstance().addTexture("tex",tex);
      box.setTexture("tex"); box.build();
      world.addObject(box); box.setSpecularLighting(true);
      gnd.build(); world.addObject(gnd);
      vec.set(0,50,0); gnd.setOrigin(vec); gnd.rotateX((float)Math.PI/2);
   }

   protected void onCreate(Bundle a) {
      super.onCreate(a); renderer=new MyRenderer();
      GLview=new GLSurfaceView(getApplication());
      if (gl2) GLview.setEGLContextClientVersion(2); else
      GLview.setEGLConfigChooser(new GLSurfaceView.EGLConfigChooser() {
         public EGLConfig chooseConfig(EGL10 egl,EGLDisplay display) {
            int[] attributes=new int[]{EGL10.EGL_DEPTH_SIZE,16,EGL10.EGL_NONE};
            EGLConfig[] configs=new EGLConfig[1]; int[] result=new int[1];
            egl.eglChooseConfig(display,attributes,configs,1,result);
            return configs[0]; } } );
      GLview.setRenderer(renderer); setContentView(GLview); }

   @Override
   protected void onPause() { super.onPause(); GLview.onPause(); }
   @Override
   protected void onResume() { super.onResume(); GLview.onResume(); }
   @Override
   protected void onStop() { super.onStop(); }

   class MyRenderer implements GLSurfaceView.Renderer {
      public void onSurfaceCreated(GL10 g,EGLConfig c) {}
      public void onSurfaceChanged(GL10 g,int w,int h) {
         if (gl2) fb=new FrameBuffer(w,h);
         else fb=new FrameBuffer(g,w,h);
         init(); }

      public void onDrawFrame(GL10 g) {
         float a=0.01f; yaw-=a; cam.rotateY(a);
         vec.set(50*(float)Math.sin(yaw),10f,50*(float)Math.cos(yaw));
         box.setOrigin(vec);
         fb.clear(); world.renderScene(fb);
         world.draw(fb); fb.display(); } }
}
Title: Re: default shader lighting problem
Post by: EgonOlsen on September 07, 2016, 08:34:44 am
Thanks for that. I'll look into it.
Title: Re: default shader lighting problem
Post by: EgonOlsen on September 08, 2016, 11:48:40 pm
FYI: I'm working on it. I've to refactor the default shaders to make this work.
Title: Re: default shader lighting problem
Post by: EgonOlsen on September 09, 2016, 09:22:41 pm
Please try this jar: http://jpct.de/download/beta/jpct_ae.jar (http://jpct.de/download/beta/jpct_ae.jar)
Title: Re: default shader lighting problem
Post by: MichaelJPCT on September 10, 2016, 01:52:47 pm
it seems to work correctly like the desktop version now. thanks.
i see the specTerm param is gone, but i never knew what it was - it didn't make difference in my desktop app.
Title: Re: default shader lighting problem
Post by: EgonOlsen on September 10, 2016, 07:56:04 pm
It wasn't used in the Android version anyway. I'll check the desktop version, if it still has any use in that one.
Title: Re: default shader lighting problem
Post by: EgonOlsen on September 20, 2016, 10:15:03 pm
I've updated the beta jar: http://jpct.de/download/beta/jpct_ae.jar (http://jpct.de/download/beta/jpct_ae.jar)
The fixed shaders were too large to compile on Vivante GPUs and crashed the VM when trying. So I got myself a cheap, used Galaxy Tab3 to debug it and finally fixed the problem by using some different shaders for Vivante based devices. This is the first time that I had to do that (use different shaders, not buy a device to debug stuff...I did that several times... ;)).