Ver Fonte

*Added light materials
*First changes in renderer for the new scene graph integration
*Change in the light nodes (because of the above)

Panagiotis Christopoulos Charitos há 16 anos atrás
pai
commit
b42a8c68b3

+ 4 - 4
shaders/dp_generic.glsl

@@ -2,12 +2,12 @@
 
 #pragma anki include "shaders/hw_skinning.glsl"
 
-varying vec2 tex_coords;
+varying vec2 tex_coords_v2f;
 
 void main()
 {
 	#if defined( _GRASS_LIKE_ )
-		tex_coords = gl_MultiTexCoord0.xy;
+		tex_coords_v2f = gl_MultiTexCoord0.xy;
 	#endif
 
 	#if defined( _HW_SKINNING_ )
@@ -26,12 +26,12 @@ void main()
 #pragma anki frag_shader_begins
 
 uniform sampler2D diffuse_map;
-varying vec2 tex_coords;
+varying vec2 tex_coords_v2f;
 
 void main()
 {
 	#if defined( _GRASS_LIKE_ )
-		vec4 _diff = texture2D( diffuse_map, tex_coords );
+		vec4 _diff = texture2D( diffuse_map, tex_coords_v2f );
 		if( _diff.a == 0.0 ) discard;
 	#endif
 }

+ 7 - 7
src/renderer/r_bs.cpp

@@ -111,22 +111,22 @@ void RunStage( const camera_t& cam )
 
 
 	// render the meshes
-	for( uint i=0; i<scene::meshes.size(); i++ )
+	for( uint i=0; i<scene::mesh_nodes.size(); i++ )
 	{
-		mesh_node_t* mesh = scene::meshes[i];
-		if( mesh->material->blends )
+		mesh_node_t* mesh_node = scene::mesh_nodes[i];
+		if( mesh_node->material->blends )
 		{
 			b_fbo.Bind();
-			mesh->material->Setup();
-			mesh->Render();
+			mesh_node->material->Setup();
+			mesh_node->Render();
 		}
 		else if( mesh->material->refracts )
 		{
 			// write to the rFbo
 			r_fbo.Bind();
 			glClear( GL_COLOR_BUFFER_BIT );
-			mesh->material->Setup();
-			mesh->Render();
+			mesh_node->material->Setup();
+			mesh_node->Render();
 
 			b_fbo.Bind();
 		}

Diff do ficheiro suprimidas por serem muito extensas
+ 1 - 0
src/renderer/r_is.cpp


+ 5 - 7
src/renderer/r_is_shadows.cpp

@@ -4,6 +4,7 @@
 #include "resource.h"
 #include "r_private.h"
 #include "fbo.h"
+#include "material.h"
 
 namespace r {
 namespace is {
@@ -100,13 +101,10 @@ void RunPass( const camera_t& cam )
 	glEnable( GL_POLYGON_OFFSET_FILL );
 
 	// render all meshes
-	for( uint i=0; i<scene::meshes.size(); i++ )
-		RenderDepth<mesh_node_t, true>( *scene::meshes[i] );
-
-	// render all smodels
-	for( uint i=0; i<scene::smodels.size(); i++ )
-		RenderDepth<smodel_t, true>( *scene::smodels[i] );
-
+	for( uint i=0; i<scene::mesh_nodes.size(); i++ )
+	{
+		RenderDepth<mesh_node_t, true>( *scene::mesh_nodes[i] );
+	}
 
 	glDisable( GL_POLYGON_OFFSET_FILL );
 

+ 13 - 17
src/renderer/r_ms.cpp

@@ -25,12 +25,9 @@ texture_t normal_fai, diffuse_fai, specular_fai, depth_fai;
 
 
 
-/*
-=======================================================================================================================================
-Init                                                                                                                                  =
-init FBO                                                                                                                              =
-=======================================================================================================================================
-*/
+//=====================================================================================================================================
+// Init                                                                                                                               =
+//=====================================================================================================================================
 void Init()
 {
 	// create FBO
@@ -71,11 +68,9 @@ void Init()
 }
 
 
-/*
-=======================================================================================================================================
-RunStage                                                                                                                              =
-=======================================================================================================================================
-*/
+//=====================================================================================================================================
+// RunStage                                                                                                                           =
+//=====================================================================================================================================
 void RunStage( const camera_t& cam )
 {
 #if defined( _EARLY_Z_ )
@@ -101,12 +96,13 @@ void RunStage( const camera_t& cam )
 #endif
 
 	// render the meshes
-	for( uint i=0; i<scene::meshes.size(); i++ )
-		Render<mesh_node_t, false>( scene::meshes[i] );
-
-	// render the smodels
-	for( uint i=0; i<scene::smodels.size(); i++ )
-		Render<smodel_t, false>( scene::smodels[i] );
+	for( uint i=0; i<scene::mesh_nodes.size(); i++ )
+	{
+		mesh_node_t* mesh_node = scene::mesh_nodes[0];
+		if( mesh_node->material->blends ) continue;
+		mesh_node->material->Setup();
+		mesh_node->Render();
+	}
 
 	glPolygonMode( GL_FRONT, GL_FILL ); // the rendering above fucks the polygon mode
 

+ 67 - 0
src/resources/light_mtl.cpp

@@ -0,0 +1,67 @@
+#include "light_mtl.h"
+#include "parser.h"
+#include "texture.h"
+
+
+//=====================================================================================================================================
+// Load                                                                                                                               =
+//=====================================================================================================================================
+bool light_mtl_t::Load( const char* filename )
+{
+scanner_t scanner;
+	if( !scanner.LoadFile( filename ) ) return false;
+
+	const scanner_t::token_t* token;
+
+	do
+	{
+		token = &scanner.GetNextToken();
+
+		//** DIFFUSE_COL **
+		if( token->code == scanner_t::TC_IDENTIFIER && !strcmp( token->value.string, "DIFFUSE_COL" ) )
+		{
+			ParseArrOfNumbers<float>( scanner, true, true, 3, &diffuse_col[0] );
+		}
+		//** SPECULAR_COL **
+		else if( token->code == scanner_t::TC_IDENTIFIER && !strcmp( token->value.string, "SPECULAR_COL" ) )
+		{
+			ParseArrOfNumbers<float>( scanner, true, true, 3, &specular_col[0] );
+		}
+		//** TEXTURE **
+		else if( token->code == scanner_t::TC_IDENTIFIER && !strcmp( token->value.string, "TEXTURE" ) )
+		{
+			token = &scanner.GetNextToken();
+			if( token->code != scanner_t::TC_STRING )
+			{
+				PARSE_ERR_EXPECTED( "string" );
+				return false;
+			}
+				
+			texture = rsrc::textures.Load( token->value.string );
+		}
+		// end of file
+		else if( token->code == scanner_t::TC_EOF )
+		{
+			break;
+		}
+		// other crap
+		else
+		{
+			PARSE_ERR_UNEXPECTED();
+			return false;
+		}
+
+	}while( true );
+	
+	return true;
+}
+
+
+//=====================================================================================================================================
+// Unload                                                                                                                             =
+//=====================================================================================================================================
+void light_mtl_t::Unload()
+{
+	if( texture != NULL )
+		rsrc::textures.Unload( texture );
+}

+ 32 - 0
src/resources/light_mtl.h

@@ -0,0 +1,32 @@
+#ifndef _LIGHT_MTL_H_
+#define _LIGHT_MTL_H_
+
+#include "common.h"
+#include "resource.h"
+#include "gmath.h"
+
+
+class texture_t;
+
+
+/// Light material resource
+class light_mtl_t: public resource_t
+{
+	// data
+	PROPERTY_R( vec3_t, diffuse_col, GetDiffuseColor );
+	PROPERTY_R( vec3_t, specular_col, GetSpecularColor );
+		
+	private:
+		texture_t* texture;
+	public:
+		const texture_t* GetTexture() const { DEBUG_ERR(texture==NULL); return texture; }
+	
+	// funcs	
+	public:
+		light_mtl_t(): diffuse_col(0.5), specular_col(0.5), texture(NULL) {}
+		virtual ~light_mtl_t() { /* ToDo */ }
+		bool Load( const char* filename );
+		void Unload();
+};
+
+#endif

+ 22 - 0
src/resources/material.h

@@ -86,6 +86,28 @@ class material_t: public resource_t
 		bool wireframe;
 		bool casts_shadow; ///< Used in EarlyZ and in shadowmapping passes
 
+		struct
+		{
+			shader_prog_t* shader_prog; ///< Depth pass shader program
+			texture_t* alpha_testing_map;
+			
+			struct
+			{
+				int position;
+				int tex_coords;
+
+				// for hw skinning
+				int vert_weight_bones_num;
+				int vert_weight_bone_ids;
+				int vert_weight_weights;
+			} attribute_locs;
+			
+			struct
+			{
+				int alpha_testing_map;
+			} uni_locs;
+		} dp;
+
 		/**
 		 * Used mainly in depth passes. If the grass_map pointer is != NULL then the entity is "grass like".
 		 * Most of the time the grass_map is the same as the diffuse map

+ 2 - 1
src/resources/resource.cpp

@@ -4,6 +4,7 @@
 #include "shader_prog.h"
 #include "mesh.h"
 #include "skel_anim.h"
+#include "light_mtl.h"
 
 
 namespace rsrc {
@@ -20,6 +21,6 @@ container_t<material_t>    materials;
 container_t<mesh_t>        meshes;
 container_t<skeleton_t>    skeletons;
 container_t<skel_anim_t>   skel_anims;
-
+container_t<light_mtl_t>   light_mtls;
 
 } // end namespace

+ 3 - 0
src/resources/resource.h

@@ -11,6 +11,7 @@ class shader_prog_t;
 class mesh_t;
 class skeleton_t;
 class skel_anim_t;
+class light_mtl_t;
 
 
 // forward decl
@@ -38,6 +39,7 @@ class resource_t
 	friend class rsrc::container_t<skeleton_t>;
 	friend class rsrc::container_t<mesh_t>;
 	friend class rsrc::container_t<skel_anim_t>;
+	friend class rsrc::container_t<light_mtl_t>;
 	friend class shader_prog_t;
 
 	public:
@@ -59,6 +61,7 @@ extern container_t<material_t>    materials;
 extern container_t<mesh_t>        meshes;
 extern container_t<skeleton_t>    skeletons;
 extern container_t<skel_anim_t>   skel_anims;
+extern container_t<light_mtl_t>   light_mtls;
 
 
 /// resource container class

+ 1 - 1
src/resources/shader_prog.h

@@ -32,7 +32,7 @@ class shader_prog_t: public resource_t
 		virtual ~shader_prog_t() {}
 		
 		inline void Bind() const { DEBUG_ERR( gl_id==0 ); glUseProgram(gl_id); }
-		static void Unbind() { glUseProgram(NULL); }
+		static void Unbind() { glUseProgram(0); }
 		static uint GetCurrentProgram() { int i; glGetIntegerv( GL_CURRENT_PROGRAM, &i ); return i; }
 
 		bool Load( const char* filename );

+ 21 - 2
src/scene/light.cpp

@@ -1,6 +1,25 @@
 #include "light.h"
 #include "collision.h"
 #include "renderer.h"
+#include "light_mtl.h"
+
+
+//=====================================================================================================================================
+// Init                                                                                                                               =
+//=====================================================================================================================================
+void light_t::Init( const char* filename )
+{
+	light_mtl = rsrc::light_mtls.Load( filename );
+}
+
+
+//=====================================================================================================================================
+// Deinit                                                                                                                             =
+//=====================================================================================================================================
+void light_t::Deinit()
+{
+	rsrc::light_mtls.Unload( light_mtl );
+}
 
 
 //=====================================================================================================================================
@@ -23,7 +42,7 @@ static void RenderSphere( const mat4_t& tsl, const vec3_t& col )
 //=====================================================================================================================================
 void point_light_t::Render()
 {
-	RenderSphere( transformation_wspace, diffuse_color );
+	RenderSphere( transformation_wspace, light_mtl->GetDiffuseColor() );
 }
 
 
@@ -32,5 +51,5 @@ void point_light_t::Render()
 //=====================================================================================================================================
 void spot_light_t::Render()
 {
-	RenderSphere( transformation_wspace, diffuse_color );
+	RenderSphere( transformation_wspace, light_mtl->GetDiffuseColor() );
 }

+ 16 - 15
src/scene/light.h

@@ -1,11 +1,3 @@
-#ifndef _LIGHT_H_
-#define _LIGHT_H_
-
-#include "common.h"
-#include "texture.h"
-#include "node.h"
-#include "camera.h"
-
 /*
 LIGHTING MODEL
 
@@ -22,6 +14,16 @@ Specular intensity of light:    Sl
 Specular intensity of material: Sm
 */
 
+#ifndef _LIGHT_H_
+#define _LIGHT_H_
+
+#include "common.h"
+#include "texture.h"
+#include "node.h"
+#include "camera.h"
+
+class light_mtl_t;
+
 
 /// light_t (A)
 class light_t: public node_t
@@ -29,17 +31,17 @@ class light_t: public node_t
 	public:
 		enum types_e { LT_POINT, LT_SPOT };
 
-	PROPERTY_RW( vec3_t, diffuse_color, GetDiffuseColor, SetDiffuseColor );
-	PROPERTY_RW( vec3_t, specular_color, GetSpecularColor, SetSpecularColor );
 	PROPERTY_R( types_e, type, GetType );
 
 	friend class point_light_t;
 	friend class spot_light_t;
 
-
-
 	public:
+		light_mtl_t* light_mtl;
+	
 		light_t( types_e type_ ): node_t(NT_LIGHT), type(type_) {}
+		void Init( const char* filename );
+		void Deinit();
 };
 
 
@@ -59,13 +61,12 @@ class spot_light_t: public light_t
 {
 	public:
 		camera_t camera;
-		texture_t* texture;
 		bool casts_shadow;
 
-		spot_light_t(): light_t(LT_SPOT), texture(NULL), casts_shadow(false) { AddChild( &camera ); }
+		spot_light_t(): light_t(LT_SPOT), casts_shadow(false) { AddChild( &camera ); }
 		float GetDistance() const { return camera.GetZFar(); }
 		void  SetDistance( float d ) { camera.SetZFar(d); }
-		void Render();
+		void  Render();
 };
 
 

+ 1 - 0
src/tokenizer/parser.h

@@ -2,6 +2,7 @@
 #define _PARSER_H_
 
 #include "common.h"
+#include "scanner.h"
 
 /*
 =======================================================================================================================================

Alguns ficheiros não foram mostrados porque muitos ficheiros mudaram neste diff