better physics
This commit is contained in:
@@ -1,34 +0,0 @@
|
||||
#include <metal_stdlib>
|
||||
using namespace metal;
|
||||
|
||||
struct VertexOut {
|
||||
float4 position [[position]];
|
||||
float2 texCoord;
|
||||
};
|
||||
|
||||
vertex VertexOut vertex_main(uint vertexID [[vertex_id]]) {
|
||||
float2 pos[] = {
|
||||
{-1.0, -1.0},
|
||||
{ 1.0, -1.0},
|
||||
{-1.0, 1.0},
|
||||
{ 1.0, 1.0},
|
||||
};
|
||||
|
||||
float2 uv[] = {
|
||||
{0.0, 1.0},
|
||||
{1.0, 1.0},
|
||||
{0.0, 0.0},
|
||||
{1.0, 0.0},
|
||||
};
|
||||
|
||||
VertexOut out;
|
||||
out.position = float4(pos[vertexID], 0.0, 1.0);
|
||||
out.texCoord = uv[vertexID];
|
||||
return out;
|
||||
}
|
||||
|
||||
fragment float4 fragment_main(VertexOut in [[stage_in]],
|
||||
texture2d<float> tex [[texture(0)]]) {
|
||||
constexpr sampler s(filter::linear);
|
||||
return pow(tex.sample(s, in.texCoord), 0.45f);
|
||||
}
|
||||
@@ -1,94 +0,0 @@
|
||||
|
||||
|
||||
[[vk::binding(0)]]
|
||||
RWTexture2D<float4> g_imageIn;
|
||||
[[vk::binding(1)]]
|
||||
RWTexture2D<float4> g_imageOut;
|
||||
|
||||
#define AGX_LOOK 2
|
||||
|
||||
float3 agxDefaultContrastApprox(float3 x) {
|
||||
float3 x2 = x * x;
|
||||
float3 x4 = x2 * x2;
|
||||
|
||||
return + 15.5 * x4 * x2
|
||||
- 40.14 * x4 * x
|
||||
+ 31.96 * x4
|
||||
- 6.868 * x2 * x
|
||||
+ 0.4298 * x2
|
||||
+ 0.1191 * x
|
||||
- 0.00232;
|
||||
}
|
||||
|
||||
float3 agx(float3 val) {
|
||||
const float3x3 agx_mat = float3x3(
|
||||
0.842479062253094, 0.0423282422610123, 0.0423756549057051,
|
||||
0.0784335999999992, 0.878468636469772, 0.0784336,
|
||||
0.0792237451477643, 0.0791661274605434, 0.879142973793104);
|
||||
|
||||
const float min_ev = -12.47393f;
|
||||
const float max_ev = 4.026069f;
|
||||
|
||||
val = mul(agx_mat, val);
|
||||
|
||||
val = clamp(log2(val), min_ev, max_ev);
|
||||
val = (val - min_ev) / (max_ev - min_ev);
|
||||
|
||||
val = agxDefaultContrastApprox(val);
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
float3 agxEotf(float3 val) {
|
||||
const float3x3 agx_mat_inv = float3x3(
|
||||
1.19687900512017, -0.0528968517574562, -0.0529716355144438,
|
||||
-0.0980208811401368, 1.15190312990417, -0.0980434501171241,
|
||||
-0.0990297440797205, -0.0989611768448433, 1.15107367264116);
|
||||
|
||||
val = mul(agx_mat_inv, val);
|
||||
val = pow(val, float3(2.2));
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
float3 agxLook(float3 val) {
|
||||
float3 offset = float3(0.0);
|
||||
float3 slope = float3(1.0);
|
||||
float3 power = float3(1.0);
|
||||
float sat = 1.0;
|
||||
|
||||
#if AGX_LOOK == 1
|
||||
slope = float3(1.0, 0.9, 0.5);
|
||||
power = float3(0.8);
|
||||
sat = 0.8;
|
||||
#elif AGX_LOOK == 2
|
||||
slope = float3(1.0);
|
||||
power = float3(1.35, 1.35, 1.35);
|
||||
sat = 1.4;
|
||||
#endif
|
||||
|
||||
// ASC CDL
|
||||
val = pow(val * slope + offset, power);
|
||||
|
||||
const float3 lw = float3(0.2126, 0.7152, 0.0722);
|
||||
float luma = dot(val, lw);
|
||||
|
||||
return luma + sat * (val - luma);
|
||||
}
|
||||
|
||||
[shader("compute")]
|
||||
[numthreads(32,32,1)]
|
||||
void main(uint3 threadId: SV_DispatchThreadID)
|
||||
{
|
||||
uint2 coord = threadId.xy;
|
||||
float3 color = g_imageIn.Load(coord).xyz;
|
||||
color = pow(color,2.2);
|
||||
color = agx(color);
|
||||
color = agxLook(color);
|
||||
color = agxEotf(color);
|
||||
color = pow(color,0.45);
|
||||
color = clamp(color, 0, 1);
|
||||
g_imageOut[coord] = float4(color,1);
|
||||
};
|
||||
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
#include "fgui_rect_shared.slang"
|
||||
|
||||
[shader("fragment")]
|
||||
float4 _main(
|
||||
VertexOutput input,
|
||||
uint triid: SV_PrimitiveID,
|
||||
) : SV_TARGET
|
||||
{
|
||||
return float4(color);
|
||||
}
|
||||
|
||||
@@ -1,18 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
struct VertexOutput
|
||||
{
|
||||
float4 position: SV_Position;
|
||||
}
|
||||
#include "shader_base.h"
|
||||
|
||||
DECLARE_CONSTANTS()
|
||||
{
|
||||
uint2 resolution;
|
||||
uint2 size;
|
||||
int2 position;
|
||||
float4 color;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -1,17 +0,0 @@
|
||||
#include "fgui_rect_shared.slang"
|
||||
|
||||
struct VertexInput
|
||||
{
|
||||
float2 position: POSITION;
|
||||
};
|
||||
|
||||
[shader("vertex")]
|
||||
VertexOutput _main(
|
||||
VertexInput input,
|
||||
)
|
||||
{
|
||||
VertexOutput output;
|
||||
output.position = float4((input.position*size+position)/resolution*2-1, 0, 1.0f);
|
||||
FIX_VERTEX_POSITION(output.position);
|
||||
return output;
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
#include "fgui_text_shared.slang"
|
||||
|
||||
[shader("fragment")]
|
||||
float4 _main(
|
||||
VertexOutput input,
|
||||
uint triid: SV_PrimitiveID,
|
||||
) : SV_TARGET
|
||||
{
|
||||
float dist = SampleTexture(font, (input.uv+glyphPos)*glyphSize).x;
|
||||
float smoothing = 0.4;
|
||||
float alpha = clamp(smoothstep(0.5-smoothing, 0.5+smoothing, dist),0,1);
|
||||
return float4(fontColor.xyz, alpha);
|
||||
}
|
||||
|
||||
@@ -1,22 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
struct VertexOutput
|
||||
{
|
||||
float4 position: SV_Position;
|
||||
float2 uv: TEXCOORD0;
|
||||
}
|
||||
#include "shader_base.h"
|
||||
|
||||
DECLARE_CONSTANTS()
|
||||
{
|
||||
int2 resolution;
|
||||
uint2 size;
|
||||
int2 position;
|
||||
float4 fontColor;
|
||||
float2 glyphPos;
|
||||
float2 glyphSize;
|
||||
uint font;
|
||||
};
|
||||
|
||||
DECLARE_TEXTURES(29);
|
||||
|
||||
@@ -1,19 +0,0 @@
|
||||
#include "fgui_text_shared.slang"
|
||||
|
||||
struct VertexInput
|
||||
{
|
||||
float2 position: POSITION;
|
||||
float2 uv: TEXCOORD0;
|
||||
};
|
||||
|
||||
[shader("vertex")]
|
||||
VertexOutput _main(
|
||||
VertexInput input,
|
||||
)
|
||||
{
|
||||
VertexOutput output;
|
||||
output.position = float4((input.position*size+position)/resolution*2-1, 0, 1.0f);
|
||||
output.uv = input.uv;
|
||||
FIX_VERTEX_POSITION(output.position);
|
||||
return output;
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
#include "shader_base.h"
|
||||
@@ -1,12 +0,0 @@
|
||||
#include "mesh_shared.slang"
|
||||
|
||||
|
||||
[shader("fragment")]
|
||||
float4 _main(
|
||||
VertexOutput input,
|
||||
uint triid: SV_PrimitiveID,
|
||||
) : SV_TARGET
|
||||
{
|
||||
return float4(SampleTexture(albedoID, input.uv).xyz,1);
|
||||
}
|
||||
|
||||
@@ -1,16 +0,0 @@
|
||||
|
||||
#include "mesh_raytracer_shared.slang"
|
||||
|
||||
[shader("raygeneration")]
|
||||
void _main()
|
||||
{
|
||||
uint2 launchIndex = DispatchRaysIndex().xy;
|
||||
uint8_t edgemask = inputMask.Load(uint3(launchIndex, 0));
|
||||
uint8_t edgemask1 = inputMask.Load(uint3(launchIndex, 1));
|
||||
uint8_t edgemask2 = inputMask.Load(uint3(launchIndex, 2));
|
||||
uint8_t edgemask3 = inputMask.Load(uint3(launchIndex, 3));
|
||||
uint8_t nBits = (countbits(edgemask) + countbits(edgemask1) + countbits(edgemask2) + countbits(edgemask3));
|
||||
if ( nBits != 16 && nBits != 0 )
|
||||
outputTest[launchIndex] = float4(1,0,0,0);
|
||||
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
struct RayPayload
|
||||
{
|
||||
bool bHit;
|
||||
float fDistance;
|
||||
};
|
||||
|
||||
#include "shader_base.slang"
|
||||
|
||||
DECLARE_CBUFFER(0)
|
||||
{
|
||||
float4x4 projection;
|
||||
}
|
||||
|
||||
DECLARE_DATA(1, Texture2DMS<float> inputDepth;);
|
||||
DECLARE_DATA(2, Texture2DMS<uint8_t> inputMask;);
|
||||
DECLARE_DATA(3, RWTexture2D<float4> outputTest;);
|
||||
|
||||
DECLARE_TEXTURES(29)
|
||||
@@ -1,21 +0,0 @@
|
||||
struct VertexOutput
|
||||
{
|
||||
float4 position: SV_Position;
|
||||
float2 uv: TEXCOORD0;
|
||||
};
|
||||
|
||||
#include "shader_base.h"
|
||||
DECLARE_CONSTANTS()
|
||||
{
|
||||
float4x4 modelMatrix;
|
||||
uint albedoID;
|
||||
uint roughnessID;
|
||||
uint metalnessID;
|
||||
};
|
||||
|
||||
DECLARE_CBUFFER(0)
|
||||
{
|
||||
float4x4 projection;
|
||||
};
|
||||
|
||||
DECLARE_TEXTURES(1)
|
||||
@@ -1,19 +0,0 @@
|
||||
#include "mesh_shared.slang"
|
||||
|
||||
struct VertexInput
|
||||
{
|
||||
float3 position: POSITION;
|
||||
float2 uv: TEXCOORD0;
|
||||
};
|
||||
|
||||
[shader("vertex")]
|
||||
VertexOutput _main(
|
||||
VertexInput input,
|
||||
)
|
||||
{
|
||||
VertexOutput output;
|
||||
output.position = mul(projection, mul(modelMatrix, float4(input.position,1)));
|
||||
FIX_VERTEX_POSITION(output.position);
|
||||
output.uv = input.uv;
|
||||
return output;
|
||||
}
|
||||
@@ -1,89 +0,0 @@
|
||||
#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); \
|
||||
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); \
|
||||
};
|
||||
|
||||
void _mlGetSampler()
|
||||
{
|
||||
__intrinsic_asm R"(
|
||||
constexpr sampler s(filter::linear, address::repeat);
|
||||
return s;
|
||||
)";
|
||||
}
|
||||
SamplerState mlGetSampler()
|
||||
{
|
||||
_mlGetSampler();
|
||||
};
|
||||
|
||||
#define DECLARE_CBUFFER(n) \
|
||||
[[vk::binding(n)]] cbuffer cbuffer_##b : register(b##n)
|
||||
|
||||
#define DECLARE_CONSTANTS() \
|
||||
[[vk::push_constant]] \
|
||||
cbuffer cbuffer_constants : register(b29)
|
||||
|
||||
#define FIX_VERTEX_POSITION(g) g = float4(g.x, -g.y, g.z, g.w);
|
||||
|
||||
#elif defined(__SPIRV__)
|
||||
|
||||
#define DECLARE_TEXTURES(n) \
|
||||
[[vk::binding(n)]] \
|
||||
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
|
||||
|
||||
#define FIX_VERTEX_POSITION(x)
|
||||
|
||||
#else
|
||||
#define DECLARE_TEXTURES()
|
||||
float4 SampleTexture(uint32_t binding, float2 uv);
|
||||
#define DECLARE_CBUFFER() cbuffer cbuffer_constants
|
||||
#define DECLARE_DATA() cbuffer cbuffer_constants
|
||||
#define DECLARE_CONSTANTS() cbuffer cbuffer_constants
|
||||
#define FIX_VERTEX_POSITION(x)
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -1,25 +0,0 @@
|
||||
#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.
|
||||
*/
|
||||
#define DECLARE_TEXTURES(n) \
|
||||
[[vk::binding(n)]] \
|
||||
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
|
||||
|
||||
#define FIX_VERTEX_POSITION(x)
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -1,14 +0,0 @@
|
||||
[
|
||||
{
|
||||
"class": "mesh",
|
||||
"model": "test_map.fmesh",
|
||||
"material": "test_map.fmat",
|
||||
"physics": "test_map.fmesh",
|
||||
"position": [0, 0, 0],
|
||||
"rotation": [1, 0, 0, 0]
|
||||
},
|
||||
{
|
||||
"class": "point_light",
|
||||
"position": [100, 0, 0]
|
||||
}
|
||||
]
|
||||
Binary file not shown.
@@ -1,4 +1,5 @@
|
||||
{
|
||||
"mesh": "game/core/meshes/cube.fmesh_c",
|
||||
"material": "game/core/materials/cube.fmat"
|
||||
"Mesh": "game/core/meshes/cube.fmesh_c",
|
||||
"Material": "game/core/materials/cube.fmat",
|
||||
"Physics": "game/core/physics/cube.fpx"
|
||||
}
|
||||
|
||||
4
funnyassets/physics/cube.fpx
Normal file
4
funnyassets/physics/cube.fpx
Normal file
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"Type": "Sphere",
|
||||
"Radius": "1.0"
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,11 +0,0 @@
|
||||
{
|
||||
"classname" "worldspawn"
|
||||
{
|
||||
( 0 0 0 ) ( 256 0 0 ) ( 256 256 0 ) ( 0 0 ) ( 1 0 ) ( 1 1 ) BRICK1
|
||||
}
|
||||
}
|
||||
{
|
||||
"classname" "light"
|
||||
"origin" "128 128 96"
|
||||
"light" "400"
|
||||
}
|
||||
Reference in New Issue
Block a user