Sign in to follow this  
BlinksTale

Closure's logo - disappating vapor effect

Recommended Posts

BlinksTale    318
Abstract question here, anyone know how the PSN game Closure did its logo? As seen in the first twenty five seconds here:

http://www.youtube.com/watch?v=cQd4GCCg6DI

There's this awesome "disappating vapors" effect as I'm calling it, it looks like clouds appearing and disappearing in the sky (sped up to triple speed though) and I'd love to use the same effect for flames coming out of the top of a fire. (tweaked to be one directional though, maybe a higher chance of being together the lower on the flame it is) So, has anyone seen this effect before, or know how it's done?

Share this post


Link to post
Share on other sites
tylerglaiel    110
All the game's shader source files are included in the resources folder for the game (if you get the steam version), for reference here's the relevant ones


default vertex shader
[CODE]
void main (half4 position : POSITION,
half2 texCoord : TEXCOORD0,
uniform half4 color,

uniform float4x4 Proj,
uniform float4x4 modelView,
out half4 oPosition : POSITION,
out half2 oTexCoord : TEXCOORD0,
out half4 frontcolor : COLOR0
)
{
oPosition = mul(Proj, mul (modelView, position));
oTexCoord = texCoord;
frontcolor = color;
}
[/CODE]

Title Screen Logo fragment shader
[CODE]
void main (half2 texCoord : TEXCOORD0,
half4 color : COLOR0,
uniform half4 tint = half4(0, 0, 0, 0),
sampler2D tex : TEXTUNIT0,
uniform sampler2D noise : TEXUNIT1,
uniform float timer,
uniform float flicker,
uniform float2 blurflicker,
uniform float threshold_max,
uniform float threshold_min,
out half4 oColor : COLOR)
{
float wave = sin(timer+texCoord.x*20)*.005;
oColor = tex2D (tex, texCoord + float2(0.0, wave)) * color + tint;
float fogcol = tex2D(noise, texCoord*float2(.5, .5)+ float2(0.0, wave*.5)).r;
float threshold = cos(timer*.2)*.4+.25; //threshold bounds between .3 and .5
if(threshold > min(threshold_max, .5)) threshold = min(threshold_max, .5); //black
if(threshold < max(threshold_min, .3)) threshold = max(threshold_min, .3); //white
if(fogcol < threshold) fogcol = 0; else fogcol = 1;

if(oColor.r > .6){
oColor = fogcol;
} else {
if(oColor.r>.1){
oColor = float4(.2, .2, .2, oColor.a)+fogcol*.3;
}
}

if(blurflicker.r>.5){
float blurrer = 0;
for(float i = -5.0; i<5.0; i+=1.0){
blurrer += tex2D (tex, texCoord + float2(i/256.0, wave));
}
oColor = oColor*.5+float4((blurrer / 10.0).rrr, oColor.a);
}
if(blurflicker.g>.5){
float blurrer = 0;
for(float i = -5.0; i<5.0; i+=1.0){
blurrer += tex2D (tex, texCoord + float2(0, wave+i/128.0));
}
oColor = oColor*.5+float4((blurrer / 10.0).rrr, oColor.a);
}
oColor *= flicker*2;
// oColor = float4(fogcol.rrr, 1);
}
[/CODE]

these 2 go together
============================

Fog vertex shader
[CODE]
void main (float4 position : POSITION,
float2 texCoord : TEXCOORD0,
uniform float4 color,
//uniform float4x4 modelViewProj,
uniform float4x4 Proj,
uniform float4x4 modelView,
uniform float4x4 camera,
uniform float4x4 lighttransform,
uniform float4 level0,
uniform float4 level1,
uniform float4 level2,
uniform float4 level3,
uniform float4 level4,

out float3 coords0 : TEXCOORD0,
out float3 coords1 : TEXCOORD1,
out float3 coords2 : TEXCOORD2,
out float3 coords3 : TEXCOORD3,
out float3 coords4 : TEXCOORD4,
out float2 lighttexcoord : TEXCOORD5,
out float4 oPosition : POSITION
)
{
coords0 = float3((level0.xy+texCoord.xy)*level0.z, level0.w);
coords1 = float3((level1.xy+texCoord.xy)*level1.z, level1.w);
coords2 = float3((level2.xy+texCoord.xy)*level2.z, level2.w);
coords3 = float3((level3.xy+texCoord.xy)*level3.z, level3.w);
coords4 = float3((level4.xy+texCoord.xy)*level4.z, level4.w);

float4 screenposition = mul(Proj, mul (modelView, position));
lighttexcoord = (mul(lighttransform, screenposition)).xy;
oPosition = mul(mul(mul(Proj, camera), modelView), position);//Proj*camera*modelView*position;
}
[/CODE]

fog fragment shader

[CODE]
//fast cubic texture fetch functions
inline float w0(const float x){
return (-x*x*x + 3.0*x*x - 3.0*x + 1.0)/6.0;
}
inline float w1(const float x){
return (3.0*x*x*x - 6.0*x*x + 4.0)/6.0;
}
inline float w2(const float x){
return (-3.0*x*x*x + 3.0*x*x + 3.0*x + 1.0)/6.0;
}
inline float w3(const float x){
return (x*x*x)/6.0;
}
inline float g0(const float x){
return w0(x)+w1(x);
}
inline float g1(const float x){
return w2(x)+w3(x);
}
inline float h0(const float x){
return 1.0-(w1(x)/(w0(x)+w1(x)))+x;
}
inline float h1(const float x){
return 1.0+(w3(x)/(w2(x)+w3(x)))-x;
}

inline float texture2DCubicX(sampler2D tex_source, const float2 coord_source){
const float size_source = 512.0;
const float e_x = (1.0/512.0);

const float coord_hg = coord_source.x*size_source-.5;
const float3 hg_x = float3(h0(frac(coord_hg)), h1(frac(coord_hg)), g0(frac(coord_hg)));

const float coord_source1 = coord_source.x - hg_x.x * e_x;
const float coord_source0 = coord_source.x + hg_x.y * e_x;

float tex_source0 = h1tex2D( tex_source, float2(coord_source0, coord_source.y) );
float tex_source1 = h1tex2D( tex_source, float2(coord_source1, coord_source.y) );
tex_source0 = lerp( tex_source0, tex_source1, hg_x.z );
return tex_source0;
}
inline float texture2DCubicFast(sampler2D tex_source, const float2 coord_source){
const float size_source = 512.0;
const float e_x = (1.0/512.0);

const float coord_hg = coord_source.y*size_source-.5;
const float3 hg_x = float3(h0(frac(coord_hg)), h1(frac(coord_hg)), g0(frac(coord_hg)));

const float coord_source1 = coord_source.y - hg_x.x * e_x;
const float coord_source0 = coord_source.y + hg_x.y * e_x;

float tex_source0 = texture2DCubicX( tex_source, float2(coord_source.x, coord_source0) );
float tex_source1 = texture2DCubicX( tex_source, float2(coord_source.x, coord_source1) );
tex_source0 = lerp( tex_source0, tex_source1, hg_x.z );
return tex_source0;
}

inline float level(float3 data, sampler2D fogg){
//float Angle = texture2D(fog, data.xy)*2*3.141592+timer*5;
// mat2 RotationMatrix = mat2( cos( Angle ), -sin( Angle ),
// sin( Angle ), cos( Angle ));
return texture2DCubicFast(fogg, data.xy/*RotationMatrix*(Angle-timer*5)*.05*/)*data.z;
}
/*
float4 pallatemap(float index, sampler2D pallate){
return float4(1,1,1,1);//tex2D(pallate, float2(index, 0.0));
}

/*
uniform sampler2D fog;
uniform sampler2D light;
uniform sampler2D pallate;
//format: vx,vy, scale, brightness
varying vec3 coords[5];
varying vec2 lighttexcoord;
uniform float timer;
*/
void main (float4 color : COLOR0,
uniform sampler2D fog : TEXUNIT0,
uniform sampler2D light : TEXUNIT1,
uniform sampler2D pallate : TEXUNIT2,
uniform float timer,

float2 lighttexcoord : TEXCOORD5,
float3 coords0 : TEXCOORD0,
float3 coords1 : TEXCOORD1,
float3 coords2 : TEXCOORD2,
float3 coords3 : TEXCOORD3,
float3 coords4 : TEXCOORD4,

out float4 oColor : COLOR)
{

float4 lightfrag = tex2D(light, lighttexcoord);

float4 fogcol = float4((level(coords0, fog)+level(coords1, fog)+level(coords2, fog)+level(coords3, fog)+level(coords4, fog)).xxx, 1.0)*float4(.9, .9, 1, 1);


oColor = fogcol*lightfrag;
if(lightfrag.r<0.01){
oColor = float4(0,0,0,0);
}

//float4 lightfrag = tex2D(light, lighttexcoord);
//if(lightfrag.r<0.01) discard;
//oColor = texture2DCubicFast(fog, coords[4]+timer);
}
[/CODE]


these 2 go together


The fog is rendered to a texture, and the texture is fed into the title screen logo shader.

The fog shader is the same one that makes the background fog effect in-game, these 2 could probably be the same shader, but there's not much else going on on the title screen so I didn't need to do that.


You can use these for learning but don't just copy paste the code, its terrible code anyway, and you won't really be able to just use them cause they require a lot of setup in the game code to look right.

- Tyler


fun fact the title logo effect was my attempt to replicate the after-effects filter Jon used for the trailer http://www.youtube.com/watch?v=uuOB6AHNGPs Edited by Tyler Glaiel

Share this post


Link to post
Share on other sites
BlinksTale    318
Oh wow, I never could have imagined this response. First, thank you Mr. Glaiel for the indepth look at the code, and congratulations on getting the game out! (a bit late to saying that, but any shipped game is a huge accomplishment) I have no intention of copying the code. In fact, I don't think I'd have the ability - I still need to learn the basics of shaders.

I'm trying pretty hard to understand the code I'm seeing (and thank you MrOMGWTF for another good source on it too), but right now a lot of it is over my head. I'm seeing numbers from Pascal's triangle, checks above and below boundaries to represent visibility, and the impression I'm getting is that there is a randomly generated fog effect that is being applied through shaders to some projection. So, might I ask how the fog is generated on an abstract or high end level? Are there vertices that are trying to move on a single polygon, but sometimes have the ability to break apart? Or is it more raster based and there is a probability that tiles will convert from light to dark based on their surroundings? Or maybe I'm way off xD

This is really interesting, thank you all! I may not be an expert at graphics, but I'm kinda crazy about how cool everything in this forum is.

Share this post


Link to post
Share on other sites
tylerglaiel    110
The fog is one noise texture (noise.png), which is scaled up, translated, and blended with itself 5 times (doubling the scale each time, I pass the values for that in from the game's code), most of the code in the fog shader is just doing a cubic blend between the pixels (instead of bilinear by default), which is completely unnecessary if you just want the basic effect. Cubic just looks a lot nicer for fog.

Share this post


Link to post
Share on other sites
BlinksTale    318
Cool, thank you! I've used randomly generated fog in Photoshop before, but I never knew it could be blended/animated like this for such an effect. Definitely going to keep this in the back of my head for future projects.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this