brought back functionality from previous builds but now cross-platform
This commit is contained in:
1
funnyassets/gfx_shaders/mesh_bindings.h
Normal file
1
funnyassets/gfx_shaders/mesh_bindings.h
Normal file
@@ -0,0 +1 @@
|
||||
#include "shader_base.h"
|
||||
@@ -1,23 +1,12 @@
|
||||
#include "mesh_shared.slang"
|
||||
|
||||
uint32_t hash32(uint32_t x) {
|
||||
x = ((x >> 16) ^ x) * 0x45d9f3b;
|
||||
x = ((x >> 16) ^ x) * 0x45d9f3b;
|
||||
x = (x >> 16) ^ x;
|
||||
return x;
|
||||
}
|
||||
|
||||
[[vk::binding(1)]]
|
||||
uniform Sampler2D textures[];
|
||||
|
||||
[shader("fragment")]
|
||||
float4 main(
|
||||
float4 _main(
|
||||
VertexOutput input,
|
||||
uint triid: SV_PrimitiveID,
|
||||
uniform PushConstants constants,
|
||||
) : SV_TARGET
|
||||
{
|
||||
return float4(textures[constants.albedoID].Sample(input.uv).xyz, 1);
|
||||
|
||||
return float4(SampleTexture(albedoID, input.uv).xyz,1);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#pragma once
|
||||
#include "shader_base.h"
|
||||
|
||||
struct VertexOutput
|
||||
{
|
||||
@@ -6,10 +7,17 @@ struct VertexOutput
|
||||
float2 uv: TEXCOORD0;
|
||||
};
|
||||
|
||||
struct PushConstants
|
||||
DECLARE_CONSTANTS()
|
||||
{
|
||||
float4x4 modelMatrix;
|
||||
uint albedoID;
|
||||
uint roughnessID;
|
||||
uint metalnessID;
|
||||
};
|
||||
|
||||
DECLARE_CBUFFER(0)
|
||||
{
|
||||
float4x4 projection;
|
||||
};
|
||||
|
||||
DECLARE_TEXTURES(1)
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
#include "shader_base.h"
|
||||
#include "mesh_shared.slang"
|
||||
|
||||
struct VertexInput
|
||||
@@ -6,20 +7,13 @@ struct VertexInput
|
||||
float2 uv: TEXCOORD0;
|
||||
};
|
||||
|
||||
[[vk::binding(0)]]
|
||||
cbuffer CameraInfo
|
||||
{
|
||||
float4x4 projection;
|
||||
};
|
||||
|
||||
[shader("vertex")]
|
||||
VertexOutput main(
|
||||
VertexOutput _main(
|
||||
VertexInput input,
|
||||
uniform PushConstants constants,
|
||||
)
|
||||
{
|
||||
VertexOutput output;
|
||||
output.position = mul(projection, mul(constants.modelMatrix, float4(input.position,1)));
|
||||
output.position = mul(projection, mul(modelMatrix, float4(input.position,1)));
|
||||
output.uv = input.uv;
|
||||
return output;
|
||||
}
|
||||
|
||||
85
funnyassets/gfx_shaders/shader_base.h
Normal file
85
funnyassets/gfx_shaders/shader_base.h
Normal file
@@ -0,0 +1,85 @@
|
||||
#ifndef SHADER_BASE_SLANG
|
||||
#define SHADER_BASE_SLANG
|
||||
|
||||
/*
|
||||
* I hope you are not looking at these war crimes.
|
||||
* They are truly horrible crimes.
|
||||
* Don't even try to understand what the fuck is happening here.
|
||||
*/
|
||||
|
||||
#if defined(__METAL__)
|
||||
/* We hijack all the argument buffers, which allows to use a bit more textures at cost of buffers */
|
||||
#define DECLARE_TEXTURES(b) \
|
||||
struct TextureBinding {Texture2D textures[96];}; \
|
||||
[[vk::binding(21)]] ParameterBlock<TextureBinding> g_textures0 : register(t21); \
|
||||
ParameterBlock<TextureBinding> g_textures1 : register(t22); \
|
||||
ParameterBlock<TextureBinding> g_textures2 : register(t23); \
|
||||
ParameterBlock<TextureBinding> g_textures3 : register(t24); \
|
||||
ParameterBlock<TextureBinding> g_textures4 : register(t25); \
|
||||
ParameterBlock<TextureBinding> g_textures5 : register(t26); \
|
||||
ParameterBlock<TextureBinding> g_textures6 : register(t27); \
|
||||
ParameterBlock<TextureBinding> g_textures7 : register(t28);
|
||||
|
||||
void _mlGetSampler()
|
||||
{
|
||||
__intrinsic_asm R"(
|
||||
constexpr sampler s(filter::linear, address::repeat);
|
||||
return s;
|
||||
)";
|
||||
}
|
||||
SamplerState mlGetSampler()
|
||||
{
|
||||
_mlGetSampler();
|
||||
};
|
||||
|
||||
float4 SampleTexture(uint32_t binding, float2 uv)
|
||||
{
|
||||
SamplerState sampler = mlGetSampler();
|
||||
uint8_t textureArray = 0;
|
||||
uint8_t textureSamplerArray = (binding >> 16) & 0xFF;
|
||||
uint8_t textureSampler = (binding >> 8) & 0xFF;
|
||||
uint8_t textureIndex = 1;
|
||||
return g_textures0.textures[1].Sample(sampler, uv);
|
||||
};
|
||||
|
||||
#define DECLARE_CBUFFER(b) \
|
||||
[[vk::binding(b)]] cbuffer cbuffer_##b : register(t##b)
|
||||
|
||||
#define DECLARE_CONSTANTS() \
|
||||
[[vk::push_constant]] \
|
||||
cbuffer cbuffer_constants : register(t29)
|
||||
|
||||
|
||||
#elif defined(__SPIRV__)
|
||||
|
||||
#define DECLARE_TEXTURES(b) \
|
||||
[[vk::binding(b)]] \
|
||||
Sampler2D g_textures[];
|
||||
|
||||
float4 SampleTexture(uint32_t binding, float2 uv)
|
||||
{
|
||||
return g_textures[binding].Sample(uv);
|
||||
};
|
||||
|
||||
#define DECLARE_CBUFFER(b) \
|
||||
[[vk::binding(b)]] \
|
||||
cbuffer cbuffer_##b
|
||||
|
||||
|
||||
#define DECLARE_DATA(b,r) \
|
||||
[[vk::binding(b)]] \
|
||||
r
|
||||
|
||||
#define DECLARE_CONSTANTS() \
|
||||
[[vk::push_constant]] \
|
||||
cbuffer cbuffer_constants
|
||||
|
||||
#else
|
||||
#define DECLARE_TEXTURES()
|
||||
float4 SampleTexture(uint32_t binding, float2 uv);
|
||||
#define DECLARE_CBUFFER() cbuffer cbuffer_constats
|
||||
#define DECLARE_DATA() cbuffer cbuffer_constats
|
||||
#define DECLARE_CONSTANTS() cbuffer cbuffer_constats
|
||||
#endif
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user