customIPP FX

customIPP FX

Postby ikam » Thursday, 08.November 2012, 17:04

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
You do not have the required permissions to view the files attached to this post.
ikam
Operator
Operator
 
Posts: 911
Joined: Friday, 14.October 2011, 13:00
Location: France

Re: customIPP FX

Postby Skinnytorus » Thursday, 08.November 2012, 17:22

CoooooL! I will revert to it as soon as I have more time to spend with wz! Many thanks! :)
Skinnytorus
Operator
Operator
 
Posts: 1300
Joined: Monday, 06.February 2012, 17:46

Re: customIPP FX

Postby Skinnytorus » Thursday, 08.November 2012, 17:31

By the way - is there any decent lightning (or electric charge) shader that could work with the custom material/ipp op?
Skinnytorus
Operator
Operator
 
Posts: 1300
Joined: Monday, 06.February 2012, 17:46

Re: customIPP FX

Postby ikam » Thursday, 08.November 2012, 19:08

surely, I'll try to find you a lightning shader.
ikam
Operator
Operator
 
Posts: 911
Joined: Friday, 14.October 2011, 13:00
Location: France

Re: customIPP FX

Postby Skinnytorus » Thursday, 08.November 2012, 20:18

Thanks. I've always raved about electric charges in wz. That would be soooo great! :)
Skinnytorus
Operator
Operator
 
Posts: 1300
Joined: Monday, 06.February 2012, 17:46

Re: customIPP FX

Postby ikam » Friday, 09.November 2012, 14:06

I've found a really cool lightning effect on web

Image
You do not have the required permissions to view the files attached to this post.
ikam
Operator
Operator
 
Posts: 911
Joined: Friday, 14.October 2011, 13:00
Location: France

Re: customIPP FX

Postby ikam » Friday, 09.November 2012, 16:41

and a way to render ipp on textures
You do not have the required permissions to view the files attached to this post.
ikam
Operator
Operator
 
Posts: 911
Joined: Friday, 14.October 2011, 13:00
Location: France

Re: customIPP FX

Postby Skinnytorus » Friday, 09.November 2012, 18:42

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.
Skinnytorus
Operator
Operator
 
Posts: 1300
Joined: Monday, 06.February 2012, 17:46

Re: customIPP FX

Postby ikam » Friday, 09.November 2012, 19:08

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...
ikam
Operator
Operator
 
Posts: 911
Joined: Friday, 14.October 2011, 13:00
Location: France

Re: customIPP FX

Postby Skinnytorus » Friday, 09.November 2012, 19:23

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 ;)
Skinnytorus
Operator
Operator
 
Posts: 1300
Joined: Monday, 06.February 2012, 17:46

Re: customIPP FX

Postby ikam » Friday, 09.November 2012, 20:10

yes don't forget to sacrifice a rabbit and 2 virgin :)
in wait it works with render target
You do not have the required permissions to view the files attached to this post.
ikam
Operator
Operator
 
Posts: 911
Joined: Friday, 14.October 2011, 13:00
Location: France

Re: customIPP FX

Postby Skinnytorus » Friday, 09.November 2012, 21:18

Done, CodeGuru :)
It works, but what if I want to add a master camera? The custom ipp reappears and won't go away... :(
You do not have the required permissions to view the files attached to this post.
Skinnytorus
Operator
Operator
 
Posts: 1300
Joined: Monday, 06.February 2012, 17:46

Re: customIPP FX

Postby Skinnytorus » Friday, 09.November 2012, 21:35

OK. I got it working! Use BillboardCamera instead! :)
You do not have the required permissions to view the files attached to this post.
Skinnytorus
Operator
Operator
 
Posts: 1300
Joined: Monday, 06.February 2012, 17:46

Re: customIPP FX

Postby ikam » Saturday, 10.November 2012, 08:26

Great with billboardcam
I've found a way to animate the render op, so it works with Tex2DAnim.
You do not have the required permissions to view the files attached to this post.
ikam
Operator
Operator
 
Posts: 911
Joined: Friday, 14.October 2011, 13:00
Location: France

Re: customIPP FX

Postby Skinnytorus » Saturday, 10.November 2012, 08:51

Cool! Thanks.
Skinnytorus
Operator
Operator
 
Posts: 1300
Joined: Monday, 06.February 2012, 17:46


Return to Tutorials



Who is online

Users browsing this forum: No registered users and 16 guests

cron