nettoyage des assets
This commit is contained in:
@@ -1,5 +0,0 @@
|
||||
{
|
||||
"name":"basicColor",
|
||||
"vert":"basicColor/basicColor.vert",
|
||||
"frag":"basicColor/basicColor.frag"
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
#version 330 core
|
||||
// The result : color of the fragment.
|
||||
out vec4 FragColor;
|
||||
|
||||
|
||||
// The input variable from the vertex shader (same name and same type).
|
||||
in vec3 color;
|
||||
uniform float intensity;
|
||||
uniform vec4 colorDiffuse0; // Input Color.
|
||||
|
||||
void main() {
|
||||
|
||||
vec3 ambient = vec3(0.7333, 0.7333, 0.7333);
|
||||
vec3 diffuse = color;
|
||||
FragColor = intensity * vec4(ambient + diffuse, 1.0)*colorDiffuse0;
|
||||
}
|
||||
@@ -1,30 +0,0 @@
|
||||
#version 330 core
|
||||
// Input : vertex attributes.
|
||||
layout (location = 0) in vec3 aPos; // Position of the vertex.
|
||||
layout (location = 1) in vec3 aNormal; // Normal of the vertex.
|
||||
layout (location = 2) in vec2 aTexCoords; // Texture coordonate of the vertex.
|
||||
layout (location = 3) in vec3 aTangent; // Texture coordonate of the vertex.
|
||||
layout (location = 4) in vec3 aBitangent; // Texture coordonate of the vertex.
|
||||
|
||||
// The result : color of the fragment.
|
||||
out vec3 color;
|
||||
|
||||
// Uniform input variable.
|
||||
uniform mat4 projection; // Projection of the camera.
|
||||
uniform mat4 model; // Transforms transformation.
|
||||
uniform mat4 view; // View transformation of the camera.
|
||||
uniform vec3 lightPos;
|
||||
|
||||
void main() {
|
||||
|
||||
gl_Position = projection * view * model * vec4(aPos, 1.0);
|
||||
vec4 newPos = model * vec4(aPos, 1.0);
|
||||
// vec4 newNormal = model * vec4(aNormal, 1.0);
|
||||
vec3 newPos3 = newPos.xyz;
|
||||
// vec3 newNormal3 = newNormal.xyz;
|
||||
vec3 newNormal3 = mat3(transpose(inverse(model))) * aNormal;
|
||||
vec3 lightVec = vec3(normalize((lightPos - newPos3)));
|
||||
float diffuse = dot(lightVec, newNormal3);
|
||||
//color = vec3(1,1,1);
|
||||
color = vec3(diffuse);
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
{
|
||||
"name":"basicColor2",
|
||||
"vert":"basicColor2/basicColor2.vert",
|
||||
"frag":"basicColor2/basicColor2.frag"
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
#version 330 core
|
||||
// The result : color of the fragment.
|
||||
out vec4 FragColor;
|
||||
|
||||
|
||||
// The input variable from the vertex shader (same name and same type).
|
||||
in vec3 color;
|
||||
in vec2 TexCoords;
|
||||
uniform float intensity;
|
||||
uniform vec4 colorDiffuse0; // Input Color.
|
||||
uniform sampler2D textureDiffuse0;
|
||||
void main() {
|
||||
|
||||
vec3 ambient = vec3(0.7333, 0.7333, 0.7333);
|
||||
vec3 diffuse = color;
|
||||
FragColor = intensity * vec4(ambient + diffuse, 1.0)*colorDiffuse0 * texture(textureDiffuse0, TexCoords);
|
||||
}
|
||||
@@ -1,32 +0,0 @@
|
||||
#version 330 core
|
||||
// Input : vertex attributes.
|
||||
layout (location = 0) in vec3 aPos; // Position of the vertex.
|
||||
layout (location = 1) in vec3 aNormal; // Normal of the vertex.
|
||||
layout (location = 2) in vec2 aTexCoords; // Texture coordonate of the vertex.
|
||||
layout (location = 3) in vec3 aTangent; // Texture coordonate of the vertex.
|
||||
layout (location = 4) in vec3 aBitangent; // Texture coordonate of the vertex.
|
||||
|
||||
// The result : color of the fragment.
|
||||
out vec3 color;
|
||||
out vec2 TexCoords;
|
||||
|
||||
// Uniform input variable.
|
||||
uniform mat4 projection; // Projection of the camera.
|
||||
uniform mat4 model; // Transforms transformation.
|
||||
uniform mat4 view; // View transformation of the camera.
|
||||
uniform vec3 lightPos;
|
||||
|
||||
void main() {
|
||||
|
||||
gl_Position = projection * view * model * vec4(aPos, 1.0);
|
||||
vec4 newPos = model * vec4(aPos, 1.0);
|
||||
// vec4 newNormal = model * vec4(aNormal, 1.0);
|
||||
vec3 newPos3 = newPos.xyz;
|
||||
// vec3 newNormal3 = newNormal.xyz;
|
||||
vec3 newNormal3 = mat3(transpose(inverse(model))) * aNormal;
|
||||
vec3 lightVec = vec3(normalize((lightPos - newPos3)));
|
||||
float diffuse = dot(lightVec, newNormal3);
|
||||
//color = vec3(1,1,1);
|
||||
color = vec3(diffuse);
|
||||
TexCoords = aTexCoords;
|
||||
}
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -1,31 +1,188 @@
|
||||
static float2 positions[3] = float2[](
|
||||
float2(0.0, -0.5),
|
||||
float2(0.5, 0.5),
|
||||
float2(-0.5, 0.5)
|
||||
);
|
||||
|
||||
static float3 colors[3] = float3[](
|
||||
float3(1.0, 0.0, 0.0),
|
||||
float3(0.0, 1.0, 0.0),
|
||||
float3(0.0, 0.0, 1.0)
|
||||
);
|
||||
|
||||
struct VertexOutput {
|
||||
float3 color;
|
||||
float4 sv_position : SV_Position;
|
||||
struct VSInput {
|
||||
[[vk::location(0)]] float3 inPosition;
|
||||
[[vk::location(1)]] float4 inColor;
|
||||
[[vk::location(2)]] float3 inNormal;
|
||||
[[vk::location(3)]] float2 inUV;
|
||||
[[vk::location(4)]] float3 inTangent;
|
||||
[[vk::location(5)]] float3 inBitangent;
|
||||
};
|
||||
|
||||
struct VSOutput
|
||||
{
|
||||
float4 pos : SV_Position;
|
||||
float4 color : COLOR;
|
||||
float2 uv : TEXCOORD0;
|
||||
float3 normal : NORMAL;
|
||||
float3 fragPos : TEXCOORD1; // position monde
|
||||
float3 viewPos : TEXCOORD2; // position caméra
|
||||
};
|
||||
|
||||
// set 0 - Camera
|
||||
struct CameraUBO {
|
||||
float4x4 view;
|
||||
float4x4 projection;
|
||||
};
|
||||
[[vk::binding(0, 0)]] ConstantBuffer<CameraUBO> camera;
|
||||
|
||||
// set 1 - Transform
|
||||
struct TransformUBO {
|
||||
float4x4 model;
|
||||
};
|
||||
[[vk::binding(0, 1)]] ConstantBuffer<TransformUBO> transform;
|
||||
|
||||
// set 2 - Material
|
||||
[[vk::binding(1, 2)]] Sampler2D albedoTexture; // texture + sampler combinés, pas de warning
|
||||
[[vk::binding(2, 2)]] Sampler2D normalTexture; // deuxième texture si besoin
|
||||
|
||||
struct LightData {
|
||||
float4 position; // w = type
|
||||
float4 direction; // w = range
|
||||
float4 color; // w = intensity
|
||||
float innerCosAngle;
|
||||
float outerCosAngle;
|
||||
float attenuation;
|
||||
float padding;
|
||||
};
|
||||
|
||||
struct LightsBuffer {
|
||||
LightData lights[32];
|
||||
int lightCount;
|
||||
};
|
||||
|
||||
[[vk::binding(0, 3)]] StructuredBuffer<LightsBuffer> lightsBuffer;
|
||||
|
||||
[shader("vertex")]
|
||||
VertexOutput vertMain(uint vid : SV_VertexID) {
|
||||
VertexOutput output;
|
||||
output.sv_position = float4(positions[vid], 0.0, 1.0);
|
||||
output.color = colors[vid];
|
||||
VSOutput vertMain(VSInput input) {
|
||||
VSOutput output;
|
||||
|
||||
float4x4 modelMatrix = transform.model;
|
||||
float4 worldPos = mul(modelMatrix, float4(input.inPosition, 1.0));
|
||||
output.pos = mul(camera.projection, mul(camera.view, worldPos));
|
||||
output.color = input.inColor;
|
||||
output.uv = input.inUV;
|
||||
|
||||
// Pour une mise à l'échelle uniforme, on peut utiliser directement la matrice 3x3
|
||||
float3x3 normalMatrix = (float3x3)modelMatrix;
|
||||
// Si mises à l'échelle non-uniforme :
|
||||
// float3x3 normalMatrix = transpose(inverse((float3x3)modelMatrix));
|
||||
|
||||
output.normal = normalize(mul(normalMatrix, input.inNormal));
|
||||
output.fragPos = worldPos.xyz;
|
||||
|
||||
// Position de la caméra dans le monde
|
||||
float3x3 R = (float3x3)camera.view;
|
||||
output.viewPos = -mul(transpose(R), camera.view[3].xyz);
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
[shader("fragment")]
|
||||
float4 fragMain(VertexOutput inVert) : SV_Target
|
||||
float3 computeDirectional(LightData light, VSOutput vertIn)
|
||||
{
|
||||
float3 color = inVert.color;
|
||||
return float4(color, 1.0);
|
||||
// Normaliser la normale (l'interpolation peut la dénormaliser)
|
||||
float3 normal = normalize(vertIn.normal);
|
||||
|
||||
// Direction de la lumière (utiliser les données de la lumière)
|
||||
float3 lightDir = normalize(-light.direction.xyz);
|
||||
|
||||
// Direction de la vue
|
||||
float3 viewDir = normalize(vertIn.viewPos - vertIn.fragPos);
|
||||
|
||||
// Diffuse (Lambertian)
|
||||
float diff = max(dot(normal, lightDir), 0.0);
|
||||
float3 diffuse = diff * light.color.xyz * light.color.w;
|
||||
|
||||
// Specular (Blinn-Phong)
|
||||
float3 halfVec = normalize(lightDir + viewDir);
|
||||
float spec = pow(max(dot(normal, halfVec), 0.0), 32.0);
|
||||
float3 specular = spec * light.color.xyz * light.color.w * 0.5;
|
||||
|
||||
// Retourner la somme
|
||||
return (diffuse + specular) * light.attenuation;
|
||||
}
|
||||
|
||||
float3 computePoint(LightData light, VSOutput vertIn)
|
||||
{
|
||||
float3 normal = normalize(vertIn.normal);
|
||||
float3 viewDir = normalize(vertIn.viewPos - vertIn.fragPos);
|
||||
|
||||
// Direction de la lumière (du point lumineux vers le fragment)
|
||||
float3 lightDir = normalize(light.position.xyz - vertIn.fragPos);
|
||||
|
||||
// Distance pour l'atténuation
|
||||
float distance = length(light.position.xyz - vertIn.fragPos);
|
||||
float attenuation = 1.0 / (1.0 + light.attenuation * distance * distance);
|
||||
|
||||
// Diffuse
|
||||
float diff = max(dot(normal, lightDir), 0.0);
|
||||
float3 diffuse = diff * light.color.xyz * light.color.w;
|
||||
|
||||
// Specular
|
||||
float3 halfVec = normalize(lightDir + viewDir);
|
||||
float spec = pow(max(dot(normal, halfVec), 0.0), 32.0);
|
||||
float3 specular = spec * light.color.xyz * light.color.w * 0.5;
|
||||
|
||||
return (diffuse + specular) * attenuation;
|
||||
}
|
||||
|
||||
float3 computeSpot(LightData light, VSOutput vertIn)
|
||||
{
|
||||
float3 normal = normalize(vertIn.normal);
|
||||
float3 viewDir = normalize(vertIn.viewPos - vertIn.fragPos);
|
||||
|
||||
// Direction du fragment vers la lumière
|
||||
float3 lightDir = normalize(light.position.xyz - vertIn.fragPos);
|
||||
|
||||
// Distance et atténuation
|
||||
float distance = length(light.position.xyz - vertIn.fragPos);
|
||||
float attenuation = 1.0 / (1.0 + light.attenuation * distance * distance);
|
||||
|
||||
// Spot light (cosinus de l'angle entre la direction du spot et la direction vers le fragment)
|
||||
float cosAngle = dot(-light.direction.xyz, lightDir);
|
||||
float spotFactor = smoothstep(light.outerCosAngle, light.innerCosAngle, cosAngle);
|
||||
|
||||
// Diffuse
|
||||
float diff = max(dot(normal, lightDir), 0.0);
|
||||
float3 diffuse = diff * light.color.xyz * light.color.w;
|
||||
|
||||
// Specular
|
||||
float3 halfVec = normalize(lightDir + viewDir);
|
||||
float spec = pow(max(dot(normal, halfVec), 0.0), 32.0);
|
||||
float3 specular = spec * light.color.xyz * light.color.w * 0.5;
|
||||
|
||||
return (diffuse + specular) * attenuation * spotFactor;
|
||||
}
|
||||
|
||||
[shader("fragment")]
|
||||
float4 fragMain(VSOutput vertIn) : SV_Target {
|
||||
// Sample textures
|
||||
float3 albedo = albedoTexture.Sample(vertIn.uv).rgb;
|
||||
|
||||
// Ambient
|
||||
float3 ambient = 0.03 * albedo;
|
||||
|
||||
// Lighting accumulé
|
||||
float3 lighting = float3(0.0, 0.0, 0.0);
|
||||
|
||||
// Récupérer les lumières
|
||||
LightsBuffer lb = lightsBuffer[0];
|
||||
|
||||
for (int i = 0; i < lb.lightCount; i++) {
|
||||
LightData light = lb.lights[i];
|
||||
int lightType = (int)light.position.w;
|
||||
|
||||
if (lightType == 0)
|
||||
lighting += computeDirectional(light, vertIn);
|
||||
else if (lightType == 1)
|
||||
lighting += computePoint(light, vertIn);
|
||||
else if (lightType == 2)
|
||||
lighting += computeSpot(light, vertIn);
|
||||
}
|
||||
|
||||
// Résultat final
|
||||
float3 finalColor = (ambient + lighting) * albedo;
|
||||
|
||||
// Tone mapping simple (optionnel)
|
||||
// finalColor = finalColor / (finalColor + 1.0);
|
||||
|
||||
return float4(finalColor, 1.0);
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
// =====================================================
|
||||
// UI Shader pour CosmicCore
|
||||
// Set 0 : Transform (UBO - par objet)
|
||||
// Set 1 : Material (UBO + Texture)
|
||||
// Set 2 : Projection (UBO - global)
|
||||
// =====================================================
|
||||
|
||||
// ─── Inputs ────────────────────────────────────────────
|
||||
struct VSInput {
|
||||
[[vk::location(0)]] float2 inPosition;
|
||||
[[vk::location(1)]] float2 inUV;
|
||||
[[vk::location(2)]] float4 inColor;
|
||||
};
|
||||
|
||||
// ─── Outputs ───────────────────────────────────────────
|
||||
struct VSOutput {
|
||||
float4 pos : SV_Position;
|
||||
float2 uv : TEXCOORD0;
|
||||
float4 color : COLOR;
|
||||
};
|
||||
|
||||
// ─── Set 0 : Transform (UBO par objet) ─────────────────
|
||||
struct TransformUBO {
|
||||
float4x4 model;
|
||||
float2 size;
|
||||
float zOrder;
|
||||
float padding;
|
||||
};
|
||||
|
||||
[[vk::binding(0, 0)]] ConstantBuffer<TransformUBO> transform;
|
||||
|
||||
[[vk::binding(1, 1)]] Sampler2D uiTexture;
|
||||
|
||||
// ─── Set 2 : Projection (UBO global) ──────────────────
|
||||
[[vk::binding(0, 2)]] ConstantBuffer<float4x4> projection;
|
||||
|
||||
// ─── Vertex Shader ──────────────────────────────────────
|
||||
[shader("vertex")]
|
||||
VSOutput vertMain(VSInput input) {
|
||||
VSOutput output;
|
||||
|
||||
// Transforme local vers monde
|
||||
float4 worldPos = mul(transform.model, float4(input.inPosition, 0.0, 1.0));
|
||||
|
||||
// Applique la projection
|
||||
output.pos = mul(projection, worldPos);
|
||||
|
||||
output.uv = input.inUV;
|
||||
output.color = input.inColor;
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
// ─── Fragment Shader ────────────────────────────────────
|
||||
[shader("fragment")]
|
||||
float4 fragMain(VSOutput vertIn) : SV_Target {
|
||||
float4 texColor = uiTexture.Sample(vertIn.uv);
|
||||
return vertIn.color * texColor;
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
// =====================================================
|
||||
// UI Shader pour CosmicCore
|
||||
// Set 0 : Transform (UBO - par objet)
|
||||
// Set 1 : Material (UBO + Texture)
|
||||
// Set 2 : Projection (UBO - global)
|
||||
// =====================================================
|
||||
|
||||
// ─── Inputs ────────────────────────────────────────────
|
||||
struct VSInput {
|
||||
[[vk::location(0)]] float2 inPosition;
|
||||
[[vk::location(1)]] float2 inUV;
|
||||
[[vk::location(2)]] float4 inColor;
|
||||
};
|
||||
|
||||
// ─── Outputs ───────────────────────────────────────────
|
||||
struct VSOutput {
|
||||
float4 pos : SV_Position;
|
||||
float2 uv : TEXCOORD0;
|
||||
float4 color : COLOR;
|
||||
};
|
||||
|
||||
// ─── Set 0 : Transform (UBO par objet) ─────────────────
|
||||
struct TransformUBO {
|
||||
float4x4 model;
|
||||
float2 size;
|
||||
float zOrder;
|
||||
float padding;
|
||||
};
|
||||
|
||||
[[vk::binding(0, 0)]] ConstantBuffer<TransformUBO> transform;
|
||||
|
||||
[[vk::binding(1, 1)]] Sampler2D uiTexture;
|
||||
|
||||
// ─── Set 2 : Projection (UBO global) ──────────────────
|
||||
[[vk::binding(0, 2)]] ConstantBuffer<float4x4> projection;
|
||||
|
||||
// ─── Vertex Shader ──────────────────────────────────────
|
||||
[shader("vertex")]
|
||||
VSOutput vertMain(VSInput input) {
|
||||
VSOutput output;
|
||||
|
||||
// Transforme local vers monde
|
||||
float4 worldPos = mul(transform.model, float4(input.inPosition, 0.0, 1.0));
|
||||
|
||||
// Applique la projection
|
||||
output.pos = mul(projection, worldPos);
|
||||
|
||||
output.uv = input.inUV;
|
||||
output.color = input.inColor;
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
float median(float r, float g, float b) {
|
||||
return max(min(r, g), min(max(r, g), b));
|
||||
}
|
||||
|
||||
[shader("fragment")]
|
||||
float4 fragMain(VSOutput vertIn) : SV_Target {
|
||||
float3 msd = uiTexture.Sample(vertIn.uv).rgb;
|
||||
float sigDist = median(msd.r, msd.g, msd.b) - 0.5;
|
||||
|
||||
// largeur du dégradé en pixels écran (anti-aliasing correct)
|
||||
float2 unitRange = float2(1.0, 1.0) / float2(212.0, 212.0);
|
||||
float2 screenTexSize = 1.0 / fwidth(vertIn.uv);
|
||||
float screenPxRange = max(0.5 * dot(unitRange, screenTexSize), 1.0);
|
||||
|
||||
float opacity = clamp(screenPxRange * sigDist + 0.5, 0.0, 1.0);
|
||||
|
||||
return float4(vertIn.color.rgb, vertIn.color.a * opacity);
|
||||
}
|
||||
Reference in New Issue
Block a user