Ajout de Jolt Physics + 1ere version des factory entitecomposants - camera, transform, rigidbody, collider, renderer

This commit is contained in:
Tom Ray
2026-03-22 00:28:03 +01:00
parent 6695d46bcd
commit 48348936a8
1147 changed files with 214331 additions and 353 deletions

View File

@@ -0,0 +1,27 @@
Texture2D ShaderTexture : register(t2);
SamplerState SampleType : register(s0);
struct PS_INPUT
{
float4 Position : SV_POSITION;
float2 Tex : TEXCOORD0;
float4 Color : COLOR0;
};
struct PS_OUTPUT
{
float4 RGBColor : SV_TARGET;
};
PS_OUTPUT main(PS_INPUT In)
{
PS_OUTPUT Output;
float t = ShaderTexture.Sample(SampleType, In.Tex).r;
if (t < 0.5)
discard;
Output.RGBColor = float4(In.Color.rgb, t);
return Output;
}

View File

@@ -0,0 +1,35 @@
#include "VertexConstants.h"
struct VS_INPUT
{
float3 vPos : POSITION;
float2 vTex : TEXCOORD0;
float4 vCol : COLOR;
};
struct VS_OUTPUT
{
float4 Position : SV_POSITION;
float2 Tex : TEXCOORD0;
float4 Color : COLOR0;
};
VS_OUTPUT main(VS_INPUT input)
{
VS_OUTPUT Output;
float4 pos = float4(input.vPos, 1.0f);
// Transform the position from object space to homogeneous projection space
pos = mul(View, pos);
pos = mul(Projection, pos);
Output.Position = pos;
// Output texture coordinates
Output.Tex = input.vTex;
// Output color
Output.Color = input.vCol;
return Output;
}

View File

@@ -0,0 +1,19 @@
struct PS_INPUT
{
float4 Position : SV_POSITION;
float4 Color : COLOR0;
};
struct PS_OUTPUT
{
float4 RGBColor : SV_TARGET;
};
PS_OUTPUT main(PS_INPUT In)
{
PS_OUTPUT Output;
Output.RGBColor = In.Color;
return Output;
}

View File

@@ -0,0 +1,30 @@
#include "VertexConstants.h"
struct VS_INPUT
{
float3 vPos : POSITION;
float3 vColor : COLOR;
};
struct VS_OUTPUT
{
float4 Position : SV_POSITION;
float4 Color : COLOR0;
};
VS_OUTPUT main(VS_INPUT input)
{
VS_OUTPUT Output;
float4 pos = float4(input.vPos, 1.0f);
// Transform the position from object space to homogeneous projection space
pos = mul(View, pos);
pos = mul(Projection, pos);
Output.Position = pos;
// Output color
Output.Color = float4(input.vColor, 1.0f);
return Output;
}

View File

@@ -0,0 +1,4 @@
// We only write depth, so this shader does nothing
void main()
{
}

View File

@@ -0,0 +1,43 @@
#include "VertexConstants.h"
struct VS_INPUT
{
// Per vertex data
float3 vPos : POSITION;
float3 vNorm : NORMAL;
float2 vTex : TEXCOORD0;
float4 vCol : COLOR;
// Per instance data
matrix iModel : INSTANCE_TRANSFORM; // model matrix
matrix iModelInvTrans : INSTANCE_INV_TRANSFORM; // (model matrix^-1)^T
float4 iCol : INSTANCE_COLOR; // color of the model
};
struct VS_OUTPUT
{
float4 Position : SV_POSITION;
};
VS_OUTPUT main(VS_INPUT input)
{
VS_OUTPUT output;
// Check if the alpha = 0
if (input.vCol.a * input.iCol.a == 0.0)
{
// Don't draw the triangle by moving it to an invalid location
output.Position = float4(0, 0, 0, 0);
}
else
{
// Transform the position from world space to homogeneous projection space for the light
float4 pos = float4(input.vPos, 1.0f);
pos = mul(input.iModel, pos);
pos = mul(LightView, pos);
pos = mul(LightProjection, pos);
output.Position = pos;
}
return output;
}

View File

@@ -0,0 +1,121 @@
// Shader that uses a shadow map for rendering shadows, see:
// http://www.opengl-tutorial.org/intermediate-tutorials/tutorial-16-shadow-mapping/
// https://takinginitiative.wordpress.com/2011/05/25/directx10-tutorial-10-shadow-mapping-part-2/
Texture2D LightDepthTexture : register(t2);
SamplerComparisonState LightDepthSampler : register(s2);
cbuffer PixelShaderConstantBuffer : register(b1)
{
float3 CameraPos;
float3 LightPos;
};
struct PS_INPUT
{
float4 Position : SV_POSITION; // interpolated vertex position
float3 Normal : TEXCOORD0;
float3 WorldPos : TEXCOORD1;
float2 Tex : TEXCOORD2;
float4 PositionL : TEXCOORD3; // interpolated vertex position in light space
float4 Color : COLOR0;
};
struct PS_OUTPUT
{
float4 RGBColor : SV_TARGET;
};
PS_OUTPUT main(PS_INPUT input)
{
// Constants
float AmbientFactor = 0.3;
float3 DiffuseColor = float3(input.Color.r, input.Color.g, input.Color.b);
float3 SpecularColor = float3(1, 1, 1);
float SpecularPower = 100.0;
float bias = 1.0e-7;
// Homogenize position in light space
input.PositionL.xyz /= input.PositionL.w;
// Calculate dot product between direction to light and surface normal and clamp between [0, 1]
float3 view_dir = normalize(CameraPos - input.WorldPos);
float3 world_to_light = LightPos - input.WorldPos;
float3 light_dir = normalize(world_to_light);
float3 normal = normalize(input.Normal);
if (dot(view_dir, normal) < 0) // If we're viewing the triangle from the back side, flip the normal to get the correct lighting
normal = -normal;
float normal_dot_light_dir = saturate(dot(normal, light_dir));
// Calculate texture coordinates in light depth texture
float2 tex_coord;
tex_coord.x = input.PositionL.x / 2.0 + 0.5;
tex_coord.y = -input.PositionL.y / 2.0 + 0.5;
// Check that the texture coordinate is inside the depth texture, if not we don't know if it is lit or not so we assume lit
float shadow_factor = 1.0;
if (input.Color.a > 0 // Alpha = 0 means don't receive shadows
&& tex_coord.x == saturate(tex_coord.x) && tex_coord.y == saturate(tex_coord.y))
{
// Modify shadow bias according to the angle between the normal and the light dir
float modified_bias = bias * tan(acos(normal_dot_light_dir));
modified_bias = min(modified_bias, 10.0 * bias);
// Get texture size
float width, height, levels;
LightDepthTexture.GetDimensions(0, width, height, levels);
width = 1.0 / width;
height = 1.0 / height;
// Samples to take
uint num_samples = 16;
float2 offsets[] = {
float2(-1.5 * width, -1.5 * height),
float2(-0.5 * width, -1.5 * height),
float2(0.5 * width, -1.5 * height),
float2(1.5 * width, -1.5 * height),
float2(-1.5 * width, -0.5 * height),
float2(-0.5 * width, -0.5 * height),
float2(0.5 * width, -0.5 * height),
float2(1.5 * width, -0.5 * height),
float2(-1.5 * width, 0.5 * height),
float2(-0.5 * width, 0.5 * height),
float2(0.5 * width, 0.5 * height),
float2(1.5 * width, 0.5 * height),
float2(-1.5 * width, 1.5 * height),
float2(-0.5 * width, 1.5 * height),
float2(0.5 * width, 1.5 * height),
float2(1.5 * width, 1.5 * height),
};
// Calculate depth of this pixel relative to the light
float light_depth = input.PositionL.z + modified_bias;
// Sample shadow factor
shadow_factor = 0.0;
[unroll] for (uint i = 0; i < num_samples; ++i)
shadow_factor += LightDepthTexture.SampleCmp(LightDepthSampler, tex_coord + offsets[i], light_depth);
shadow_factor /= num_samples;
}
// Calculate diffuse and specular
float diffuse = normal_dot_light_dir;
float specular = diffuse > 0.0? pow(saturate(-dot(reflect(light_dir, normal), view_dir)), SpecularPower) : 0.0;
// Apply procedural pattern based on the uv coordinates
bool2 less_half = input.Tex - floor(input.Tex) < float2(0.5, 0.5);
float darken_factor = less_half.r ^ less_half.g? 0.5 : 1.0;
// Fade out checkerboard pattern when it tiles too often
float2 dx = ddx(input.Tex), dy = ddy(input.Tex);
float texel_distance = sqrt(dot(dx, dx) + dot(dy, dy));
darken_factor = lerp(darken_factor, 0.75, clamp(5.0 * texel_distance - 1.5, 0.0, 1.0));
// Calculate color
PS_OUTPUT output;
output.RGBColor = float4(saturate((AmbientFactor + diffuse * shadow_factor) * darken_factor * DiffuseColor + SpecularColor * specular * shadow_factor), 1);
return output;
}

View File

@@ -0,0 +1,59 @@
#include "VertexConstants.h"
struct VS_INPUT
{
// Per vertex data
float3 vPos : POSITION;
float3 vNorm : NORMAL;
float2 vTex : TEXCOORD0;
float4 vCol : COLOR;
// Per instance data
matrix iModel : INSTANCE_TRANSFORM; // model matrix
matrix iModelInvTrans : INSTANCE_INV_TRANSFORM; // (model matrix^-1)^T
float4 iCol : INSTANCE_COLOR; // color of the model
};
struct VS_OUTPUT
{
float4 Position : SV_POSITION;
float3 Normal : TEXCOORD0;
float3 WorldPos : TEXCOORD1;
float2 Tex : TEXCOORD2;
float4 PositionL : TEXCOORD3;
float4 Color : COLOR0;
};
VS_OUTPUT main(VS_INPUT input)
{
VS_OUTPUT output;
// Get world position
float4 pos = float4(input.vPos, 1.0f);
float4 world_pos = mul(input.iModel, pos);
// Transform the position from world space to homogeneous projection space
float4 proj_pos = mul(View, world_pos);
proj_pos = mul(Projection, proj_pos);
output.Position = proj_pos;
// Transform the position from world space to projection space of the light
float4 proj_lpos = mul(LightView, world_pos);
proj_lpos = mul(LightProjection, proj_lpos);
output.PositionL = proj_lpos;
// output normal
float4 norm = float4(input.vNorm, 0.0f);
output.Normal = normalize(mul(input.iModelInvTrans, norm).xyz);
// output world position of the vertex
output.WorldPos = world_pos.xyz;
// output texture coordinates
output.Tex = input.vTex;
// output color
output.Color = input.vCol * input.iCol;
return output;
}

View File

@@ -0,0 +1,23 @@
Texture2D ShaderTexture : register(t2);
SamplerState SampleType : register(s1);
struct PS_INPUT
{
float4 Position : SV_POSITION;
float2 Tex : TEXCOORD0;
float4 Color : COLOR0;
};
struct PS_OUTPUT
{
float4 RGBColor : SV_TARGET;
};
PS_OUTPUT main(PS_INPUT In)
{
PS_OUTPUT Output;
Output.RGBColor = In.Color * ShaderTexture.Sample(SampleType, In.Tex);
return Output;
}

View File

@@ -0,0 +1,20 @@
struct PS_INPUT
{
float4 Position : SV_POSITION;
float2 Tex : TEXCOORD0;
float4 Color : COLOR0;
};
struct PS_OUTPUT
{
float4 RGBColor : SV_TARGET;
};
PS_OUTPUT main(PS_INPUT In)
{
PS_OUTPUT Output;
Output.RGBColor = In.Color;
return Output;
}

View File

@@ -0,0 +1,34 @@
#include "VertexConstants.h"
struct VS_INPUT
{
float3 vPos : POSITION;
float2 vTex : TEXCOORD0;
float4 vCol : COLOR;
};
struct VS_OUTPUT
{
float4 Position : SV_POSITION;
float2 Tex : TEXCOORD0;
float4 Color : COLOR0;
};
VS_OUTPUT main(VS_INPUT input)
{
VS_OUTPUT Output;
float4 pos = float4(input.vPos, 1.0f);
// Transform the position from object space to ortho space
pos = mul(Projection, pos);
Output.Position = pos;
// Output texture coordinates
Output.Tex = input.vTex;
// Output color
Output.Color = input.vCol;
return Output;
}

View File

@@ -0,0 +1,7 @@
cbuffer VertexShaderConstantBuffer : register(b0)
{
matrix View; // view matrix
matrix Projection; // projection matrix
matrix LightView; // view matrix of the light
matrix LightProjection; // projection matrix of the light
};