Skip to content

Instantly share code, notes, and snippets.

@eddietree
Last active December 31, 2015 00:59
Show Gist options
  • Save eddietree/7910870 to your computer and use it in GitHub Desktop.
Save eddietree/7910870 to your computer and use it in GitHub Desktop.
pseudocode for cloud shader. if you are billboarding the cloud quad, basically takes the direction the cloud is facing and changes the amount sampled per RGB channel
// passed in variables
float3 billboard_normal; // defined - (where billboard is facing), [-1,1] range
float2 uv; // defined - the UV of the quad [0,1] range
float time; // defined - passed in
texsampler tex_cloud_0; // cloud tex, each channel in RGB stores different monochrome texture
texsampler tex_cloud_1;
// normalize to [0,1] range
float3 billboard_normal_normalized = billboard_normal * 0.5f + float3(0.5f);
// sample from the texture
// (you can do things like animating the uv slowly)
float4 tex_sample_0 = tex2D( tex_cloud_0, uv );
float4 tex_sample_1 = tex2D( tex_cloud_1, uv );
// this part basically uses the normal and weights each channel
float cloud_val_0 = dot( tex_sample_0, billboard_normal_normalized ) / 3.0f;
float cloud_val_1 = dot( tex_sample_1, billboard_normal_normalized ) / 3.0f;
float cloud_val_final = lerp( cloud_val_0, cloud_val_1, sin(time)*0.5+0.5 );
@eddietree
Copy link
Author

basically, store a different cloud texture in each of the three RGB channels!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment