Page 1 of 3

customIPP FX

PostPosted: Thursday, 08.November 2012, 17:04
by ikam
Hi

I would like to show you how you can obtain cool fx with customIPP like those on this web pages :

http://glsl.heroku.com/
http://www.iquilezles.org/apps/shadertoy/

these shader are written in GLSL, it's the opengl version of HLSL. These 2 language are very close so it's very easy to convert one code to ther one

for example if you go to http://glsl.heroku.com/ and create new effect you obtain this code :

Code: Select all
#ifdef GL_ES
precision mediump float;
#endif

uniform float time;
uniform vec2 mouse;
uniform vec2 resolution;

void main( void ) {

   vec2 position = ( gl_FragCoord.xy / resolution.xy ) + mouse / 4.0;

   float color = 0.0;
   color += sin( position.x * cos( time / 15.0 ) * 80.0 ) + cos( position.y * cos( time / 15.0 ) * 10.0 );
   color += sin( position.y * sin( time / 10.0 ) * 40.0 ) + cos( position.x * sin( time / 25.0 ) * 40.0 );
   color += sin( position.x * sin( time / 5.0 ) * 10.0 ) + sin( position.y * sin( time / 35.0 ) * 80.0 );
   color *= sin( time / 10.0 ) * 0.5;

   gl_FragColor = vec4( vec3( color, color * 0.5, sin( color + time / 3.0 ) * 0.75 ), 1.0 );
}




here the HLSL version, that you can use with customIPP :

Code: Select all
uniform float time : register(c9);  // var0
uniform float4 var1 : register(c10); // var1
uniform float4 var2 : register(c11); // var2
uniform float4 var3 : register(c12); // var3
uniform float4 var4 : register(c13); // var4

void main
(
 in float2 uv0 : TEXCOORD0,
 out float4 color0 : COLOR0,
 in float2 vpos : VPOS
)
{

 //float2 position = ( vpos.xy / resolution.xy ) + 0 / 4.0;
 float2 position = uv0 - 0.5;

 float color = 0.0;
 color += sin( position.x * cos( time / 15.0 ) * 80.0 ) + cos( position.y * cos( time / 15.0 ) * 10.0 );
 color += sin( position.y * sin( time / 10.0 ) * 40.0 ) + cos( position.x * sin( time / 25.0 ) * 40.0 );
 color += sin( position.x * sin( time / 5.0 ) * 10.0 ) + sin( position.y * sin( time / 35.0 ) * 80.0 );
 color *= sin( time / 10.0 ) * 0.5;

 color0 = float4( float3( color, color * 0.5, sin( color + time / 3.0 ) * 0.75 ), 1.0 ); 
}



The diff (GLSL => HLSL) :

gl_FragColor => color0
gl_FragCoord => vpos
vec4 (vec3, vec2) => float4 (float3, float2) (just replace vec with float)

declared variables :

uniform float time => uniform float time : register(c9); // ps_var0, so you need to edit the animation script and pass to ps_var0 the time value
uniform vec2 mouse => not used (there is no mouse interaction in werkkzeug), so just remove references of this variable
uniform vec2 resolution => (screen resolution) for now not known by customIPP, but I've posted a fix to pass this info to the pixel shader of customIPP.

in wait of screen resolution you can replace screen coordinate with uv coord, like this :

// float2 position = ( vpos.xy / resolution.xy ) + 0 / 4.0; // screen coord
float2 position = uv0 - 0.5; // uv coord

the only diff is taht ratio is unknow without screen resolution, so shape could be crushed...


If you obtain this error : "error X3014: incorrect number of arguments to numeric-type constructor" (in debug shadercode)

this is manly due to this mistake :

float3 pos = float3(0); // BAD, each value (x,y,z) need to be define into constructor in HLSL
float3 pos = float3(0,0,0); // GOOD BOY !!!

for example you can obtain this error with this bad declaration :

uniform float4 time : register(c9); // BAD, in most of code example time is a float, not a float4




Most of intrinsic functions are the same on both languages, but there is some specific case :

(non exhaustive list)

(GLSL => HLSL)
mix => lerp
mod => fmod
texture2D => tex2D
fract => frac
atan(y,x) => atan2(y,x)
...

Don't forrget to consult doc for help :

GLSL => http://www.opengl.org/sdk/docs/manglsl/
HLSL => msdn.microsoft.com/en-us/library/windows/desktop/ff471376%28v=vs.85%29.aspx


And here the wz4 example used on this post

Re: customIPP FX

PostPosted: Thursday, 08.November 2012, 17:22
by Skinnytorus
CoooooL! I will revert to it as soon as I have more time to spend with wz! Many thanks! :)

Re: customIPP FX

PostPosted: Thursday, 08.November 2012, 17:31
by Skinnytorus
By the way - is there any decent lightning (or electric charge) shader that could work with the custom material/ipp op?

Re: customIPP FX

PostPosted: Thursday, 08.November 2012, 19:08
by ikam
surely, I'll try to find you a lightning shader.

Re: customIPP FX

PostPosted: Thursday, 08.November 2012, 20:18
by Skinnytorus
Thanks. I've always raved about electric charges in wz. That would be soooo great! :)

Re: customIPP FX

PostPosted: Friday, 09.November 2012, 14:06
by ikam
I've found a really cool lightning effect on web

Image

Re: customIPP FX

PostPosted: Friday, 09.November 2012, 16:41
by ikam
and a way to render ipp on textures

Re: customIPP FX

PostPosted: Friday, 09.November 2012, 18:42
by Skinnytorus
Yes! Yes! Yes! Awesome work! :)
Some questions as usual:
1) Is there a way to make this charge gradually grow and branch (like a real lightning)?
2) The lightning material won't animate (F6). How to make it work?
Thank you.

Re: customIPP FX

PostPosted: Friday, 09.November 2012, 19:08
by ikam
1/ you can grow it gradually yes, and move it on screen but not create branch with this actual code. Look at the variable to tweak and bind them with ps_var to animate them with animation script.

2/ render operator is only static, if you want an animated i think you need a render target or a loop and animated texture. I think it can be use also with custommaterial (not tested) but for now it doesn't support animation, I'll need code an new operator to do that, maybe soon...

Re: customIPP FX

PostPosted: Friday, 09.November 2012, 19:23
by Skinnytorus
1) OK. The lightning is awesome as it is :)
2) I tried Loop on Render op's Time para - doesn't work for me :(. Yes. There is a real need for material animation. Animatable UV tranform controls would be handy too. I will ask Almighty Megatron to boost your creative powers ;)

Re: customIPP FX

PostPosted: Friday, 09.November 2012, 20:10
by ikam
yes don't forget to sacrifice a rabbit and 2 virgin :)
in wait it works with render target

Re: customIPP FX

PostPosted: Friday, 09.November 2012, 21:18
by Skinnytorus
Done, CodeGuru :)
It works, but what if I want to add a master camera? The custom ipp reappears and won't go away... :(

Re: customIPP FX

PostPosted: Friday, 09.November 2012, 21:35
by Skinnytorus
OK. I got it working! Use BillboardCamera instead! :)

Re: customIPP FX

PostPosted: Saturday, 10.November 2012, 08:26
by ikam
Great with billboardcam
I've found a way to animate the render op, so it works with Tex2DAnim.

Re: customIPP FX

PostPosted: Saturday, 10.November 2012, 08:51
by Skinnytorus
Cool! Thanks.