Răsfoiți Sursa

Working on the skybox

Panagiotis Christopoulos Charitos 15 ani în urmă
părinte
comite
421eb9f246

+ 56 - 0
shaders/MsMpSkybox.glsl

@@ -0,0 +1,56 @@
+#pragma anki vertShaderBegins
+
+attribute vec3 position;
+attribute vec2 texCoords;
+
+uniform mat4 viewProjectionMat;
+uniform mat4 viewMat;
+
+varying vec2 texCoordsV2f;
+
+void main()
+{
+	texCoordsV2f = texCoords;
+	
+	....
+	gl_Position = ;
+}
+
+#pragma anki fragShaderBegins
+
+uniform sampler2D colorMap;
+uniform sampler2D noiseMap;
+uniform float timer;
+uniform vec3 sceneAmbientCol;
+varying vec2 texCoordsV2f;
+
+#define PI 3.14159265358979323846
+
+
+void main()
+{
+	vec3 _noise_vec;
+	vec2 displacement;
+	float scaled_timer;
+
+	displacement = texCoordsV2f;
+
+	scaled_timer = timer*0.4;
+
+	displacement.x -= scaled_timer;
+	displacement.y -= scaled_timer;
+
+	_noise_vec = normalize( texture2D(noisemap, displacement).xyz );
+	_noise_vec = (_noise_vec * 2.0 - 1.0);
+
+	// edge_factor is a value that varies from 1.0 to 0.0 and then again to 1.0. Its zero in the edge of the skybox quad
+	// and white in the middle of the quad. We use it in order to reduse the distortion at the edges because of artefacts
+	float _edge_factor = sin( texCoordsV2f.s * PI ) * sin( texCoordsV2f.t * PI );
+
+	const float _strength_factor = 0.015;
+
+	_noise_vec = _noise_vec * _strength_factor * _edge_factor;
+
+	gl_FragData[1].rgb = texture2D(colormap, texCoordsV2f + _noise_vec.xy).rgb * sceneAmbientCol; // write to the diffuse buffer
+}
+

+ 7 - 0
shaders/Pps.glsl

@@ -166,6 +166,13 @@ void main (void)
 		color += hdr;
 	#endif
 
+	/*vec4 sample[9];
+	for(int i = 0; i < 9; i++)
+	{
+		sample[i] = texture2D(sampler0, gl_TexCoord[0].st + tc_offset[i]);
+	}
+	color = (sample[4] * 9.0) - (sample[0] + sample[1] + sample[2] + sample[3] + sample[5] + sample[6] + sample[7] + sample[8]);*/
+
 	color = BlendHardLight( vec3(0.6, 0.62, 0.4), color );
 
 	gl_FragData[0].rgb = color;

+ 6 - 6
shaders/PpsSsaoBlur.glsl

@@ -19,12 +19,12 @@ void main()
 	#endif
 	const int KERNEL_SIZE = 7;
 	float kernel[KERNEL_SIZE] = float[]( 0.0 * offset, 
-	                                     -1.0 * offset, 1.0 * offset, 
-	                                     -2.0 * offset, 2.0 * offset,
-																			 -3.0 * offset, 3.0 * offset/*,
-																			 -4.0 * offset, 4.0 * offset,
-																			 -5.0 * offset, 5.0 * offset,
-																			 -6.0 * offset, 6.0 * offset*/ );
+	                                    -1.0 * offset, 1.0 * offset,
+	                                    -2.0 * offset, 2.0 * offset,
+																			-3.0 * offset, 3.0 * offset/*,
+																			-4.0 * offset, 4.0 * offset,
+																			-5.0 * offset, 5.0 * offset,
+																			-6.0 * offset, 6.0 * offset*/ );
 
 	float factor = 0.0;
 	for( int i=0; i<KERNEL_SIZE; i++ )

+ 7 - 0
shaders/ms_mp_dnske.glsl

@@ -0,0 +1,7 @@
+#define _DIFFUSE_MAPPING_
+#define _NORMAL_MAPPING_
+#define _SPECULAR_MAPPING_
+#define _HARDWARE_SKINNING_
+#define _ENVIRONMENT_MAPPING_
+
+#pragma anki include "shaders/ms_mp_generic.glsl"

+ 1 - 1
src/Misc/skybox.cpp

@@ -55,7 +55,7 @@ render
 */
 void Skybox::Render(const Mat3& rotation)
 {
-	//glDisable(GL_DEPTH_TEST);
+	glDisable(GL_DEPTH_TEST);
 	glDisable(GL_BLEND);
 
 	glPushMatrix();

+ 1 - 1
src/Renderer/Ms.cpp

@@ -36,7 +36,7 @@ void Renderer::Ms::init()
 
 	//glFramebufferTexture2DEXT(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_TEXTURE_2D, depthFai.getGlId(), 0);
 	glFramebufferTexture2DEXT(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, depthFai.getGlId(), 0);
-	glFramebufferTexture2DEXT(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_TEXTURE_2D, depthFai.getGlId(), 0);
+	//glFramebufferTexture2DEXT(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_TEXTURE_2D, depthFai.getGlId(), 0);
 
 	// test if success
 	if(!fbo.isGood())

+ 6 - 1
src/Renderer/Renderer.cpp

@@ -1,5 +1,5 @@
 #include "Renderer.h"
-#include "Camera.h" /// @todo remove this
+#include "Camera.h"
 #include "RendererInitializer.h"
 #include "Material.h"
 #include "App.h"
@@ -69,6 +69,8 @@ void Renderer::render(Camera& cam_)
 {
 	cam = &cam_;
 
+	viewProjectionMat = cam->getProjectionMatrix() * cam->getViewMatrix();
+
 	ms.run();
 	is.run();
 	pps.run();
@@ -154,6 +156,9 @@ void Renderer::setupMaterial(const Material& mtl, const SceneNode& sceneNode, co
 	if(mtl.stdUniVars[Material::SUV_MODELVIEW_MAT])
 		mtl.stdUniVars[Material::SUV_MODELVIEW_MAT]->setMat4(&modelViewMat);
 
+	if(mtl.stdUniVars[Material::SUV_VIEWPROJECTION_MAT])
+		mtl.stdUniVars[Material::SUV_VIEWPROJECTION_MAT]->setMat4(&viewProjectionMat);
+
 	if(mtl.stdUniVars[Material::SUV_NORMAL_MAT])
 	{
 		normalMat = modelViewMat.getRotationPart();

+ 11 - 3
src/Renderer/Renderer.h

@@ -142,7 +142,7 @@ class Renderer
 						Smo(Renderer& r_): RenderingStage(r_) {}
 
 					private:
-						static float sMOUvSCoords []; ///< Illumination stage stencil masking optimizations UV sphere vertex positions
+						static float sMOUvSCoords[]; ///< Illumination stage stencil masking optimizations UV sphere vertex positions
 						static Vbo sMOUvSVbo; ///< Illumination stage stencil masking optimizations UV sphere VBO
 						static SmoShaderProg sProg;
 
@@ -201,8 +201,15 @@ class Renderer
 				Vec3 viewVectors[4];
 				Vec2 planes;
 
-				void calcViewVector(); ///< Calc the view vector that we will use inside the shader to calculate the frag pos in view space
-				void calcPlanes(); ///< Calc the planes that we will use inside the shader to calculate the frag pos in view space
+				/**
+				 * Calc the view vector that we will use inside the shader to calculate the frag pos in view space
+				 */
+				void calcViewVector();
+
+				/**
+				 * Calc the planes that we will use inside the shader to calculate the frag pos in view space
+				 */
+				void calcPlanes();
 				void ambientPass(const Vec3& color);
 				void pointLightPass(const PointLight& light);
 				void spotLightPass(const SpotLight& light);
@@ -456,6 +463,7 @@ class Renderer
 		const Camera* cam; ///< Current camera
 		static float quadVertCoords [][2];
 		static int maxColorAtachments; ///< Max color attachments a FBO can accept
+		Mat4 viewProjectionMat; ///< In case anyone needs it
 
 		static void drawQuad(int vertCoordsUniLoc);
 		void setupMaterial(const Material& mtl, const SceneNode& sceneNode, const Camera& cam);

+ 3 - 0
src/Resources/Material.cpp

@@ -35,6 +35,7 @@ Material::StdVarInfo Material::stdUniVarInfos[SUV_NUM] =
 	{ "viewMat", GL_FLOAT_MAT4 },
 	{ "projectionMat", GL_FLOAT_MAT4 },
 	{ "modelViewMat", GL_FLOAT_MAT4 },
+	{ "ViewProjectionMat", GL_FLOAT_MAT4 },
 	{ "normalMat", GL_FLOAT_MAT3 },
 	{ "modelViewProjectionMat", GL_FLOAT_MAT4 },
 	{ "msNormalFai", GL_SAMPLER_2D },
@@ -271,6 +272,8 @@ bool Material::load(const char* filename)
 						if(token->getCode() == Scanner::TC_STRING)
 						{
 							var.value.texture = Rsrc::textures.load(token->getValue().getString());
+							if(var.value.texture == NULL)
+								return false;
 						}
 						else
 						{

+ 2 - 1
src/Resources/Material.h

@@ -45,7 +45,7 @@ class Material: public Resource
 		 * After changing the enum update also:
 		 * - some statics in Material.cpp
 		 * - Renderer::setupMaterial
-		 * - the generic material shader
+		 * - the generic material shader (optional)
 		 */
 		enum StdUniVars
 		{
@@ -57,6 +57,7 @@ class Material: public Resource
 			SUV_VIEW_MAT,
 			SUV_PROJECTION_MAT,
 			SUV_MODELVIEW_MAT,
+			SUV_VIEWPROJECTION_MAT,
 			SUV_NORMAL_MAT,
 			SUV_MODELVIEWPROJECTION_MAT,
 			// FAIs (for materials in blending stage)

+ 5 - 2
src/Scene/Camera.cpp

@@ -93,7 +93,9 @@ void Camera::updateWSpaceFrustumPlanes()
 {
 	for(uint i=0; i<6; i++)
 	{
-		wspaceFrustumPlanes[i] = lspaceFrustumPlanes[i].Transformed(getWorldTransform().getOrigin(), getWorldTransform().getRotation(), getWorldTransform().getScale());
+		wspaceFrustumPlanes[i] = lspaceFrustumPlanes[i].Transformed(getWorldTransform().getOrigin(),
+		                                                            getWorldTransform().getRotation(),
+		                                                            getWorldTransform().getScale());
 	}
 }
 
@@ -191,7 +193,8 @@ void Camera::updateViewMatrix()
 	 * The point at which the camera looks:
 	 * Vec3 viewpoint = translationLspace + z_axis;
 	 * as we know the up vector, we can easily use gluLookAt:
-	 * gluLookAt(translationLspace.x, translationLspace.x, translationLspace.z, z_axis.x, z_axis.y, z_axis.z, y_axis.x, y_axis.y, y_axis.z);
+	 * gluLookAt(translationLspace.x, translationLspace.x, translationLspace.z, z_axis.x, z_axis.y, z_axis.z, y_axis.x,
+	 *           y_axis.y, y_axis.z);
 	*/
 
 	// The view matrix is: Mview = camera.world_transform.Inverted(). Bus instead of inverting we do the following: