Replace basicmaterial nodes by NZSL source
This commit is contained in:
parent
7cd772a254
commit
428a706fbe
|
|
@ -8,6 +8,8 @@
|
||||||
#include <Nazara/Graphics/PredefinedShaderStructs.hpp>
|
#include <Nazara/Graphics/PredefinedShaderStructs.hpp>
|
||||||
#include <Nazara/Graphics/UberShader.hpp>
|
#include <Nazara/Graphics/UberShader.hpp>
|
||||||
#include <Nazara/Renderer/Renderer.hpp>
|
#include <Nazara/Renderer/Renderer.hpp>
|
||||||
|
#include <Nazara/Shader/ShaderLangLexer.hpp>
|
||||||
|
#include <Nazara/Shader/ShaderLangParser.hpp>
|
||||||
#include <Nazara/Shader/Ast/AstSerializer.hpp>
|
#include <Nazara/Shader/Ast/AstSerializer.hpp>
|
||||||
#include <Nazara/Utility/BufferMapper.hpp>
|
#include <Nazara/Utility/BufferMapper.hpp>
|
||||||
#include <Nazara/Utility/FieldOffsets.hpp>
|
#include <Nazara/Utility/FieldOffsets.hpp>
|
||||||
|
|
@ -19,12 +21,8 @@ namespace Nz
|
||||||
{
|
{
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
const UInt8 r_fragmentShader[] = {
|
const UInt8 r_shader[] = {
|
||||||
#include <Nazara/Graphics/Resources/Shaders/basicmaterial.frag.shader.h>
|
#include <Nazara/Graphics/Resources/Shaders/basicmaterial.nzsl.h>
|
||||||
};
|
|
||||||
|
|
||||||
const UInt8 r_vertexShader[] = {
|
|
||||||
#include <Nazara/Graphics/Resources/Shaders/basicmaterial.vert.shader.h>
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -151,8 +149,10 @@ namespace Nz
|
||||||
auto& fragmentShader = settings.shaders[UnderlyingCast(ShaderStageType::Fragment)];
|
auto& fragmentShader = settings.shaders[UnderlyingCast(ShaderStageType::Fragment)];
|
||||||
auto& vertexShader = settings.shaders[UnderlyingCast(ShaderStageType::Vertex)];
|
auto& vertexShader = settings.shaders[UnderlyingCast(ShaderStageType::Vertex)];
|
||||||
|
|
||||||
fragmentShader = std::make_shared<UberShader>(ShaderStageType::Fragment, ShaderAst::UnserializeShader(r_fragmentShader, sizeof(r_fragmentShader)));
|
ShaderAst::StatementPtr shaderAst = ShaderLang::Parse(std::string_view(reinterpret_cast<const char*>(r_shader), sizeof(r_shader)));
|
||||||
vertexShader = std::make_shared<UberShader>(ShaderStageType::Vertex, ShaderAst::UnserializeShader(r_vertexShader, sizeof(r_vertexShader)));
|
|
||||||
|
fragmentShader = std::make_shared<UberShader>(ShaderStageType::Fragment, shaderAst);
|
||||||
|
vertexShader = std::make_shared<UberShader>(ShaderStageType::Vertex, shaderAst);
|
||||||
|
|
||||||
// Conditions
|
// Conditions
|
||||||
|
|
||||||
|
|
|
||||||
Binary file not shown.
File diff suppressed because one or more lines are too long
|
|
@ -0,0 +1,88 @@
|
||||||
|
option HAS_DIFFUSE_TEXTURE: bool;
|
||||||
|
option HAS_ALPHA_TEXTURE: bool;
|
||||||
|
option ALPHA_TEST: bool;
|
||||||
|
|
||||||
|
[layout(std140)]
|
||||||
|
struct BasicSettings
|
||||||
|
{
|
||||||
|
AlphaThreshold: f32,
|
||||||
|
DiffuseColor: vec4<f32>
|
||||||
|
}
|
||||||
|
|
||||||
|
[layout(std140)]
|
||||||
|
struct InstanceData
|
||||||
|
{
|
||||||
|
worldMatrix: mat4<f32>,
|
||||||
|
invWorldMatrix: mat4<f32>
|
||||||
|
}
|
||||||
|
|
||||||
|
[layout(std140)]
|
||||||
|
struct ViewerData
|
||||||
|
{
|
||||||
|
projectionMatrix: mat4<f32>,
|
||||||
|
invProjectionMatrix: mat4<f32>,
|
||||||
|
viewMatrix: mat4<f32>,
|
||||||
|
invViewMatrix: mat4<f32>,
|
||||||
|
viewProjMatrix: mat4<f32>,
|
||||||
|
invViewProjMatrix: mat4<f32>,
|
||||||
|
renderTargetSize: vec2<f32>,
|
||||||
|
invRenderTargetSize: vec2<f32>,
|
||||||
|
eyePosition: vec3<f32>
|
||||||
|
}
|
||||||
|
|
||||||
|
external
|
||||||
|
{
|
||||||
|
[set(0), binding(0)] viewerData: uniform<ViewerData>,
|
||||||
|
[set(1), binding(0)] instanceData: uniform<InstanceData>,
|
||||||
|
[set(2), binding(0)] settings: uniform<BasicSettings>,
|
||||||
|
[set(2), binding(2)] MaterialAlphaMap: sampler2D<f32>,
|
||||||
|
[set(2), binding(1)] MaterialDiffuseMap: sampler2D<f32>
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fragment stage
|
||||||
|
struct FragIn
|
||||||
|
{
|
||||||
|
[location(0)] uv: vec2<f32>
|
||||||
|
}
|
||||||
|
|
||||||
|
struct FragOut
|
||||||
|
{
|
||||||
|
[location(0)] RenderTarget0: vec4<f32>
|
||||||
|
}
|
||||||
|
|
||||||
|
[entry(frag)]
|
||||||
|
fn main(input: FragIn) -> FragOut
|
||||||
|
{
|
||||||
|
let output: FragOut;
|
||||||
|
let diffuseColor = select_opt(HAS_DIFFUSE_TEXTURE, MaterialDiffuseMap.Sample(input.uv) * settings.DiffuseColor, settings.DiffuseColor);
|
||||||
|
let diffuseColor = select_opt(HAS_ALPHA_TEXTURE, vec4<f32>(diffuseColor.x, diffuseColor.y, diffuseColor.z, ((MaterialAlphaMap.Sample(input.uv)).x) * diffuseColor.w), diffuseColor);
|
||||||
|
|
||||||
|
if (select_opt(ALPHA_TEST, diffuseColor.w < settings.AlphaThreshold, false))
|
||||||
|
discard;
|
||||||
|
|
||||||
|
output.RenderTarget0 = diffuseColor;
|
||||||
|
return output;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Vertex stage
|
||||||
|
struct VertIn
|
||||||
|
{
|
||||||
|
[location(0)] pos: vec3<f32>,
|
||||||
|
[location(1)] uv: vec2<f32>
|
||||||
|
}
|
||||||
|
|
||||||
|
struct VertOut
|
||||||
|
{
|
||||||
|
[location(0)] uv: vec2<f32>,
|
||||||
|
[builtin(position)] position: vec4<f32>
|
||||||
|
}
|
||||||
|
|
||||||
|
[entry(vert)]
|
||||||
|
fn main(input: VertIn) -> VertOut
|
||||||
|
{
|
||||||
|
let output: VertOut;
|
||||||
|
output.uv = input.uv;
|
||||||
|
output.position = viewerData.projectionMatrix * viewerData.viewMatrix * instanceData.worldMatrix * vec4<f32>(input.pos, 1.0);
|
||||||
|
|
||||||
|
return output;
|
||||||
|
}
|
||||||
File diff suppressed because one or more lines are too long
|
|
@ -0,0 +1,55 @@
|
||||||
|
[layout(std140)]
|
||||||
|
struct BasicSettings
|
||||||
|
{
|
||||||
|
AlphaThreshold: f32,
|
||||||
|
DiffuseColor: vec4<f32>
|
||||||
|
}
|
||||||
|
|
||||||
|
[layout(std140)]
|
||||||
|
struct InstanceData
|
||||||
|
{
|
||||||
|
worldMatrix: mat4<f32>,
|
||||||
|
invWorldMatrix: mat4<f32>
|
||||||
|
}
|
||||||
|
|
||||||
|
[layout(std140)]
|
||||||
|
struct ViewerData
|
||||||
|
{
|
||||||
|
projectionMatrix: mat4<f32>,
|
||||||
|
invProjectionMatrix: mat4<f32>,
|
||||||
|
viewMatrix: mat4<f32>,
|
||||||
|
invViewMatrix: mat4<f32>,
|
||||||
|
viewProjMatrix: mat4<f32>,
|
||||||
|
invViewProjMatrix: mat4<f32>,
|
||||||
|
renderTargetSize: vec2<f32>,
|
||||||
|
invRenderTargetSize: vec2<f32>,
|
||||||
|
eyePosition: vec3<f32>
|
||||||
|
}
|
||||||
|
|
||||||
|
external
|
||||||
|
{
|
||||||
|
[set(0), binding(0)] viewerData: uniform<ViewerData>,
|
||||||
|
[set(1), binding(0)] instanceData: uniform<InstanceData>,
|
||||||
|
[set(2), binding(0)] settings: uniform<BasicSettings>
|
||||||
|
}
|
||||||
|
|
||||||
|
struct InputData
|
||||||
|
{
|
||||||
|
[location(0)] inPos: vec3<f32>,
|
||||||
|
[location(1)] inTexCoord: vec2<f32>
|
||||||
|
}
|
||||||
|
|
||||||
|
struct OutputData
|
||||||
|
{
|
||||||
|
[location(0)] vertUV: vec2<f32>,
|
||||||
|
[builtin(position)] position: vec4<f32>
|
||||||
|
}
|
||||||
|
|
||||||
|
[entry(vert)]
|
||||||
|
fn main(input: InputData) -> OutputData
|
||||||
|
{
|
||||||
|
let output: OutputData;
|
||||||
|
output.vertUV = input.inTexCoord;
|
||||||
|
output.position = ((viewerData.projectionMatrix * viewerData.viewMatrix) * instanceData.worldMatrix) * (vec4<f32>(input.inPos, 1.000000));
|
||||||
|
return output;
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1 @@
|
||||||
|
91,108,97,121,111,117,116,40,115,116,100,49,52,48,41,93,10,115,116,114,117,99,116,32,66,97,115,105,99,83,101,116,116,105,110,103,115,10,123,10,9,65,108,112,104,97,84,104,114,101,115,104,111,108,100,58,32,102,51,50,44,10,9,68,105,102,102,117,115,101,67,111,108,111,114,58,32,118,101,99,52,60,102,51,50,62,10,125,10,10,91,108,97,121,111,117,116,40,115,116,100,49,52,48,41,93,10,115,116,114,117,99,116,32,73,110,115,116,97,110,99,101,68,97,116,97,10,123,10,9,119,111,114,108,100,77,97,116,114,105,120,58,32,109,97,116,52,60,102,51,50,62,44,10,9,105,110,118,87,111,114,108,100,77,97,116,114,105,120,58,32,109,97,116,52,60,102,51,50,62,10,125,10,10,91,108,97,121,111,117,116,40,115,116,100,49,52,48,41,93,10,115,116,114,117,99,116,32,86,105,101,119,101,114,68,97,116,97,10,123,10,9,112,114,111,106,101,99,116,105,111,110,77,97,116,114,105,120,58,32,109,97,116,52,60,102,51,50,62,44,10,9,105,110,118,80,114,111,106,101,99,116,105,111,110,77,97,116,114,105,120,58,32,109,97,116,52,60,102,51,50,62,44,10,9,118,105,101,119,77,97,116,114,105,120,58,32,109,97,116,52,60,102,51,50,62,44,10,9,105,110,118,86,105,101,119,77,97,116,114,105,120,58,32,109,97,116,52,60,102,51,50,62,44,10,9,118,105,101,119,80,114,111,106,77,97,116,114,105,120,58,32,109,97,116,52,60,102,51,50,62,44,10,9,105,110,118,86,105,101,119,80,114,111,106,77,97,116,114,105,120,58,32,109,97,116,52,60,102,51,50,62,44,10,9,114,101,110,100,101,114,84,97,114,103,101,116,83,105,122,101,58,32,118,101,99,50,60,102,51,50,62,44,10,9,105,110,118,82,101,110,100,101,114,84,97,114,103,101,116,83,105,122,101,58,32,118,101,99,50,60,102,51,50,62,44,10,9,101,121,101,80,111,115,105,116,105,111,110,58,32,118,101,99,51,60,102,51,50,62,10,125,10,10,101,120,116,101,114,110,97,108,10,123,10,9,91,115,101,116,40,48,41,44,32,98,105,110,100,105,110,103,40,48,41,93,32,118,105,101,119,101,114,68,97,116,97,58,32,117,110,105,102,111,114,109,60,86,105,101,119,101,114,68,97,116,97,62,44,10,9,91,115,101,116,40,49,41,44,32,98,105,110,100,105,110,103,40,48,41,93,32,105,110,115,116,97,110,99,101,68,97,116,97,58,32,117,110,105,102,111,114,109,60,73,110,115,116,97,110,99,101,68,97,116,97,62,44,10,9,91,115,101,116,40,50,41,44,32,98,105,110,100,105,110,103,40,48,41,93,32,115,101,116,116,105,110,103,115,58,32,117,110,105,102,111,114,109,60,66,97,115,105,99,83,101,116,116,105,110,103,115,62,10,125,10,10,115,116,114,117,99,116,32,73,110,112,117,116,68,97,116,97,10,123,10,9,91,108,111,99,97,116,105,111,110,40,48,41,93,32,105,110,80,111,115,58,32,118,101,99,51,60,102,51,50,62,44,10,9,91,108,111,99,97,116,105,111,110,40,49,41,93,32,105,110,84,101,120,67,111,111,114,100,58,32,118,101,99,50,60,102,51,50,62,10,125,10,10,115,116,114,117,99,116,32,79,117,116,112,117,116,68,97,116,97,10,123,10,9,91,108,111,99,97,116,105,111,110,40,48,41,93,32,118,101,114,116,85,86,58,32,118,101,99,50,60,102,51,50,62,44,10,9,91,98,117,105,108,116,105,110,40,112,111,115,105,116,105,111,110,41,93,32,112,111,115,105,116,105,111,110,58,32,118,101,99,52,60,102,51,50,62,10,125,10,10,91,101,110,116,114,121,40,118,101,114,116,41,93,10,102,110,32,109,97,105,110,40,105,110,112,117,116,58,32,73,110,112,117,116,68,97,116,97,41,32,45,62,32,79,117,116,112,117,116,68,97,116,97,10,123,10,9,108,101,116,32,111,117,116,112,117,116,58,32,79,117,116,112,117,116,68,97,116,97,59,10,9,111,117,116,112,117,116,46,118,101,114,116,85,86,32,61,32,105,110,112,117,116,46,105,110,84,101,120,67,111,111,114,100,59,10,9,111,117,116,112,117,116,46,112,111,115,105,116,105,111,110,32,61,32,40,40,118,105,101,119,101,114,68,97,116,97,46,112,114,111,106,101,99,116,105,111,110,77,97,116,114,105,120,32,42,32,118,105,101,119,101,114,68,97,116,97,46,118,105,101,119,77,97,116,114,105,120,41,32,42,32,105,110,115,116,97,110,99,101,68,97,116,97,46,119,111,114,108,100,77,97,116,114,105,120,41,32,42,32,40,118,101,99,52,60,102,51,50,62,40,105,110,112,117,116,46,105,110,80,111,115,44,32,49,46,48,48,48,48,48,48,41,41,59,10,9,114,101,116,117,114,110,32,111,117,116,112,117,116,59,10,125,10,
|
||||||
Binary file not shown.
|
|
@ -1 +0,0 @@
|
||||||
78,83,72,82,0,0,0,1,0,0,0,24,0,0,0,7,0,0,0,20,0,0,0,0,13,66,97,115,105,99,83,101,116,116,105,110,103,115,1,0,0,0,1,0,0,0,2,0,0,0,14,65,108,112,104,97,84,104,114,101,115,104,111,108,100,1,0,0,0,1,0,0,0,0,12,68,105,102,102,117,115,101,67,111,108,111,114,7,0,0,0,4,0,0,0,1,0,0,0,0,20,0,0,0,0,12,73,110,115,116,97,110,99,101,68,97,116,97,1,0,0,0,1,0,0,0,2,0,0,0,11,119,111,114,108,100,77,97,116,114,105,120,3,0,0,0,4,0,0,0,4,0,0,0,1,0,0,0,0,14,105,110,118,87,111,114,108,100,77,97,116,114,105,120,3,0,0,0,4,0,0,0,4,0,0,0,1,0,0,0,0,20,0,0,0,0,10,86,105,101,119,101,114,68,97,116,97,1,0,0,0,1,0,0,0,9,0,0,0,16,112,114,111,106,101,99,116,105,111,110,77,97,116,114,105,120,3,0,0,0,4,0,0,0,4,0,0,0,1,0,0,0,0,19,105,110,118,80,114,111,106,101,99,116,105,111,110,77,97,116,114,105,120,3,0,0,0,4,0,0,0,4,0,0,0,1,0,0,0,0,10,118,105,101,119,77,97,116,114,105,120,3,0,0,0,4,0,0,0,4,0,0,0,1,0,0,0,0,13,105,110,118,86,105,101,119,77,97,116,114,105,120,3,0,0,0,4,0,0,0,4,0,0,0,1,0,0,0,0,14,118,105,101,119,80,114,111,106,77,97,116,114,105,120,3,0,0,0,4,0,0,0,4,0,0,0,1,0,0,0,0,17,105,110,118,86,105,101,119,80,114,111,106,77,97,116,114,105,120,3,0,0,0,4,0,0,0,4,0,0,0,1,0,0,0,0,16,114,101,110,100,101,114,84,97,114,103,101,116,83,105,122,101,7,0,0,0,2,0,0,0,1,0,0,0,0,19,105,110,118,82,101,110,100,101,114,84,97,114,103,101,116,83,105,122,101,7,0,0,0,2,0,0,0,1,0,0,0,0,11,101,121,101,80,111,115,105,116,105,111,110,7,0,0,0,3,0,0,0,1,0,0,0,0,17,0,0,0,0,3,0,0,0,10,118,105,101,119,101,114,68,97,116,97,6,0,0,0,10,86,105,101,119,101,114,68,97,116,97,1,0,0,0,0,1,0,0,0,0,0,0,0,12,105,110,115,116,97,110,99,101,68,97,116,97,6,0,0,0,12,73,110,115,116,97,110,99,101,68,97,116,97,1,0,0,0,0,1,0,0,0,1,0,0,0,8,115,101,116,116,105,110,103,115,6,0,0,0,13,66,97,115,105,99,83,101,116,116,105,110,103,115,1,0,0,0,0,1,0,0,0,2,0,0,0,20,0,0,0,0,9,73,110,112,117,116,68,97,116,97,0,0,0,0,2,0,0,0,8,112,111,115,105,116,105,111,110,7,0,0,0,3,0,0,0,1,2,0,0,0,0,0,0,0,9,116,101,120,67,111,111,114,100,115,7,0,0,0,2,0,0,0,1,2,0,0,0,1,0,0,0,20,0,0,0,0,10,79,117,116,112,117,116,68,97,116,97,0,0,0,0,2,0,0,0,6,118,101,114,116,85,86,7,0,0,0,2,0,0,0,1,2,0,0,0,0,0,0,0,8,112,111,115,105,116,105,111,110,7,0,0,0,4,0,0,0,1,1,0,0,0,0,0,0,0,0,18,0,0,0,4,109,97,105,110,2,0,0,0,10,79,117,116,112,117,116,68,97,116,97,4,0,0,0,1,0,0,0,0,0,0,0,0,0,1,0,0,0,5,105,110,112,117,116,2,0,0,0,9,73,110,112,117,116,68,97,116,97,0,0,0,4,0,0,0,21,0,0,0,0,6,111,117,116,112,117,116,2,0,0,0,10,79,117,116,112,117,116,68,97,116,97,255,255,255,255,0,0,0,23,0,0,0,2,0,0,0,0,0,0,0,0,0,0,0,9,0,0,0,6,111,117,116,112,117,116,0,0,0,1,0,0,0,6,118,101,114,116,85,86,0,0,0,0,0,0,0,9,0,0,0,5,105,110,112,117,116,0,0,0,1,0,0,0,9,116,101,120,67,111,111,114,100,115,0,0,0,23,0,0,0,2,0,0,0,0,0,0,0,0,0,0,0,9,0,0,0,6,111,117,116,112,117,116,0,0,0,1,0,0,0,8,112,111,115,105,116,105,111,110,0,0,0,3,0,0,0,2,0,0,0,3,0,0,0,2,0,0,0,0,0,0,0,9,0,0,0,10,118,105,101,119,101,114,68,97,116,97,0,0,0,1,0,0,0,14,118,105,101,119,80,114,111,106,77,97,116,114,105,120,0,0,0,0,0,0,0,9,0,0,0,12,105,110,115,116,97,110,99,101,68,97,116,97,0,0,0,1,0,0,0,11,119,111,114,108,100,77,97,116,114,105,120,0,0,0,6,7,0,0,0,4,0,0,0,1,0,0,0,0,0,0,0,9,0,0,0,5,105,110,112,117,116,0,0,0,1,0,0,0,8,112,111,115,105,116,105,111,110,0,0,0,8,0,0,0,1,63,128,0,0,255,255,255,255,255,255,255,255,0,0,0,26,0,0,0,9,0,0,0,6,111,117,116,112,117,116,0,0,16,112,114,111,106,101,99,116,105,111,110,77,97,116,114,105,120,0,0,0,0,0,0,0,9,0,0,0,10,118,105,101,119,101,114,68,97,116,97,0,0,0,1,0,0,0,10,118,105,101,119,77,97,116,114,105,120,0,0,0,0,0,0,0,9,0,0,0,12,105,110,115,116,97,110,99,101,68,97,116,97,0,0,0,1,0,0,0,11,119,111,114,108,100,77,97,116,114,105,120,0,0,0,6,7,0,0,0,4,0,0,0,1,0,0,0,0,0,0,0,9,0,0,0,5,105,110,112,117,116,0,0,0,1,0,0,0,5,105,110,80,111,115,0,0,0,8,0,0,0,1,63,128,0,0,255,255,255,255,255,255,255,255,0,0,0,26,0,0,0,9,0,0,0,6,111,117,116,112,117,116,
|
|
||||||
Loading…
Reference in New Issue