Преглед изворни кода

*New material inside the material for depth passes (shadowmapping)
*Changed rendering code because of the above
*Working on blending stage

Panagiotis Christopoulos Charitos пре 16 година
родитељ
комит
2e051b6ff3

+ 6 - 5
shaders/dp_generic.glsl

@@ -1,16 +1,17 @@
+//
 #pragma anki vert_shader_begins
 
 #pragma anki include "shaders/hw_skinning.glsl"
 
-uniform vec3 position;
-uniform vec2 tex_coords;
+attribute vec3 position;
+attribute vec2 tex_coords;
 
 varying vec2 tex_coords_v2f;
 
 void main()
 {
 	#if defined( _GRASS_LIKE_ )
-		tex_coords_v2f = gl_MultiTexCoord0.xy;
+		tex_coords_v2f = tex_coords;
 	#endif
 
 	#if defined( _HW_SKINNING_ )
@@ -19,10 +20,10 @@ void main()
 
 		HWSkinning( _rot, _tsl );
 		
-		vec3 pos_lspace = ( _rot * gl_Vertex.xyz) + _tsl;
+		vec3 pos_lspace = ( _rot * position) + _tsl;
 		gl_Position =  gl_ModelViewProjectionMatrix * vec4(pos_lspace, 1.0);
 	#else
-	  gl_Position = ftransform();
+	  gl_Position =  gl_ModelViewProjectionMatrix * vec4(position, 1.0);
 	#endif
 }
 

+ 1 - 0
shaders/ms_mp_generic.glsl

@@ -1,3 +1,4 @@
+//
 #if defined( _DIFFUSE_MAPPING_ ) || defined( _NORMAL_MAPPING_ ) || defined( _SPECULAR_MAPPING_ )
 	#define NEEDS_TEX_MAPPING 1
 #else

+ 1 - 1
shaders/pps.glsl

@@ -188,6 +188,6 @@ void main (void)
 	//gl_FragColor = texture2D( pps_boom_fai, tex_coords );
 	//gl_FragColor = texture2D( is_fai, tex_coords );
 	//gl_FragData[0].rgb = UnpackNormal( texture2D( ms_normal_fai, tex_coords ).rg );
-	//gl_FragData[0] = vec4( hdr, 1.0 );
+	gl_FragData[0] = vec4( hdr, 1.0 );
 }
 

+ 3 - 0
src/main.cpp

@@ -72,6 +72,9 @@ void Init()
 	spot_lights[0] = new spot_light_t();
 	spot_lights[0]->Init( "maps/temple/light2.light" );
 	spot_lights[0]->SetLocalTransformation( vec3_t( 1.3, 4.3, 3.0 ), mat3_t( euler_t(ToRad(-20), ToRad(20), 0.0) ), 1.0 );
+	spot_lights[1] = new spot_light_t();
+	spot_lights[1]->Init( "maps/temple/light3.light" );
+	spot_lights[1]->SetLocalTransformation( vec3_t( -2.3, 6.3, 2.9 ), mat3_t( euler_t(ToRad(-70), ToRad(-20), 0.0) ), 1.0 );
 
 	// horse
 	horse = new mesh_node_t();

+ 9 - 8
src/renderer/r_bs.cpp

@@ -25,7 +25,7 @@ VARS
 static fbo_t b_fbo; ///< blending models FBO
 static fbo_t r_fbo; ///< refracting models FBO
 
-static texture_t r_fai; ///< RGB for color and A for mask (0 doesnt pass, 1 pass)
+/*static*/ texture_t r_fai; ///< RGB for color and A for mask (0 doesnt pass, 1 pass)
 
 static shader_prog_t* r2b_shdr;
 
@@ -117,13 +117,7 @@ void RunStage( const camera_t& cam )
 	for( uint i=0; i<scene::mesh_nodes.size(); i++ )
 	{
 		mesh_node_t* mesh_node = scene::mesh_nodes[i];
-		if( mesh_node->material->blends )
-		{
-			b_fbo.Bind();
-			mesh_node->material->Setup();
-			mesh_node->Render();
-		}
-		else if( mesh_node->material->refracts )
+		if( mesh_node->material->refracts )
 		{
 			// write to the rFbo
 			r_fbo.Bind();
@@ -131,8 +125,15 @@ void RunStage( const camera_t& cam )
 			mesh_node->material->Setup();
 			mesh_node->Render();
 
+			//b_fbo.Bind();
+		}
+		else if( mesh_node->material->blends )
+		{
 			b_fbo.Bind();
+			mesh_node->material->Setup();
+			mesh_node->Render();
 		}
+
 	}
 
 	// render the smodels

+ 7 - 1
src/renderer/r_is_shadows.cpp

@@ -104,7 +104,13 @@ void RunPass( const camera_t& cam )
 	// render all meshes
 	for( uint i=0; i<scene::mesh_nodes.size(); i++ )
 	{
-		RenderDepth<mesh_node_t, true>( *scene::mesh_nodes[i] );
+		mesh_node_t* mesh_node = scene::mesh_nodes[i];
+		if( mesh_node->material->blends || mesh_node->material->refracts ) continue;
+
+		DEBUG_ERR( mesh_node->material->dp_mtl == NULL );
+
+		mesh_node->material->dp_mtl->Setup();
+		mesh_node->RenderDepth();
 	}
 
 	glDisable( GL_POLYGON_OFFSET_FILL );

+ 2 - 2
src/renderer/r_ms_earlyz.cpp

@@ -63,7 +63,7 @@ RunPass
 */
 void RunPass( const camera_t& cam )
 {
-	// FBO
+	/*// FBO
 	fbo.Bind();
 
 	// matrix
@@ -88,7 +88,7 @@ void RunPass( const camera_t& cam )
 	glColorMask( true, true, true, true );
 
 	// end
-	fbo.Unbind();
+	fbo.Unbind();*/
 }
 
 

+ 4 - 1
src/renderer/r_pps.cpp

@@ -136,8 +136,11 @@ void RunStage( const camera_t& cam )
 
 	if( r::pps::hdr::enabled )
 	{
-		r::pps::hdr::pass2_fai.Bind(3);
+		//r::pps::hdr::pass2_fai.Bind(3);
+		r::bs::r_fai.Bind(3);
 		glUniform1i( shdr_vars::hdr_fai, 3 );
+
+
 	}
 
 	if( r::pps::lscatt::enabled )

+ 2 - 0
src/renderer/r_private.h

@@ -92,6 +92,8 @@ namespace bs
 	extern void Init();
 	extern void RunStage( const camera_t& cam );
 	extern texture_t fai_bs_scene;
+
+	extern texture_t r_fai; // ToDo: remove it
 }
 
 

+ 1 - 1
src/renderer/renderer.cpp

@@ -125,7 +125,7 @@ void Init()
 	if( !glewIsSupported("GL_ARB_vertex_buffer_object") )
 		WARNING( "Vertex Buffer Objects not supported. The application may crash (and burn)" );
 
-	glClearColor( 0.1, 0.1, 0.1, 0.0 );
+	glClearColor( 0.1, 0.1, 0.1, 1.0 );
 	glClearDepth( 1.0 );
 	glClearStencil( 0 );
 	glDepthFunc( GL_LEQUAL );

+ 1 - 0
src/resources/light_props.cpp

@@ -98,6 +98,7 @@ scanner_t scanner;
 			}
 				
 			texture = rsrc::textures.Load( token->value.string );
+			texture->TexParameter( GL_TEXTURE_MAX_ANISOTROPY_EXT, 0 );
 		}
 		// end of file
 		else if( token->code == scanner_t::TC_EOF )

+ 17 - 5
src/resources/material.cpp

@@ -95,6 +95,19 @@ bool material_t::Load( const char* filename )
 			}
 			depth.shader_prog = rsrc::shaders.Load( token->value.string );
 		}*/
+		//** DEPTH_MATERIAL **
+		else if( token->code == scanner_t::TC_IDENTIFIER && !strcmp( token->value.string, "DEPTH_PASS_MATERIAL" ) )
+		{
+			if( dp_mtl ) ERROR( "Depth material already loaded" );
+
+			token = &scanner.GetNextToken();
+			if( token->code != scanner_t::TC_STRING )
+			{
+				PARSE_ERR_EXPECTED( "string" );
+				return false;
+			}
+			dp_mtl = rsrc::materials.Load( token->value.string );
+		}
 		//** BLENDS **
 		else if( token->code == scanner_t::TC_IDENTIFIER && !strcmp( token->value.string, "BLENDS" ) )
 		{
@@ -405,16 +418,15 @@ void material_t::SetToDefault()
 	grass_map = NULL;
 	casts_shadow = true;
 	refracts = false;
+	dp_mtl = NULL;
 	/*depth.shader_prog = NULL;
 	depth.alpha_testing_map = NULL;*/
 }
 
 
-/*
-=======================================================================================================================================
-Setup                                                                                                                                 =
-=======================================================================================================================================
-*/
+//=====================================================================================================================================
+// Setup                                                                                                                              =
+//=====================================================================================================================================
 void material_t::Setup()
 {
 	shader_prog->Bind();

+ 3 - 0
src/resources/material.h

@@ -102,6 +102,8 @@ class material_t: public resource_t
 			} uni_locs;
 		} depth;*/
 
+		material_t* dp_mtl;
+
 	//===================================================================================================================================
 	// funcs                                                                                                                            =
 	//===================================================================================================================================
@@ -116,6 +118,7 @@ class material_t: public resource_t
 		void Unload();
 
 		bool HasHWSkinning() const { return attrib_locs.vert_weight_bones_num != -1; }
+		bool HasAlphaTesting() const { return dp_mtl!=NULL && dp_mtl->attrib_locs.tex_coords!=-1; }
 };
 
 

+ 11 - 57
src/scene/mesh_node.cpp

@@ -33,10 +33,8 @@ void mesh_node_t::Deinit()
 // Render                                                                                                                             =
 //=====================================================================================================================================
 /// Called in material or blending stages
-void mesh_node_t::Render()
+void mesh_node_t::Render( material_t* mtl ) const
 {
-	const material_t* mtl = material;
-
 	glPushMatrix();
 	r::MultMatrix( transformation_wspace );
 
@@ -112,62 +110,18 @@ void mesh_node_t::Render()
 
 
 //=====================================================================================================================================
-// RenderDepth                                                                                                                        =
+// Render                                                                                                                             =
 //=====================================================================================================================================
-void mesh_node_t::RenderDepth()
+void mesh_node_t::Render()
 {
-	glPushMatrix();
-	r::MultMatrix( transformation_wspace );
-
-	mesh->vbos.vert_coords.Bind();
-	glVertexPointer( 3, GL_FLOAT, 0, NULL );
-
-	if( material->grass_map )
-	{
-		mesh->vbos.tex_coords.Bind();
-		glTexCoordPointer( 2, GL_FLOAT, 0, NULL );
-		glEnableClientState( GL_TEXTURE_COORD_ARRAY );
-	}
-
-	// if we have skeleton controller
-	if( skel_controller )
-	{
-		// first the uniforms
-		glUniformMatrix3fv( material->uni_locs.skinning_rotations, skel_controller->skel_node->skeleton->bones.size(), 1,
-		                    &(skel_controller->skel_node->skel_anim_controller->bone_rotations[0])[0] );
-		glUniform3fv( material->uni_locs.skinning_translations, skel_controller->skel_node->skeleton->bones.size(),
-		              &(skel_controller->skel_node->skel_anim_controller->bone_translations[0])[0] );
-
-		// then the attributes
-		DEBUG_ERR( material->attrib_locs.vert_weight_bones_num == -1 );
-
-		mesh->vbos.vert_weights.Bind();
-		glEnableVertexAttribArray( r::is::shadows::shdr_depth_hw_skinning->GetAttributeLocation(0) );
-		glVertexAttribPointer( r::is::shadows::shdr_depth_hw_skinning->GetAttributeLocation(0), 1, GL_FLOAT, GL_FALSE, sizeof(mesh_t::vertex_weight_t), BUFFER_OFFSET(0) );
-		glEnableVertexAttribArray(r::is::shadows::shdr_depth_hw_skinning->GetAttributeLocation(1) );
-		glVertexAttribPointer( r::is::shadows::shdr_depth_hw_skinning->GetAttributeLocation(1), 4, GL_FLOAT, GL_FALSE, sizeof(mesh_t::vertex_weight_t), BUFFER_OFFSET(4) );
-		glEnableVertexAttribArray( r::is::shadows::shdr_depth_hw_skinning->GetAttributeLocation(2) );
-		glVertexAttribPointer( r::is::shadows::shdr_depth_hw_skinning->GetAttributeLocation(2), 4, GL_FLOAT, GL_FALSE, sizeof(mesh_t::vertex_weight_t), BUFFER_OFFSET(20) );
-	}
-
-	mesh->vbos.vert_indeces.Bind();
-
-	glEnableClientState( GL_VERTEX_ARRAY );
-
-	glDrawElements( GL_TRIANGLES, mesh->vert_indeces.size(), GL_UNSIGNED_SHORT, 0 );
-
-	// disable
-	glDisableClientState( GL_VERTEX_ARRAY );
-	glDisableClientState( GL_TEXTURE_COORD_ARRAY );
-
-	if( skel_controller )
-	{
-		glDisableVertexAttribArray( material->attrib_locs.vert_weight_bones_num );
-		glDisableVertexAttribArray( material->attrib_locs.vert_weight_bone_ids );
-		glDisableVertexAttribArray( material->attrib_locs.vert_weight_weights );
-	}
+	Render( material );
+}
 
-	vbo_t::UnbindAllTargets();
 
-	glPopMatrix();
+//=====================================================================================================================================
+// RenderDepth                                                                                                                        =
+//=====================================================================================================================================
+void mesh_node_t::RenderDepth()
+{
+	Render( material->dp_mtl );
 }

+ 3 - 0
src/scene/mesh_node.h

@@ -13,6 +13,9 @@ class material_t;
 /// Mesh node
 class mesh_node_t: public node_t
 {
+	private:
+		void Render( material_t* mtl ) const;
+
 	public:
 		// resources
 		mesh_t* mesh;