ShadowHelper and special Textures

Started by Windmiller, December 04, 2021, 01:49:29 PM

Previous topic - Next topic

Windmiller

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..


sphere.setTexture("entityTexturePlanet");


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


setTexture(sphere);


Calling the following function..


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..


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,

EgonOlsen

Quote from: Windmiller on December 04, 2021, 01:49:29 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.

Windmiller

#2
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


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


// 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.

EgonOlsen

Can you please set the Logger to LL_DEBUG and post what gets printed out when adding the sphere as a receiver?

Windmiller

#4
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..


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.

Windmiller

#5
When I added the following config..


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.

EgonOlsen

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.

Windmiller

#7
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 :)

AeroShark333

Quote from: Windmiller on December 07, 2021, 11:16:46 AMIs 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

Quote from: Windmiller 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.
Would be interesting to know indeed