-
Notifications
You must be signed in to change notification settings - Fork 0
/
SkyboxShader.hpp
77 lines (62 loc) · 1.37 KB
/
SkyboxShader.hpp
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
#pragma once
#include "Vertex.h"
#include "SceneContext.h"
#include "VertexShaderMatHelper.h"
#include <glm/glm.hpp>
#include <glm/gtc/matrix_transform.hpp>
#include <memory>
class SkyboxShader
{
public:
using UseDerivative = std::false_type;
struct VSOut {
glm::vec4 proj_pos;
glm::vec3 pos;
VSOut& operator+=(const VSOut& rhs)
{
proj_pos += rhs.proj_pos;
pos += rhs.pos;
return *this;
}
VSOut operator+(const VSOut& rhs) const
{
return VSOut(*this) += rhs;
}
VSOut& operator*=(float v) {
proj_pos *= v;
pos *= v;
return *this;
}
VSOut operator*(float rhs) const
{
return VSOut(*this) *= rhs;
}
void Lerp(const VSOut& v0, const VSOut& v1, const VSOut& v2, float a, float b, float c) noexcept {
pos = v0.pos * a + v1.pos * b + v2.pos * c;
}
};
class VertexShader : public VertexShaderMatHelper {
public:
VSOut operator()(const Vertex& v) const
{
glm::vec4 proj_pos = proj_view * glm::vec4(v.position, 0.0f);
proj_pos.z = proj_pos.w;
return {
proj_pos,
v.position
};
}
};
class PixelShader {
public:
std::shared_ptr<SceneContext> pContext;
glm::vec4 operator()(const VSOut& v, const VSOut& ddx, const VSOut& ddy, int modelId, int meshId) const
{
glm::vec4 color = pContext->skybox->Sample(v.pos.x, v.pos.y, v.pos.z);
return color;
}
};
public:
VertexShader vs;
PixelShader ps;
};