Add HLSL and related languages support through shader-language-server (#1093)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
DevonandClaude Opus 4.6 authored and GitHub committed 2026-03-04 19:28:50 +01:00
1 parent dadf3f6a18
commit dbd7bf7596
12 files changed
+603 -3

No files matched your search

@@ -0,0 +1,29 @@
#ifndef COMMON_HLSL
#define COMMON_HLSL
struct VertexInput
{
float3 position : POSITION;
float3 normal : NORMAL;
float2 uv : TEXCOORD0;
};
struct VertexOutput
{
float4 clipPos : SV_POSITION;
float3 worldNormal : TEXCOORD0;
float2 uv : TEXCOORD1;
};
float3 SafeNormalize(float3 v)
{
float len = length(v);
return len > 0.0001 ? v / len : float3(0, 0, 0);
}
float Remap(float value, float fromMin, float fromMax, float toMin, float toMax)
{
return toMin + (value - fromMin) * (toMax - toMin) / (fromMax - fromMin);
}
#endif // COMMON_HLSL
@@ -0,0 +1,26 @@
#include "common.hlsl"
RWTexture2D<float4> OutputTexture : register(u0);
Texture2D<float4> InputTexture : register(t0);
cbuffer ComputeParams : register(b0)
{
uint2 TextureSize;
float BlurRadius;
float _Pad;
};
[numthreads(8, 8, 1)]
void CSMain(uint3 id : SV_DispatchThreadID)
{
if (id.x >= TextureSize.x || id.y >= TextureSize.y)
return;
float4 color = InputTexture[id.xy];
float3 remapped = float3(
Remap(color.r, 0.0, 1.0, 0.2, 0.8),
Remap(color.g, 0.0, 1.0, 0.2, 0.8),
Remap(color.b, 0.0, 1.0, 0.2, 0.8)
);
OutputTexture[id.xy] = float4(remapped, color.a);
}
@@ -0,0 +1,37 @@
#ifndef LIGHTING_HLSL
#define LIGHTING_HLSL
#include "common.hlsl"
cbuffer LightingConstants : register(b0)
{
float4x4 ViewProjection;
float3 LightDirection;
float LightIntensity;
float3 AmbientColor;
float _Padding;
};
float3 CalculateDiffuse(float3 normal, float3 lightDir, float3 albedo)
{
float ndotl = max(dot(normal, -lightDir), 0.0);
return albedo * ndotl;
}
float3 CalculateSpecular(float3 normal, float3 lightDir, float3 viewDir, float shininess)
{
float3 halfVec = SafeNormalize(-lightDir + viewDir);
float ndoth = max(dot(normal, halfVec), 0.0);
return pow(ndoth, shininess);
}
VertexOutput TransformVertex(VertexInput input)
{
VertexOutput output;
output.clipPos = mul(ViewProjection, float4(input.position, 1.0));
output.worldNormal = input.normal;
output.uv = input.uv;
return output;
}
#endif // LIGHTING_HLSL
@@ -0,0 +1,33 @@
#ifndef TERRAIN_SDF_HLSL
#define TERRAIN_SDF_HLSL
#include "../common.hlsl"
struct SDFBrickData
{
float3 center;
float halfExtent;
int resolution;
float maxDistance;
};
float3 WorldOffset;
float SampleSDF(float3 worldPos, SDFBrickData brick)
{
float3 localPos = worldPos - brick.center;
float dist = length(localPos) - brick.halfExtent;
return dist;
}
float3 CalculateGradient(float3 worldPos, SDFBrickData brick)
{
float eps = 0.01;
float3 gradient;
gradient.x = SampleSDF(worldPos + float3(eps, 0, 0), brick) - SampleSDF(worldPos - float3(eps, 0, 0), brick);
gradient.y = SampleSDF(worldPos + float3(0, eps, 0), brick) - SampleSDF(worldPos - float3(0, eps, 0), brick);
gradient.z = SampleSDF(worldPos + float3(0, 0, eps), brick) - SampleSDF(worldPos - float3(0, 0, eps), brick);
return SafeNormalize(gradient);
}
#endif // TERRAIN_SDF_HLSL