# Shader Material Not Compiling when using raytracing

**URL:** <https://forums.unrealengine.com/t/shader-material-not-compiling-when-using-raytracing/1917203>\
**Category:** Programming & Scripting\
**Tags:** compiling-shaders, unreal-engine, Shaders, question\
**Created:** [June 26, 2024, 11:36am UTC](https://forums.unrealengine.com/t/shader-material-not-compiling-when-using-raytracing/1917203 "2024-06-26T11:36:53Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Salvo\_Nostrato](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Salvo\_Nostrato](https://forums.unrealengine.com/u/Salvo_Nostrato)\
**Post date:** [June 26, 2024, 11:36am UTC](https://forums.unrealengine.com/t/shader-material-not-compiling-when-using-raytracing/1917203/1 "2024-06-26T11:36:53Z")

</div>

I am trying to make a shader material using the Custom Node.

```auto
// Inputs
// uv (float2) - UV coordinates
// Tex (Texture Object) - Texture

float3 color = Tex.Sample(TexSampler, uv).rgb;

float3 blurred = float3(0.0, 0.0, 0.0);
for (int i = -2; i <= 2; i++) {
    for (int j = -2; j <= 2; j++) {
        blurred += Tex.Sample(TexSampler, uv + float2(i, j) * Strength).rgb;
    }
}
blurred /= 25.0;

float3 edges = abs(color - Tex.Sample(TexSampler, uv + float2(0.01, 0.01)).rgb);
float edgeFactor = length(edges) * Offset;

float3 watercolor = lerp(blurred, color, edgeFactor);

// Output the watercolor color
return float4(watercolor, 1.0);

```

The code works good but if I switch my project to “Support Hardware Ray Tracing” the shader wont compiling anymore giving the error:

> [SM6] RayTracingMaterialHitShaders.dxil:3935:28: error: Opcode Sample not valid in shader model lib\_6\_6(closesthit).

> [SM6] note: at ‘%649 = call %dx.types.ResRet.f32 @dx.op.sample.f32(i32 60, %dx.types.Handle %622, %dx.types.Handle %624, float %647, float %648, float undef, float undef, i32 0, i32 0, i32 undef, float undef)’ in block ‘#29’ of function ‘?MaterialCHS@@YAXUFPackedMaterialClosestHitPayload@@UFRayTracingIntersectionAttributes@@@Z’.

Any idea why?

 ![Screenshot 2024-06-26 133839](https://d3kjluh73b9h9o.cloudfront.net/original/4X/e/8/6/e8600ca335ecc2335e6b4a5ea901bca80234bc76.jpeg)

---

<div class="post-metadata">

**Author:** ![Salvo\_Nostrato](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Salvo\_Nostrato](https://forums.unrealengine.com/u/Salvo_Nostrato)\
**Post date:** [June 26, 2024, 1:09pm UTC](https://forums.unrealengine.com/t/shader-material-not-compiling-when-using-raytracing/1917203/2 "2024-06-26T13:09:01Z")

</div>

Texture2DSample(Tex, TexSampler, uv + offset).rgb //for sm6

solved

---

<div class="post-metadata">

**Author:** ![system](https://d3kjluh73b9h9o.cloudfront.net/original/4X/7/1/3/713c9d3f58553f0de89543d76a8a3a2779dc9fa4.png) [@system](https://forums.unrealengine.com/u/system)\
**Post date:** [July 26, 2024, 1:09pm UTC](https://forums.unrealengine.com/t/shader-material-not-compiling-when-using-raytracing/1917203/3 "2024-07-26T13:09:19Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
