Jump to content
  • Advertisement
Sign in to follow this  
antoanbekele

Crysis Cloak Shader

This topic is 3664 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites
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!

Share this post


Link to post
Share on other sites
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..

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!