Browse Source

*Added new functionality to shader programs
*Changed the names of the functions of median filter

Panagiotis Christopoulos Charitos 16 năm trước cách đây
mục cha
commit
3a9cd11b50

+ 8 - 1
shaders/median_filter.glsl

@@ -13,6 +13,10 @@ http://graphics.cs.williams.edu
 #define mnmx5(a, b, c, d, e)	s2(a, b); s2(c, d); mn3(a, c, e); mx3(b, d, e);           // 6 exchanges
 #define mnmx6(a, b, c, d, e, f) s2(a, d); s2(b, e); s2(c, f); mn3(a, b, c); mx3(d, e, f); // 7 exchanges
 
+
+//=====================================================================================================================================
+// MedianFilterRGB                                                                                                                    =
+//=====================================================================================================================================
 vec3 MedianFilter( in sampler2D tex, in vec2 tex_coords )
 {
 	vec2 tex_inv_size = 1.0/vec2(textureSize(tex, 0));
@@ -43,7 +47,10 @@ vec3 MedianFilter( in sampler2D tex, in vec2 tex_coords )
 }
 
 
-float MedianFilterAlpha( in sampler2D tex, in vec2 tex_coords )
+//=====================================================================================================================================
+// MedianFilterA                                                                                                                      =
+//=====================================================================================================================================
+float MedianFilterA( in sampler2D tex, in vec2 tex_coords )
 {
 	vec2 tex_inv_size = 1.0/vec2(textureSize(tex, 0));
   float v[9];

+ 1 - 1
shaders/pps_hdr_generic.glsl

@@ -58,7 +58,7 @@ void main()
 		gl_FragData[0].rgb = color / KERNEL_SIZE;
 
 	#else // _PPS_HDR_PASS_2_
-		vec3 color = MedianFilter( tex, tex_coords );
+		vec3 color = MedianFilterRGB( tex, tex_coords );
 		//vec3 color = texture2D( tex, tex_coords ).rgb;
 
 		float Y = dot(vec3(0.30, 0.59, 0.11), color);

+ 1 - 1
shaders/pps_ssao_blur.glsl

@@ -13,5 +13,5 @@ uniform sampler2D tex;
 
 void main()
 {
-	gl_FragColor.a = MedianFilterAlpha( tex, tex_coords );
+	gl_FragData[0].a = MedianFilterA( tex, tex_coords );
 }

+ 17 - 6
src/uncategorized/shader_prog.cpp

@@ -12,7 +12,7 @@
 //=====================================================================================================================================
 // CreateAndCompileShader                                                                                                             =
 //=====================================================================================================================================
-uint shader_prog_t::CreateAndCompileShader( const char* source_code, int type ) const
+uint shader_prog_t::CreateAndCompileShader( const char* source_code, const char* preproc, int type ) const
 {
 	uint gl_id = 0;
 	const char* source_strs[2] = {NULL, NULL};
@@ -22,7 +22,7 @@ uint shader_prog_t::CreateAndCompileShader( const char* source_code, int type )
 
 	// attach the source
 	source_strs[1] = source_code;
-	source_strs[0] = r::GetStdShaderPreprocDefines().c_str();
+	source_strs[0] = preproc;
 
 	// compile
 	glShaderSource( gl_id, 2, source_strs, NULL );
@@ -213,18 +213,29 @@ bool shader_prog_t::FillTheCustomLocationsVectors( const shader_parser_t& pars )
 // Load                                                                                                                               =
 //=====================================================================================================================================
 bool shader_prog_t::Load( const char* filename )
+{
+	if( !CustomLoad( filename, "" ) return false;
+	return true;
+}
+
+
+//=====================================================================================================================================
+// CustomLoad                                                                                                                         =
+//=====================================================================================================================================
+bool shader_prog_t::CustomLoad( const char* filename, const char* extra_source )
 {
 	shader_parser_t pars;
 
 	if( !pars.ParseFile( filename ) ) return false;
 
-	//PRINT( pars.frag_shader_source )
+	//r::GetStdShaderPreprocDefines().c_str()
 
 	// create, compile, attach and link
-	uint vert_gl_id = CreateAndCompileShader( pars.vert_shader_source.c_str(), GL_VERTEX_SHADER );
+	string preproc_source = r::GetStdShaderPreprocDefines() + extra_source;
+	uint vert_gl_id = CreateAndCompileShader( pars.vert_shader_source.c_str(), preproc_source.c_str(), GL_VERTEX_SHADER );
 	if( vert_gl_id == 0 ) return false;
 
-	uint frag_gl_id = CreateAndCompileShader( pars.frag_shader_source.c_str(), GL_FRAGMENT_SHADER );
+	uint frag_gl_id = CreateAndCompileShader( pars.frag_shader_source.c_str(), preproc_source.c_str(), GL_FRAGMENT_SHADER );
 	if( frag_gl_id == 0 ) return false;
 
 	gl_id = glCreateProgram();
@@ -237,7 +248,7 @@ bool shader_prog_t::Load( const char* filename )
 	// init the rest
 	GetUniAndAttribLocs();
 	if( !FillTheCustomLocationsVectors( pars ) ) return false;
-	
+
 	return true;
 }
 

+ 2 - 2
src/uncategorized/shader_prog.h

@@ -24,7 +24,7 @@ class shader_prog_t: public resource_t
 		
 		void GetUniAndAttribLocs();
 		bool FillTheCustomLocationsVectors( const shader_parser_t& pars );
-		uint CreateAndCompileShader( const char* source_code, int type ) const; ///< @return Returns zero on falure
+		uint CreateAndCompileShader( const char* source_code, const char* preproc, int type ) const; ///< @return Returns zero on falure
 		bool Link();
 		
 	public:
@@ -36,7 +36,7 @@ class shader_prog_t: public resource_t
 		static uint GetCurrentProgram() { int i; glGetIntegerv( GL_CURRENT_PROGRAM, &i ); return i; }
 
 		bool Load( const char* filename );
-		bool CustomLoad( const char*  );
+		bool CustomLoad( const char* filename, const char* extra_source );
 		void Unload() { /* ToDo: add code */ }
 
 		int GetUniformLocation( const char* name ) const; ///< Returns -1 if fail and throws error