summaryrefslogtreecommitdiffstats
path: root/src/Runtime/Source/Qt3DSRuntimeRender/Include/Qt3DSRenderMaterialShaderGenerator.h
blob: e8b9880d2197b08b6f6703f754f64b311948baec (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
/****************************************************************************
**
** Copyright (C) 2008-2012 NVIDIA Corporation.
** Copyright (C) 2017 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of Qt 3D Studio.
**
** $QT_BEGIN_LICENSE:GPL$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 or (at your option) any later version
** approved by the KDE Free Qt Foundation. The licenses are as published by
** the Free Software Foundation and appearing in the file LICENSE.GPL3
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
**
** $QT_END_LICENSE$
**
****************************************************************************/
#pragma once
#ifndef QT3DS_RENDER_MATERIAL_SHADER_GENERATOR_H
#define QT3DS_RENDER_MATERIAL_SHADER_GENERATOR_H
#include "Qt3DSRender.h"
#include "foundation/Qt3DSRefCounted.h"
#include "Qt3DSRenderShaderKeys.h"
#include "Qt3DSRenderShaderCache.h"
#include "Qt3DSRenderShaderCodeGeneratorV2.h"

namespace qt3ds {
namespace render {

// these are our current shader limits
#define QT3DS_MAX_NUM_LIGHTS 16
#define QT3DS_MAX_NUM_SHADOWS 8

    // note this struct must exactly match the memory layout of the
    // struct sampleLight.glsllib and sampleArea.glsllib. If you make changes here you need
    // to adjust the code in sampleLight.glsllib and sampleArea.glsllib as well
    struct SLightSourceShader
    {
        QT3DSVec4 m_position;
        QT3DSVec4 m_direction; // Specifies the light direction in world coordinates.
        QT3DSVec4 m_up;
        QT3DSVec4 m_right;
        QT3DSVec4 m_diffuse;
        QT3DSVec4 m_ambient;
        QT3DSVec4 m_specular;
        QT3DSF32 m_spotExponent; // Specifies the intensity distribution of the light.
        QT3DSF32 m_spotCutoff; // Specifies the maximum spread angle of the light.
        QT3DSF32 m_constantAttenuation; // Specifies the constant light attenuation factor.
        QT3DSF32 m_linearAttenuation; // Specifies the linear light attenuation factor.
        QT3DSF32 m_quadraticAttenuation; // Specifies the quadratic light attenuation factor.
        QT3DSF32 m_range; // Specifies the maximum distance of the light influence
        QT3DSF32 m_width; // Specifies the width of the area light surface.
        QT3DSF32 m_height; // Specifies the height of the area light surface;
        QT3DSVec4 m_shadowControls;
        QT3DSMat44 m_shadowView;
        QT3DSI32 m_shadowIdx;
        QT3DSF32 m_padding1[3];
    };

    struct SLayerGlobalRenderProperties
    {
        const SLayer &m_Layer;
        SCamera &m_Camera;
        QT3DSVec3 m_CameraDirection;
        NVDataRef<SLight *> m_Lights;
        NVDataRef<QT3DSVec3> m_LightDirections;
        Qt3DSShadowMap *m_ShadowMapManager;
        NVRenderTexture2D *m_DepthTexture;
        NVRenderTexture2D *m_SSaoTexture;
        SImage *m_LightProbe;
        SImage *m_LightProbe2;
        QT3DSF32 m_ProbeHorizon;
        QT3DSF32 m_ProbeBright;
        QT3DSF32 m_Probe2Window;
        QT3DSF32 m_Probe2Pos;
        QT3DSF32 m_Probe2Fade;
        QT3DSF32 m_ProbeFOV;

        SLayerGlobalRenderProperties(const SLayer &inLayer, SCamera &inCamera,
                                     QT3DSVec3 inCameraDirection, NVDataRef<SLight *> inLights,
                                     NVDataRef<QT3DSVec3> inLightDirections,
                                     Qt3DSShadowMap *inShadowMapManager,
                                     NVRenderTexture2D *inDepthTexture,
                                     NVRenderTexture2D *inSSaoTexture, SImage *inLightProbe,
                                     SImage *inLightProbe2, QT3DSF32 inProbeHorizon,
                                     QT3DSF32 inProbeBright, QT3DSF32 inProbe2Window, QT3DSF32 inProbe2Pos,
                                     QT3DSF32 inProbe2Fade, QT3DSF32 inProbeFOV)
            : m_Layer(inLayer)
            , m_Camera(inCamera)
            , m_CameraDirection(inCameraDirection)
            , m_Lights(inLights)
            , m_LightDirections(inLightDirections)
            , m_ShadowMapManager(inShadowMapManager)
            , m_DepthTexture(inDepthTexture)
            , m_SSaoTexture(inSSaoTexture)
            , m_LightProbe(inLightProbe)
            , m_LightProbe2(inLightProbe2)
            , m_ProbeHorizon(inProbeHorizon)
            , m_ProbeBright(inProbeBright)
            , m_Probe2Window(inProbe2Window)
            , m_Probe2Pos(inProbe2Pos)
            , m_Probe2Fade(inProbe2Fade)
            , m_ProbeFOV(inProbeFOV)
        {
        }
    };

    class IMaterialShaderGenerator : public NVRefCounted
    {
    public:
        struct SImageVariableNames
        {
            const char8_t *m_ImageSampler;
            const char8_t *m_ImageFragCoords;
        };

        virtual SImageVariableNames GetImageVariableNames(QT3DSU32 inIdx) = 0;
        virtual void GenerateImageUVCoordinates(IShaderStageGenerator &inVertexPipeline, QT3DSU32 idx,
                                                QT3DSU32 uvSet, SRenderableImage &image) = 0;

        // inPipelineName needs to be unique else the shader cache will just return shaders from
        // different pipelines.
        virtual NVRenderShaderProgram *GenerateShader(
            const SGraphObject &inMaterial, SShaderDefaultMaterialKey inShaderDescription,
            IShaderStageGenerator &inVertexPipeline, TShaderFeatureSet inFeatureSet,
            NVDataRef<SLight *> inLights, SRenderableImage *inFirstImage, bool inHasTransparency,
            const char8_t *inVertexPipelineName, const char8_t *inCustomMaterialName = "") = 0;

        // Also sets the blend function on the render context.
        virtual void
        SetMaterialProperties(NVRenderShaderProgram &inProgram, const SGraphObject &inMaterial,
                              const QT3DSVec2 &inCameraVec, const QT3DSMat44 &inModelViewProjection,
                              const QT3DSMat33 &inNormalMatrix, const QT3DSMat44 &inGlobalTransform,
                              SRenderableImage *inFirstImage, QT3DSF32 inOpacity,
                              SLayerGlobalRenderProperties inRenderProperties) = 0;
    };
}
}

#endif