Crysis Cloak Shader

Started by
8 comments, last by antoanbekele 15 years, 4 months ago
Does anybody have any pointers on how to implement the translucient 'cloak on' effect in Crysis? Is there anything like this covered in the ShaderX or GPU Gems book series? Any comments would be much appreciated.
Advertisement
AFAICT it's just a refraction shader with a slight blue tint. There's a little bit of chromatic dispersion too, but the underlying principles remain the same. nVidia made some things in their shader library you might find practical.

EDIT: Actually I can do you one better. This is the actual pixel shader:
pixout CloakRefrationPS(vtxOUT IN){  pixout OUT;       // Debug output #if %_RT_DEBUG0 || %_RT_DEBUG1 || %_RT_DEBUG2 || %_RT_DEBUG3   DebugOutput(OUT.Color, float4(IN.baseTC, 0, 1));   return OUT; #endif    half4 baseColor = tex2D(diffuseMapSampler, IN.baseTC.xy);    half4 normalVec=half4(0,0,1,1);  normalVec.xyz = GetNormalMap(bumpMapSampler, IN.baseTC.xy) * (1-saturate( 0.05 * IN.screenPos.w ) );        half3 eyeVec = normalize(IN.viewVec.xyz);  half NdotE = saturate(dot(eyeVec.xyz, normalVec.xyz));        // Get refraction color    half2 refrTC = (IN.screenPos.xy/IN.screenPos.ww) ;    // optimize this  half4 interferenceColA = tex2D(screenNoiseSampler, refrTC.xy * half2(1.0, 1.1 * InterferenceSizeScale) * (ScrSize.xy / 64.0) + half2(0, IN.constsTbl.z));  half4 interferenceColB = tex2D(screenNoiseSampler, refrTC.xy * half2(1.0, InterferenceSizeScale) * (ScrSize.xy / 64.0) - half2(0, IN.constsTbl.z));    half4 interferenceCol = interferenceColA * interferenceColB;    half4 refrColorR = tex2D(envMapSamplerRefr, refrTC.xy - (normalVec.xy * interferenceCol *(half) IN.constsTbl.w)*1.5);  half4 refrColorG = tex2D(envMapSamplerRefr, refrTC.xy - (normalVec.xy * interferenceCol *(half) IN.constsTbl.w)*1);  half4 refrColorB = tex2D(envMapSamplerRefr, refrTC.xy - (normalVec.xy * interferenceCol *(half) IN.constsTbl.w)*0.1);    half4 refrColor = half4(refrColorR.r, refrColorG.g, refrColorB.b, 1);                                                                      half3  fVis = saturate(1-NdotE*0.05);  half4 finalColor = 1;  finalColor.xyz = refrColor; //fVis.xyz;      half  fEdgeSmooth = saturate(dot(eyeVec.xyz, normalVec.xyz));  fEdgeSmooth = pow(saturate(fEdgeSmooth), 4);      #if %_RT_FOG      //ComputeGlobalFogPS(finalColor.xyz, IN.viewVec.w);  //finalColor.xyz = IN.AvgFogVolumeContrib.xyz + finalColor.xyz * IN.AvgFogVolumeContrib.w;  //finalColor.w *= IN.viewVec.w;#endif  	//finalColor.xyz refrColor.xyz*	finalColor.w *= 0.7;//  finalColor.xyz = 1-saturate( 0.05 * IN.screenPos.w );  //finalColor.w = 1;    HDROutput(OUT, finalColor, 1);  return OUT;  }pixout CloakDifractionPS(vtxOUT IN){  pixout OUT;       // Debug output #if %_RT_DEBUG0 || %_RT_DEBUG1 || %_RT_DEBUG2 || %_RT_DEBUG3   DebugOutput(OUT.Color, float4(IN.baseTC, 0, 1));   return OUT; #endif    half4 baseColor = tex2D(diffuseMapSampler, IN.baseTC.xy);    half4 normalVec=half4(0,0,1,1);  normalVec.xyz = GetNormalMap(bumpMapSampler, IN.baseTC.xy);    half4 glossColor = normalVec.w;#ifdef %GLOSS_MAP    glossColor = tex2D(glossMapSampler, IN.baseTC.xy);#endif      half3 eyeVec = normalize(IN.viewVec.xyz);  half NdotE = saturate(dot(eyeVec.xyz, normalVec.xyz));     // optimize this      half2 refrTC = (IN.screenPos.xy/IN.screenPos.ww);    half4 interferenceColA = tex2D(screenNoiseSampler, refrTC.xy * half2(1.0, 1.1 * InterferenceSizeScale) * (ScrSize.xy / 64.0) + half2(0, IN.constsTbl.z));  half4 interferenceColB = tex2D(screenNoiseSampler, refrTC.xy * half2(1.0, InterferenceSizeScale) * (ScrSize.xy / 64.0) - half2(0, IN.constsTbl.z));    half4 interferenceCol = interferenceColA * interferenceColB;        half4 finalColor=1;      half3 eyeVecInf = normalize(ViewPos.xyz);  half fringeLookup = (1.0 / dot(normalize(normalVec.xyz*float3(0.1, 0.1, 1.0)), eyeVec.xyz)) * DifractionWrap;  half3 fringeColor = tex2D(fringeMapSampler, fringeLookup.xx).xyz;                         finalColor.xyz = interferenceCol* DifractionAmount *(pow(saturate(NdotE), MatSpecColor.w)) * glossColor.xyz * fringeColor.xyz* (1-saturate( 0.05 * IN.screenPos.w ) );  //ComputeGlobalFogPS(finalColor.xyz, IN.viewVec.w);#if %_RT_FOG        finalColor.xyz = finalColor.xyz * IN.AvgFogVolumeContrib.w * IN.viewVec.w;  #endif            HDROutput(OUT, finalColor , 1);  return OUT;  }

If this is considered legally iffy or whatever I don't mind taking it down. It's for science!
clb: At the end of 2012, the positions of jupiter, saturn, mercury, and deimos are aligned so as to cause a denormalized flush-to-zero bug when computing earth's gravitational force, slinging it to the sun.
Depends on where you got that code from. Is it yours, or is it a reprint from somewhere?
Jeromy Walsh
Sr. Tools & Engine Programmer | Software Engineer
Microsoft Windows Phone Team
Chronicles of Elyria (An In-development MMORPG)
GameDevelopedia.com - Blog & Tutorials
GDNet Mentoring: XNA Workshop | C# Workshop | C++ Workshop
"The question is not how far, the question is do you possess the constitution, the depth of faith, to go as far as is needed?" - Il Duche, Boondock Saints
All of crysis' shaders source code are in one of their pack files, which you can easily open with an unzipping program (I wonder why they did that...)
So im guessing that code is theirs..
Why shouldn't they? Id Software does it as well! :)
Thanks for the info InvalidPointer, just what I was looking for. I was aware I could unpack the assets, but was looking for the principles involved like what you mentioned, tis difficult to abstract those out otherwise by looking at the code alone.

What's really cool is the dynamic 'running electricity' effect over the refraction layer, also as seen in the predator cloack. Wonder how they did that?

Thanks again.
Are you refering to Crysis 1 or 2?

I thought Crysis 2 had their files compressed with their own compression format
Crysis 1, not Warhead.
Quote:Original post by antoanbekele
What's really cool is the dynamic 'running electricity' effect over the refraction layer, also as seen in the predator cloack. Wonder how they did that?
Keep in mind that I haven't actually seen the effect in question, but you should be able to use a tiling lightning texture, and animate the texture coordinates.

Tristam MacDonald. Ex-BigTech Software Engineer. Future farmer. [https://trist.am]

Ah, I see. Thanks for that SwiftCoder. Think I'm all set to have a go and put it all together.

Cheers

This topic is closed to new replies.

Advertisement