www.jpct.net

jPCT-AE - a 3d engine for Android => Support => Topic started by: specularlighting123 on April 16, 2021, 12:36:19 pm

Title: i use setSpecificLighting (true) for Object3D,invalid on mobile phone。
Post by: specularlighting123 on April 16, 2021, 12:36:19 pm
hi, :-[

i use setSpecificLighting (true) for Object3D,invalid on mobile phone。

but in the android studio virtual simulator,i can see the reflection of the highlights。
Title: Re: i use setSpecificLighting (true) for Object3D,invalid on mobile phone。
Post by: EgonOlsen on April 16, 2021, 01:20:58 pm
Some devices don't really support it even if they should. Which version of OpenGL is your app using? if it's OpenGL ES 1.x, try OpenGL ES 2.0 instead. See: https://www.jpct.net/wiki/index.php?title=OpenGL_ES_2.0_support (https://www.jpct.net/wiki/index.php?title=OpenGL_ES_2.0_support)
Title: Re: i use setSpecificLighting (true) for Object3D,invalid on mobile phone。
Post by: specularlighting123 on April 16, 2021, 01:54:12 pm
after I set it up,the simulator also lost its effectiveness,it looks like there's no contrast,and saturation is very high。
(simulator:x86 , phone:arm)
Title: Re: i use setSpecificLighting (true) for Object3D,invalid on mobile phone。
Post by: EgonOlsen on April 16, 2021, 04:43:35 pm
You can forget about the simulator in OpenGL ES 2.0 mode. At least that was my experience, so I stopped using it altogether. There are some alternative Android emulators available, maybe one of them works better.
Title: Re: i use setSpecificLighting (true) for Object3D,invalid on mobile phone。
Post by: specularlighting123 on April 16, 2021, 05:18:08 pm
(https://i.loli.net/2021/04/16/3AZWrhg8NeojUlO.png) (https://sm.ms/image/3AZWrhg8NeojUlO)
(https://i.loli.net/2021/04/16/k1RWtJIxwbVQsPo.png) (https://sm.ms/image/k1RWtJIxwbVQsPo)
(https://i.loli.net/2021/04/16/uAU53PwJg7QvliF.png) (https://sm.ms/image/uAU53PwJg7QvliF)

x86 emulator,running is effective
other mobile phones,only shadows and higher saturation
Title: Re: i use setSpecificLighting (true) for Object3D,invalid on mobile phone。
Post by: EgonOlsen on April 17, 2021, 11:31:42 am
I'm not sure what you mean. Which image is which? Is that in ES 2.0 or 1.x mode?
Title: Re: i use setSpecificLighting (true) for Object3D,invalid on mobile phone。
Post by: specularlighting123 on April 17, 2021, 03:05:40 pm
The first one:Run on ARM chip mobile phone
The second one:Run on android studio X86 emulator
I just started learning OpenGL,Just use demo to run a model file,Confused about the differences between the two platforms。The second image looks like a mirror reflection。
Title: Re: i use setSpecificLighting (true) for Object3D,invalid on mobile phone&#12
Post by: AeroShark333 on April 18, 2021, 10:37:31 am
OpenGL implementations differ per device model.
For myself, I have found that emulators actually produce most consistently good results (maybe this was different in the past but it seems fine for me).
I believe the specular lighting doesn't seem to work properly for you on one of both (I'm not sure which screenshot is tied to which device).
You can reduce the sun intensity values to reduce the 'mirror'-like reflections. (Specular lighting).

PS: do you have another phone/tablet you can test on?
Title: Re: i use setSpecificLighting (true) for Object3D,invalid on mobile phone。
Post by: specularlighting123 on April 18, 2021, 01:21:01 pm
I tested about five different brands of mobile phones, and the mirror light was very weak.
I reduced the light source provided by the world class. It has a weak effect. But the effect looks bad.
Is there any way to improve?
Title: Re: i use setSpecificLighting (true) for Object3D,invalid on mobile phone。
Post by: AeroShark333 on April 18, 2021, 06:54:39 pm
I'm not entirely sure what you mean by that it looks 'bad'.
In one of your figures the specular lighting seems missing entirely..?

I believe the default specular lightning implementation uses Gouroud shading.
If you're unhappy with the results, I'd recommend writing your own shaders to implement Phong shading.
Title: Re: i use setSpecificLighting (true) for Object3D,invalid on mobile phone。
Post by: specularlighting123 on April 19, 2021, 02:53:57 am
Thank you for your reply,I'm a rookie,Can you show me a shader example ;D。
Why is there a big gap between the first and the second?
The second one runs on the emulator。
The first one runs on the mobile phone。


Title: Re: i use setSpecificLighting (true) for Object3D,invalid on mobile phone。
Post by: AeroShark333 on April 19, 2021, 12:42:22 pm
Shader example: https://www.jpct.net/wiki/index.php/Shaders
Scroll to last images/code for specular lighting implementation that might be interesting for you.
You can use this to load shader textfiles (both vertex shader and fragment shader) to String variables: https://www.jpct.net/jpct-ae/doc/com/threed/jpct/Loader.html#loadTextFile-java.io.InputStream-
You can use this to create your own GLSLShader: https://www.jpct.net/jpct-ae/doc/com/threed/jpct/GLSLShader.html#GLSLShader-java.lang.String-java.lang.String-
And finally you can use this to apply a GLSLShader to your Object3D: https://www.jpct.net/jpct-ae/doc/com/threed/jpct/Object3D.html#setShader-com.threed.jpct.GLSLShader-

About the gap in graphical output:
OpenGL implementations differ per device model.
This means that one device might have a worse compiler (for the (default) shaders) than another device.
This will lead to artifacts in the graphical/rendered output.
Title: Re: i use setSpecificLighting (true) for Object3D,invalid on mobile phone。
Post by: EgonOlsen on April 19, 2021, 02:58:04 pm
It might also help to know what exactly this "mobile phone" is!? Model number, Android version?
Title: Re: i use setSpecificLighting (true) for Object3D,invalid on mobile phone。
Post by: specularlighting123 on April 20, 2021, 05:32:31 am
In version 2.0, how can I get the default shader to modify the parameters?
Title: Re: i use setSpecificLighting (true) for Object3D,invalid on mobile phone。
Post by: EgonOlsen on April 20, 2021, 07:29:36 am
Which parameters?
Title: Re: i use setSpecificLighting (true) for Object3D,invalid on mobile phone。
Post by: specularlighting123 on April 20, 2021, 08:53:58 am
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.
Title: Re: i use setSpecificLighting (true) for Object3D,invalid on mobile phone&#12
Post by: EgonOlsen on April 20, 2021, 09:36:03 am
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?
Title: Re: i use setSpecificLighting (true) for Object3D,invalid on mobile phone&#12
Post by: specularlighting123 on April 20, 2021, 11:01:44 am
(https://i.loli.net/2021/04/20/eSXE4qYNK9kW2V8.png) (https://sm.ms/image/eSXE4qYNK9kW2V8)
(https://i.loli.net/2021/04/20/x8CEOMhR35uPUfW.png) (https://sm.ms/image/x8CEOMhR35uPUfW)
(https://i.loli.net/2021/04/20/yCQnqpEcXWJMRw8.png) (https://sm.ms/image/yCQnqpEcXWJMRw8)
(https://i.loli.net/2021/04/20/btJMxNZhn35Bk9f.png) (https://sm.ms/image/btJMxNZhn35Bk9f)
(https://i.loli.net/2021/04/20/4avpRGBebZ9KSNf.png) (https://sm.ms/image/4avpRGBebZ9KSNf)
(https://i.loli.net/2021/04/20/DP94KBCv1islGoE.jpg) (https://sm.ms/image/DP94KBCv1islGoE)
(https://i.loli.net/2021/04/20/RAKbXrlBedoOztw.jpg) (https://sm.ms/image/RAKbXrlBedoOztw)
The first five are set up by you.
The last two use the gl1.0
Title: Re: i use setSpecificLighting (true) for Object3D,invalid on mobile phone。
Post by: specularlighting123 on April 20, 2021, 11:58:32 am
(https://i.loli.net/2021/04/20/yZdLbpKvWq8mEGQ.jpg) (https://sm.ms/image/yZdLbpKvWq8mEGQ)
(https://i.loli.net/2021/04/20/CncX3Nu2rxMqUO6.jpg) (https://sm.ms/image/CncX3Nu2rxMqUO6)
(https://i.loli.net/2021/04/20/978ekiSb4oljJmv.jpg) (https://sm.ms/image/978ekiSb4oljJmv)
Disable mirror with your demo.
Title: Re: i use setSpecificLighting (true) for Object3D,invalid on mobile phone&#12
Post by: EgonOlsen on April 20, 2021, 06:14:17 pm
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?
Title: Re: i use setSpecificLighting (true) for Object3D,invalid on mobile phone&#12
Post by: specularlighting123 on April 21, 2021, 03:55:58 am
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。
Title: Re: i use setSpecificLighting (true) for Object3D,invalid on mobile phone。
Post by: AeroShark333 on April 21, 2021, 04:15:34 am
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..?
Title: Re: i use setSpecificLighting (true) for Object3D,invalid on mobile phone。
Post by: specularlighting123 on April 21, 2021, 09:06:41 am
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?

Title: Re: i use setSpecificLighting (true) for Object3D,invalid on mobile phone。
Post by: EgonOlsen on April 21, 2021, 02:18:16 pm
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.