Author Topic: 2 Questions: Tiling and a Shader for Shadows  (Read 2783 times)

Offline AGP

  • quad
  • ******
  • Posts: 1526
    • View Profile
2 Questions: Tiling and a Shader for Shadows
« on: January 28, 2015, 10:20:18 pm »
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:

Code: [Select]
     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?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11776
    • View Profile
    • http://www.jpct.net
Re: 2 Questions: Tiling and a Shader for Shadows
« Reply #1 on: January 28, 2015, 11:02:41 pm »
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?

Offline AGP

  • quad
  • ******
  • Posts: 1526
    • View Profile
Re: 2 Questions: Tiling and a Shader for Shadows
« Reply #2 on: January 29, 2015, 03:55:46 pm »
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:

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11776
    • View Profile
    • http://www.jpct.net
Re: 2 Questions: Tiling and a Shader for Shadows
« Reply #3 on: January 29, 2015, 05:15:16 pm »
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.

Offline AGP

  • quad
  • ******
  • Posts: 1526
    • View Profile
Re: 2 Questions: Tiling and a Shader for Shadows
« Reply #4 on: January 31, 2015, 03:31:28 pm »
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).

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11776
    • View Profile
    • http://www.jpct.net
Re: 2 Questions: Tiling and a Shader for Shadows
« Reply #5 on: January 31, 2015, 03:36:57 pm »
If the tiling doesn't work as well, that's an indication that your object is already compiled at that stage.

Offline AGP

  • quad
  • ******
  • Posts: 1526
    • View Profile
Re: 2 Questions: Tiling and a Shader for Shadows
« Reply #6 on: January 31, 2015, 03:52:11 pm »
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!

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11776
    • View Profile
    • http://www.jpct.net
Re: 2 Questions: Tiling and a Shader for Shadows
« Reply #7 on: January 31, 2015, 05:29:26 pm »
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.

Offline AGP

  • quad
  • ******
  • Posts: 1526
    • View Profile
Re: 2 Questions: Tiling and a Shader for Shadows
« Reply #8 on: January 31, 2015, 05:37:46 pm »
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().

Offline AGP

  • quad
  • ******
  • Posts: 1526
    • View Profile
Re: 2 Questions: Tiling and a Shader for Shadows
« Reply #9 on: January 31, 2015, 05:50:25 pm »
More testing and, trust me, it is the merging that's causing the problem.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11776
    • View Profile
    • http://www.jpct.net
Re: 2 Questions: Tiling and a Shader for Shadows
« Reply #10 on: January 31, 2015, 05:55:02 pm »
I still don't see how. I guess i need a test case then...

Offline AGP

  • quad
  • ******
  • Posts: 1526
    • View Profile
Re: 2 Questions: Tiling and a Shader for Shadows
« Reply #11 on: January 31, 2015, 05:55:52 pm »
OK. Coming up in your mailbox.

Offline AGP

  • quad
  • ******
  • Posts: 1526
    • View Profile
Re: 2 Questions: Tiling and a Shader for Shadows
« Reply #12 on: February 02, 2015, 05:21:39 pm »
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.

Offline AGP

  • quad
  • ******
  • Posts: 1526
    • View Profile
Re: 2 Questions: Tiling and a Shader for Shadows
« Reply #13 on: February 02, 2015, 05:34:33 pm »
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?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11776
    • View Profile
    • http://www.jpct.net
Re: 2 Questions: Tiling and a Shader for Shadows
« Reply #14 on: February 02, 2015, 08:24:20 pm »
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.