|
virtual std::string | GetTypeName () const override |
|
virtual void | SetID (uint32_t newID) override |
|
virtual void | SetName (std::string newName) override |
|
| WShader (class Wasabi *const app, uint32_t ID=0) |
|
virtual void | Load (bool bSaveData=false) |
|
virtual bool | Valid () const override |
|
virtual WError | SaveToStream (WFile *file, std::ostream &outputStream) override |
|
virtual WError | LoadFromStream (WFile *file, std::istream &inputStream, std::vector< void * > &args, std::string nameSuffix) override |
|
| WFileAsset (class Wasabi *const app, uint32_t ID=0) |
|
virtual WError | LoadFromStream (class WFile *file, std::istream &inputStream, vector< void * > &args, std::string nameSuffix)=0 |
|
| WBase (class Wasabi *const app, uint32_t ID=0) |
|
uint32_t | GetID () const |
|
std::string | GetName () const |
|
class Wasabi * | GetAppPtr () const |
|
void | AddReference () |
|
void | RemoveReference () |
|
Encapsulation of a shader object. A shader is a small program bound to the graphics (or compute) Vulkan pipelines that does its work on the GPU.
To create a WShader, one must define a child class which implements WShader::Load(). The load function needs to fill in the m_desc and m_module protected variables. m_module is automatically filled by a call to one of the LoadCode* functions (which needs to be called during the Load() call). The m_desc structure should be initialized to describe the shader and the resources that can/need to be bound to it.
Examples:
Creating a simple vertex shader type that is compatible with the default vertex layout of Wasabi (see WDefaultVertex).
public:
virtual void Load(
bool bSaveData =
false) {
}),
};
})};
"#version 450\n"
""
"#extension GL_ARB_separate_shader_objects : enable\n"
"#extension GL_ARB_shading_language_420pack : enable\n"
""
"layout(location = 0) in vec3 inPos;\n"
"layout(location = 1) in vec3 inTang;\n"
"layout(location = 2) in vec3 inNorm;\n"
"layout(location = 3) in vec2 inUV;\n"
""
"layout(binding = 0) uniform UBO {\n"
" mat4 projectionMatrix;\n"
" mat4 modelMatrix;\n"
" mat4 viewMatrix;\n"
"} ubo;\n"
""
"layout(location = 0) out vec2 outUV;\n"
""
"void main() {\n"
" outUV = inUV;\n"
" gl_Position = ubo.projectionMatrix * \n"
" ubo.viewMatrix * \n"
" ubo.modelMatrix * \n"
" vec4(outWorldPos, 1.0);\n"
"}\n"
, bSaveData);
}
};
Simple pixel (or fragment) shader, compatible with the above vertex shader:
public:
virtual void Load(
bool bSaveData =
false) {
"#version 450\n"
""
"#extension GL_ARB_separate_shader_objects : enable\n"
"#extension GL_ARB_shading_language_420pack : enable\n"
""
"layout(location = 0) in vec2 inUV;\n"
""
"layout(location = 0) out vec4 outFragColor;\n"
""
"void main() {\n"
" outFragColor = vec4(inUV.x, inUV.y, 0, 1);\n"
"}\n"
, bSaveData);
}
};
Using the above shaders to create an effect: