www.jpct.net

jPCT-AE - a 3d engine for Android => Support => Topic started by: AeroShark333 on December 06, 2014, 12:07:56 pm

Title: Object3D's transparency issue
Post by: AeroShark333 on December 06, 2014, 12:07:56 pm
Hey everyone,

I had a hard time trying to register to this forums, so I used my schoolemail...  :o
Anyway, I have an issue with 2 Object3D's...
Both objects are cubed. They have individual textures on each face.
Both objects have this transparency value:
Code: [Select]
this.setTransparency(300);
Box1 is in box2. (their center point is equal)
Box1's dimensions: 2f * 2f * 2f
Box2's dimensions: 2.2f * 2.2f * 2.2f
Box2 has more transparent area's than box1.
However, box2's non-transparent textures don't seem to be visible...
When I remove
Code: [Select]
this.setTransparency(300); from box1, then those non-transparent textures do show up... (but then I get black-ish areas on the box1 texture...)

How can I solve this problem?

Cheers,
Abiram

PS: This library is AWESOME   ;D
Title: Re: Object3D's transparency issue
Post by: EgonOlsen on December 06, 2014, 03:07:46 pm
That's most likely caused by render order. Transparent objects are sorted by depth, but that happens on a per object base. If you put one object into another one, there's no correct ordering. Your case is a quite special one. It might be sufficient to force an order between the two cubes. Try something like box1.setSortOffset(10) and see if that helps.
Title: Re: Object3D's transparency issue
Post by: AeroShark333 on December 06, 2014, 05:28:34 pm
Thanks for the quick reply and it worked! :D

However, I have another issue now...
I have a box3 and a box4 next to each other (touched).
Both faces that touch each othe, do intersect each other on the whole face.
And I get something like in the picture... (both have transparency set to 300)

Picture: Left one is what I got. Right one is what I want.
Title: Re: Object3D's transparency issue
Post by: EgonOlsen on December 06, 2014, 11:11:10 pm
That's basically the same issue. Transparent have to be sorted and that happen per object (it has to). This sorting isn't perfect in cases where object intersect or a close to one another. Sorting issues with transparent objects can only be avoided by not using them in the first place. Or by tweaking the sort order like you did in the former case, but for the general case, this isn't possible. I'm not sure if it is in your case. What's the actual idea behind what you are doing? What are these boxes, in which ways are then moving and why do they touch?
Title: Re: Object3D's transparency issue
Post by: AeroShark333 on December 06, 2014, 11:31:42 pm
Well here is the idea:
The app I am working on is a skinviewer for Minecraft and Minebuilder.
The user selects a .png file skin and the app will 'visualise' a 3D version of it.
Since skin files usually contain transparent areas, I have decided to enable transparency on every object.
The objects do not move (yet), but the camera rotates around the objects/skin. (I will add user input and animation-ish movements later)

I released the app today:
https://play.google.com/store/apps/details?id=com.aeroshark333.skinviewer (this version has box1's transparency disabled though, the next update will include the sorting order)

I am not a really good developer, neither am I very good with Java and OpenGL. But this is some kind of hobby :)

The transparency issue with the objects next to each other depends on the device too I guess

Title: Re: Object3D's transparency issue
Post by: EgonOlsen on December 07, 2014, 03:20:58 pm
No, they have nothing to do with the device. Not even with the engine. They are a common problem whenever transparent objects intersect. The only option would be use alpha testing instead of alpha blending. But jPCT-AE doesn't support this out of the box. You would have to use the OpenGL ES 2.0 pipeline and write an alpha testing shader.
If you can provide a simplified test case that shows the issue, i'll have a look and provide you with something to get you started.
Title: Re: Object3D's transparency issue
Post by: AeroShark333 on December 08, 2014, 04:40:24 pm
The 'issue' is very small though, but noticable. (see screenshot in attachment)
Since the camera rotates around the 'center', the 'issue' moves from the left leg to the right leg and visa versa.

Well this is my code:

SkinActivity.class (the GameRenderer class in this class only)
Code: [Select]
class GameRenderer implements GLSurfaceView.Renderer {
final World mainWorld;
final Camera mainCamera;
FrameBuffer frameBuffer;

public GameRenderer(World world) {
this.mainWorld = world;
this.mainCamera = this.mainWorld.getCamera();
}


@Override
public void onSurfaceCreated(GL10 gl, EGLConfig config) {

}

@Override
public void onSurfaceChanged(GL10 gl, int width, int height) {
this.frameBuffer = new FrameBuffer(width, height);

totalSkin.hasAlpha();
InnerHead iH = new InnerHead();
OuterHead oH = new OuterHead();
Body b = new Body();
RightArm rA = new RightArm();
LeftArm lA = new LeftArm();
RightLeg rL = new RightLeg();
LeftLeg lL = new LeftLeg();

mainWorld.addObject(iH);
mainWorld.addObject(oH);
mainWorld.addObject(b);
mainWorld.addObject(rA);
mainWorld.addObject(lA);
mainWorld.addObject(rL);
mainWorld.addObject(lL);

this.mainWorld.setAmbientLight(255, 255, 255);

final float dScreen = (float) height/(float)width;

this.mainCamera.setPosition(0, 0.25f, (-9 / dScreen));
this.mainCamera.lookAt(b.getCenter());

iH.translate(0, -2.51f, 0);
oH.translate(0, -2.605f, 0);
rA.translate(-1.5f, 0, 0);
lA.translate(1.5f, 0, 0);
rL.translate(-0.5f, 3f, 0);
lL.translate(0.5f, 3f, 0);


System.runFinalization();
System.gc();
MemoryHelper.compact();
}

@Override
public void onDrawFrame(GL10 gl) {
frameBuffer.clear(new RGBColor(132, 189, 240));

SimpleVector moveLine = new SimpleVector(0.333f, 0, 0.333f);
com.threed.jpct.Matrix m = moveLine.normalize().getRotationMatrix();
m.rotateAxis(m.getYAxis(), (float) -Math.PI / 2f);
mainCamera.moveCamera(Camera.CAMERA_MOVEIN, 10);
mainCamera.rotateAxis(m.invert3x3().getYAxis(),
moveLine.length() / 30f);
mainCamera.moveCamera(Camera.CAMERA_MOVEOUT, 10);
mainCamera.lookAt(mainWorld.getObjectByName("body").getCenter());

final Texture t1 = TextureManager.getInstance().getTexture("bg");
frameBuffer.blit(t1, 0, t1.getHeight(), 0, 0, t1.getWidth(),
-t1.getHeight(), frameBuffer.getWidth(),
frameBuffer.getHeight(), -1, false);
mainWorld.renderScene(frameBuffer);
mainWorld.draw(frameBuffer);
frameBuffer.display();
}

}

Body:
Code: [Select]
package com.aeroshark333.skinviewer.skinparts;

import com.threed.jpct.Object3D;
import com.threed.jpct.SimpleVector;
import com.threed.jpct.TextureManager;

public class Body extends Object3D {

private static final long serialVersionUID = 8216608860877707087L;

public Body() {

super(12);

final Object3D box = this;

SimpleVector upperLeftFront = new SimpleVector(-1, -1.5f, -0.5f);
SimpleVector upperRightFront = new SimpleVector(1, -1.5f, -0.5f);
SimpleVector lowerLeftFront = new SimpleVector(-1, 1.5f, -0.5f);
SimpleVector lowerRightFront = new SimpleVector(1, 1.5f, -0.5f);

SimpleVector upperLeftBack = new SimpleVector(-1, -1.5f, 0.5f);
SimpleVector upperRightBack = new SimpleVector(1, -1.5f, 0.5f);
SimpleVector lowerLeftBack = new SimpleVector(-1, 1.5f, 0.5f);
SimpleVector lowerRightBack = new SimpleVector(1, 1.5f, 0.5f);

// Front
box.addTriangle(upperLeftFront, 0, 0, lowerLeftFront, 0, 1,
upperRightFront, 1, 0, TextureManager.getInstance()
.getTextureID("bodyfront"));
box.addTriangle(upperRightFront, 1, 0, lowerLeftFront, 0, 1,
lowerRightFront, 1, 1, TextureManager.getInstance()
.getTextureID("bodyfront"));
// Back
box.addTriangle(upperLeftBack, 0, 0, upperRightBack, 1, 0,
lowerLeftBack, 0, 1,
TextureManager.getInstance().getTextureID("bodyback"));
box.addTriangle(upperRightBack, 1, 0, lowerRightBack, 1, 1,
lowerLeftBack, 0, 1,
TextureManager.getInstance().getTextureID("bodyback"));
// Top
box.addTriangle(upperLeftBack, 0, 0, upperLeftFront, 0, 1,
upperRightBack, 1, 0, TextureManager.getInstance()
.getTextureID("bodytop"));
box.addTriangle(upperRightBack, 1, 0, upperLeftFront, 0, 1,
upperRightFront, 1, 1, TextureManager.getInstance()
.getTextureID("bodytop"));
// Bottom
box.addTriangle(lowerLeftBack, 0, 0, lowerRightBack, 1, 0,
lowerLeftFront, 0, 1, TextureManager.getInstance()
.getTextureID("bodybottom"));
box.addTriangle(lowerRightBack, 1, 0, lowerRightFront, 1, 1,
lowerLeftFront, 0, 1, TextureManager.getInstance()
.getTextureID("bodybottom"));
// Right
box.addTriangle(upperLeftFront, 0, 0, upperLeftBack, 1, 0,
lowerLeftFront, 0, 1, TextureManager.getInstance()
.getTextureID("bodyright"));
box.addTriangle(upperLeftBack, 1, 0, lowerLeftBack, 1, 1,
lowerLeftFront, 0, 1, TextureManager.getInstance()
.getTextureID("bodyright"));
// Left
box.addTriangle(upperRightFront, 0, 0, lowerRightFront, 0, 1,
upperRightBack, 1, 0, TextureManager.getInstance()
.getTextureID("bodyleft"));
box.addTriangle(upperRightBack, 1, 0, lowerRightFront, 0, 1,
lowerRightBack, 1, 1, TextureManager.getInstance()
.getTextureID("bodyleft"));

this.setTransparency(300);

box.setName("body");

box.build();
}
}


Innerhead:
Code: [Select]
package com.aeroshark333.skinviewer.skinparts;

import com.threed.jpct.Object3D;
import com.threed.jpct.SimpleVector;
import com.threed.jpct.TextureManager;

public class InnerHead extends Object3D {

private static final long serialVersionUID = 4848178494608221837L;

public InnerHead() {

super(12);

final Object3D box = this;

SimpleVector upperLeftFront = new SimpleVector(-1, -1, -1);
SimpleVector upperRightFront = new SimpleVector(1, -1, -1);
SimpleVector lowerLeftFront = new SimpleVector(-1, 1, -1);
SimpleVector lowerRightFront = new SimpleVector(1, 1, -1);

SimpleVector upperLeftBack = new SimpleVector(-1, -1, 1);
SimpleVector upperRightBack = new SimpleVector(1, -1, 1);
SimpleVector lowerLeftBack = new SimpleVector(-1, 1, 1);
SimpleVector lowerRightBack = new SimpleVector(1, 1, 1);

// Front
box.addTriangle(upperLeftFront, 0, 0, lowerLeftFront, 0, 1,
upperRightFront, 1, 0, TextureManager.getInstance()
.getTextureID("headfront"));
box.addTriangle(upperRightFront, 1, 0, lowerLeftFront, 0, 1,
lowerRightFront, 1, 1, TextureManager.getInstance()
.getTextureID("headfront"));
// Back
box.addTriangle(upperLeftBack, 0, 0, upperRightBack, 1, 0,
lowerLeftBack, 0, 1,
TextureManager.getInstance().getTextureID("headback"));
box.addTriangle(upperRightBack, 1, 0, lowerRightBack, 1, 1,
lowerLeftBack, 0, 1,
TextureManager.getInstance().getTextureID("headback"));
// Top
box.addTriangle(upperLeftBack, 0, 0, upperLeftFront, 0, 1,
upperRightBack, 1, 0, TextureManager.getInstance()
.getTextureID("headtop"));
box.addTriangle(upperRightBack, 1, 0, upperLeftFront, 0, 1,
upperRightFront, 1, 1, TextureManager.getInstance()
.getTextureID("headtop"));
// Bottom
box.addTriangle(lowerLeftBack, 0, 0, lowerRightBack, 1, 0,
lowerLeftFront, 0, 1, TextureManager.getInstance()
.getTextureID("headbottom"));
box.addTriangle(lowerRightBack, 1, 0, lowerRightFront, 1, 1,
lowerLeftFront, 0, 1, TextureManager.getInstance()
.getTextureID("headbottom"));
// Right
box.addTriangle(upperLeftFront, 0, 0, upperLeftBack, 1, 0,
lowerLeftFront, 0, 1, TextureManager.getInstance()
.getTextureID("headright"));
box.addTriangle(upperLeftBack, 1, 0, lowerLeftBack, 1, 1,
lowerLeftFront, 0, 1, TextureManager.getInstance()
.getTextureID("headright"));
// Left
box.addTriangle(upperRightFront, 0, 0, lowerRightFront, 0, 1,
upperRightBack, 1, 0, TextureManager.getInstance()
.getTextureID("headleft"));
box.addTriangle(upperRightBack, 1, 0, lowerRightFront, 0, 1,
lowerRightBack, 1, 1, TextureManager.getInstance()
.getTextureID("headleft"));

this.setTransparency(300);

box.setName("head");

box.setSortOffset(9);

box.build();
}
}

Leftarm:
Code: [Select]
package com.aeroshark333.skinviewer.skinparts;

import com.threed.jpct.Object3D;
import com.threed.jpct.SimpleVector;
import com.threed.jpct.TextureManager;

//biological left :p
public class LeftArm extends Object3D{

/**
*
*/
private static final long serialVersionUID = -5036321054138114930L;

public LeftArm() {

super(12);

final Object3D box = this;

SimpleVector upperLeftFront = new SimpleVector(-0.5f, -1.5f, -0.5f);
SimpleVector upperRightFront = new SimpleVector(0.5f, -1.5f, -0.5f);
SimpleVector lowerLeftFront = new SimpleVector(-0.5f, 1.5f, -0.5f);
SimpleVector lowerRightFront = new SimpleVector(0.5f, 1.5f, -0.5f);

SimpleVector upperLeftBack = new SimpleVector(-0.5f, -1.5f, 0.5f);
SimpleVector upperRightBack = new SimpleVector(0.5f, -1.5f, 0.5f);
SimpleVector lowerLeftBack = new SimpleVector(-0.5f, 1.5f, 0.5f);
SimpleVector lowerRightBack = new SimpleVector(0.5f, 1.5f, 0.5f);

// Front
box.addTriangle(upperLeftFront, 0, 0, lowerLeftFront, 0, 1,
upperRightFront, 1, 0, TextureManager.getInstance()
.getTextureID("armfront"));
box.addTriangle(upperRightFront, 1, 0, lowerLeftFront, 0, 1,
lowerRightFront, 1, 1, TextureManager.getInstance()
.getTextureID("armfront"));
// Back
box.addTriangle(upperLeftBack, 0, 0, upperRightBack, 1, 0,
lowerLeftBack, 0, 1,
TextureManager.getInstance().getTextureID("armback"));
box.addTriangle(upperRightBack, 1, 0, lowerRightBack, 1, 1,
lowerLeftBack, 0, 1,
TextureManager.getInstance().getTextureID("armback"));
// Top
box.addTriangle(upperLeftBack, 0, 0, upperLeftFront, 0, 1,
upperRightBack, 1, 0, TextureManager.getInstance()
.getTextureID("armtop"));
box.addTriangle(upperRightBack, 1, 0, upperLeftFront, 0, 1,
upperRightFront, 1, 1, TextureManager.getInstance()
.getTextureID("armtop"));
// Bottom
box.addTriangle(lowerLeftBack, 0, 0, lowerRightBack, 1, 0,
lowerLeftFront, 0, 1, TextureManager.getInstance()
.getTextureID("armbottom"));
box.addTriangle(lowerRightBack, 1, 0, lowerRightFront, 1, 1,
lowerLeftFront, 0, 1, TextureManager.getInstance()
.getTextureID("armbottom"));
// Right
box.addTriangle(upperLeftFront, 0, 0, upperLeftBack, 1, 0,
lowerLeftFront, 0, 1, TextureManager.getInstance()
.getTextureID("armright"));
box.addTriangle(upperLeftBack, 1, 0, lowerLeftBack, 1, 1,
lowerLeftFront, 0, 1, TextureManager.getInstance()
.getTextureID("armright"));
// Left
box.addTriangle(upperRightFront, 0, 0, lowerRightFront, 0, 1,
upperRightBack, 1, 0, TextureManager.getInstance()
.getTextureID("armleft"));
box.addTriangle(upperRightBack, 1, 0, lowerRightFront, 0, 1,
lowerRightBack, 1, 1, TextureManager.getInstance()
.getTextureID("armleft"));

this.setTransparency(300);

box.setName("leftarm");


box.build();
}
}

Leftleg:
Code: [Select]
package com.aeroshark333.skinviewer.skinparts;

import com.threed.jpct.Object3D;
import com.threed.jpct.SimpleVector;
import com.threed.jpct.TextureManager;

//biological left
public class LeftLeg extends Object3D{
/**
*
*/
private static final long serialVersionUID = 4705719438846904180L;

public LeftLeg() {

super(12);

final Object3D box = this;

SimpleVector upperLeftFront = new SimpleVector(-0.5f, -1.5f, -0.5f);
SimpleVector upperRightFront = new SimpleVector(0.5f, -1.5f, -0.5f);
SimpleVector lowerLeftFront = new SimpleVector(-0.5f, 1.5f, -0.5f);
SimpleVector lowerRightFront = new SimpleVector(0.5f, 1.5f, -0.5f);

SimpleVector upperLeftBack = new SimpleVector(-0.5f, -1.5f, 0.5f);
SimpleVector upperRightBack = new SimpleVector(0.5f, -1.5f, 0.5f);
SimpleVector lowerLeftBack = new SimpleVector(-0.5f, 1.5f, 0.5f);
SimpleVector lowerRightBack = new SimpleVector(0.5f, 1.5f, 0.5f);

// Front
box.addTriangle(upperLeftFront, 0, 0, lowerLeftFront, 0, 1,
upperRightFront, 1, 0, TextureManager.getInstance()
.getTextureID("legfront"));
box.addTriangle(upperRightFront, 1, 0, lowerLeftFront, 0, 1,
lowerRightFront, 1, 1, TextureManager.getInstance()
.getTextureID("legfront"));
// Back
box.addTriangle(upperLeftBack, 0, 0, upperRightBack, 1, 0,
lowerLeftBack, 0, 1,
TextureManager.getInstance().getTextureID("legback"));
box.addTriangle(upperRightBack, 1, 0, lowerRightBack, 1, 1,
lowerLeftBack, 0, 1,
TextureManager.getInstance().getTextureID("legback"));
// Top
box.addTriangle(upperLeftBack, 0, 0, upperLeftFront, 0, 1,
upperRightBack, 1, 0, TextureManager.getInstance()
.getTextureID("legtop"));
box.addTriangle(upperRightBack, 1, 0, upperLeftFront, 0, 1,
upperRightFront, 1, 1, TextureManager.getInstance()
.getTextureID("legtop"));
// Bottom
box.addTriangle(lowerLeftBack, 0, 0, lowerRightBack, 1, 0,
lowerLeftFront, 0, 1, TextureManager.getInstance()
.getTextureID("legbottom"));
box.addTriangle(lowerRightBack, 1, 0, lowerRightFront, 1, 1,
lowerLeftFront, 0, 1, TextureManager.getInstance()
.getTextureID("legbottom"));
// Right
box.addTriangle(upperLeftFront, 0, 0, upperLeftBack, 1, 0,
lowerLeftFront, 0, 1, TextureManager.getInstance()
.getTextureID("legright"));
box.addTriangle(upperLeftBack, 1, 0, lowerLeftBack, 1, 1,
lowerLeftFront, 0, 1, TextureManager.getInstance()
.getTextureID("legright"));
// Left
box.addTriangle(upperRightFront, 0, 0, lowerRightFront, 0, 1,
upperRightBack, 1, 0, TextureManager.getInstance()
.getTextureID("legleft"));
box.addTriangle(upperRightBack, 1, 0, lowerRightFront, 0, 1,
lowerRightBack, 1, 1, TextureManager.getInstance()
.getTextureID("legleft"));

this.setTransparency(300);

box.setName("leftleg");


box.build();
}
}

Outerhead:
Code: [Select]
package com.aeroshark333.skinviewer.skinparts;

import com.threed.jpct.Object3D;
import com.threed.jpct.SimpleVector;
import com.threed.jpct.TextureManager;

public class OuterHead extends Object3D{

private static final long serialVersionUID = 3950765561884516490L;

public OuterHead() {

super(12);

final Object3D box = this;

SimpleVector upperLeftFront = new SimpleVector(-1.1f, -1.1f, -1.1f);
SimpleVector upperRightFront = new SimpleVector(1.1f, -1.1f, -1.1f);
SimpleVector lowerLeftFront = new SimpleVector(-1.1f, 1.1f, -1.1f);
SimpleVector lowerRightFront = new SimpleVector(1.1f, 1.1f, -1.1f);

SimpleVector upperLeftBack = new SimpleVector(-1.1f, -1.1f, 1.1f);
SimpleVector upperRightBack = new SimpleVector(1.1f, -1.1f, 1.1f);
SimpleVector lowerLeftBack = new SimpleVector(-1.1f, 1.1f, 1.1f);
SimpleVector lowerRightBack = new SimpleVector(1.1f, 1.1f, 1.1f);

// Front
box.addTriangle(upperLeftFront, 0, 0, lowerLeftFront, 0, 1,
upperRightFront, 1, 0, TextureManager.getInstance()
.getTextureID("hatfront"));
box.addTriangle(upperRightFront, 1, 0, lowerLeftFront, 0, 1,
lowerRightFront, 1, 1, TextureManager.getInstance()
.getTextureID("hatfront"));
// Back
box.addTriangle(upperLeftBack, 0, 0, upperRightBack, 1, 0,
lowerLeftBack, 0, 1,
TextureManager.getInstance().getTextureID("hatback"));
box.addTriangle(upperRightBack, 1, 0, lowerRightBack, 1, 1,
lowerLeftBack, 0, 1,
TextureManager.getInstance().getTextureID("hatback"));
// Top
box.addTriangle(upperLeftBack, 0, 0, upperLeftFront, 0, 1,
upperRightBack, 1, 0, TextureManager.getInstance()
.getTextureID("hattop"));
box.addTriangle(upperRightBack, 1, 0, upperLeftFront, 0, 1,
upperRightFront, 1, 1, TextureManager.getInstance()
.getTextureID("hattop"));
// Bottom
box.addTriangle(lowerLeftBack, 0, 0, lowerRightBack, 1, 0,
lowerLeftFront, 0, 1, TextureManager.getInstance()
.getTextureID("hatbottom"));
box.addTriangle(lowerRightBack, 1, 0, lowerRightFront, 1, 1,
lowerLeftFront, 0, 1, TextureManager.getInstance()
.getTextureID("hatbottom"));
// Right
box.addTriangle(upperLeftFront, 0, 0, upperLeftBack, 1, 0,
lowerLeftFront, 0, 1, TextureManager.getInstance()
.getTextureID("hatright"));
box.addTriangle(upperLeftBack, 1, 0, lowerLeftBack, 1, 1,
lowerLeftFront, 0, 1, TextureManager.getInstance()
.getTextureID("hatright"));
// Left
box.addTriangle(upperRightFront, 0, 0, lowerRightFront, 0, 1,
upperRightBack, 1, 0, TextureManager.getInstance()
.getTextureID("hatleft"));
box.addTriangle(upperRightBack, 1, 0, lowerRightFront, 0, 1,
lowerRightBack, 1, 1, TextureManager.getInstance()
.getTextureID("hatleft"));

this.setTransparency(300);


box.setName("hat");

box.build();
}
}

Rightarm:
Code: [Select]
package com.aeroshark333.skinviewer.skinparts;

import com.threed.jpct.Object3D;
import com.threed.jpct.SimpleVector;
import com.threed.jpct.TextureManager;

//biological right
public class RightArm extends Object3D{

/**
*
*/
private static final long serialVersionUID = -5257845406283197478L;

public RightArm() {

super(12);

final Object3D box = this;

SimpleVector upperLeftFront = new SimpleVector(-0.5f, -1.5f, -0.5f);
SimpleVector upperRightFront = new SimpleVector(0.5f, -1.5f, -0.5f);
SimpleVector lowerLeftFront = new SimpleVector(-0.5f, 1.5f, -0.5f);
SimpleVector lowerRightFront = new SimpleVector(0.5f, 1.5f, -0.5f);

SimpleVector upperLeftBack = new SimpleVector(-0.5f, -1.5f, 0.5f);
SimpleVector upperRightBack = new SimpleVector(0.5f, -1.5f, 0.5f);
SimpleVector lowerLeftBack = new SimpleVector(-0.5f, 1.5f, 0.5f);
SimpleVector lowerRightBack = new SimpleVector(0.5f, 1.5f, 0.5f);

// Front
box.addTriangle(upperLeftFront, 0, 0, lowerLeftFront, 0, 1,
upperRightFront, 1, 0, TextureManager.getInstance()
.getTextureID("armfront"));
box.addTriangle(upperRightFront, 1, 0, lowerLeftFront, 0, 1,
lowerRightFront, 1, 1, TextureManager.getInstance()
.getTextureID("armfront"));
// Back
box.addTriangle(upperLeftBack, 0, 0, upperRightBack, 1, 0,
lowerLeftBack, 0, 1,
TextureManager.getInstance().getTextureID("armback"));
box.addTriangle(upperRightBack, 1, 0, lowerRightBack, 1, 1,
lowerLeftBack, 0, 1,
TextureManager.getInstance().getTextureID("armback"));
// Top
box.addTriangle(upperLeftBack, 0, 0, upperLeftFront, 0, 1,
upperRightBack, 1, 0, TextureManager.getInstance()
.getTextureID("armtop"));
box.addTriangle(upperRightBack, 1, 0, upperLeftFront, 0, 1,
upperRightFront, 1, 1, TextureManager.getInstance()
.getTextureID("armtop"));
// Bottom
box.addTriangle(lowerLeftBack, 0, 0, lowerRightBack, 1, 0,
lowerLeftFront, 0, 1, TextureManager.getInstance()
.getTextureID("armbottom"));
box.addTriangle(lowerRightBack, 1, 0, lowerRightFront, 1, 1,
lowerLeftFront, 0, 1, TextureManager.getInstance()
.getTextureID("armbottom"));
// Right
box.addTriangle(upperLeftFront, 0, 0, upperLeftBack, 1, 0,
lowerLeftFront, 0, 1, TextureManager.getInstance()
.getTextureID("armright"));
box.addTriangle(upperLeftBack, 1, 0, lowerLeftBack, 1, 1,
lowerLeftFront, 0, 1, TextureManager.getInstance()
.getTextureID("armright"));
// Left
box.addTriangle(upperRightFront, 0, 0, lowerRightFront, 0, 1,
upperRightBack, 1, 0, TextureManager.getInstance()
.getTextureID("armleft"));
box.addTriangle(upperRightBack, 1, 0, lowerRightFront, 0, 1,
lowerRightBack, 1, 1, TextureManager.getInstance()
.getTextureID("armleft"));

this.setTransparency(300);

box.setName("rightarm");


box.build();
}
}

Rightleg:
Code: [Select]
package com.aeroshark333.skinviewer.skinparts;

import com.threed.jpct.Object3D;
import com.threed.jpct.SimpleVector;
import com.threed.jpct.TextureManager;

//biological right
public class RightLeg extends Object3D {

/**
*
*/
private static final long serialVersionUID = 8223363127837467932L;

public RightLeg() {

super(12);

final Object3D box = this;

SimpleVector upperLeftFront = new SimpleVector(-0.5f, -1.5f, -0.5f);
SimpleVector upperRightFront = new SimpleVector(0.5f, -1.5f, -0.5f);
SimpleVector lowerLeftFront = new SimpleVector(-0.5f, 1.5f, -0.5f);
SimpleVector lowerRightFront = new SimpleVector(0.5f, 1.5f, -0.5f);

SimpleVector upperLeftBack = new SimpleVector(-0.5f, -1.5f, 0.5f);
SimpleVector upperRightBack = new SimpleVector(0.5f, -1.5f, 0.5f);
SimpleVector lowerLeftBack = new SimpleVector(-0.5f, 1.5f, 0.5f);
SimpleVector lowerRightBack = new SimpleVector(0.5f, 1.5f, 0.5f);

// Front
box.addTriangle(upperLeftFront, 0, 0, lowerLeftFront, 0, 1,
upperRightFront, 1, 0, TextureManager.getInstance()
.getTextureID("legfront"));
box.addTriangle(upperRightFront, 1, 0, lowerLeftFront, 0, 1,
lowerRightFront, 1, 1, TextureManager.getInstance()
.getTextureID("legfront"));
// Back
box.addTriangle(upperLeftBack, 0, 0, upperRightBack, 1, 0,
lowerLeftBack, 0, 1,
TextureManager.getInstance().getTextureID("legback"));
box.addTriangle(upperRightBack, 1, 0, lowerRightBack, 1, 1,
lowerLeftBack, 0, 1,
TextureManager.getInstance().getTextureID("legback"));
// Top
box.addTriangle(upperLeftBack, 0, 0, upperLeftFront, 0, 1,
upperRightBack, 1, 0, TextureManager.getInstance()
.getTextureID("legtop"));
box.addTriangle(upperRightBack, 1, 0, upperLeftFront, 0, 1,
upperRightFront, 1, 1, TextureManager.getInstance()
.getTextureID("legtop"));
// Bottom
box.addTriangle(lowerLeftBack, 0, 0, lowerRightBack, 1, 0,
lowerLeftFront, 0, 1, TextureManager.getInstance()
.getTextureID("legbottom"));
box.addTriangle(lowerRightBack, 1, 0, lowerRightFront, 1, 1,
lowerLeftFront, 0, 1, TextureManager.getInstance()
.getTextureID("legbottom"));
// Right
box.addTriangle(upperLeftFront, 0, 0, upperLeftBack, 1, 0,
lowerLeftFront, 0, 1, TextureManager.getInstance()
.getTextureID("legright"));
box.addTriangle(upperLeftBack, 1, 0, lowerLeftBack, 1, 1,
lowerLeftFront, 0, 1, TextureManager.getInstance()
.getTextureID("legright"));
// Left
box.addTriangle(upperRightFront, 0, 0, lowerRightFront, 0, 1,
upperRightBack, 1, 0, TextureManager.getInstance()
.getTextureID("legleft"));
box.addTriangle(upperRightBack, 1, 0, lowerRightFront, 0, 1,
lowerRightBack, 1, 1, TextureManager.getInstance()
.getTextureID("legleft"));

this.setTransparency(300);

box.setName("rightleg");


box.build();
}
}
Title: Re: Object3D's transparency issue
Post by: EgonOlsen on December 08, 2014, 05:23:59 pm
An example in form of a zipped project would help. I can't be bithered to create one out of individual sources.
Title: Re: Object3D's transparency issue
Post by: Lobby on December 08, 2014, 05:38:28 pm
As already suggested, a fragment shader using alpha testing would be the best solution. Except if you want semi transparent textures...

Here a little sample how this works: https://dl.dropboxusercontent.com/u/1618711/web/software/AlphaTest.zip
Title: Re: Object3D's transparency issue
Post by: AeroShark333 on December 09, 2014, 05:45:14 pm
Thanks for the replies!

I kind of solved my problem already.
I added
Code: [Select]
box.setSortOffset(9); to both RightLeg.java and LeftLeg.java (which seemed to work)
I think this fix was a bit logical (now that I think about it... :|)

Thanks a lot for the support! (I have no idea what alpha testing is, so I guess it is better I don't have to use that difficult stuff xD)

My final question: Is my app project-worthy? (for this page: http://www.jpct.net/projects.html)
Title: Re: Object3D's transparency issue
Post by: AeroShark333 on December 29, 2014, 04:15:39 pm
The issue in post #2 does not happen on all devices for some reason...
But it does on a few...
Is there an easier solution?
Title: Re: Object3D's transparency issue
Post by: EgonOlsen on December 29, 2014, 05:24:26 pm
Can you provide a more detailed screen shot? If it's a transparency issue, it has to appear on all devices. There's no way that the device has any influence on it...unless it's another issue, but i can't tell it from the shots.
Title: Re: Object3D's transparency issue
Post by: AeroShark333 on December 31, 2014, 01:25:45 pm
On tablet the issue is visible, on phones it isn't (I suppose the width of the screen does have an effect on the bug's visibility)

Anyway, here is a screenshot: https://dl.dropboxusercontent.com/u/47988037/Android/Skin%20Viewer%203D/Screenshot/bug.png
(Look at the right arm (biological left arm))
Title: Re: Object3D's transparency issue
Post by: EgonOlsen on January 01, 2015, 08:06:28 pm
Looks just like the usual sorting issues that we already described. I don't see any way in which these can depend on the device. On randoness maybe, but not on the device. Given that textures, why are you using transparency anyway? I don't see any transparent parts on them... ???
Title: Re: Object3D's transparency issue
Post by: AeroShark333 on January 01, 2015, 08:59:37 pm
It is possible to use transparent skins in Minecraft.
A skin is a 64x32 png file.
Since every bodypart can have transparent elements, I decided to enable transparency for every part.
Is 'alpha testing' easy to do?
Or are there other solutions?

I tried to make the parts not touch each other using about 0.03f space between the parts. But it did not help at all...
Is it possible to have more drawing/sorting precision? Using the Config perhaps?

What will happen in I enlarge the parts a lot and zoom out the camera? The same?
Title: Re: Object3D's transparency issue
Post by: Lobby on January 01, 2015, 09:09:46 pm
As a matter of fact, alpha testing is an easy thing if you already have the shader. If you have the shader code, then you have just to load the shader and apply it to all objects that should use alpha testing. Do you have question about my little sample?
Title: Re: Object3D's transparency issue
Post by: AeroShark333 on January 02, 2015, 11:44:10 pm
Your shader does solve the problem for the horizontal orbiting camera (around the model). But not really for free (incl. vertical) orbiting around the model.
Title: Re: Object3D's transparency issue
Post by: Lobby on January 03, 2015, 11:38:57 am
Maybe you should make sure that you call setTransparency(-1) on your objects so they will use the Z-buffer correctly.
Title: Re: Object3D's transparency issue
Post by: AeroShark333 on January 03, 2015, 01:15:10 pm
It seems to have worked completely! :D
Thanks a lot!

Question: will it work if I add a third 'box' around the 2 existing boxes?
Title: Re: Object3D's transparency issue
Post by: Lobby on January 03, 2015, 01:54:34 pm
Indeed it will ;) . Alpha testing is also used in minecraft btw.
Title: Re: Object3D's transparency issue
Post by: AeroShark333 on January 05, 2015, 03:17:21 pm
A new issue appeared since the use of the shader. (and using setTransparency(-1))

Image:
https://dl.dropboxusercontent.com/u/47988037/Android/Skin%20Viewer%203D/v3%2C1/Bug/Screenshot_2015-01-05-17-34-37.jpg

A user sent me this screenshot.
Basically everything is black... (the user said it was not black before the shader update)
This does not happen on my devices though
Title: Re: Object3D's transparency issue
Post by: Lobby on January 05, 2015, 03:35:24 pm
I can't open the image :( .
Title: Re: Object3D's transparency issue
Post by: EgonOlsen on January 05, 2015, 05:14:45 pm
If everything is black, it's usually either some value out of range (i.e. larger than 65536) or a problem with the shader code that occurs only with some gpus/shader compilers. These problems are usually logged at runtime. It would be helpful to have the log and a more detailed device info available.
Title: Re: Object3D's transparency issue
Post by: AeroShark333 on January 05, 2015, 08:47:07 pm
Sorry for the dead link:
https://dl.dropboxusercontent.com/u/47988037/Android/Skin%20Viewer%203D/v3.1/Bug/Screenshot_2015-01-05-17-34-37.jpg

The borders of the model (of alpha channel) do seem to show up. (see head)
Only the textures become black
Title: Re: Object3D's transparency issue
Post by: EgonOlsen on January 06, 2015, 07:59:42 am
That doesn't really help without the details mentioned above. It's most likely a flaw in the shader's code that one shader compiler ignores but the other doesn't.
Title: Re: Object3D's transparency issue
Post by: AeroShark333 on January 06, 2015, 04:30:18 pm
I got some more information from the user.
The phone is:
Asus Zenfone 4 (Android 4.2.2)

I sent the bugreport (txt-file) to you in PM EgonOlsen and Lobby)

Note: not sure if the opengl texture size warning can be ignored... but the same sizes were used before I added the shader. (and it worked for the user before)
Title: Re: Object3D's transparency issue
Post by: EgonOlsen on January 06, 2015, 05:24:14 pm
I can't spot anything obviously wrong in that log except for the texture size issue. Before adding the shader, were you actually using OpenGL ES 2.0 already? Because if not, this might be the problem.
Title: Re: Object3D's transparency issue
Post by: EgonOlsen on January 06, 2015, 05:28:06 pm
My final question: Is my app project-worthy? (for this page: http://www.jpct.net/projects.html)
I somehow overlooked this question...of course it is. I'll add it later...
Title: Re: Object3D's transparency issue
Post by: AeroShark333 on January 06, 2015, 06:15:15 pm
My final question: Is my app project-worthy? (for this page: http://www.jpct.net/projects.html)
I somehow overlooked this question...of course it is. I'll add it later...
Thanks :)

About your previous post, this is my current code:
Code: [Select]
gLView.setEGLContextClientVersion(2);
viewerRenderer = new ViewerRenderer();
gLView.setRenderer(viewerRenderer);

The shader is loaded in the constructor of ViewerRenderer
The objects are created in the constructor as well (after the shader loading code)

The objects are added to the world in
Code: [Select]
public void onSurfaceChanged(GL10 gl, int width, int height) {I did not pass the GL10 to the framebuffer.

The OpenGLversion is set to 2 before calling the constructor.

The application works fine on most devices... This is the only device I got a report from... And that is since the usage of the shader.

Title: Re: Object3D's transparency issue
Post by: EgonOlsen on January 06, 2015, 06:19:20 pm
That wasn't my actual question. The question was: The version that didn't use the custom shader..was it ES 2.0 already?
Title: Re: Object3D's transparency issue
Post by: AeroShark333 on January 06, 2015, 06:23:17 pm
It was using OpenGL 2 yes
I am 100% sure I am using OpenGL2 since the beginning.

Sorry for the misinterpretation by the way
Title: Re: Object3D's transparency issue
Post by: EgonOlsen on January 06, 2015, 08:04:35 pm
Try this fragment shader instead:

Code: [Select]
precision mediump float;

uniform sampler2D textureUnit0;
uniform sampler2D textureUnit1;
uniform sampler2D textureUnit2;
uniform sampler2D textureUnit3;

uniform int textureCount;
uniform int blendingMode[4];

varying vec2 texCoord[4];
varying vec4 vertexColor;
varying float fogWeight;
varying vec3 fogVertexColor;

const vec4 WHITE = vec4(1,1,1,1);

void main() {
vec4 col = texture2D(textureUnit0, texCoord[0]) * vertexColor;
if (col.a < 0.5) {
discard;
} else {
if (textureCount>1) {

// Can't index texture samplers and switch doesn't seem to compile(?)...end result:

int mode=blendingMode[1];
vec2 texCo=texCoord[1];

if (mode==0) {
// Modulate
col *= texture2D(textureUnit1, texCo);
} else if (mode==1) {
// Add
col += texture2D(textureUnit1, texCo);
} else if (mode==3) {
// Blend
col *= (WHITE - texture2D(textureUnit1, texCo));
} else if (mode==2) {
// Replace
col = texture2D(textureUnit1, texCo);
} else if (mode==4) {
// Decal
vec4 col2=texture2D(textureUnit1, texCo);
col = vec4(mix(col.rgb, col2.rgb, col2.a), col2.a);
}

if (textureCount>2) {

mode=blendingMode[2];
texCo=texCoord[2];

if (mode==0) {
// Modulate
col *= texture2D(textureUnit2, texCo);
} else if (mode==1) {
// Add
col += texture2D(textureUnit2, texCo);
} else if (mode==3) {
// Blend
col *= (WHITE - texture2D(textureUnit2, texCo));
} else if (mode==2) {
// Replace
col = texture2D(textureUnit2, texCo);
} else if (mode==4) {
// Decal
vec4 col2=texture2D(textureUnit2, texCo);
col = vec4(mix(col.rgb, col2.rgb, col2.a), col2.a);
}

if (textureCount>3) {

mode=blendingMode[3];
texCo=texCoord[3];

if (mode==0) {
// Modulate
col *= texture2D(textureUnit3, texCo);
} else if (mode==1) {
// Add
col += texture2D(textureUnit3, texCo);
} else if (mode==3) {
// Blend
col *= (WHITE - texture2D(textureUnit3, texCo));
} else if (mode==2) {
// Replace
col = texture2D(textureUnit3, texCo);
} else if (mode==4) {
// Decal
vec4 col2=texture2D(textureUnit3, texCo);
col = vec4(mix(col.rgb, col2.rgb, col2.a), col2.a);
}
}
}
}

if (fogWeight>-0.9) {
col.xyz = (1.0-fogWeight) * col.xyz + fogVertexColor;
}
}

gl_FragColor=col;
}

There are known issues with the discard; on PowerVR GPUs. So i put the actual calculations in an additional else branch. Maybe that helps. If not, then it's getting harder. You actually need access to such a device to debug it properly. Shaders can be real pain, because even correct code can be "optimized" to complete rubbish by some shader compilers. That's why jPCT-AE's default shaders contain such strange hacks at times.
Title: Re: Object3D's transparency issue
Post by: EgonOlsen on January 06, 2015, 08:41:44 pm
I've added it to the projects page.
Title: Re: Object3D's transparency issue
Post by: AeroShark333 on January 07, 2015, 03:05:51 am
Thanks for adding it to the projectlist!

Some bad news from the user, the new fragment shader does not work... :(
Title: Re: Object3D's transparency issue
Post by: EgonOlsen on January 07, 2015, 06:39:35 am
I'm almost out of ideas then. This is the exact same shader code that jPCT's default shader uses except for the additional discard. The only option left (without access to a device) is to make all textures square and hope for the best...
Title: Re: Object3D's transparency issue
Post by: AeroShark333 on January 08, 2015, 11:30:48 am
No luck with the textures square as well :(
Are there any other options?
Perhaps similar/alternative code that does the same as
Code: [Select]
discard;? (I don't think 'return;' would solve it.
Title: Re: Object3D's transparency issue
Post by: EgonOlsen on January 08, 2015, 12:22:05 pm
It might be worth a try. Everything is.

You might as well try to move the discard/return down like here:

Code: [Select]
precision mediump float;

uniform sampler2D textureUnit0;
uniform sampler2D textureUnit1;
uniform sampler2D textureUnit2;
uniform sampler2D textureUnit3;

uniform int textureCount;
uniform int blendingMode[4];

varying vec2 texCoord[4];
varying vec4 vertexColor;
varying float fogWeight;
varying vec3 fogVertexColor;

const vec4 WHITE = vec4(1,1,1,1);

void main() {
vec4 col = texture2D(textureUnit0, texCoord[0]) * vertexColor;

if (textureCount>1) {

// Can't index texture samplers and switch doesn't seem to compile(?)...end result:

int mode=blendingMode[1];
vec2 texCo=texCoord[1];

if (mode==0) {
// Modulate
col *= texture2D(textureUnit1, texCo);
} else if (mode==1) {
// Add
col += texture2D(textureUnit1, texCo);
} else if (mode==3) {
// Blend
col *= (WHITE - texture2D(textureUnit1, texCo));
} else if (mode==2) {
// Replace
col = texture2D(textureUnit1, texCo);
} else if (mode==4) {
// Decal
vec4 col2=texture2D(textureUnit1, texCo);
col = vec4(mix(col.rgb, col2.rgb, col2.a), col2.a);
}

if (textureCount>2) {

mode=blendingMode[2];
texCo=texCoord[2];

if (mode==0) {
// Modulate
col *= texture2D(textureUnit2, texCo);
} else if (mode==1) {
// Add
col += texture2D(textureUnit2, texCo);
} else if (mode==3) {
// Blend
col *= (WHITE - texture2D(textureUnit2, texCo));
} else if (mode==2) {
// Replace
col = texture2D(textureUnit2, texCo);
} else if (mode==4) {
// Decal
vec4 col2=texture2D(textureUnit2, texCo);
col = vec4(mix(col.rgb, col2.rgb, col2.a), col2.a);
}

if (textureCount>3) {

mode=blendingMode[3];
texCo=texCoord[3];

if (mode==0) {
// Modulate
col *= texture2D(textureUnit3, texCo);
} else if (mode==1) {
// Add
col += texture2D(textureUnit3, texCo);
} else if (mode==3) {
// Blend
col *= (WHITE - texture2D(textureUnit3, texCo));
} else if (mode==2) {
// Replace
col = texture2D(textureUnit3, texCo);
} else if (mode==4) {
// Decal
vec4 col2=texture2D(textureUnit3, texCo);
col = vec4(mix(col.rgb, col2.rgb, col2.a), col2.a);
}
}
}
}

if (fogWeight>-0.9) {
col.xyz = (1.0-fogWeight) * col.xyz + fogVertexColor;
}


if (col.a < 0.5) {
discard;
}
gl_FragColor=col;
//if (col.a < 0.5) {
// discard;
//}
}

...either before or after the gl_FragColor...

It might also be worth a try to replace the "precision mediump float;" by "precision highp float;" in the first line. All of this doesn't actually make sense...but anyway. Abother idea is to remove the discard completely. Maybe we a re looking at the problem from the wrong side. Maybe the shader itself is the problem and not the discard...
Title: Re: Object3D's transparency issue
Post by: AeroShark333 on January 09, 2015, 12:05:22 pm
Okay I tried a few things.
1. discard before gl_FragColor
2. discard after gl_FragColor
3. Option 1 + highp
4. Option 2 + highp
5. The shader code by Lobby without discard

Apparently none worked, so the problem is not the discard (I think)
Title: Re: Object3D's transparency issue
Post by: EgonOlsen on January 09, 2015, 05:46:40 pm
...either that, or your updated versions won't get executed on the actual device. Can you somehow confirm that your changes really make it onto the device? If you remove the discard, the resulting shader is the normal default shader that jPCT-AE uses and i'm not aware of any problems with that. Also, please make sure that you are calling build() on all of your Object3Ds.

However, there are other, simpler default shaders. We could try to modify one of them. But for choosing one, i have to know which features you are actually using. So...

Title: Re: Object3D's transparency issue
Post by: AeroShark333 on January 09, 2015, 10:00:30 pm
...either that, or your updated versions won't get executed on the actual device. Can you somehow confirm that your changes really make it onto the device? If you remove the discard, the resulting shader is the normal default shader that jPCT-AE uses and i'm not aware of any problems with that. Also, please make sure that you are calling build() on all of your Object3Ds.

However, there are other, simpler default shaders. We could try to modify one of them. But for choosing one, i have to know which features you are actually using. So...

  • Are you using light sources or just ambient lighting?
  • If you are using lights, how many?
  • Are you using fog?

Code: [Select]
package com.aeroshark333.skinviewer.skinparts;

import com.threed.jpct.GLSLShader;
import com.threed.jpct.Object3D;
import com.threed.jpct.SimpleVector;
import com.threed.jpct.TextureManager;

public class Body extends Object3D {

private static final long serialVersionUID = 8216608860877707087L;

public Body(final GLSLShader shader) {

super(12);

final Object3D box = this;

SimpleVector upperLeftFront = new SimpleVector(-1, -1.5f, -0.5f);
SimpleVector upperRightFront = new SimpleVector(1, -1.5f, -0.5f);
SimpleVector lowerLeftFront = new SimpleVector(-1, 1.5f, -0.5f);
SimpleVector lowerRightFront = new SimpleVector(1, 1.5f, -0.5f);

SimpleVector upperLeftBack = new SimpleVector(-1, -1.5f, 0.5f);
SimpleVector upperRightBack = new SimpleVector(1, -1.5f, 0.5f);
SimpleVector lowerLeftBack = new SimpleVector(-1, 1.5f, 0.5f);
SimpleVector lowerRightBack = new SimpleVector(1, 1.5f, 0.5f);

// Front
box.addTriangle(upperLeftFront, 0, 0, lowerLeftFront, 0, 1,
upperRightFront, 1, 0, TextureManager.getInstance()
.getTextureID("bodyfront"));
box.addTriangle(upperRightFront, 1, 0, lowerLeftFront, 0, 1,
lowerRightFront, 1, 1, TextureManager.getInstance()
.getTextureID("bodyfront"));
// Back
box.addTriangle(upperLeftBack, 0, 0, upperRightBack, 1, 0,
lowerLeftBack, 0, 1,
TextureManager.getInstance().getTextureID("bodyback"));
box.addTriangle(upperRightBack, 1, 0, lowerRightBack, 1, 1,
lowerLeftBack, 0, 1,
TextureManager.getInstance().getTextureID("bodyback"));
// Top
box.addTriangle(upperLeftBack, 0, 0, upperLeftFront, 0, 1,
upperRightBack, 1, 0, TextureManager.getInstance()
.getTextureID("bodytop"));
box.addTriangle(upperRightBack, 1, 0, upperLeftFront, 0, 1,
upperRightFront, 1, 1, TextureManager.getInstance()
.getTextureID("bodytop"));
// Bottom
box.addTriangle(lowerLeftBack, 0, 0, lowerRightBack, 1, 0,
lowerLeftFront, 0, 1, TextureManager.getInstance()
.getTextureID("bodybottom"));
box.addTriangle(lowerRightBack, 1, 0, lowerRightFront, 1, 1,
lowerLeftFront, 0, 1, TextureManager.getInstance()
.getTextureID("bodybottom"));
// Right
box.addTriangle(upperLeftFront, 0, 0, upperLeftBack, 1, 0,
lowerLeftFront, 0, 1, TextureManager.getInstance()
.getTextureID("bodyright"));
box.addTriangle(upperLeftBack, 1, 0, lowerLeftBack, 1, 1,
lowerLeftFront, 0, 1, TextureManager.getInstance()
.getTextureID("bodyright"));
// Left
box.addTriangle(upperRightFront, 0, 0, lowerRightFront, 0, 1,
upperRightBack, 1, 0, TextureManager.getInstance()
.getTextureID("bodyleft"));
box.addTriangle(upperRightBack, 1, 0, lowerRightFront, 0, 1,
lowerRightBack, 1, 1, TextureManager.getInstance()
.getTextureID("bodyleft"));

box.setName("body");
this.setTransparency(-1);
this.setCollisionMode(Object3D.COLLISION_CHECK_OTHERS);
this.setShader(shader);
this.compile();
this.strip();
box.build();
}
}
This code is okay right?


Code: [Select]
this.mainWorld.setAmbientLight(255, 255, 255);

Well... I gave him an .apk file with the custom shader not set to the right leg.
That DID show him the right leg properly.
Title: Re: Object3D's transparency issue
Post by: EgonOlsen on January 09, 2015, 10:12:40 pm
Yes, that code looks fine. It confuses me a little that "this" and box are actually the same instance, but anyway.

If you are using ambient only, no fog and only one texture layer (...are you?), try these shaders instead:

Vertex:
Code: [Select]
uniform mat4 modelViewProjectionMatrix;

uniform vec4 additionalColor;
uniform vec4 ambientColor;

uniform float alpha;
uniform bool useColors;

attribute vec4 position;
attribute vec3 normal;
attribute vec4 color;
attribute vec2 texture0;

varying vec2 texCoord;
varying vec4 vertexColor;

const vec4 WHITE = vec4(1,1,1,1);

void main() {
texCoord = texture0;
vec4 pos = position;
vec3 normalDummy = normal;

vertexColor=vec4(min(WHITE, ambientColor + additionalColor).xyz, alpha);

if (useColors) {
vertexColor *= color;
}

gl_Position = modelViewProjectionMatrix * pos;
}


Fragment:
Code: [Select]
precision highp float;

uniform sampler2D textureUnit0;

varying vec2 texCoord;
varying vec4 vertexColor;

void main() {
gl_FragColor= texture2D(textureUnit0, texCoord) * vertexColor;
        if (gl_FragColor.a<0.5) {
           discard;
        }
}
Title: Re: Object3D's transparency issue
Post by: AeroShark333 on January 10, 2015, 02:09:31 pm
You sir, are an hero!
The shader worked for him (as well for me)
Thanks so much :D

Yeah... I should have kept using either box# or this# and not both... It does not really look neat at the moment.

And correct, I am only using ambient lighting, no fog and one texturelayer per object.

Thanks for your time, input and fast responses :)
I hope not to have wasted your time... If so, I am sorry.
Title: Re: Object3D's transparency issue
Post by: EgonOlsen on January 10, 2015, 04:59:11 pm
No, it wasn't a waste of time. It's an indication that the fully blown default shader doesn't work on all devices if not all the features that it offers are used. And while that's not a real problem because it doesn't happen in real life, it's not supposed to happen. That shader is supposed to work fine even if not all of it's features are being used. I'll have a look at the engine's code to see if i can spot the problem.
Title: Re: Object3D's transparency issue
Post by: EgonOlsen on January 10, 2015, 07:54:39 pm
Can't find anything that's fishy with the shader or the way in which it's being initialized. I tried to reproduce the problem on my only PowerVR based device, but i can't. Everything works just fine. Until i know any better, i consider this problem to be a bug in the shader compiler on that particular device. It wouldn't be the first one of that kind that darkens everything. Case closed  for now...
Title: Re: Object3D's transparency issue
Post by: AeroShark333 on April 24, 2015, 10:41:34 am
Hmm, okay! Thanks for the help. (it happened on just one device, I guess the user is unlucky then...)

A new stacktrace:
Code: [Select]
java.lang.NullPointerException: Attempt to invoke virtual method 'int com.threed.jpct.Texture.getOpenGLID(int)' on a null object reference
at com.threed.jpct.GLRenderer.setTextures(GLRenderer.java:2441)
at com.threed.jpct.GLRenderer.drawVertexArray(GLRenderer.java:2297)
at com.threed.jpct.World.draw(World.java:1417)
at com.threed.jpct.World.draw(World.java:1100)
at com.aeroshark333.skinviewer.SkinActivity$ViewerRenderer.onDrawFrame(SkinActivity.java:1659)
at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1531)
at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1248)

line #1659
Code: [Select]
mainWorld.draw(frameBuffer);
Amount of reports: 1
Android: 5.0
Device: Samsung Galaxy S5

As far as I know... I am not messing with Object textures...
Title: Re: Object3D's transparency issue
Post by: EgonOlsen on April 24, 2015, 11:15:00 am
That can happen only if the object to be rendered references a texture that doesn't exist (anymore). That not possible IMHO unless one calls flush() on the TextureManager in some other than the rendering thread. I could catch that exception, but that won't help much because something is in an undefined state here anyway.
Title: Re: Object3D's transparency issue
Post by: AeroShark333 on April 25, 2015, 03:41:07 pm
So...
This is the problem causer? (the only time I use .flush();):
Code: [Select]
@Override
public void onPause() {
hasRendererLoaded = false;
gLView.onPause();
super.onPause();
TextureManager.getInstance().flush();
this.finish();
}

But even then...:
Code: [Select]
@Override
public void onDrawFrame(GL10 gl) {
if (!hasRendererLoaded) {
return;

                // irrelevant code

                       }

}

Textures won't really be used if it 'return;'s.

Also... I have a new stacktrace from an user:
Code: [Select]
java.lang.RuntimeException: [ 1429958366470 ] - ERROR: Failed to load and compile fragment shaders!
at com.threed.jpct.Logger.log(Logger.java:206)
at com.threed.jpct.GLSLShader.loadProgram(GLSLShader.java:1077)
at com.threed.jpct.GLSLShader.preInit(GLSLShader.java:285)
at com.threed.jpct.GL20.setShader(GL20.java:362)
at com.threed.jpct.GLRenderer.setShader(GLRenderer.java:553)
at com.threed.jpct.CompiledInstance.render(CompiledInstance.java:189)
at com.threed.jpct.GLRenderer.drawVertexArray(GLRenderer.java:2308)
at com.threed.jpct.World.draw(World.java:1417)
at com.threed.jpct.World.draw(World.java:1100)
at com.aeroshark333.skinviewer.SkinActivity$ViewerRenderer.onDrawFrame(SkinActivity.java:1659)
at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1363)
at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1118)

Line #1659
Code: [Select]
mainWorld.draw(frameBuffer);
Device information:
LG-P920 (cosmo_TMO-XXX)
Android 2.3.3 - 2.3.7
Title: Re: Object3D's transparency issue
Post by: EgonOlsen on April 25, 2015, 11:55:49 pm
That flush is most likely the problem. Your flag doesn't ensure anything if both methods are called in different threads. If you want to avoid this, use proper synchronization instead....or simply don't flush the textures. Why are you doing this in onPause anyway?
Title: Re: Object3D's transparency issue
Post by: AeroShark333 on April 26, 2015, 01:10:57 pm
Hmm, you're right... I don't really have a reason for the flushing in onPause... So I guess I'll remove that line.

And what about the stacktrace?
Title: Re: Object3D's transparency issue
Post by: EgonOlsen on April 27, 2015, 05:02:11 pm
Nothing new about the Stacktraces of that kind. I highly doubt that it's a real issue with the shader itself. It might be a driver problem (also unlikely at that stage) or maybe some problem with an unintialized GL context because of the app shutting down or whatever...
Title: Re: Object3D's transparency issue
Post by: AeroShark333 on May 03, 2015, 06:43:20 pm
I have a small issue and I do not know why I have this problem.
The head on Android 2.2 does look filtered, while it is not filtered on Android 4.3.
(Android 2.2 uses OpenGL 1.0 (SDK emulator) and Android 4.3 uses OpenGL 2.0 (Genymotion emulator))
The weird thing is: the rest of the body is not filtered on Android 2.2 (or looks not filtered), which is why I think this issue does not make sense.
And when I apply a body texture to the head object (in code), then it is not filtered.
So I cannot blame the object for filtering the textures.
I do not know why the head textures are filtered on Android 2.2 but not on Android 4.3.
Title: Re: Object3D's transparency issue
Post by: AeroShark333 on May 03, 2015, 06:44:18 pm
An Android 4.3 reference image (see previous post)
Title: Re: Object3D's transparency issue
Post by: EgonOlsen on May 03, 2015, 10:24:49 pm
As long as this is the result of the emulator only, i wouldn't give it a second thought. The emulator still does strange things when it comes to OpenGL.
Title: Re: Object3D's transparency issue
Post by: AeroShark333 on May 30, 2015, 01:42:40 pm
Hmm, I have been getting a nullpointerexception and I have no idea how to fix it.
Basically I am trying to alter the meshdata while running the application.
Code:
Code: [Select]
Mesh mesh = rA.getMesh();
mesh.setVertexController(new GenericVertexController(){

private static final long serialVersionUID = 1311476511641434156L;

@Override
public void apply() {
SimpleVector[] s = getSourceMesh();
//System.out.println("length:"+ s.length);
SimpleVector[] d = getDestinationMesh();
for (int i = 0; i < 26;i++){
d[i].z =  s[i].z - (lastX - firstX)*0.001f * (i/2) * (i/2);
d[i+26].z =  s[i+26].z -(lastX - firstX)* 0.001f * (i/2) * (i/2);
d[i].x = s[i].x;
d[i].y = s[i].y;
}
}

}, true);
mesh.applyVertexController();
mesh.removeVertexController();

Stacktrace:
Code: [Select]
05-30 13:36:21.741: W/dalvikvm(5893): threadid=17: thread exiting with uncaught exception (group=0xa61f2908)
05-30 13:36:21.745: E/AndroidRuntime(5893): FATAL EXCEPTION: GLThread 392
05-30 13:36:21.745: E/AndroidRuntime(5893): java.lang.NullPointerException
05-30 13:36:21.745: E/AndroidRuntime(5893): at com.threed.jpct.GenericVertexController.init(GenericVertexController.java:88)
05-30 13:36:21.745: E/AndroidRuntime(5893): at com.threed.jpct.Mesh.setVertexController(Mesh.java:164)
05-30 13:36:21.745: E/AndroidRuntime(5893): at com.aeroshark333.skinviewer.SkinActivity$18.run(SkinActivity.java:1251)
05-30 13:36:21.745: E/AndroidRuntime(5893): at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1462)
05-30 13:36:21.745: E/AndroidRuntime(5893): at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1240)

The code is run in a queued GL-thread.
Title: Re: Object3D's transparency issue
Post by: EgonOlsen on May 30, 2015, 04:15:16 pm
Where is this code located? In the render thread or in some listener method?
Title: Re: Object3D's transparency issue
Post by: AeroShark333 on May 30, 2015, 04:21:08 pm
I tried both: both lead to the same stacktrace/crash.
The only place it does work is when it is initializing the renderer. (before adding it to the world)

EDIT: If I remove Object3D.strip() then it won't crash, however the new meshdata is not completely applied.
It is applied (since I can see another Object3D, which is tied to a the Object3D's mesh's SimpleVector, does move)
But the new shape/texturedeforming is not visible. Only the initialized meshdata form is applied, not the changes that I want to apply in the renderer/listener.
Title: Re: Object3D's transparency issue
Post by: EgonOlsen on May 30, 2015, 05:05:47 pm
I see...that's because objects get compiled and uploaded to the GPU at build time. If you want to modify the geometry afterwards, the object has to be compiled in dynamic mode. You can do this by either make an explicit call to compile(true) after calling build() or let the engine to this automagically...for which you have to assign the vertex controller before calling build. Then apply your controller, then call touch() on the object.
In any way, this will trigger a re-upload of the mesh to the GPU. If you are doing this constantly, it might cause a performance penalty.
Title: Re: Object3D's transparency issue
Post by: AeroShark333 on May 30, 2015, 09:57:57 pm
Thanks for the help! It works like a charm and it doesn't lag at all really :)