Jump to content

Vignette Shader


photo

Recommended Posts

I finally got around to writing a shader for unigine. 
So far I have only tested with OpenGL (waiting for a windows machine - to become free in the office).

vertex shader is essentially a copy of  vertex_blur_radial.shader.

 

fragment shader looks like this.

#include <core/shaders/default/common/fragment_base.h>

/******************************************************************************\
*
* OpenGL
*
\******************************************************************************/

#ifdef OPENGL

uniform sampler2D s_texture_0;
uniform half lens_radius;
uniform half lens_feathering;

/*
 */
void main() {
	float2 texcoord = s_texcoord_0.xy;
	half3 color = texture(s_texture_0,texcoord).xyz;

	float dist = distance(texcoord, vec2(0.5,0.5));
	vec3 vig = vec3(smoothstep(lens_radius, (lens_radius-0.001)*lens_feathering, dist));
	s_frag_color = half4(vec4(color*vig, 1.0));
}


/******************************************************************************\
 *
 * Direct3D11
 *
 * \******************************************************************************/


#elif DIRECT3D11

Texture2D s_texture_0 : register(t0);

struct FRAGMENT_IN {
	float4 position : SV_POSITION;
	float2 texcoord_0 : TEXCOORD0;
};

float lens_radius;
float lens_feathering;

float3 main(FRAGMENT_IN IN) : SV_TARGET {
	float2 texcoord = IN.texcoord_0;
	float3 color = s_texture_0.Sample(s_sampler_0,texcoord.xy).xyz;
	float dist = distance(texcoord, float2(0.5,0.5));
        float v = smoothstep(lens_radius,(lens_radius-0.001)*lens_feathering, dist);
	return color * float3(v,v,v);
}


/******************************************************************************\
 *
 * Direct3D9
 *
 \ *******************************************************************************/

#elif DIRECT3D9

struct FRAGMENT_IN {
	float2 texcoord_0 : TEXCOORD0;
};

half lens_radius;
half lens_feathering;

/*
 */
half4 main(FRAGMENT_IN IN) : COLOR {

	float2 texcoord = IN.texcoord_0;
	half3 color = tex2D(s_texture_0,texcoord).xyz;
	float dist = distance(texcoord, float2(0.5,0.5));
        float v = smoothstep(lens_radius,(lens_radius-0.001)*lens_feathering, dist);
	return half4(color * float3(v,v,v),1.0f);
}

/******************************************************************************\
 *
 * PlayStation3
 *
 \ *******************************************************************************/

#elif PLAYSTATION3

##pragma disablepc all

uniform sampler2D s_texture_0 : TEXUNIT0;

struct FRAGMENT_IN {
	float2 texcoord_0 : TEXCOORD0;
};

uniform half lens_radius;
uniform half lens_feathering;

/*
 */
half4 main(FRAGMENT_IN IN) : COLOR {

	float2 texcoord = IN.texcoord_0;
	half3 color = h3tex2D(s_texture_0,texcoord);

	float dist = distance(texcoord,float2(0.5f,0.5f));
        float v = smoothstep(lens_radius,(lens_radius-0.001)*lens_feathering,dist);
       
	return half4(color * float3(v,v,v),1.0f);
}


#endif

material definition looks like this.
 

<!--
/* Vignette material
*/
-->
<material name="post_vignette">

<!-- shaders -->
<shader pass="post"
		vertex="core/shaders/default/post/vertex_vignette.shader"
		fragment="core/shaders/default/post/fragment_vignette.shader"/>

<!-- textures -->
<texture name="color" pass="post" type="procedural"/>

<!-- parameters -->
<parameter name="lens_radius" type="slider" shared="1" min="0.0" max="1.0" flags="max_expand">0.65</parameter>
<parameter name="lens_feathering" type="slider" shared="1" min="0.0" max="1.0" flags="max_expand">0.0</parameter>
</material>

edit: fixed direct3d9 and 11 versions - though only 11 has been tested

Link to comment
  • 2 months later...

Hi Danni, glad to see you there. :)

 

That's weird, could you make a test scene? I just launched our post_bombing_00 scene in samples/shaders and everything is good, I can turn on and off both visualizer and profiler.

Link to comment
×
×
  • Create New...