0
\$\begingroup\$

I am trying to port a HLSL shader to GLSL. I'm just not quite sure how to convert this line:

  outA += Input.Color.a * tex2D(s, Input.TexCoord.xy + float2(-4.0 * pxSz.x * blurSize,0)).a * 0.05;

It's mostly the Tex2D I'm having trouble with. In GLSL, it seems to work differently.

I'm porting a horizontal blur

 texture al_tex;
   sampler2D s = sampler_state {
      texture = <al_tex>;
   };

   int tWidth;
   int tHeight;
   float blurSize = 5.0;
   float4 ps_main(VS_OUTPUT Input) : COLOR0
   {
      float2 pxSz = float2(1.0 / tWidth,1.0 / tHeight);
      float4 outC = 0;
      float outA = 0;
      outA += Input.Color.a * tex2D(s, Input.TexCoord.xy + float2(-4.0 * pxSz.x * blurSize,0)).a * 0.05;
      outA += Input.Color.a * tex2D(s, Input.TexCoord.xy + float2(-3.0 * pxSz.x * blurSize,0)).a * 0.09;
      outA += Input.Color.a * tex2D(s, Input.TexCoord.xy + float2(-2.0 * pxSz.x * blurSize,0)).a * 0.12;
      outA += Input.Color.a * tex2D(s, Input.TexCoord.xy + float2(-pxSz.x * blurSize,0)).a * 0.15;
      outA += Input.Color.a * tex2D(s, Input.TexCoord.xy + float2(0,0)).a * 0.16;
      outA += Input.Color.a * tex2D(s, Input.TexCoord.xy + float2(pxSz.x * blurSize,0)).a * 0.15;
      outA += Input.Color.a * tex2D(s, Input.TexCoord.xy + float2(2.0 * pxSz.x * blurSize,0)).a * 0.12;
      outA += Input.Color.a * tex2D(s, Input.TexCoord.xy + float2(3.0 * pxSz.x * blurSize,0)).a * 0.09;
      outA += Input.Color.a * tex2D(s, Input.TexCoord.xy + float2(4.0 * pxSz.x * blurSize,0)).a * 0.05;

     outC.a = outA;

      return outC;
   }

Thanks

\$\endgroup\$
1
2
\$\begingroup\$

Use texture2D (...) on older versions of OpenGL (before OpenGL 3.0) and texture (...) on newer versions.

Newer versions of GLSL (1.3+, which corresponds to OpenGL 3.0) are nice about this, they automatically determine the texture overload based on sampler type and texture coordinates you use. So you don't have to do textureCube (...), texture3D (...), etc.

Also, use proper texel centers when porting from D3D9. You don't need a half-texel offset in OpenGL or Direct3D 10.

\$\endgroup\$
0
\$\begingroup\$

The GLSL function you're looking for is called texture.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.