Quellcode durchsuchen

- Removing old files
- New SSAO algorithm (WIP)

Panagiotis Christopoulos Charitos vor 14 Jahren
Ursprung
Commit
d538a6c3bf
7 geänderte Dateien mit 72 neuen und 33 gelöschten Zeilen
  1. 0 1
      shaders/Dp.glsl
  2. 17 16
      shaders/PpsSsao-2.glsl
  3. 0 3
      shaders/dp_grass.glsl
  4. 0 7
      shaders/dp_hw_skinning.glsl
  5. 4 2
      src/Renderer/Is.cpp
  6. 41 4
      src/Renderer/Ssao.cpp
  7. 10 0
      src/Renderer/Ssao.h

+ 0 - 1
shaders/Dp.glsl

@@ -1 +0,0 @@
-#pragma anki include "shaders/dp_generic.glsl"

+ 17 - 16
shaders/PpsSsao-2.glsl

@@ -4,7 +4,7 @@ layout(location = 0) in vec2 position; ///< the vert coords are {1.0,1.0}, {0.0,
 layout(location = 1) in vec3 viewVector;
 
 out vec2 vTexCoords;
-out vec3 vPosition;
+out vec3 vViewVector;
 
 
 //======================================================================================================================
@@ -12,7 +12,7 @@ out vec3 vPosition;
 //======================================================================================================================
 void main()
 {
-	vPosition = viewVector;
+	vViewVector = viewVector;
 	vTexCoords = position;
 	vec2 vertPosNdc = position * 2.0 - 1.0;
 	gl_Position = vec4(vertPosNdc, 0.0, 1.0);
@@ -29,18 +29,18 @@ uniform vec2 planes; ///< for the calculation of frag pos in view space
 uniform sampler2D msDepthFai; ///< for the calculation of frag pos in view space	
 uniform sampler2D noiseMap;
 uniform sampler2D msNormalFai;
-
-uniform float noiseMapSize;
-uniform float g_sample_rad;
-uniform float g_intensity;
-uniform float g_scale;
-uniform float g_bias;
+uniform float noiseMapSize = 100.0; /// Used in getRandom
+uniform float sampleRad = 0.006;  /// Used in main
+uniform float scale = 0.01; /// Used in doAmbientOcclusion
+uniform float intensity = 0.5; /// Used in doAmbientOcclusion
+uniform float bias = 0.01; /// Used in doAmbientOcclusion
+uniform vec2 screenSize; /// Used in getRandom
 /// @}
 
 /// @name Varyings
 /// @{
 in vec2 vTexCoords;
-in vec3 vPosition; ///< for the calculation of frag pos in view space
+in vec3 vViewVector; ///< for the calculation of frag pos in view space
 /// @}
 
 /// @name Output
@@ -48,14 +48,15 @@ in vec3 vPosition; ///< for the calculation of frag pos in view space
 layout(location = 0) out float fColor;
 /// @}
 
+
 /// Get frag position in view space
-/// globals: msDepthFai, planes, vPosition
+/// globals: msDepthFai, planes, vViewVector
 vec3 getPosition(in vec2 uv)
 {
 	float depth = texture2D(msDepthFai, uv).r;
 
 	vec3 fragPosVspace;
-	vec3 vposn = normalize(vPosition);
+	vec3 vposn = normalize(vViewVector);
 	fragPosVspace.z = -planes.y / (planes.x + depth);
 	fragPosVspace.xy = vposn.xy * (fragPosVspace.z / vposn.z);
 	return fragPosVspace;
@@ -80,8 +81,8 @@ float doAmbientOcclusion(in vec2 tcoord, in vec2 uv, in vec3 p, in vec3 cnorm)
 {
 	vec3 diff = getPosition(tcoord + uv) - p;
 	vec3 v = normalize(diff);
-	float d = length(diff) * g_scale;
-	return max(0.0, dot(cnorm, v) - g_bias) * (1.0 / (1.0 + d)) * g_intensity;
+	float d = length(diff) * scale;
+	return max(0.0, dot(cnorm, v) - bias) * (1.0 / (1.0 + d)) * intensity;
 }
 
 
@@ -96,11 +97,11 @@ void main(void)
 	vec2 rand = getRandom(vTexCoords);
 
 	float ao = 0.0f;
-	float rad = g_sample_rad / p.z;
+	float rad = sampleRad / p.z;
 
 	// SSAO Calculation
-	const int iterations = 4;
-	for(int j = 0; j < iterations; ++j)
+	const int ITERATIONS = 4;
+	for(int j = 0; j < ITERATIONS; ++j)
 	{
 		vec2 coord1 = reflect(kernel[j], rand) * rad;
 		vec2 coord2 = vec2(coord1.x * 0.707 - coord1.y * 0.707, coord1.x * 0.707 + coord1.y * 0.707);

+ 0 - 3
shaders/dp_grass.glsl

@@ -1,3 +0,0 @@
-#define _GRASS_LIKE_
-
-#pragma anki include "shaders/dp_generic.glsl"

+ 0 - 7
shaders/dp_hw_skinning.glsl

@@ -1,7 +0,0 @@
-#define _HW_SKINNING_
-
-#pragma anki attribute vertWeightBonesNum 0
-#pragma anki attribute vertWeightBoneIds 1
-#pragma anki attribute vertWeightWeights 2
-
-#pragma anki include "shaders/dp_generic.glsl"

+ 4 - 2
src/Renderer/Is.cpp

@@ -141,7 +141,8 @@ void Is::init(const RendererInitializer& initializer)
 	ambientPassSProg.loadRsrc("shaders/IsAp.glsl");
 
 	// point light
-	pointLightSProg.loadRsrc(ShaderProg::createSrcCodeToCache("shaders/IsLpGeneric.glsl", "#define POINT_LIGHT_ENABLED\n",
+	pointLightSProg.loadRsrc(ShaderProg::createSrcCodeToCache("shaders/IsLpGeneric.glsl",
+	                                                          "#define POINT_LIGHT_ENABLED\n",
 	                                                          "Point").c_str());
 
 	// spot light no shadow
@@ -151,7 +152,8 @@ void Is::init(const RendererInitializer& initializer)
 
 	// spot light w/t shadow
 	std::string pps = std::string("\n#define SPOT_LIGHT_ENABLED\n#define SHADOW_ENABLED\n") +
-	                              "#define SHADOWMAP_SIZE " + boost::lexical_cast<std::string>(sm.getResolution()) + "\n";
+	                              "#define SHADOWMAP_SIZE " + boost::lexical_cast<std::string>(sm.getResolution()) +
+	                              "\n";
 	std::string prefix = "SpotShadowSmSize" + boost::lexical_cast<std::string>(sm.getResolution());
 	if(sm.isPcfEnabled())
 	{

+ 41 - 4
src/Renderer/Ssao.cpp

@@ -97,6 +97,23 @@ void Ssao::init(const RendererInitializer& initializer)
 	//noise_map->setTexParameter(GL_TEXTURE_MIN_FILTER, GL_NEAREST);
 	Texture::compressionEnabled = texCompr;
 	Texture::mipmappingEnabled = mipmaping;*/
+	
+	//
+	// Geom
+	//
+	
+	float quadVertCoords[][2] = {{1.0, 1.0}, {0.0, 1.0}, {0.0, 0.0}, {1.0, 0.0}};
+	quadPositionsVbo.create(GL_ARRAY_BUFFER, sizeof(quadVertCoords), quadVertCoords, GL_STATIC_DRAW);
+
+	ushort quadVertIndeces[2][3] = {{0, 1, 3}, {1, 2, 3}};
+	quadVertIndecesVbo.create(GL_ELEMENT_ARRAY_BUFFER, sizeof(quadVertIndeces), quadVertIndeces, GL_STATIC_DRAW);
+
+	viewVectorsVbo.create(GL_ARRAY_BUFFER, 4 * sizeof(Vec3), NULL, GL_DYNAMIC_DRAW);
+
+	vao.create();
+	vao.attachArrayBufferVbo(quadPositionsVbo, 0, 2, GL_FLOAT, false, 0, NULL);
+	vao.attachArrayBufferVbo(viewVectorsVbo, 1, 3, GL_FLOAT, false, 0, NULL);
+	vao.attachElementArrayBufferVbo(quadVertIndecesVbo);
 }
 
 
@@ -115,18 +132,38 @@ void Ssao::run()
 
 	Renderer::setViewport(0, 0, width, height);
 
+	//
 	// 1st pass
+	//
+	
+	boost::array<Vec3, 4> viewVectors;
+	boost::array<float, 2> gScreenSize = {{r.getWidth(), r.getHeight()}};
+	Is::calcViewVectors(gScreenSize, cam.getInvProjectionMatrix(), viewVectors);
+	viewVectorsVbo.write(&viewVectors[0]);
+	
+	Vec2 planes;
+	Is::calcPlanes(Vec2(r.getCamera().getZNear(), r.getCamera().getZFar()), planes);
+	
 	ssaoFbo.bind();
 	ssaoSProg->bind();
-	Vec2 camRange(cam.getZNear(), cam.getZFar());
-	ssaoSProg->findUniVar("camerarange")->set(&camRange);
+	
+	ssaoSProg->findUniVar("planes")->set(&planes);
 	ssaoSProg->findUniVar("msDepthFai")->set(r.getMs().getDepthFai(), 0);
 	ssaoSProg->findUniVar("noiseMap")->set(*noiseMap, 1);
 	ssaoSProg->findUniVar("msNormalFai")->set(r.getMs().getNormalFai(), 2);
-	r.drawQuad();
+	Vec2 screenSize(width, height);
+	ssaoSProg->findUniVar("screenSize")->set(&screenSize);
+	float noiseMapSize = noiseMap->getWidth();
+	ssaoSProg->findUniVar("noiseMapSize")->set(&noiseMapSize);
+	
+	vao.bind();
+	glDrawElements(GL_TRIANGLES, 2 * 3, GL_UNSIGNED_SHORT, 0);
+	vao.unbind();
 
 
-	// blurring passes
+	//
+	// Blurring passes
+	//
 	hblurFai.setRepeat(false);
 	fai.setRepeat(false);
 	for(uint i = 0; i < blurringIterationsNum; i++)

+ 10 - 0
src/Renderer/Ssao.h

@@ -6,6 +6,8 @@
 #include "Texture.h"
 #include "ShaderProg.h"
 #include "RsrcPtr.h"
+#include "Vbo.h"
+#include "Vao.h"
 
 
 /// Screen space ambient occlusion pass
@@ -42,6 +44,14 @@ class Ssao: private RenderingPass
 		RsrcPtr<ShaderProg> ssaoSProg;
 		RsrcPtr<ShaderProg> hblurSProg;
 		RsrcPtr<ShaderProg> vblurSProg;
+		
+		/// @name For the quad drawing in light passes
+		/// @{
+		Vbo quadPositionsVbo; ///< The VBO for quad positions
+		Vbo viewVectorsVbo; ///< The VBO to pass the @ref viewVectors.
+		Vbo quadVertIndecesVbo; ///< The VBO for quad array buffer elements
+		Vao vao; ///< This VAO is used in light passes only
+		/// @}
 
 		void createFbo(Fbo& fbo, Texture& fai);
 };