Plasma Engine  2.0
Loading...
Searching...
No Matches
ShaderUtils.h
1#pragma once
2
3#include <RendererFoundation/RendererFoundationDLL.h>
4
5#include <Foundation/Math/Float16.h>
6#include <Foundation/Math/Vec2.h>
7#include <Foundation/Math/Vec3.h>
8
10{
11public:
12 PL_ALWAYS_INLINE static plUInt32 Float3ToRGB10(plVec3 value)
13 {
14 const plVec3 unsignedValue = value * 0.5f + plVec3(0.5f);
15
16 const plUInt32 r = plMath::Clamp(static_cast<plUInt32>(unsignedValue.x * 1023.0f + 0.5f), 0u, 1023u);
17 const plUInt32 g = plMath::Clamp(static_cast<plUInt32>(unsignedValue.y * 1023.0f + 0.5f), 0u, 1023u);
18 const plUInt32 b = plMath::Clamp(static_cast<plUInt32>(unsignedValue.z * 1023.0f + 0.5f), 0u, 1023u);
19
20 return r | (g << 10) | (b << 20);
21 }
22
23 PL_ALWAYS_INLINE static plUInt32 PackFloat16intoUint(plFloat16 x, plFloat16 y)
24 {
25 const plUInt32 r = x.GetRawData();
26 const plUInt32 g = y.GetRawData();
27
28 return r | (g << 16);
29 }
30
31 PL_ALWAYS_INLINE static plUInt32 Float2ToRG16F(plVec2 value)
32 {
33 const plUInt32 r = plFloat16(value.x).GetRawData();
34 const plUInt32 g = plFloat16(value.y).GetRawData();
35
36 return r | (g << 16);
37 }
38
39 PL_ALWAYS_INLINE static void Float4ToRGBA16F(plVec4 value, plUInt32& out_uiRG, plUInt32& out_uiBA)
40 {
41 out_uiRG = Float2ToRG16F(plVec2(value.x, value.y));
42 out_uiBA = Float2ToRG16F(plVec2(value.z, value.w));
43 }
44
45 enum class plBuiltinShaderType
46 {
47 CopyImage,
48 CopyImageArray,
49 DownscaleImage,
50 DownscaleImageArray,
51 };
52
54 {
55 plGALShaderHandle m_hActiveGALShader;
56 plGALBlendStateHandle m_hBlendState;
57 plGALDepthStencilStateHandle m_hDepthStencilState;
58 plGALRasterizerStateHandle m_hRasterizerState;
59 };
60
61 PL_RENDERERFOUNDATION_DLL static plDelegate<void(plBuiltinShaderType type, plBuiltinShader& out_shader)> g_RequestBuiltinShaderCallback;
62
63 PL_ALWAYS_INLINE static void RequestBuiltinShader(plBuiltinShaderType type, plBuiltinShader& out_shader)
64 {
65 g_RequestBuiltinShaderCallback(type, out_shader);
66 }
67};
68PL_DEFINE_AS_POD_TYPE(plShaderUtils::plBuiltinShaderType);
A 16 bit IEEE float class. Often called "half".
Definition Float16.h:11
plUInt16 GetRawData() const
Returns the raw 16 Bit data.
Definition Float16.h:29
Definition RendererFoundationDLL.h:467
Definition RendererFoundationDLL.h:460
Definition RendererFoundationDLL.h:474
Definition RendererFoundationDLL.h:404
Definition ShaderUtils.h:10
constexpr PL_ALWAYS_INLINE T Clamp(T value, T min_val, T max_val)
Clamps "value" to the range [min; max]. Returns "value", if it is inside the range already.
Definition Math_inl.h:51
A generic delegate class which supports static functions and member functions.
Definition Delegate.h:76
Definition ShaderUtils.h:54