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

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11776
    • View Profile
    • http://www.jpct.net
Re: default shader lighting problem
« Reply #15 on: August 30, 2016, 05:53:58 pm »
I'll look into it...

Offline EgonOlsen

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

Offline MichaelJPCT

  • long
  • ***
  • Posts: 140
    • View Profile
Re: default shader lighting problem
« Reply #17 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.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11776
    • View Profile
    • http://www.jpct.net
Re: default shader lighting problem
« Reply #18 on: August 31, 2016, 06:54:18 am »
There's no real overhead in that workaround, so it's just fine.

Offline EgonOlsen

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

Offline MichaelJPCT

  • long
  • ***
  • Posts: 140
    • View Profile
Re: default shader lighting problem
« Reply #20 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.

Offline EgonOlsen

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

Offline MichaelJPCT

  • long
  • ***
  • Posts: 140
    • View Profile
Re: default shader lighting problem
« Reply #22 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.

Offline EgonOlsen

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

Offline MichaelJPCT

  • long
  • ***
  • Posts: 140
    • View Profile
Re: default shader lighting problem
« Reply #24 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?

Offline EgonOlsen

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

Offline MichaelJPCT

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

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11776
    • View Profile
    • http://www.jpct.net
Re: default shader lighting problem
« Reply #27 on: September 07, 2016, 08:34:44 am »
Thanks for that. I'll look into it.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11776
    • View Profile
    • http://www.jpct.net
Re: default shader lighting problem
« Reply #28 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.
« Last Edit: September 08, 2016, 11:50:17 pm by EgonOlsen »

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11776
    • View Profile
    • http://www.jpct.net
Re: default shader lighting problem
« Reply #29 on: September 09, 2016, 09:22:41 pm »