Jump to content

  • Log In with Google      Sign In   
  • Create Account

Tyler Glaiel

Member Since 09 Dec 2012
Offline Last Active Dec 11 2012 03:46 PM

Posts I've Made

In Topic: Closure's logo - disappating vapor effect

09 December 2012 - 05:41 PM

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.

In Topic: Closure's logo - disappating vapor effect

09 December 2012 - 02:40 PM

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
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;
}

Title Screen Logo fragment shader
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);
}

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

Fog vertex shader
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;
}

fog fragment shader

//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);
}


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

PARTNERS