Author Topic: ShadowHelper and special Textures  (Read 2991 times)

Offline Windmiller

  • byte
  • *
  • Posts: 21
    • View Profile
ShadowHelper and special Textures
« on: December 04, 2021, 01:49:29 pm »
Hi,

The problems seems to be piling up for me now, don't know why.

I added a ShadowHelper and added a Sphere as a receiver and a Primitives.getCube as a caster placed just over the surface of the Sphere, the sphere is made in Blender.

Everything is working and I've made the shadow visible like it should be, but that's only if I'm applying the sphere's texture directly with the following code..

Code: [Select]
sphere.setTexture("entityTexturePlanet");

From there everything is just fine, but if I'm using the following method to add the texture..

Code: [Select]
setTexture(sphere);

Calling the following function..

Code: [Select]
private static void setTexture(Object3D obj) {
        TextureManager tm = TextureManager.getInstance();

        obj.calcBoundingBox();

        float[] bb = obj.getMesh().getBoundingBox();

        float minX = bb[0];
        float maxX = bb[1];
        float minY = bb[2];
        float maxY = bb[3];
        float dx = maxX - minX;
        float dy = maxY - minY;

        float dxs = dx;
        float dys = dy;

        dx /= 20f;
        dy /= 20f;

        float dxd = dx;
        float dyd = dy;

        int tid = tm.getTextureID("entityTexturePlanet");
        int bid = tm.getTextureID("ice");

        PolygonManager pm = obj.getPolygonManager();
        for (int i = 0; i < pm.getMaxPolygonID(); i++) {

            SimpleVector v0 = pm.getTransformedVertex(i, 0);
            SimpleVector v1 = pm.getTransformedVertex(i, 1);
            SimpleVector v2 = pm.getTransformedVertex(i, 2);

            // Assign textures for the first three layers (the "normal"
            // textures)...
            TextureInfo ti = new TextureInfo(tid, v0.x / dx, v0.y / dy, v1.x / dx, v1.y / dy, v2.x / dx, v2.y / dy);

            // Assign the splatting texture...
            ti.add(bid, -(v0.x - minX) / dxs, (v0.y - minY) / dys, -(v1.x - minX) / dxs, (v1.y - minY) / dys, -(v2.x - minX) / dxs, (v2.y - minY) / dys, TextureInfo.MODE_ADD);
            pm.setPolygonTexture(i, ti);
        }

Then the shadow totally disappears, this also happens if I'm using the bump map example that I've previously found..

Code: [Select]
TextureManager tm = TextureManager.getInstance();

                    Texture face = new Texture(res.openRawResource(R.raw.face2));
                    Texture normals = new Texture(res.openRawResource(R.raw.face_norm), true);
                    Texture heighty = new Texture(res.openRawResource(R.raw.face_height2));

                    TexelGrabber grabber = new TexelGrabber();
                    heighty.setEffect(grabber);
                    heighty.applyEffect();
                    int[] heighties = grabber.getAlpha();

                    AlphaMerger setter = new AlphaMerger(heighties);
                    normals.setEffect(setter);
                    normals.applyEffect();

                    tm.addTexture("face", face);
                    tm.addTexture("normals", normals);

                    TextureInfo ti = new TextureInfo(TextureManager.getInstance().getTextureID("face"));
                    ti.add(TextureManager.getInstance().getTextureID("normals"), TextureInfo.MODE_BLEND);

                    // Calculate for texturing..
                    sphere.calcTextureWrapSpherical();

                    sphere.setTexture(ti);

                    sphere.compile();
                    sphere.build();

Must be something that I'm not thinking of here? :/
Is these two later methods overwriting the shadow map? What is going on here?

Regards,
« Last Edit: December 04, 2021, 02:05:08 pm by Windmiller »

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: ShadowHelper and special Textures
« Reply #1 on: December 06, 2021, 08:57:20 pm »
Is these two later methods overwriting the shadow map? What is going on here?

Yes, that's the problem here. Shadow mapping is two pass operation. Firstly, the scene when rendered when viewed from the light source and the depth of each (caster-)pixel is stored into the depth map. Then, the scene is rendered normally expect that the shadow mapp gets projected into the scene in addition and a check is done to compare the distance from each pixel to the light source with the value stored in the depth map. If it's larger, the pixel is shadowed. Otherwise, it's not. For that to work, the shadow map has to be part of each object receiving the shadow.

In your case, you are removing the shadow map from the object with that code, hence no shadows. If you call your method before setting up the shadow helper, it should actually work.

Offline Windmiller

  • byte
  • *
  • Posts: 21
    • View Profile
Re: ShadowHelper and special Textures
« Reply #2 on: December 06, 2021, 11:55:11 pm »
Ok, so if I understand, it should be in this order.

1. Load the sphere
2. call my setTexture function
3. add sphere to world
3. Load the Primitives.getCube
4. add cube to the world
5. create ShadowHelper instance
6. set up the shadowhelper, sphere as a receiver and the cube as a caster
7. followed by the following

Code: [Select]
shadowHelper.updateShadowMap(buffer, world);

buffer.clear(back);
world.renderScene(buffer);
world.draw(buffer);

buffer.display();

This is the order that I'm doing this in, without seeing any shadows sadly :/

EDIT: It works if I remove the splatting texture

Code: [Select]
// Assign the splatting texture...
ti.add(bid, -(v0.x - minX) / dxs, (v0.y - minY) / dys, -(v1.x - minX) / dxs, (v1.y - minY) / dys, -(v2.x - minX) / dxs, (v2.y - minY) / dys, TextureInfo.MODE_ADD)

Which means that something is happening when going into multi texture?
This must actually happen to everyone.
« Last Edit: December 07, 2021, 08:44:12 am by Windmiller »

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: ShadowHelper and special Textures
« Reply #3 on: December 07, 2021, 08:37:02 am »
Can you please set the Logger to LL_DEBUG and post what gets printed out when adding the sphere as a receiver?

Offline Windmiller

  • byte
  • *
  • Posts: 21
    • View Profile
Re: ShadowHelper and special Textures
« Reply #4 on: December 07, 2021, 09:15:01 am »
Since it's not a test case but a big game, there are a lot of things going on.
I guess I will have to set up a test case first but something that struck me while looking at the log was the following lines..

Code: [Select]
12-07 08:52:44.028 6572-6643/com.storyofagame.vast I/jPCT-AE: Loading /shadowFragmentPostPCFEF.src
12-07 08:52:44.031 6572-6643/com.storyofagame.vast I/jPCT-AE: Loading file from InputStream
12-07 08:52:44.031 6572-6643/com.storyofagame.vast I/jPCT-AE: Text file from InputStream loaded...1604 bytes
12-07 08:52:44.032 6572-6643/com.storyofagame.vast I/jPCT-AE: Loading /shadowFragmentPostTex0PCFEF.src
12-07 08:52:44.034 6572-6643/com.storyofagame.vast I/jPCT-AE: Loading file from InputStream
12-07 08:52:44.035 6572-6643/com.storyofagame.vast I/jPCT-AE: Text file from InputStream loaded...934 bytes
12-07 08:52:44.035 6572-6643/com.storyofagame.vast I/jPCT-AE: glGetIntegerv(3379, java.nio.ByteBufferAsIntBuffer[position=0,limit=16,capacity=16]) took 56094ns
12-07 08:52:44.036 6572-6643/com.storyofagame.vast I/jPCT-AE: This device supports up to 16384*16384 textures!
12-07 08:52:44.037 6572-6643/com.storyofagame.vast W/jPCT-AE: [ 1638863564037 ] - WARNING: No further texture stage available (2/1/2)!
12-07 08:52:44.037 6572-6643/com.storyofagame.vast W/jPCT-AE: [ 1638863564037 ] - WARNING: No further texture stage available (2/1/2)!
12-07 08:52:44.037 6572-6643/com.storyofagame.vast W/jPCT-AE: [ 1638863564037 ] - WARNING: No further texture stage available (2/1/2)!
12-07 08:52:44.037 6572-6643/com.storyofagame.vast W/jPCT-AE: [ 1638863564037 ] - WARNING: No further texture stage available (2/1/2)!
12-07 08:52:44.037 6572-6643/com.storyofagame.vast W/jPCT-AE: [ 1638863564037 ] - WARNING: No further texture stage available (2/1/2)!
12-07 08:52:44.037 6572-6643/com.storyofagame.vast W/jPCT-AE: [ 1638863564037 ] - WARNING: No further texture stage available (2/1/2)!
12-07 08:52:44.037 6572-6643/com.storyofagame.vast W/jPCT-AE: [ 1638863564037 ] - WARNING: No further texture stage available (2/1/2)!
12-07 08:52:44.037 6572-6643/com.storyofagame.vast W/jPCT-AE: [ 1638863564037 ] - WARNING: No further texture stage available (2/1/2)!
12-07 08:52:44.037 6572-6643/com.storyofagame.vast W/jPCT-AE: [ 1638863564037 ] - WARNING: No further texture stage available (2/1/2)!
12-07 08:52:44.037 6572-6643/com.storyofagame.vast W/jPCT-AE: [ 1638863564037 ] - WARNING: No further texture stage available (2/1/2)!
12-07 08:52:44.037 6572-6643/com.storyofagame.vast W/jPCT-AE: [ 1638863564037 ] - WARNING: No further texture stage available (2/1/2)!
12-07 08:52:44.038 6572-6643/com.storyofagame.vast W/jPCT-AE: [ 1638863564038 ] - WARNING: No further texture stage available (2/1/2)!
12-07 08:52:44.038 6572-6643/com.storyofagame.vast W/jPCT-AE: [ 1638863564038 ] - WARNING: No further texture stage available (2/1/2)!
12-07 08:52:44.038 6572-6643/com.storyofagame.vast W/jPCT-AE: [ 1638863564038 ] - WARNING: No further texture stage available (2/1/2)!
12-07 08:52:44.038 6572-6643/com.storyofagame.vast W/jPCT-AE: [ 1638863564038 ] - WARNING: No further texture stage available (2/1/2)!
12-07 08:52:44.038 6572-6643/com.storyofagame.vast W/jPCT-AE: [ 1638863564038 ] - WARNING: No further texture stage available (2/1/2)!
12-07 08:52:44.038 6572-6643/com.storyofagame.vast W/jPCT-AE: [ 1638863564038 ] - WARNING: No further texture stage available (2/1/2)!
12-07 08:52:44.038 6572-6643/com.storyofagame.vast W/jPCT-AE: [ 1638863564038 ] - WARNING: No further texture stage available (2/1/2)!
12-07 08:52:44.038 6572-6643/com.storyofagame.vast W/jPCT-AE: [ 1638863564038 ] - WARNING: No further texture stage available (2/1/2)!
12-07 08:52:44.038 6572-6643/com.storyofagame.vast W/jPCT-AE: [ 1638863564038 ] - WARNING: No further texture stage available (2/1/2)!

Repeating

12-07 08:52:44.063 6572-6643/com.storyofagame.vast W/jPCT-AE: [ 1638863564063 ] - WARNING: No further texture stage available (2/1/2)!
12-07 08:52:44.063 6572-6643/com.storyofagame.vast W/jPCT-AE: [ 1638863564063 ] - WARNING: No further texture stage available (2/1/2)!
12-07 08:52:44.063 6572-6643/com.storyofagame.vast W/jPCT-AE: [ 1638863564063 ] - WARNING: No further texture stage available (2/1/2)!
12-07 08:52:44.063 6572-6643/com.storyofagame.vast W/jPCT-AE: [ 1638863564063 ] - WARNING: No further texture stage available (2/1/2)!
12-07 08:52:44.063 6572-6643/com.storyofagame.vast W/jPCT-AE: [ 1638863564063 ] - WARNING: No further texture stage available (2/1/2)!
12-07 08:52:44.063 6572-6643/com.storyofagame.vast W/jPCT-AE: [ 1638863564063 ] - WARNING: No further texture stage available (2/1/2)!
12-07 08:52:44.063 6572-6643/com.storyofagame.vast W/jPCT-AE: [ 1638863564063 ] - WARNING: No further texture stage available (2/1/2)!
12-07 08:52:44.063 6572-6643/com.storyofagame.vast W/jPCT-AE: [ 1638863564063 ] - WARNING: No further texture stage available (2/1/2)!
12-07 08:52:44.063 6572-6643/com.storyofagame.vast W/jPCT-AE: [ 1638863564063 ] - WARNING: No further texture stage available (2/1/2)!
12-07 08:52:44.063 6572-6643/com.storyofagame.vast W/jPCT-AE: [ 1638863564063 ] - WARNING: No further texture stage available (2/1/2)!
12-07 08:52:44.063 6572-6643/com.storyofagame.vast W/jPCT-AE: [ 1638863564063 ] - WARNING: No further texture stage available (2/1/2)!
12-07 08:52:44.063 6572-6643/com.storyofagame.vast W/jPCT-AE: [ 1638863564063 ] - WARNING: No further texture stage available (2/1/2)!
12-07 08:52:44.063 6572-6643/com.storyofagame.vast W/jPCT-AE: [ 1638863564063 ] - WARNING: No further texture stage available (2/1/2)!
12-07 08:52:44.063 6572-6643/com.storyofagame.vast W/jPCT-AE: [ 1638863564063 ] - WARNING: No further texture stage available (2/1/2)!
12-07 08:52:44.063 6572-6643/com.storyofagame.vast W/jPCT-AE: [ 1638863564063 ] - WARNING: No further texture stage available (2/1/2)!
12-07 08:52:44.063 6572-6643/com.storyofagame.vast W/jPCT-AE: [ 1638863564063 ] - WARNING: No further texture stage available (2/1/2)!
12-07 08:52:44.063 6572-6643/com.storyofagame.vast W/jPCT-AE: [ 1638863564063 ] - WARNING: No further texture stage available (2/1/2)!
12-07 08:52:44.063 6572-6643/com.storyofagame.vast W/jPCT-AE: [ 1638863564063 ] - WARNING: No further texture stage available (2/1/2)!
12-07 08:52:44.063 6572-6643/com.storyofagame.vast W/jPCT-AE: [ 1638863564063 ] - WARNING: No further texture stage available (2/1/2)!
12-07 08:52:44.063 6572-6643/com.storyofagame.vast W/jPCT-AE: [ 1638863564063 ] - WARNING: No further texture stage available (2/1/2)!
12-07 08:52:44.064 6572-6643/com.storyofagame.vast I/jPCT-AE: glEnable(3089) took 68646ns
12-07 08:52:44.065 6572-6643/com.storyofagame.vast I/jPCT-AE: glScissor(1, 1, 1022, 1022) took 106667ns
12-07 08:52:44.075 6572-6643/com.storyofagame.vast I/jPCT-AE: glGenTextures(1, java.nio.ByteBufferAsIntBuffer[position=0,limit=1,capacity=1]) took 87188ns
12-07 08:52:44.075 6572-6643/com.storyofagame.vast I/jPCT-AE: glBindTexture(3553, 9) took 54479ns
12-07 08:52:44.075 6572-6643/com.storyofagame.vast I/jPCT-AE: glTexParameterx(3553, 10241, 9729) took 22969ns
12-07 08:52:44.075 6572-6643/com.storyofagame.vast I/jPCT-AE: glTexParameterx(3553, 10240, 9729) took 14375ns
12-07 08:52:44.075 6572-6643/com.storyofagame.vast I/jPCT-AE: glTexParameterx(3553, 10242, 10497) took 11563ns
12-07 08:52:44.075 6572-6643/com.storyofagame.vast I/jPCT-AE: glTexParameterx(3553, 10243, 10497) took 10677ns
12-07 08:52:44.092 6572-6643/com.storyofagame.vast I/jPCT-AE: glTexImage2D(3553, 0, 6408, 1024, 1024, 0, 6408, 5121, java

It was spitting out lines every millisecound so it was hard to catch anything before the log was overfilled.
Therefore I will need to create a test case for better viewing of the log file.
« Last Edit: December 07, 2021, 09:22:59 am by Windmiller »

Offline Windmiller

  • byte
  • *
  • Posts: 21
    • View Profile
Re: ShadowHelper and special Textures
« Reply #5 on: December 07, 2021, 09:35:03 am »
When I added the following config..

Code: [Select]
Config.maxTextureLayers = 3;

Then it was working! :O
Could not set it to anything less than 3

Default was 2, and does that mean that the shadow itself counts as 1?
Because I'm only adding 2 myself..

Or is it tricked to calculate the baked texture in the sphereīs file from Blender as the third one, even though itīs just the name of a texture in there, its an .obj file by the way.
« Last Edit: December 07, 2021, 09:49:45 am by Windmiller »

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: ShadowHelper and special Textures
« Reply #6 on: December 07, 2021, 10:43:46 am »
Yes, the shadow is an additional texture as mentioned above. I wasn't aware that you are adding 2 layers yourself, so that explains it.

Offline Windmiller

  • byte
  • *
  • Posts: 21
    • View Profile
Re: ShadowHelper and special Textures
« Reply #7 on: December 07, 2021, 11:16:46 am »
Thanks a bunch for all the help and support, and the engine is wonderful by the way I think I've never mentioned it before.
Is there somewhere I can read of how, when and why the engine came to be? It would be very interesting to read and know more about the background, there's a lot of information about it to read but I donīt think I've seen anything about that.

Is it Helge Foerster who made the engine?

I've decided to send a mail to the info address instead with these questions.

Thanks again :)
« Last Edit: December 07, 2021, 01:56:13 pm by Windmiller »

Offline AeroShark333

  • float
  • ****
  • Posts: 319
    • View Profile
Re: ShadowHelper and special Textures
« Reply #8 on: December 08, 2021, 03:08:56 pm »
Is it Helge Foerster who made the engine?

I've decided to send a mail to the info address instead with these questions.

Thanks again :)
Seems so... https://www.jpct.net/imprint.html
Most likely also the very person you've been talking with hehe

Thanks a bunch for all the help and support, and the engine is wonderful by the way I think I've never mentioned it before.
Is there somewhere I can read of how, when and why the engine came to be? It would be very interesting to read and know more about the background, there's a lot of information about it to read but I donīt think I've seen anything about that.
Would be interesting to know indeed