Author Topic: i use setSpecificLighting (true) for Object3D,invalid on mobile phone。  (Read 839 times)

Offline specularlighting123

  • byte
  • *
  • Posts: 12
    • View Profile
I'm using OpenGL 2.0 now,
The result looks like the first picture.
How can I make him look like the second picture.
The second picture, using OpenGL 1.0, runs in the android studio default emulator.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12205
    • View Profile
    • http://www.jpct.net
There's no need to set any parameters in the default shaders. Their purpose is to mimic GL 1.x behaviour automatically. I'm unsure why this doesn't happen here though.

Here's a test case that I've hacked together that show specular lighting on a sphere in ES 2.0. Maybe you can run that on your device with and without specular lighting enabled and report the results.

Code: [Select]
package com.threed.jpct.example;

import java.lang.reflect.Field;

import javax.microedition.khronos.egl.EGLConfig;
import javax.microedition.khronos.opengles.GL10;

import android.app.Activity;
import android.opengl.GLSurfaceView;
import android.os.Bundle;
import android.util.Log;

import com.threed.jpct.Camera;
import com.threed.jpct.FrameBuffer;
import com.threed.jpct.Light;
import com.threed.jpct.Logger;
import com.threed.jpct.Object3D;
import com.threed.jpct.Primitives;
import com.threed.jpct.RGBColor;
import com.threed.jpct.SimpleVector;
import com.threed.jpct.Texture;
import com.threed.jpct.World;
import com.threed.jpct.util.MemoryHelper;

public class HelloWorld extends Activity {

private static HelloWorld master = null;

private GLSurfaceView mGLView;
private MyRenderer renderer = null;
private FrameBuffer fb = null;
private World world = null;

private int fps = 0;

private Light sun = null;

private GL10 lastGl = null;

private RGBColor back = new RGBColor(50, 50, 10);
public Object3D obj;
public Texture texture;

protected void onCreate(Bundle savedInstanceState) {

Logger.log("onCreate");

if (master != null) {
copy(master);
}

super.onCreate(savedInstanceState);

mGLView = new GLSurfaceView(getApplication());
mGLView.setEGLContextClientVersion(2);
mGLView.setPreserveEGLContextOnPause(true);

renderer = new MyRenderer();
mGLView.setRenderer(renderer);
setContentView(mGLView);
}

@Override
protected void onPause() {
super.onPause();
mGLView.onPause();
}

@Override
protected void onResume() {
super.onResume();
mGLView.onResume();
}

@Override
protected void onStop() {
super.onStop();
System.exit(0);
}

private void copy(Object src) {
try {
Logger.log("Copying data from master Activity!");
Field[] fs = src.getClass().getDeclaredFields();
for (Field f : fs) {
f.setAccessible(true);
f.set(this, f.get(src));
}
} catch (Exception e) {
throw new RuntimeException(e);
}
}

protected boolean isFullscreenOpaque() {
return true;
}

class MyRenderer implements GLSurfaceView.Renderer {

private long time = System.currentTimeMillis();

public MyRenderer() {
}

public void onSurfaceChanged(GL10 gl, int w, int h) {

// Renew the frame buffer
if (lastGl != gl) {
Log.i("HelloWorld", "Init buffer");
if (fb != null) {
fb.dispose();
}
fb = new FrameBuffer(w, h);
fb.setVirtualDimensions(fb.getWidth(), fb.getHeight());
lastGl = gl;
} else {
fb.resize(w, h);
fb.setVirtualDimensions(w, h);
}

if (master == null) {
world = new World();
world.setAmbientLight(70, 70, 70);

sun = new Light(world);
sun.setIntensity(200, 200, 200);

obj = Primitives.getSphere(50,15);
world.addObject(obj);
obj.translate(0, 0, 0);
obj.build();

// Specular lighting
obj.setSpecularLighting(true);

Camera cam = world.getCamera();
cam.moveCamera(Camera.CAMERA_MOVEOUT, 35);
cam.lookAt(SimpleVector.ORIGIN);

SimpleVector sv = new SimpleVector();
sv.set(SimpleVector.ORIGIN);
sv.y -= 70;
sv.z -= 70;
sun.setPosition(sv);
MemoryHelper.compact();

if (master == null) {
Logger.log("Saving master Activity!");
master = HelloWorld.this;
}
}
}

public void onSurfaceCreated(GL10 gl, EGLConfig config) {
//
}

public void onDrawFrame(GL10 gl) {
SimpleVector sv=sun.getPosition();
sv.rotateY(0.02f);
sun.setPosition(sv);

fb.clear(back);
world.renderScene(fb);
world.draw(fb);
fb.display();

if (System.currentTimeMillis() - time >= 1000) {
Logger.log(fps + "fps");
fps = 0;
time = System.currentTimeMillis();
}
fps++;
}
}

public static HelloWorld getApp() {
return master;
}
}


Edit: I assume that you are using the latest version of jPCT-AE?

Offline specularlighting123

  • byte
  • *
  • Posts: 12
    • View Profile







The first five are set up by you.
The last two use the gl1.0
« Last Edit: April 20, 2021, 11:03:55 am by specularlighting123 »

Offline specularlighting123

  • byte
  • *
  • Posts: 12
    • View Profile



Disable mirror with your demo.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12205
    • View Profile
    • http://www.jpct.net
Is that on your device or in the emulator? The sphere looks fine to me, but the car somehow doesn't. There's a setting in Config called specPow. Have to tried to adjust that (higher or lower than the default of 6) to see if that changes the results under ES 2.0?
« Last Edit: April 20, 2021, 06:17:21 pm by EgonOlsen »

Offline specularlighting123

  • byte
  • *
  • Posts: 12
    • View Profile
Run in 2.0 version,The result of the emulator is the same as that of the mobile phone,Highlight is not obvious, shadow has a large serration, and the transition is not smooth。
Run in 1.0 version emulator ,The effect is the best,For example, the last two pictures。

Offline AeroShark333

  • float
  • ****
  • Posts: 266
    • View Profile
As mentioned before, try to increase/decrease the specularity:
Code: [Select]
Config.specPow = 6f; (6 is default)

I believe it'd help if you could share your phone model + Android version.
Especially knowing the GPU inside your phone might be useful to know.

I'm a little puzzled too why the GLES1.x seems to do better..?
The specular lighting seems to affect the transition badly in the spheres too if I'm not mistaken..?

Offline specularlighting123

  • byte
  • *
  • Posts: 12
    • View Profile
Samsung Huawei OnePlus 8、9、10,Most mobile phones .
x86 emulator works best,arm emulator looks bad.
Is it possible that this is the problem of the model itself?


Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12205
    • View Profile
    • http://www.jpct.net
That's not very likely. It's either a device/driver issue or some flaw in the implementation itself. Please try adjusting Config.specPow and report back with the results.