textureLod into HLSL

Posted By: 3run

textureLod into HLSL - 03/30/20 18:01

Hey,

I've been trying to convert some stuff from shadertoy into HLSL and faced this textureLod thing:
Code
vec3 col = textureLod(iChannel0, UV+n, focus).rgb;
Here how I tried to solve it:
Code
float4 s = float4(UV.x + n.x, UV.y + n.y, 0, focus);
float3 col = tex2Dlod(postTex, s).rgb;
This one does compile, but it doesn't seems to work correctly (doesn't get blurred)...
[Linked Image]

Then I tried this:
Code
Texture2D MyTexture;


float4 FP(float2 fragCoord: VPOS) : COLOR
{
	/// ... ///
	
	float3 col = MyTexture.SampleLevel(postTex, UV+n, focus).rgb;
	
	/// ... ///
}
But it gave me malfunction W1550:
[Linked Image]

Here is original version:
https://www.shadertoy.com/view/ltffzl

Best regards!
Posted By: Emre

Re: textureLod into HLSL - 03/31/20 07:04

Code
Texture2D MyTexture;


float4 FP(float2 fragCoord: VPOS) : COLOR
{
	/// ... ///
	
	float3 col = MyTexture.SampleLevel(postTex, UV+n, focus).rgb;
	
	/// ... ///
}


i think "SampleLevel" is part of shader 4.0. (Minimum dx10)

Posted By: 3run

Re: textureLod into HLSL - 03/31/20 09:28

Originally Posted by Emre
i think "SampleLevel" is part of shader 4.0. (Minimum dx10)
That's sad... so I guess there is no easy way to convert this line?
Posted By: txesmi

Re: textureLod into HLSL - 03/31/20 09:36

Originally Posted by 3run
Code
float4 s = float4(UV.x + n.x, UV.y + n.y, 0, focus);
float3 col = tex2Dlod(postTex, s).rgb;

This one does compile, but it doesn't seems to work correctly (doesn't get blurred)...


You are right there, 'tex2Dlod' is the corresponding function but the source image needs mipmaps to make a difference. It seems you are trying to blur a scene through its render target and render targets never have mipmaps.
Posted By: 3run

Re: textureLod into HLSL - 03/31/20 10:21

Oh, I was using it in a wrong way then! Thank you for making things clear! laugh
© 2024 lite-C Forums