2 Questions: Tiling and a Shader for Shadows

Started by AGP, January 28, 2015, 10:20:18 PM

Previous topic - Next topic

AGP

The following method (yours, but I was close to writing the same thing!) doesn't work at all on my ground. I think that something must have changed either in jpct or OpenGL in the years since you wrote it:


     public void tileTexture(Object3D obj, float tileFactor) {
PolygonManager pm = obj.getPolygonManager();
   
int end=pm.getMaxPolygonID();
for (int i=0; i<end; i++) {
     SimpleVector uv0=pm.getTextureUV(i,0);
     SimpleVector uv1=pm.getTextureUV(i,1);
     SimpleVector uv2=pm.getTextureUV(i,2);
     
     uv0.scalarMul(tileFactor);
     uv1.scalarMul(tileFactor);
     uv2.scalarMul(tileFactor);
     
     int id = pm.getPolygonTexture(i);
     
     TextureInfo ti=new TextureInfo(id, uv0.x, uv0.y, uv1.x, uv1.y, uv2.x, uv2.y);
     pm.setPolygonTexture(i, ti);
}
     }


And a good while ago you mentioned that you were considering a shader-based solution for shadow-casting from texture transparency (otherwise, my trees' shadows would all be rectangular). Have you started it? Has anyone else?

EgonOlsen

That code should be fine. I'm using the exact same thing and it works just fine for me. All it does it resetting the texture coordinates, it has nothing to do with the way in which OpenGL works. You have to apply it before calling compile() on the object though.

About the tree shadows...i can't remember saying something like this and no, i haven't done anything in this regard. However, i'm not sure what the problem is. Do you have a screen shot?

AGP

Right now, my ground plane isn't receiving any shadows to begin with, but if I put a Primitives-created plane over it, the shadows work:

EgonOlsen

I would think that something between the setup of the white plane and the actual ground is different then. There's no obvious reason for why it shouldn't work on that plane. If you apply the tiling to the around make sure to do that before adding it to the shadow mapper and if that doesn't change anything, try not to tile it at all.

AGP

I'm not tiling and I'm not doing anything differently from the white plane. I'm really not. I think that there's a bug somewhere in the ShadowHelper, because I really have tried everything (and since that tiling code doesn't seem to work on my ground, I'm not using it and I'd bet that the two issues are somehow related).

EgonOlsen

If the tiling doesn't work as well, that's an indication that your object is already compiled at that stage.

AGP

I just tested that both tiling and shadows work when I don't mergeObjects() (the ground is made of more than one part). Merging probably does something wrong with the mesh!

EgonOlsen

It just merges arrays. I don't see why that should affect changing the UV mapping or (which is what the ShadowHelper does) adding another texture layer. All i can still think of is that you are doing all this after calling compile(). Any chance that you have a method which does the merging that also does the compilation.

AGP

I've tried calling compileAndStrip() both before and after setting up the ShadowHelper. Neither works. The only thing that works is not calling Object3D.mergeObjects().

AGP

More testing and, trust me, it is the merging that's causing the problem.

EgonOlsen

I still don't see how. I guess i need a test case then...

AGP


AGP

My test case isn't producing the expected result. One thing that it does show is that mergeObjects adds the rotation matrices of both planes (I have to rotateMesh() and clearRotation() on one before merging them). Alas, shadows (on two Primitives-created planes) I'm getting.

AGP

So another hypothesis is that the merging of both planes produces too complex a mesh for the ShadowHelper. Is that possible? If so, is there a workaround?

EgonOlsen

mergeObjects doesn't touch rotation matrices. Whatever your test case does with rotations, it has nothing to do with the merge. If you do a rotateMesh() on both, the result will simply be the vertices and polygons of both rotated meshes merged into one. The rotation matrix of the resulting mesh will be the identity matrix.