[Stanley.Hayes]
  • About Stan
  • Projects
  • Resume
  • SubRay Website
  • ShaderToy Submissions
  • Triangle Rasterizer(C++)
  • 2d MetaBall Shader(HLSL)
  • Edge Light Shader(HLSL)
  • 2d "Wibble" shader (HLSL)
  • Valintines day shader
  • Blog

2D "Wibble" Shader(HLSL)

Simple sinusoidal  texture distortion 
My first iteration of this simply offset that coordinates to sample from of, but with that I realized how many other things could be done. Below is the final version of the shader. The wibbleParams structure has values used for a variety of different modifiers. The modifiers in the struct allow for the effect to be used for tails and plants in the game. For plants the effect needs to be less harsh and has to have a root point where the effect is not there. 
Picture
By simply using sin to find an offset we can create wave effects that can be use for the tails of objects and to make brush and things come alive in an underwater environment. 
Picture
In the animation above from the SubRay Alpha the effect an be seen in not only the tails of the 'fish' along with the glowing plants. All of these objects are using the shader but give different parameters
float4 WibblePixelShader(PixelInputType input) : SV_TARGET
{
	float4 textureColor;

	//translate the position of the texture position
	input.texDemension.x += input.instancedTex.x;
	input.texDemension.y += input.instancedTex.y;

	input.wibbleParams1.z -= 0.01; 

	if(input.texDemension.y > input.wibbleParams1.y)
	{
		float newTexDem;
		newTexDem = input.texDemension.x / input.wibbleParams1.y;
		if(input.texDemension.x < input.wibbleParams1.z)
			input.texDemension.y = input.texDemension.y + sin(input.wibbleParams2.x * input.wibbleParams2.z + 3.14159 * 2 * input.texDemension.x + input.wibbleParams2.y) * input.wibbleParams1.x * (input.texDemension.x / input.wibbleParams1.z) * .03;
		else
			input.texDemension.y = input.texDemension.y + sin(input.wibbleParams2.x * input.wibbleParams2.z + 3.14159 * 2 * input.texDemension.x + input.wibbleParams2.y) * input.wibbleParams1.x * .03;
	}

    textureColor = shaderTexture.Sample(SampleType, input.texDemension);	 

    return textureColor;
}
Powered by Create your own unique website with customizable templates.