]> git.lizzy.rs Git - dragonfireclient.git/blob - src/client/shadows/shadowsScreenQuad.cpp
Shadow mapping render pass (#11244)
[dragonfireclient.git] / src / client / shadows / shadowsScreenQuad.cpp
1 /*
2 Minetest
3 Copyright (C) 2021 Liso <anlismon@gmail.com>
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as published by
7 the Free Software Foundation; either version 2.1 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 GNU Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public License along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19
20 #include "shadowsScreenQuad.h"
21
22 shadowScreenQuad::shadowScreenQuad()
23 {
24         Material.Wireframe = false;
25         Material.Lighting = false;
26
27         video::SColor color(0x0);
28         Vertices[0] = video::S3DVertex(
29                         -1.0f, -1.0f, 0.0f, 0, 0, 1, color, 0.0f, 1.0f);
30         Vertices[1] = video::S3DVertex(
31                         -1.0f, 1.0f, 0.0f, 0, 0, 1, color, 0.0f, 0.0f);
32         Vertices[2] = video::S3DVertex(
33                         1.0f, 1.0f, 0.0f, 0, 0, 1, color, 1.0f, 0.0f);
34         Vertices[3] = video::S3DVertex(
35                         1.0f, -1.0f, 0.0f, 0, 0, 1, color, 1.0f, 1.0f);
36         Vertices[4] = video::S3DVertex(
37                         -1.0f, -1.0f, 0.0f, 0, 0, 1, color, 0.0f, 1.0f);
38         Vertices[5] = video::S3DVertex(
39                         1.0f, 1.0f, 0.0f, 0, 0, 1, color, 1.0f, 0.0f);
40 }
41
42 void shadowScreenQuad::render(video::IVideoDriver *driver)
43 {
44         u16 indices[6] = {0, 1, 2, 3, 4, 5};
45         driver->setMaterial(Material);
46         driver->setTransform(video::ETS_WORLD, core::matrix4());
47         driver->drawIndexedTriangleList(&Vertices[0], 6, &indices[0], 2);
48 }
49
50 void shadowScreenQuadCB::OnSetConstants(
51                 video::IMaterialRendererServices *services, s32 userData)
52 {
53         s32 TextureId = 0;
54         services->setPixelShaderConstant(
55                 services->getPixelShaderConstantID("ShadowMapClientMap"),
56                 &TextureId, 1);
57
58         TextureId = 1;
59         services->setPixelShaderConstant(
60                 services->getPixelShaderConstantID("ShadowMapClientMapTraslucent"),
61                 &TextureId, 1);
62
63         TextureId = 2;
64         services->setPixelShaderConstant(
65                 services->getPixelShaderConstantID("ShadowMapSamplerdynamic"),
66                 &TextureId, 1);
67 }