Shader glsl to hlsl

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
Post Reply
Opiale
Posts: 2
Joined: Tue Feb 05, 2013 3:16 pm

Shader glsl to hlsl

Post by Opiale »

Hello everyone,

I'm writing to you today because i found in you a kind of hope.
I saw a topic where someone converted a GLSL code to HLSL code.

Currently, i'm working on THE GAME OF MY LIFE every minutes of my life, and i'm stuck for some weeks.

I found this shockwave effect that i needed on this website :
http://www.geeks3d.com/20091116/shader- ... lter-glsl/
And this website found the shader on this website :
http://empire-defense.crystalin.fr/blog ... ith_shader


I tried to learn hlsl and glsl but i'm too far to succeed.
I know that's not your job to "do my work" but i'll be happy if you can give me a hand.

Here is the code I would like to convert :

Code: Select all

uniform sampler2D sceneTex; // 0
uniform vec2 center; // Mouse position
uniform float time; // effect elapsed time
uniform vec3 shockParams; // 10.0, 0.8, 0.1
 
void main() 
{ 
  vec2 uv = gl_TexCoord[0].xy;
  vec2 texCoord = uv;
  float distance = distance(uv, center);
  if ( (distance <= (time + shockParams.z)) && 
       (distance >= (time - shockParams.z)) ) 
  {
    float diff = (distance - time); 
    float powDiff = 1.0 - pow(abs(diff*shockParams.x), 
                                shockParams.y); 
    float diffTime = diff  * powDiff; 
    vec2 diffUV = normalize(uv - center); 
    texCoord = uv + (diffUV * diffTime);
  } 
  gl_FragColor = texture2D(sceneTex, texCoord);
}
Hope you can help me.
(And sorry for my awful english...)
ikam
Posts: 46
Joined: Sun Jun 24, 2007 4:46 pm
Location: France

Re: Shader glsl to hlsl

Post by ikam »

Code: Select all

uniform sampler2D sceneTex; // 0
uniform float2 center; // Mouse position
uniform float time; // effect elapsed time
uniform float3 shockParams; // 10.0, 0.8, 0.1
 
void main
(
float2 Texcoords  : TEXCOORD0,
out float4 color0 : COLOR0
)
{
  float2 uv = Texcoords.xy;
  float2 texCoord = uv;
  float dist = distance(uv, center);
  if ( (dist <= (time + shockParams.z)) &&
       (dist >= (time - shockParams.z)) )
  {
    float diff = (dist - time);
    float powDiff = 1.0 - pow(abs(diff*shockParams.x),
                                shockParams.y);
    float diffTime = diff  * powDiff;
    float2 diffUV = normalize(uv - center);
    texCoord = uv + (diffUV * diffTime);
  }
  color0 = tex2D(sceneTex, texCoord);
}
should be something like that
Opiale
Posts: 2
Joined: Tue Feb 05, 2013 3:16 pm

Re: Shader glsl to hlsl

Post by Opiale »

Thanks a lot ikam,
Encore merci.
Post Reply