-
Notifications
You must be signed in to change notification settings - Fork 0
/
ShadowShader.hpp
85 lines (66 loc) · 1.63 KB
/
ShadowShader.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
77
78
79
80
81
82
83
84
#pragma once
#include "Vertex.h"
#include "SceneContext.h"
#include "VertexShaderMatHelper.h"
#include <glm/glm.hpp>
#include <glm/gtc/matrix_transform.hpp>
#include <memory>
class ShadowShader
{
public:
using UseDerivative = std::false_type;
struct VSOut {
glm::vec4 proj_pos;
VSOut& operator+=(const VSOut& rhs)
{
proj_pos += rhs.proj_pos;
return *this;
}
VSOut operator+(const VSOut& rhs) const
{
return VSOut(*this) += rhs;
}
VSOut& operator*=(float v) {
proj_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 {
}
};
class VertexShader : public VertexShaderMatHelper {
public:
glm::mat4 light_mvp;
VSOut operator()(const Vertex& v) const
{
return {
light_mvp * glm::vec4(v.position, 1.0f)
};
}
};
class PixelShader {
public:
std::shared_ptr<SceneContext> pContext;
// http://www.klayge.org/2013/08/27/%e6%8a%8afloat%e7%bc%96%e7%a0%81%e5%88%b0rgba8/
glm::vec4 EncodeFloatToRGBA(float v)
{
glm::vec4 ret = glm::vec4(1.0f, 255.0f, 65025.0f, 16581375.0f) * v;
ret = glm::fract(ret);
glm::vec4 t(ret.y, ret.z, ret.w, ret.w); // ret.yzww
ret -= t * glm::vec4(1 / 255.0f, 1 / 255.0f, 1 / 255.0f, 0);
return ret;
}
glm::vec4 operator()(const VSOut& v, const VSOut& ddx, const VSOut& ddy, int modelId, int meshId)
{
//std::cout << v.proj_pos.z << '\n';
return EncodeFloatToRGBA(v.proj_pos.z);
//return glm::vec4(glm::vec3(v.proj_pos.z), 1.0f);
}
};
public:
VertexShader vs;
PixelShader ps;
};