/// <summary> /// Initializes the <see cref="ExplosionRefractionEffect"/> class. /// </summary> static ExplosionRefractionEffect() { // Set the default values DefaultLifeSpan = _defaultLifeSpan; DefaultExpansionRate = new Vector2(1.5f, 1.5f); DefaultIntensity = _defaultIntensity; // Check if shaders are supported if (!Shader.IsAvailable) { const string msg = "Unable to construct shader for `ExplosionRefractionEffect` - shaders are not supported on this system."; if (log.IsInfoEnabled) { log.InfoFormat(msg); } return; } // Try to create the default shader try { var code = Resources.ExplosionRefractionEffectShader; _defaultShader = ShaderExtensions.LoadFromMemory(code); } catch (LoadingFailedException ex) { const string errmsg = "Failed to load the default Shader for ExplosionRefractionEffect. Exception: {0}"; if (log.IsErrorEnabled) { log.ErrorFormat(errmsg, ex); } Debug.Fail(string.Format(errmsg, ex)); } }
/// <summary> /// Initializes the <see cref="WaterRefractionEffect"/> class. /// </summary> static WaterRefractionEffect() { // Set the default values DefaultWaterAlpha = _defaultWaterAlpha; DefaultWaveSpeed = _defaultWaveSpeed; DefaultWaveIntensity = _defaultWaveIntensity; DefaultMagnification = _defaultMagnification; // Check if shaders are supported if (!Shader.IsAvailable) { const string msg = "Unable to construct shader for `WaterRefractionEffect` - shaders are not supported on this system."; if (log.IsInfoEnabled) { log.InfoFormat(msg); } return; } // Try to create the default shader try { var code = Resources.WaterRefractionEffectShader; _defaultShader = ShaderExtensions.LoadFromMemory(code); } catch (LoadingFailedException ex) { const string errmsg = "Failed to load the default Shader for WaterRefractionEffect. Exception: {0}"; if (log.IsErrorEnabled) { log.ErrorFormat(errmsg, ex); } Debug.Fail(string.Format(errmsg, ex)); } }
/// <summary> /// Initializes the <see cref="RefractionManager"/> class. /// </summary> static RefractionManager() { // Check if shaders are supported if (!Shader.IsAvailable) { const string msg = "Unable to construct shader for `RefractionManager` - shaders are not supported on this system."; if (log.IsInfoEnabled) { log.InfoFormat(msg); } return; } const string defaultShaderCode = @" /* This effect uses the R, G, and A channels to perform a reflection distortion. Color channels are used in the following ways: R: The amount to translate on the X axis (< BaseOffset for right, > BaseOffset for left). G: The amount to translate on the Y axis (< BaseOffset for down, > BaseOffset for up). A: The alpha value of the reflected image. 0.0 shows nothing, while 1.0 shows only the reflection. */ // The distance multiplier to apply to the values unpacked from channels to get the offset. This decreases our resolution, // giving us a choppier image, but increases our range. Lower values give higher resolution but require smaller distances. // This MUST be the same in all the refraction effects! const float DistanceMultiplier = 2.0; // The value of the reflection channels that will be used to not perform any reflection. Having this non-zero allows us to // reflect in both directions instead of just borrowing pixels in one direction. Of course, this also halves our max distance. // Logically, this value is 1/2. However, a slightly different number is used due to the behavior of floating-point numbers. // This MUST be the same in all the refraction effects! const float BaseOffset = 0.4981; // The texture that contains the colors to use. Typically, a copy of the screen to be distorted. uniform sampler2D ColorMap; // The texture containing the noise that will be used to distort the ColorMap. uniform sampler2D NoiseMap; void main (void) { vec4 noiseVec; vec4 colorReflected; vec4 colorOriginal; // Get the noise vector from the noise map. noiseVec = texture2D(NoiseMap, gl_TexCoord[0].st).rgba; // Get the original texel color, which is just the texel at the ColorMap at the same position as the NoiseMap. colorOriginal = texture2D(ColorMap, gl_TexCoord[0].st); // Using the noise vector to offset the position, find the corresponding reflected color on the color map. colorReflected = texture2D(ColorMap, gl_TexCoord[0].st + ((noiseVec.xy - BaseOffset) * DistanceMultiplier)); // Mix the reflected and original texels together by the alpha of the noise vector to get the final pixel color. gl_FragColor = mix(colorOriginal, colorReflected, noiseVec.a); }"; // Try to create the default shader try { _defaultShader = ShaderExtensions.LoadFromMemory(defaultShaderCode); } catch (LoadingFailedException ex) { const string errmsg = "Failed to load the default Shader for the RefractionManager. Exception: {0}"; if (log.IsErrorEnabled) { log.ErrorFormat(errmsg, ex); } Debug.Fail(string.Format(errmsg, ex)); } }