Explorar el Código

The blending stage is near completion. Maybe I should add stencil testing to optimize

Panagiotis Christopoulos Charitos hace 16 años
padre
commit
509cab6f43

+ 21 - 0
shaders/bs_refract.glsl

@@ -0,0 +1,21 @@
+//
+#pragma anki vert_shader_begins
+
+#pragma anki include "shaders/simple_vert.glsl"
+
+#pragma anki frag_shader_begins
+
+#pragma anki uniform fai 0
+uniform sampler2D fai;
+
+varying vec2 tex_coords;
+
+
+
+void main()
+{
+	vec4 _color = texture2D( fai, tex_coords );
+	if( _color.a == 0.0 ) discard;
+
+	gl_FragData[0].rgb = _color.rgb;
+}

+ 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 );
 }
 

+ 6 - 8
shaders/simple_texturing.glsl

@@ -2,14 +2,14 @@
 
 attribute vec3 position;
 attribute vec3 normal;
-attribute vec2 tex_coords;
+//attribute vec2 tex_coords;
 
-varying vec2 tex_coords_v2f;
+//varying vec2 tex_coords_v2f;
 varying vec3 normal_v2f;
 
 void main()
 {
-	tex_coords_v2f = tex_coords;
+	//tex_coords_v2f = tex_coords;
 	normal_v2f = gl_NormalMatrix * normal;
 	gl_Position = gl_ModelViewProjectionMatrix * vec4(position, 1.0);
 }
@@ -19,7 +19,7 @@ void main()
 #pragma anki include "shaders/pack.glsl"
 
 uniform sampler2D diffuse_map, noise_map;
-varying vec2 tex_coords_v2f;
+//varying vec2 tex_coords_v2f;
 varying vec3 normal_v2f;
 
 void main()
@@ -28,10 +28,8 @@ void main()
 	_noise = _noise * 2 - 1;
 	_noise *= 7.0;*/
 
-	vec4 _texel = texture2D( diffuse_map, (gl_FragCoord.xy+(normal_v2f.xy*2))*vec2( 1.0/R_W, 1.0/R_H ) );
-
-
-	//vec4 _texel = texture2D( diffuse_map, tex_coords_v2f ) / 2;
+	vec4 _texel = texture2D( diffuse_map, (gl_FragCoord.xy+(normal_v2f.xy*40))*vec2( 1.0/R_W, 1.0/R_H ) );
+	//vec4 _texel = texture2D( diffuse_map, gl_FragCoord.xy*vec2( 1.0/R_W, 1.0/R_H ) );
 
 	gl_FragData[0] = _texel;
 }

+ 4 - 3
src/main.cpp

@@ -83,8 +83,9 @@ void Init()
 	
 	// sarge
 	sarge = new mesh_node_t();
-	sarge->Init( "meshes/sarge/sarge.mesh" );
-	sarge->SetLocalTransformation( vec3_t( 0, -2.8, 1.0 ), mat3_t( euler_t(-m::PI/2, 0.0, 0.0) ), 0.1 );
+	sarge->Init( "meshes/sphere/sphere16.mesh" );
+	//sarge->SetLocalTransformation( vec3_t( 0, -2.8, 1.0 ), mat3_t( euler_t(-m::PI/2, 0.0, 0.0) ), 1.1 );
+	sarge->SetLocalTransformation( vec3_t( 0, 2.0, 2.0 ), mat3_t::GetIdentity(), 1.2 );
 	
 	// floor
 	floor__ = new mesh_node_t();
@@ -198,7 +199,7 @@ int main( int /*argc*/, char* /*argv*/[] )
 		// std stuff follow
 		SDL_GL_SwapBuffers();
 		r::PrintLastError();
-		if( 1 )
+		if( 0 )
 		{
 			if( r::frames_num == 10 ) r::TakeScreenshot("gfx/screenshot.tga");
 			app::WaitForNextFrame();

+ 6 - 2
src/renderer/r_bs.cpp

@@ -79,7 +79,7 @@ static void InitR()
 	// unbind
 	r_fbo.Unbind();
 
-	//r2b_shdr =
+	r2b_shdr = rsrc::shaders.Load( "shaders/bs_refract.glsl" );
 }
 
 
@@ -119,7 +119,11 @@ void RunStage( const camera_t& cam )
 			mesh_node->material->Setup();
 			mesh_node->Render();
 
-			//b_fbo.Bind();
+			b_fbo.Bind();
+			glDisable( GL_DEPTH_TEST );
+			r2b_shdr->Bind();
+			r2b_shdr->LocTexUnit( r2b_shdr->GetUniformLocation(0), r_fai, 0 );
+			r::DrawQuad( r2b_shdr->GetAttributeLocation(0) );
 		}
 		else if( mesh_node->material->blends )
 		{

+ 1 - 1
src/renderer/r_ms.cpp

@@ -101,7 +101,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 ) continue;
+		if( mesh_node->material->blends || mesh_node->material->refracts ) continue;
 		mesh_node->material->Setup();
 		mesh_node->Render();
 	}

+ 2 - 4
src/renderer/r_pps.cpp

@@ -136,11 +136,9 @@ void RunStage( const camera_t& cam )
 
 	if( r::pps::hdr::enabled )
 	{
-		//r::pps::hdr::pass2_fai.Bind(3);
-		r::bs::r_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 )

+ 11 - 2
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, 1.0 );
+	glClearColor( 0.1, 0.1, 0.1, 0.0 );
 	glClearDepth( 1.0 );
 	glClearStencil( 0 );
 	glDepthFunc( GL_LEQUAL );
@@ -306,7 +306,16 @@ void PrintLastError()
 {
 	GLenum errid = glGetError();
 	if( errid != GL_NO_ERROR )
-		ERROR( "GL_ERR: " << gluErrorString( errid ) );
+		ERROR( "OpenGL Error: " << gluErrorString( errid ) );
+}
+
+
+//=====================================================================================================================================
+// GetLastError                                                                                                                       =
+//=====================================================================================================================================
+const uchar* GetLastError()
+{
+	return gluErrorString( glGetError() );
 }
 
 

+ 1 - 0
src/renderer/renderer.h

@@ -36,6 +36,7 @@ extern int  max_anisotropy; ///< Max texture anisotropy. Used in texture_t::Load
 extern void TakeScreenshot( const char* filename ); ///< Save the colorbuffer as 24bit uncompressed TGA image
 extern void Init(); ///< Inits the renderer subsystem. Setting OpenGL and executes "r::*::Init" functions among other things
 extern void PrepareNextFrame(); ///< Runs before rendering
+extern const uchar* GetLastError(); ///< GetLastError
 extern void PrintLastError(); ///< Prints last OpenGL error
 inline const string& GetStdShaderPreprocDefines() { extern string std_shader_preproc_defines; return std_shader_preproc_defines; }
 extern void Render( const camera_t& cam ); ///< The spine function of the renderer

+ 1 - 1
src/resources/material.cpp

@@ -278,7 +278,7 @@ bool material_t::Load( const char* filename )
 						}
 						else
 						{
-							PARSE_ERR_EXPECTED( "string" );
+							PARSE_ERR_EXPECTED( "string or IS_FAI or MS_NORMAL_FAI or MS_DEPTH_FAI" );
 							return false;
 						}
 						break;

+ 3 - 3
src/resources/mesh.cpp

@@ -154,7 +154,7 @@ bool mesh_t::Load( const char* filename )
 	}
 
 	CreateAllNormals();
-	CreateVertTangents();
+	if( tex_coords.size() > 0 ) CreateVertTangents();
 	CreateVertIndeces();
 	CreateVBOs();
 	CalcBSphere();
@@ -307,12 +307,12 @@ void mesh_t::CreateVBOs()
 	vbos.vert_indeces.Create( GL_ELEMENT_ARRAY_BUFFER, vert_indeces.GetSizeInBytes(), &vert_indeces[0], GL_STATIC_DRAW );
 	vbos.vert_coords.Create( GL_ARRAY_BUFFER, vert_coords.GetSizeInBytes(), &vert_coords[0], GL_STATIC_DRAW );
 	vbos.vert_normals.Create( GL_ARRAY_BUFFER, vert_normals.GetSizeInBytes(), &vert_normals[0], GL_STATIC_DRAW );
-	vbos.vert_tangents.Create( GL_ARRAY_BUFFER, vert_tangents.GetSizeInBytes(), &vert_tangents[0], GL_STATIC_DRAW );
+	if( vert_tangents.size() > 1 )
+		vbos.vert_tangents.Create( GL_ARRAY_BUFFER, vert_tangents.GetSizeInBytes(), &vert_tangents[0], GL_STATIC_DRAW );
 	if( tex_coords.size() > 1 )
 		vbos.tex_coords.Create( GL_ARRAY_BUFFER, tex_coords.GetSizeInBytes(), &tex_coords[0], GL_STATIC_DRAW );
 	if( vert_weights.size() > 1 )
 		vbos.vert_weights.Create( GL_ARRAY_BUFFER, vert_weights.GetSizeInBytes(), &vert_weights[0], GL_STATIC_DRAW );
-
 }
 
 

+ 0 - 2
src/resources/resource.cpp

@@ -5,7 +5,6 @@
 #include "mesh.h"
 #include "skel_anim.h"
 #include "light_props.h"
-#include "script.h"
 
 
 namespace rsrc {
@@ -23,6 +22,5 @@ container_t<mesh_t>        meshes;
 container_t<skeleton_t>    skeletons;
 container_t<skel_anim_t>   skel_anims;
 container_t<light_props_t> light_props;
-container_t<script_t>      scripts;
 
 } // end namespace

+ 0 - 3
src/resources/resource.h

@@ -14,7 +14,6 @@ class mesh_t;
 class skeleton_t;
 class skel_anim_t;
 class light_props_t;
-class script_t;
 
 namespace rsrc {
 template< typename type_t > class container_t;
@@ -41,7 +40,6 @@ class resource_t
 	friend class rsrc::container_t<mesh_t>;
 	friend class rsrc::container_t<skel_anim_t>;
 	friend class rsrc::container_t<light_props_t>;
-	friend class rsrc::container_t<script_t>;
 	friend class shader_prog_t;
 
 	public:
@@ -64,7 +62,6 @@ extern container_t<mesh_t>        meshes;
 extern container_t<skeleton_t>    skeletons;
 extern container_t<skel_anim_t>   skel_anims;
 extern container_t<light_props_t> light_props;
-extern container_t<script_t>      scripts;
 
 
 /// resource container template class

+ 1 - 1
src/resources/texture.cpp

@@ -370,7 +370,7 @@ void texture_t::CreateEmpty2D( float width_, float height_, int internal_format,
 
 	GLenum errid = glGetError();
 	if( errid != GL_NO_ERROR )
-		ERROR( "GL_ERR: glTexImage2D failed: " << gluErrorString( errid ) );
+		ERROR( "OpenGL Error: " << gluErrorString( errid ) );
 }
 
 

+ 6 - 0
src/scene/mesh_node.cpp

@@ -16,6 +16,12 @@ void mesh_node_t::Init( const char* filename )
 {
 	mesh = rsrc::meshes.Load( filename );
 	material = rsrc::materials.Load( mesh->material_name.c_str() );
+
+	// sanity checks
+	if( material->attrib_locs.tex_coords != -1 && mesh->vbos.tex_coords.GetGLID() == 0 )
+	{
+		ERROR( "The shader program needs information that the mesh do not have" );
+	}
 }
 
 

+ 1 - 2
src/scene/mesh_node.h

@@ -3,11 +3,10 @@
 
 #include "common.h"
 #include "node.h"
-
+#include "material.h"
 
 class skel_controller_t;
 class mesh_t;
-class material_t;
 
 
 /// Mesh node

+ 3 - 3
src/scene/skel_anim_controller.cpp

@@ -24,11 +24,11 @@ skel_anim_controller_t::skel_anim_controller_t( skel_node_t* skel_node_ ):
 //=====================================================================================================================================
 void skel_anim_controller_t::Interpolate( skel_anim_t* animation, float frame )
 {
-	DEBUG_ERR( frame >= skel_anim->frames_num );
+	DEBUG_ERR( frame >= animation->frames_num );
 
 	// calculate the t (used in slerp and lerp) and
 	// calc the l_pose and r_pose witch indicate the pose ids in witch the frame lies between
-	const vec_t<uint>& keyframes = skel_anim->keyframes;
+	const vec_t<uint>& keyframes = animation->keyframes;
 	float t = 0.0;
 	uint l_pose = 0, r_pose = 0;
 	for( uint j=0; j<keyframes.size(); j++ )
@@ -53,7 +53,7 @@ void skel_anim_controller_t::Interpolate( skel_anim_t* animation, float frame )
 	DEBUG_ERR( bone_rotations.size()<1 );
 	for( uint i=0; i<bone_rotations.size(); i++ )
 	{
-		const skel_anim_t::bone_anim_t& banim = skel_anim->bones[i];
+		const skel_anim_t::bone_anim_t& banim = animation->bones[i];
 
 		mat3_t& local_rot = bone_rotations[i];
 		vec3_t& local_transl = bone_translations[i];

+ 4 - 0
src/utility/common.h

@@ -17,6 +17,10 @@ using namespace std;
 //=====================================================================================================================================
 // misc types                                                                                                                         =
 //=====================================================================================================================================
+#ifndef uchar
+typedef unsigned char uchar;
+#endif
+
 #ifndef uint
 typedef unsigned int uint;
 #endif