Recent Posts

Pages: 1 2 [3] 4 5 ... 10
Support / Re: Different light shading with compiled objects
« Last post by Jamiro on July 24, 2018, 10:18:30 pm »
ok, thanks a lot
Support / Re: Different light shading with compiled objects
« Last post by EgonOlsen on July 24, 2018, 09:35:58 am »
That basic light formula is the same. I've noticed some differences between compiled and "normal" objects regarding vertex lighting as well depending on the GPU used. Especially older AMD based ones have a slightly different interpretation of how to shade the polygons which can result in dimmer lighting in some edge (no pun intended) cases. If you can't compensate for that with a brighter light or by changing some other values like the attenuation, you are basically out of luck and might have to switch to shaders.
Support / Re: Camera rotation issue
« Last post by AeroShark333 on July 23, 2018, 06:07:52 pm »
I think this would solve the problem, thanks! :)
I'll report back later if I can test it
Support / Object3D generating issue
« Last post by AeroShark333 on July 23, 2018, 06:05:48 pm »

I've been trying to create some code to generate a geosphere/icosphere, I got somewhere but the results aren't exactly perfect.
Issue 1: UV mapping still does not seem perfect (especially around the top and bottom, where texCoord.y is around 0.0 or 1.0) but around the middle (0.5) all seems fine
Issue 2: I seem to get black polygons on some devices (but I don't get these black polygons on an emulator..?)

The code till now (it's not really optimized yet since I ported most of the code from some C# code:
Code: [Select]
private class TriangleIndices {
public int v1;
public int v2;
public int v3;

public TriangleIndices(int v1, int v2, int v3) {
this.v1 = v1;
this.v2 = v2;
this.v3 = v3;

private ArrayList<SimpleVector> vertexData;
private ArrayList<Integer> vertexDataIndices;
private int index;
private Map<Long, Integer> middlePointIndexCache;

// add vertex to mesh, fix position to be on unit sphere, return index
private int addVertex(SimpleVector p) {
// 0.5 is a scale factor here...
double length = Math.sqrt(p.x * p.x + p.y * p.y + p.z * p.z) / 0.5;
vertexData.add(new SimpleVector(p.x / length, p.y / length, p.z
/ length));
return index++;

// return index of point in the middle of p1 and p2
private int getMiddlePoint(int p1, int p2) {
// first check if we have it already
boolean firstIsSmaller = p1 < p2;
long smallerIndex = firstIsSmaller ? p1 : p2;
long greaterIndex = firstIsSmaller ? p2 : p1;
long key = (smallerIndex << 32) + greaterIndex;

if (middlePointIndexCache.containsKey(key)) {
int ret = this.middlePointIndexCache.get(key);
return ret;

// not in cache, calculate it
SimpleVector point1 = this.vertexData.get(p1);
SimpleVector point2 = this.vertexData.get(p2);
SimpleVector middle = new SimpleVector((point1.x + point2.x) / 2.0,
(point1.y + point2.y) / 2.0, (point1.z + point2.z) / 2.0);

// add vertex makes sure point is on unit sphere
int i = addVertex(middle);

// store it, return index
this.middlePointIndexCache.put(key, i);
return i;

public Object3D create(int recursionLevel) {
this.vertexData = new ArrayList<SimpleVector>();
this.vertexDataIndices = new ArrayList<Integer>();
this.middlePointIndexCache = new HashMap<Long, Integer>();
this.index = 0;

// create 12 vertices of a icosahedron
float t = (float) ((1.0f + Math.sqrt(5.0f)) / 2.0f);

addVertex(new SimpleVector(-1, t, 0));
addVertex(new SimpleVector(1, t, 0));
addVertex(new SimpleVector(-1, -t, 0));
addVertex(new SimpleVector(1, -t, 0));

addVertex(new SimpleVector(0, -1, t));
addVertex(new SimpleVector(0, 1, t));
addVertex(new SimpleVector(0, -1, -t));
addVertex(new SimpleVector(0, 1, -t));

addVertex(new SimpleVector(t, 0, -1));
addVertex(new SimpleVector(t, 0, 1));
addVertex(new SimpleVector(-t, 0, -1));
addVertex(new SimpleVector(-t, 0, 1));

// create 20 triangles of the icosahedron
List<TriangleIndices> faces = new ArrayList<TriangleIndices>();

// 5 faces around point 0
faces.add(new TriangleIndices(0, 11, 5));
faces.add(new TriangleIndices(0, 5, 1));
faces.add(new TriangleIndices(0, 1, 7));
faces.add(new TriangleIndices(0, 7, 10));
faces.add(new TriangleIndices(0, 10, 11));

// 5 adjacent faces
faces.add(new TriangleIndices(1, 5, 9));
faces.add(new TriangleIndices(5, 11, 4));
faces.add(new TriangleIndices(11, 10, 2));
faces.add(new TriangleIndices(10, 7, 6));
faces.add(new TriangleIndices(7, 1, 8));

// 5 faces around point 3
faces.add(new TriangleIndices(3, 9, 4));
faces.add(new TriangleIndices(3, 4, 2));
faces.add(new TriangleIndices(3, 2, 6));
faces.add(new TriangleIndices(3, 6, 8));
faces.add(new TriangleIndices(3, 8, 9));

// 5 adjacent faces
faces.add(new TriangleIndices(4, 9, 5));
faces.add(new TriangleIndices(2, 4, 11));
faces.add(new TriangleIndices(6, 2, 10));
faces.add(new TriangleIndices(8, 6, 7));
faces.add(new TriangleIndices(9, 8, 1));

// refine triangles
for (int i = 0; i < recursionLevel; i++) {
List<TriangleIndices> faces2 = new ArrayList<TriangleIndices>();
for (TriangleIndices tri : faces) {
// replace triangle by 4 triangles
int a = getMiddlePoint(tri.v1, tri.v2);
int b = getMiddlePoint(tri.v2, tri.v3);
int c = getMiddlePoint(tri.v3, tri.v1);

faces2.add(new TriangleIndices(tri.v1, a, c));
faces2.add(new TriangleIndices(tri.v2, b, a));
faces2.add(new TriangleIndices(tri.v3, c, b));
faces2.add(new TriangleIndices(a, b, c));
faces = faces2;

// done, now add triangles to mesh
for (TriangleIndices tri : faces) {

Object3D obj = new Object3D(vertexDataIndices.size() / 3);

for (int c = 0; c < (vertexDataIndices.size() / 3); c++) {

final SimpleVector aa = vertexData
.get(vertexDataIndices.get(c * 3));
final SimpleVector aaP = cartesianToPolar(aa, true);
final SimpleVector bb = vertexData.get(vertexDataIndices
.get(c * 3 + 1));
final SimpleVector bbP = cartesianToPolar(bb, true);
final SimpleVector cc = vertexData.get(vertexDataIndices
.get(c * 3 + 2));
final SimpleVector ccP = cartesianToPolar(cc, true);

// texture corrections...
if (Math.abs(aaP.z - bbP.z) > 0.5f) {
if (Math.abs(aaP.z - ccP.z) > 0.5f) {
if (Math.abs(bbP.z - ccP.z) > 0.5f) {

obj.addTriangle(aa, aaP.z, aaP.y, bb, bbP.z, bbP.y, cc, ccP.z,

return obj;

public static SimpleVector cartesianToPolar(SimpleVector cartesian,
boolean normalize) {
if (normalize) {
return new SimpleVector(
1.0 - (Math.acos(cartesian.y / cartesian.length()) / Math.PI),
1.0 - (Math.atan2(cartesian.x, cartesian.z) + Math.PI / 2.0)
/ (Math.PI * 2.0) );
return new SimpleVector(cartesian.length(), Math.acos(cartesian.z
/ cartesian.length()), Math.atan2(cartesian.y, cartesian.x));


Any idea what I'm doing wrong here?
Support / Re: Different light shading with compiled objects
« Last post by Jamiro on July 23, 2018, 12:51:53 pm »
Yes, I've only used 1 for Config.lightMul. Both use the same value, so the light brightness is more or less the same, but both yield out different results where the non-compiled objects seem to have a brighter color near the light and then it quickly fades away faster than when using compiled objects. It's more noticeable when using non-compiled objects than when using compiled ones. as you can see in the image above.

No I haven't tested out this setRGB option (I will give it a look afterwards) , but this really seems a difference between lighting because of those "occlusion" like shados on the edges which the compiled objects doesn't have. Notice that I only used 1 light and both scenes use "lightMul = 1"
Support / Re: Different light shading with compiled objects
« Last post by EgonOlsen on July 23, 2018, 09:18:57 am »
It's not linear vs. non-linear. Both use the same, linear approach, but this value is 10 for non-compiled objects (for historical reasons) but 1 for compiled ones (because of the way in which the fixed function pipeline works). Have you tried to increase the intensity of the light source instead? Or played around with
Support / Re: Different light shading with compiled objects
« Last post by Jamiro on July 23, 2018, 04:15:38 am »
Ok, I know now what the problem is. So apparently it seems that compiled objects use linear lighting instead of the quadratic that the non-compiled objects are using, also there's the matter with light limitation on the compiled ones, which is 8, thus having a weird looking scene when compiling all the objects.

As for the light limitation, there's no solution other than using shaders, as for the lighting attenuation method, why does it chage? is it chosen by the hardware? If so, does this mean that when using VBO objects the light will be linear?

My problem is that I want to work with VBOs of course (do want the best performacen for my program) but I do not want the linear attenuation light, therefore I will need to use shaders, the problem is, when I use them I lose the default opengl fog effect, or I need to add it as well to the shader, but creating a shader is hard as hell, so I wanted to stick to default light and fog.

Support / Re: Different light shading with compiled objects
« Last post by Jamiro on July 21, 2018, 05:53:12 pm »
heres an example:

Support / Re: Different light shading with compiled objects
« Last post by Jamiro on July 21, 2018, 04:43:19 pm »
My question is, does a compiled object have a different light calculations than a non-compiled one? Does it have anything to do with VBO? I know it has nothing to do with max number of lights because I'm only using 1.

I tried to search on the web about this, but nothing came up. Can anyone give me a hint on this? and if its true, how can I accomplish a similar look with compiled objects?

Does it have to do with attenuation formula? (linear vs non-linear)
Support / Different light shading with compiled objects
« Last post by Jamiro on July 21, 2018, 05:38:01 am »

As I'm using compiled and non-compiled objects, I came across something that seems weird. The lighting and shading on the same objects are different when they are compiled and when they are not (for Config.lightmul = 1).

So, this basically means that the same lights cast different results on the same objects depending if those objects are compiled or not, is it supposed to be like that?
Pages: 1 2 [3] 4 5 ... 10