GLSL vs HLSL Texture Sampling
Fix the environments before comparing syntax: this GLSL fragment targets WebGL 2, while the HLSL pixel shader targets Direct3D 11 / Shader Model 5. Both sample one image and blend toward a warm tint along x. This site runs GLSL; the HLSL counterpart requires a Direct3D host to compile it and bind resources.
Fix the problem and environment
Fix the environments before comparing syntax: this GLSL fragment targets WebGL 2, while the HLSL pixel shader targets Direct3D 11 / Shader Model 5. Both sample one image and blend toward a warm tint along x. This site runs GLSL; the HLSL counterpart requires a Direct3D host to compile it and bind resources.
vec2 resembles float2, but texture sampling is not a rename: GLSL sampler2D combines the lookup entry point while HLSL separates Texture2D and SamplerState. Uniform data typically moves through a constant buffer, and fragment output is expressed with SV_Target semantics.
The controlling code
// GLSL ES 3.00 fragment, with vUv supplied by a vertex shader:
#version 300 es
precision highp float;
uniform sampler2D image;
in vec2 vUv;
out vec4 color;
void main(){
vec3 source=texture(image,vUv).rgb;
color=vec4(mix(source,vec3(1.0,0.65,0.3),vUv.x),1.0);
}
// HLSL SM5 pixel shader (compile separately, not as GLSL):
Texture2D image : register(t0);
SamplerState imageSampler : register(s0);
struct PixelInput { float4 position:SV_POSITION; float2 uv:TEXCOORD0; };
float4 main(PixelInput input):SV_Target {
float3 source=image.Sample(imageSampler,input.uv).rgb;
return float4(lerp(source,float3(1.0,0.65,0.3),input.uv.x),1.0);
}
Verify in order
Match the sampled image before comparing mix/lerp. Check the vertex-to-fragment interface, then port matrices, depth and projection.
Scope and common mistakes
Do not replace matrix multiplication mechanically. Check vector side, mathematical transform, memory layout and host upload together. HLSL cannot be pasted into a WebGL compiler.