www.jpct.net

jPCT - a 3d engine for Java => Support => Topic started by: AGP on January 28, 2015, 10:20:18 pm

Title: 2 Questions: Tiling and a Shader for Shadows
Post by: AGP 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?
Title: Re: 2 Questions: Tiling and a Shader for Shadows
Post by: EgonOlsen 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?
Title: Re: 2 Questions: Tiling and a Shader for Shadows
Post by: AGP 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:
(https://dl.dropboxusercontent.com/u/93826015/ShadowProblem.jpg)
Title: Re: 2 Questions: Tiling and a Shader for Shadows
Post by: EgonOlsen 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.
Title: Re: 2 Questions: Tiling and a Shader for Shadows
Post by: AGP 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).
Title: Re: 2 Questions: Tiling and a Shader for Shadows
Post by: EgonOlsen 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.
Title: Re: 2 Questions: Tiling and a Shader for Shadows
Post by: AGP 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!
Title: Re: 2 Questions: Tiling and a Shader for Shadows
Post by: EgonOlsen 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.
Title: Re: 2 Questions: Tiling and a Shader for Shadows
Post by: AGP 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().
Title: Re: 2 Questions: Tiling and a Shader for Shadows
Post by: AGP on January 31, 2015, 05:50:25 pm
More testing and, trust me, it is the merging that's causing the problem.
Title: Re: 2 Questions: Tiling and a Shader for Shadows
Post by: EgonOlsen on January 31, 2015, 05:55:02 pm
I still don't see how. I guess i need a test case then...
Title: Re: 2 Questions: Tiling and a Shader for Shadows
Post by: AGP on January 31, 2015, 05:55:52 pm
OK. Coming up in your mailbox.
Title: Re: 2 Questions: Tiling and a Shader for Shadows
Post by: AGP 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.
Title: Re: 2 Questions: Tiling and a Shader for Shadows
Post by: AGP 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?
Title: Re: 2 Questions: Tiling and a Shader for Shadows
Post by: EgonOlsen 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.
Title: Re: 2 Questions: Tiling and a Shader for Shadows
Post by: EgonOlsen on February 02, 2015, 08:26:56 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?
Actually no. All it does it adding the depth map as an addional texture layer to all receivers. That's independent from the mesh's size. The only size related issue that i can think of might come up if you don't compile the mesh. In that case, rendering it from the light source (which is what the ShadowHelper) might exceed the maximum number of visible polygons. If that's the case, you'll get a warning message printed into the log once.
Title: Re: 2 Questions: Tiling and a Shader for Shadows
Post by: AGP on February 03, 2015, 02:55:03 am
My observation about rotateMesh() and clearRotation() still stands: without calling them on one of the planes, the merged was rotated so that its normals didn't face the camera and the plane was invisible.

Can you hypothesize something else about the shadows? All I know is that when the planes aren't merged, the shadows (and tiling) work. When they are, they break.
Title: Re: 2 Questions: Tiling and a Shader for Shadows
Post by: EgonOlsen on February 03, 2015, 12:22:27 pm
I've double checked it: The merge operation doesn't do anything with the rotations matrices. Not with those of the source object and not with those of the merged target. It just merges two arrays into one. The resulting mesh of course differs if you have or haven't called rotateMesh on either one of the sources or both. Anyway, i'm actually not sure what your issue is, so maybe we are talking about different things here.

Back to the shadows: No, i'm out of ideas ATM. You can try to the set the Logger to debug and Config.glVerbose=true and post the log output. Maybe it will reveal something...
Title: Re: 2 Questions: Tiling and a Shader for Shadows
Post by: AGP on February 03, 2015, 03:00:53 pm
That's a good idea, thanks. I've e-mailed you the log file because it's too big to attach here. There's a "Found empty stage at 0" message that I don't know what it means but which looks suspicious to me...
Title: Re: 2 Questions: Tiling and a Shader for Shadows
Post by: EgonOlsen on February 03, 2015, 05:05:17 pm
No, that's actually a good sign... ;) It means that the shadow map has been added at stage 0 of the multi-texturing stages, which is stage 1 of the object. Or in other words: The object has one texture stage only (which is to be expected) and two after adding it as a receiver. And that's exactly how it's supposed to be. Judging from the number of messages, the object added as a receiver has ~6000 polygons. Does this match your terrain mesh?

The log looks fine to me. Can you post/mail the rest as well, i.e. the first rendering cycle up to the first visible frame?
Title: Re: 2 Questions: Tiling and a Shader for Shadows
Post by: AGP on February 03, 2015, 05:27:06 pm
What do you mean? Did I not send you the whole log via email?
Title: Re: 2 Questions: Tiling and a Shader for Shadows
Post by: EgonOlsen on February 03, 2015, 07:56:33 pm
I'm not sure. It ends with "Loading Texture...from Image"...if it would be the complete log with Config.glVerbose=true, i would expect some more details about texture uploads and such.
Title: Re: 2 Questions: Tiling and a Shader for Shadows
Post by: AGP on February 12, 2015, 08:52:40 pm
I stopped merging the planes in order to get my shadows. It works this way, so whatever.

Now, the problem is that I'm moving the shadows with the following code:

Code: [Select]
     double currentTime = time.getTimeOfDay();
     if (time.getTimeOfDay() >= 0.00f && time.getTimeOfDay() < 0.05f){
projector.setPosition(sunInitialPosition);
sun.setPosition(sunInitialPosition);
     }
     SimpleVector position = sun.getPosition();
     position.x = sunInitialPosition.x +(300f*(float)time.percentage);
     sun.setPosition(position);
     projector.setPosition(position);

The results are horrendous-looking shadows as shown in the following video:
https://drive.google.com/file/d/0Bxu4PEHAObLJVzBuNnM1bFNDTXM/view?usp=sharing (https://drive.google.com/file/d/0Bxu4PEHAObLJVzBuNnM1bFNDTXM/view?usp=sharing)
Title: Re: 2 Questions: Tiling and a Shader for Shadows
Post by: EgonOlsen on February 13, 2015, 07:31:56 am
What do you mean? I can't spot anything wrong with the shadows... ???
Title: Re: 2 Questions: Tiling and a Shader for Shadows
Post by: AGP on February 13, 2015, 02:41:51 pm
The shadows look horrendous. The first thing that anyone says when they see this is how bad the shadows look, but if I don't move the sun, the shadows look distinctly better.
Title: Re: 2 Questions: Tiling and a Shader for Shadows
Post by: EgonOlsen on February 13, 2015, 05:10:10 pm
If you are moving the sun/projector, you'll get some aliasing effects on the shadows based on the size of the shadow map, the distance of the sun from the scene and the fov of the projector. You can try to decrease the fov and/or the distance to increase the accuracy. Apart from that, there's nothing you can do with this kind of shadows. I haven't seen anything in the video that i found surprising, but the quality was pretty low though. Maybe you can upload the video that shows the problem in more detail? Maybe i'm just not sseing it.
If it still doesn't work out, just don't move the sun...