Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Design Tooling
  3. Qt Design Studio
  4. I want to use custommaterial which can show advancedcustommaterial example in QtCreator,but I got two trouble.

I want to use custommaterial which can show advancedcustommaterial example in QtCreator,but I got two trouble.

Scheduled Pinned Locked Moved Unsolved Qt Design Studio
2 Posts 2 Posters 396 Views
  • 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.
  • F Offline
    F Offline
    ForeverLoki
    wrote on 18 Mar 2023, 03:06 last edited by
    #1

    Here is my code in QtDesign studio 4.0

    CustomMaterial {
                id: customMaterial1
                property color ambient:  Qt.rgba(0.15, 0.35, 0.50, 1.0)
                property color ka: Qt.rgba(0.15, 0.35, 0.50, 1.0)//ambient
                property color specularColor: Qt.rgba(0.2, 0.2, 0.2, 1.0)
                property real shininess: 150.0
                property real textureScale: 1.0
                property real offsetx: 0.0
                property real offsety: 0.0
                property real wavescale: 0.0
                property real specularity: 1.0
                property real waveheight: 0.1
                property real waveStrenght: 0.1
                property real normalAmount: 2.0
                property real waveRandom: 1.0
    
                property real texCoordScale: 1.0
                property real vertYpos: 0.0
    
                property TextureInput foamTexture: TextureInput {
                    enabled: true
                    texture:Texture{
                        id: foamTexture
                        source:"../../../textures/foam.jpg"}
                }
                property TextureInput skyTexture: TextureInput {
                    enabled: true
                    texture: Texture{
                        id: skyTexture
                        source:"../../../textures/sky.jpg"
                    }
                }
                property TextureInput waveTexture: TextureInput {
                    enabled: true
                    texture: Texture{
                        id: waveTexture
                        source:"../../../textures/Waterwave.jpg"
                    }
                }
                property TextureInput specularTexture: TextureInput {
                    enabled: true
                    texture: Texture{
                        id: specularTexture
                        source:"../../../textures/WaterSpecular.jpg"
                    }
    
                }
                property TextureInput diffuseTexture: TextureInput {
                    enabled: true
                    texture:Texture{
                        id: diffuseTexture
                        source:"../../../textures/WaterDiffuse.jpg"
                    }
                }
                property TextureInput normalTexture: TextureInput {
                    enabled: true
                    texture:Texture{
                        id: normalTexture
                        source:"../../../textures/WaterNormal.jpg"
                    }
                }
                shadingMode: CustomMaterial.Unshaded
                vertexShader: "../../../shaders/test/water.vert"
                fragmentShader: "../../../shaders/test/water.frag"
            }
    

    I got two error in QtCreator when I am changing projection from QtDesign Studio to QtCreator
    QSpirvCompiler: Failed to parse shader
    Failed to compile vertex shader:

    "custom material -->water.vert>water.frag:a46ea2d3d2c9243dfc30960db194be3a87c3dd21;hasLighting=true;lightCount=5;specularModel=Default;;diffuseMap={;;;;};emissiveMap={;;;;};specularMap={;;;;};baseColorMap={;;;;};bumpMap={;;;;};specularAmountMap={;;;;};normalMap={;;;;};clearcoatNormalMap={;;;;};opacityMap={;;;;};roughnessMap={;;;;};metalnessMap={;;;;};occlusionMap={;;;;};translucencyMap={;;;;};heightMap={;;;;};clearcoatMap={;;;;};clearcoatRoughnessMap={;;;;};transmissionMap={;;;;};thicknessMap={;;;;};opacityMap_channel=R;roughnessMap_channel=R;metalnessMap_channel=R;occlusionMap_channel=R;translucencyMap_channel=R;heightMap_channel=R;clearcoatMap_channel=R;clearcoatRoughnessMap_channel=R;transmissionMap_channel=R;thicknessMap_channel=R;boneCount=0;overridesPosition=true;alphaMode=Default;;vertexAttributes={position=true;normal=true;texcoord0=true;;tangent=true;binormal=true;;}};morphTargetCount=0;morphTarget0Attributes={;;;;;;;}};morphTarget1Attributes={;;;;;;;}};morphTarget2Attributes={;;;;;;;}};morphTarget3Attributes={;;;;;;;}};morphTarget4Attributes={;;;;;;;}};morphTarget5Attributes={;;;;;;;}};morphTarget6Attributes={;;;;;;;}};morphTarget7Attributes={;;;;;;;}}"
    "ERROR: :65: 'location' : overlapping use of location 16\nERROR: 1 compilation errors. No code generated."
    QSpirvCompiler: Failed to parse shader
    Failed to compile vertex shader:

    "custom material -->water.vert>water.frag:a46ea2d3d2c9243dfc30960db194be3a87c3dd21;hasLighting=true;lightCount=5; ... same as above"
    "ERROR: :63: 'location' : overlapping use of location 16\nERROR: 1 compilation errors. No code generated."

    There is my shader.vert:

    #version 330 core

    VARYING vec3 vertexPosition;
    VARYING vec3 vertexNormal;
    VARYING vec2 vertexTexCoord;
    VARYING vec4 vertexTangent;

    VARYING vec3 worldPosition;
    VARYING vec3 worldNormal;
    VARYING vec4 worldTangent;
    VARYING vec2 texCoord;
    VARYING vec2 movtexCoord;
    VARYING vec2 multexCoord;
    VARYING vec2 waveTexCoord;
    VARYING vec2 skyTexCoord;
    VARYING vec3 vpos;

    VARYING mat4 modelMatrix;
    VARYING mat3 modelNormalMatrix;
    VARYING mat4 mvp;

    VARYING vec3 eyePosition;

    void MAIN()
    {
    modelMatrix = MODEL_MATRIX
    modelNormalMatrix = NORMAL_MATRIX
    mvp = MODELVIEWPROJECTION_MATRIX

    vertexPosition = VERTEX
    vertexNormal = NORMAL
    vertexTexCoord = UV0
    vertexTangent =  TANGENT
    
    eyePosition = CAMERA_POSITION
    
    // Scale texture coordinates for for fragment shader
    texCoord = vertexTexCoord * texCoordScale;
    movtexCoord = vertexTexCoord * texCoordScale;
    multexCoord = vertexTexCoord * (texCoordScale*0.5);
    waveTexCoord = vertexTexCoord * (texCoordScale * 6);
    skyTexCoord = vertexTexCoord * (texCoordScale * 0.2);
    
    // Add Animated x and y Offset to SKY, MOV and MUL texCoords
    movtexCoord = vec2(texCoord.x+offsetx,texCoord.y+offsety);
    multexCoord = vec2(texCoord.x-offsetx,texCoord.y+offsety);
    skyTexCoord = vec2(texCoord.x-(offsetx/2),texCoord.y-(offsety/2));
    
    // Transform position, normal, and tangent to world coords
    worldPosition = vec3(modelMatrix * vec4(vertexPosition, 1.0));
    worldNormal = normalize(modelNormalMatrix * vertexNormal);
    worldTangent.xyz = normalize(vec3(modelMatrix * vec4(vertexTangent.xyz, 0.0)));
    worldTangent.w = vertexTangent.w;
    
    // Calculate animated vertex positions
    
    float sinPos = (vertexPosition.z)+(vertexPosition.x);
    float sinPos2 = (vertexPosition.y/2)+(vertexPosition.z);
    vec3 vertMod = vec3(vertexPosition.x,vertexPosition.y,vertexPosition.z);
    
    vertMod = vec3(vertMod.x+=sin(vertYpos*2.2-sinPos2)*waveheight,
                   vertMod.y=sin(vertYpos*2.2+sinPos)*waveheight,
                   vertMod.z-=sin(vertYpos*2.2-cos(sinPos2))*waveheight);
    
    vec3 vertModCom = vec3(vertMod.x+=cos(vertYpos*2.2-cos(sinPos2))*waveheight,
                           vertMod.y=sin(vertYpos*2.2+cos(sinPos))*waveheight,
                           vertMod.z-=cos(vertYpos*2.2-cos(sinPos))*waveheight);
    
    
    // Add wave animation only to vertices above world pos.y zero
    if(vertexPosition.y < 0.0){vertModCom = vertexPosition;}
    else{vertModCom = vertModCom;}
    
    vpos = vertModCom;
    
    // Calculate vertex position in clip coordinates
    POSITION = mvp * vec4(vertModCom, 1.0);
    

    }

    1 Reply Last reply
    0
    • R Offline
      R Offline
      Rena Brown
      wrote on 16 Apr 2023, 06:22 last edited by
      #2

      The errors you are encountering suggest that there is a problem with the location attribute in your vertex shader. In OpenGL, the location attribute specifies the index of a vertex attribute in the shader program, and it should be unique for each attribute.

      In your case, it seems that two vertex attributes are using the same location (location 16), which is causing the conflict. To resolve this issue, you should check your vertex shader code and ensure that each attribute has a unique location specified.

      One way to do this is to explicitly specify the location for each attribute in the shader code, like this:

      layout(location = 0) in vec3 vertexPosition;
      layout(location = 1) in vec3 vertexNormal;
      layout(location = 2) in vec2 vertexTexCoord;
      layout(location = 3) in vec4 vertexTangent;

      Then, you should update your QtDesign code to match the specified locations for each vertex attribute in the shader.

      If the issue persists, you could also try checking if there are any conflicting locations specified in the QtDesign Studio UI.

      Also, you may want to ensure that you are using the correct version of the shader language in your shader code. The code you provided uses version 330 core, which should work for most modern OpenGL implementations.

      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