Author Topic: default shader lighting problem  (Read 9971 times)

Offline MichaelJPCT

  • float
  • ****
  • Posts: 264
    • View Profile
default shader lighting problem
« 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?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: default shader lighting problem
« Reply #1 on: August 29, 2016, 07:46:34 am »
Do you have screenshots of both version that you can show?

Offline MichaelJPCT

  • float
  • ****
  • Posts: 264
    • View Profile
Re: default shader lighting problem
« Reply #2 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.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: default shader lighting problem
« Reply #3 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.

Offline MichaelJPCT

  • float
  • ****
  • Posts: 264
    • View Profile
Re: default shader lighting problem
« Reply #4 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?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: default shader lighting problem
« Reply #5 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).

Offline MichaelJPCT

  • float
  • ****
  • Posts: 264
    • View Profile
Re: default shader lighting problem
« Reply #6 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.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: default shader lighting problem
« Reply #7 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.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: default shader lighting problem
« Reply #8 on: August 29, 2016, 07:12:20 pm »
This version should fix the specular issue: 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?

Offline MichaelJPCT

  • float
  • ****
  • Posts: 264
    • View Profile
Re: default shader lighting problem
« Reply #9 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(); }
   }
}

Offline MichaelJPCT

  • float
  • ****
  • Posts: 264
    • View Profile
Re: default shader lighting problem
« Reply #10 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.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: default shader lighting problem
« Reply #11 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)?

Offline MichaelJPCT

  • float
  • ****
  • Posts: 264
    • View Profile
Re: default shader lighting problem
« Reply #12 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.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: default shader lighting problem
« Reply #13 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(...);

Offline MichaelJPCT

  • float
  • ****
  • Posts: 264
    • View Profile
Re: default shader lighting problem
« Reply #14 on: August 30, 2016, 04:33:48 pm »
ok, my objects are all compiled, so that i didn't change lightmul in desktop app.