Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Weird shadow map with texture
Forum Updated to NodeBB v4.3 + New Features

Weird shadow map with texture

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
qt quick 3dtextureshadow
2 Posts 2 Posters 249 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    nelbok
    wrote on last edited by
    #1

    Hello,

    I was a problem with the shadow mapping, I think.
    Here three screenshots:
    WithTexture.png
    WithoutTexture.png
    HalfTexture.png

    As you can see, the shadow is correct when the Materials are full textured or aren't.
    The problem occurs when I have one Material with a Texture and the other without Texture.

    Here the sample code:

    import QtQuick
    import QtQuick3D
    import QtQuick3D.Helpers
    
    import test 1.0
    
    Window {
        width: 720
        height: 480
        visible: true
        title: qsTr("Hello World")
    
        View3D {
            id: root
            anchors.fill: parent
    
            environment: SceneEnvironment {
                clearColor: "skyblue"
                backgroundMode: SceneEnvironment.Color
            }
    
            // A light like the sun
            DirectionalLight {
                eulerRotation.x: -30
                eulerRotation.y: -70
                castsShadow: true
                shadowMapQuality: Light.ShadowMapQualityVeryHigh
            }
    
            // Camera with its controller to make it easy to move around the scene
            PerspectiveCamera {
                id: camera
                position: Qt.vector3d(0, 800, 1000)
                eulerRotation.x: -30
            }
            WasdController {
                controlledObject: camera
            }
    
            Model {
                source: "#Cube"
                materials: [
                    DefaultMaterial {
                        diffuseColor: Qt.rgba(0.0, 0.8, 0.0, 1.0)
                    }
                ]
                scale: Qt.vector3d(10, 1, 10);
                position: Qt.vector3d(0, -100, 0);
            }
    
    
            Model {
                geometry: TestCube {
                }
                materials: [
                    DefaultMaterial {
                        diffuseColor: Qt.rgba(0.8, 0.0, 0.0, 1.0)
                        diffuseMap: Texture {
                            source: "qrc:/logo/logo.png"
                        }
                    },
                    DefaultMaterial {
                        diffuseColor: Qt.rgba(0.8, 0.8, 0.8, 1.0)
                        // diffuseMap: Texture {
                        //     source: "qrc:/logo/logo.png"
                        // }
                    }
                ]
                scale: Qt.vector3d(100, 100, 100);
                position: Qt.vector3d(-100, 0, 0);
                eulerRotation.y: -45
            }
        }
    }
    
    #include "testcube.h"
    
    #include <QVector3D>
    
    TestCube::TestCube()
    {
        updateData();
    }
    
    void TestCube::updateData()
    {
        QByteArray v;
        v.resize(2 * 4 * 5 * sizeof(float));
        float *p = reinterpret_cast<float *>(v.data());
    
        // a triangle, front face = counter-clockwise
        *p++ = 0.0f; *p++ = 0.0f; *p++ = 0.0f; *p++ = 0.0f; *p++ = 0.0f;
        *p++ = 0.0f; *p++ = 1.0f; *p++ = 0.0f; *p++ = 0.0f; *p++ = 1.0f;
        *p++ = 1.0f; *p++ = 0.0f; *p++ = 0.0f; *p++ = 1.0f; *p++ = 0.0f;
        *p++ = 1.0f; *p++ = 1.0f; *p++ = 0.0f; *p++ = 1.0f; *p++ = 1.0f;
    
        *p++ = 11.0f; *p++ = 0.0f; *p++ = 0.0f; *p++ = 0.0f; *p++ = 0.0f;
        *p++ = 11.0f; *p++ = 1.0f; *p++ = 0.0f; *p++ = 0.0f; *p++ = 1.0f;
        *p++ = 12.0f; *p++ = 0.0f; *p++ = 0.0f; *p++ = 1.0f; *p++ = 0.0f;
        *p++ = 12.0f; *p++ = 1.0f; *p++ = 0.0f; *p++ = 1.0f; *p++ = 1.0f;
    
        QByteArray i;
        i.resize(4 * 3 * sizeof(unsigned));
        unsigned *j = reinterpret_cast<unsigned *>(i.data());
    
        // a triangle, front face = counter-clockwise
        *j++ = 0; *j++ = 2; *j++ = 1;
        *j++ = 4; *j++ = 6; *j++ = 5;
        *j++ = 1; *j++ = 2; *j++ = 3;
        *j++ = 5; *j++ = 6; *j++ = 7;
    
        addSubset(0, 6, {-1.0f, -1.0f,-1.0f}, {1.0f, 1.0f, 1.0f});
        addSubset(6, 6, {-1.0f, -1.0f,-1.0f}, {1.0f, 1.0f, 1.0f});
    
        setVertexData(v);
        setIndexData(i);
        setStride(5 * sizeof(float));
    
        setBounds({-1.0f, -1.0f,-1.0f}, {1.0f, 1.0f, 1.0f});
    
        setPrimitiveType(QQuick3DGeometry::PrimitiveType::Triangles);
        addAttribute(QQuick3DGeometry::Attribute::PositionSemantic, 0, QQuick3DGeometry::Attribute::F32Type);
        addAttribute(QQuick3DGeometry::Attribute::TexCoordSemantic, 3 * sizeof(float), QQuick3DGeometry::Attribute::F32Type);
        addAttribute(QQuick3DGeometry::Attribute::IndexSemantic, 0, QQuick3DGeometry::Attribute::U32Type);
    }
    

    My suspicions are around the setBouns, but I am not sure...
    I will try with a blank texture when there is no texture for the Material.

    Thank you if you can pinpoint my error.

    1 Reply Last reply
    0
    • J Offline
      J Offline
      Jonas Karlsson
      wrote on last edited by
      #2

      If you are trying to create a cube then it looks like your cube data is wrong as you can see from this picture:
      image.png

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved