Frederic De Groef avatar Frederic De Groef committed b9c3723

can't remember anything

Comments (0)

Files changed (8)

media/ssao/crytek/crytek_ssao.cg

 #define PI 3.141592653
 
 
+	
+float3 sphereVectors[16] = {
+	float3(0.486275, 0.674510, 0.968627),
+	float3(0.113725, 0.619608, 0.796078),
+	float3(0.905882, 0.239216, 0.372549),
+	float3(0.290196, 0.341176, 0.074510),
+	float3(0.015686, 0.552941, 0.384314),
+	float3(0.984314, 0.627451, 0.486275),
+	float3(0.600000, 0.921569, 0.250980),
+	float3(0.270588, 0.796078, 0.168627),
+	float3(0.607843, 0.101961, 0.219608),
+	float3(0.882353, 0.360784, 0.792157),
+	float3(0.674510, 0.941176, 0.658824),
+	float3(0.619608, 0.066667, 0.717647),
+	float3(0.368627, 0.270588, 0.921569),
+	float3(0.200000, 0.882353, 0.619608),
+	float3(0.639216, 0.635294, 0.039216),
+	float3(0.117647, 0.176471, 0.525490)
+};
+	  
+
 void crytek_ssao_ps(FragmentInput IN
     ,uniform float far
-    ,uniform sampler2D geomMap : TEXUNIT0
-	,uniform sampler2D randMap : TEXUNIT1
+    ,uniform sampler geomMap 
+	,uniform sampler randMap 
 	,uniform float4 cViewportSize
     ,uniform float nearClipDistance
 	,uniform float farClipDistance
     ,uniform float cFov
 	,uniform float cSampleInScreenSpace // whether to sample in screen or world space
 	,uniform float cSampleLengthScreenSpace // The sample length in screen space [0, 1]
-	,uniform float cSampleLengthWorldSpace // the sample length in world space in units
+	//,uniform float cSampleLengthWorldSpace // the sample length in world space in units
 	,uniform float cOffsetScale // [0, 1] The distance of the first sample. samples are the 
 								// placed in [cOffsetScale * cSampleLengthScreenSpace, cSampleLengthScreenSpace]
 	,uniform float cDefaultAccessibility // the default value used in the lerp() expression for invalid samples [0, 1]
 
 	// get rotation vector, rotation is tiled every 4 screen pixels
 	float2 rotationTC = IN.pixelPos * cViewportSize.xy / 4;
-	float3 rotationVector = 2 * tex2D(randMap, rotationTC).xyz - 1; // [-1, 1]x[-1. 1]x[-1. 1]
+	//float2 rotationTC = IN.pixelPos * float2(1440, 900) / float2(1439, 899);
+	float3 rotationVector = 2.0f * tex2D(randMap, rotationTC).xyz - 1; // [-1, 1]x[-1. 1]x[-1. 1]
+
+	//rotationVector = float3(1, 1, 1);
+
 	
 	float rUV = 0; // radius of influence in screen space
 	float r = 0; // radius of influence in world space
-	if (cSampleInScreenSpace == 1)
-	{
+	//if (cSampleInScreenSpace == 1)
+	//{
 		rUV = cSampleLengthScreenSpace;
 		r = tan(rUV * cFov) * fragmentWorldDepth;
-	}
-	else
-	{
-		rUV = atan(cSampleLengthWorldSpace / fragmentWorldDepth) / cFov; // the radius of influence projected into screen space
-		r = cSampleLengthWorldSpace;
-	}
-
+	//}
+	//else
+	//{
+		//rUV = atan(cSampleLengthWorldSpace / fragmentWorldDepth) / cFov; // the radius of influence projected into screen space
+		//r = cSampleLengthWorldSpace;
+	//}
+//
 	float sampleLength = cOffsetScale; // the offset for the first sample
 	const float sampleLengthStep = pow((rUV / sampleLength), 1.0f/nSampleNum);
 	
-	float accessibility = 0;
+	float accessibility = 0.5f;
 
 
-	float3 sphereVectors[8] = {
+
+
+	float3 offsetVectors[8] = {
 		float3(-1, -1, -1),
-		float3(-1, -1, 1),
-		float3(-1, 1, -1),
-		float3(-1, 1, 1),
-		float3(1, -1, -1),
-		float3(1, -1, 1),
-		float3(1, 1, -1),
-		float3(1, 1, 1)
+		float3(-1, -1,  1),
+		float3(-1,  1, -1),
+		float3(-1,  1,  1),
+		float3( 1, -1, -1),
+		float3( 1, -1,  1),
+		float3( 1,  1, -1),
+		float3( 1,  1,  1)
 	};
 
 
 	for (int i = 0; i < (nSampleNum/8); i++)
 	{
 			//generate offset vector
-			float3 offset = normalize(sphereVectors[i]) * sampleLength;
+			float3 offset = normalize(offsetVectors[i]) * sampleLength;
+			//float3 offset = sampleLength.xxx;
 			
 			// update sample length
 			sampleLength *= sampleLengthStep;
 		
 			// reflect offset vector by random rotation sample (i.e. rotating it) 
 			float3 rotatedOffset = reflect(offset, rotationVector);
+			//float3 rotatedOffset = rotationVector;
 					
 			float2 sampleTC = IN.pixelPos + rotatedOffset.xy * rUV;
-				
+			
+
+	
 			// read scene depth at sampling point and convert into world space units (m or whatever)
 			float sampleWorldDepth = tex2D(geomMap, sampleTC).r * clipDepth;
-			//float sampleWorldDepth = 0.005f * clipDepth;			
+			
 
 			// check if depths of both pixles are close enough and sampling point should affect our center pixel
 			float fRangeIsInvalid = saturate((fragmentWorldDepth - sampleWorldDepth) / r);
 			// accumulate accessibility, use default value of 0.5 if right computations are not possible
 			accessibility += lerp(sampleWorldDepth > (fragmentWorldDepth + rotatedOffset.z * r), cDefaultAccessibility, fRangeIsInvalid);
 
-			//accessibility += abs(sampleWorldDepth - fragmentWorldDepth);
+			//if(sampleWorldDepth > fragmentWorldDepth)
+			//	accessibility += sampleWorldDepth - fragmentWorldDepth;
 
-//			accessibility += (sampleWorldDepth > (fragmentWorldDepth + rotatedOffset.z * r)) + (fRangeIsInvalid);
-//			accessibility += fRangeIsInvalid;
+			//accessibility += (sampleWorldDepth > (fragmentWorldDepth + rotatedOffset.z * r)) + (fRangeIsInvalid);
+			//accessibility += fRangeIsInvalid;
+
 
 	}
 	
 
 
 
-
-}
+	
+	//rotationTC = IN.pixelPos * float2(1440, 900) / 4;
+	//rotationVector = 2.0f * tex2D(randMap, rotationTC).xyz - 1; // [-1, 1]x[-1. 1]x[-1. 1]
+	//oColor = tex2D(randMap, IN.pixelPos * cViewportSize.xy / 4);
+}							

media/ssao/crytek/crytek_ssao.material

 
 		param_named		cSampleInScreenSpace		float 1
 		param_named		cSampleLengthScreenSpace	float 0.06
-		param_named		cSampleLengthWorldSpace		float 2.0
-		param_named		cOffsetScale				float 0.01
+		//param_named		cSampleLengthWorldSpace		float 2.0
+		param_named		cOffsetScale				float 0.1
 		param_named		cDefaultAccessibility		float 0.5
-		param_named		cEdgeHighlight				float 2	
+		param_named		cEdgeHighlight				float 1.5	
 
       }
 
         filtering none
       }
 
-	  texture_unit 
+	  texture_unit randMap
 	  {
  	     texture regularSphereJittered4.png
 		 tex_address_mode wrap
 
 
 
+
+
+
+
 material SSAO/Crytek/Combine
 {
     technique

media/ssao/ssao.compositor

                 // our SSAO listener number
                 identifier 42
 
-                material SSAO/rgba_iq/ssao
+                material SSAO/Crytek/ssao
                 input 0 GBuffer
             }
         }
             {
                 // just output something, for example, use a modulate
                 // material to just multiply the scene by the ssao
-                material SSAO/Ogre/Modulate
+                material SSAO/Crytek/Combine
                 input 0 scene
                 input 1 ssao
             }

media/ssao/ssao_with_debug.compositor

                 // our SSAO listener number
                 identifier 42
 
-                material SSAO/Crytek/ssao
+                material SSAO/rgba_iq/ssao
                 input 0 GBuffer
             }
         }
             {
                 // just output something, for example, use a modulate
                 // material to just multiply the scene by the ssao
-                material SSAO/Crytek/Combine
+                material SSAO/rgba_iq/Combine
                 input 0 scene
                 input 1 ssao
             }

ogre-ssao/SSAOApp.cpp

 #include <boost/foreach.hpp>
 #include <boost/format.hpp>
 
+
+
+
+#define TAU 2*Ogre::Math::PI
+
 //-----------------------------------------------------------------------------
 SSAOApp::SSAOApp()
     :OgreApplication("SSAO sandbox", CT_MOUSE)
 //-----------------------------------------------------------------------------
 void SSAOApp::_populate()
 {   
-    _loadSponzaAtrium();
-    //_loadHebeCassini();
+    //_loadSponzaAtrium();
+    _loadHebeCassini();
     //_loadULBCampus();
 }
 //-----------------------------------------------------------------------------
 
     Ogre::SceneNode *node= _loadMesh("hebemissin", Ogre::Vector3(0, -0.19, 200));
     node->scale(20, 20, 20);
+
+    node = _loadMesh("dragon", Ogre::Vector3(200, 35, 200));
+    node->roll(Ogre::Radian(TAU / 2));
+    node->scale(50, 50, 50);
+
+                                             
 }
 //-----------------------------------------------------------------------------
 void SSAOApp::_buildRoom()

python/gen_sphere_points.py

+#!/usr/bin/env python
+
+from __future__ import division
+import random as r
+import math as m
+import numpy as np
+import matplotlib.pyplot as plt
+from mpl_toolkits.mplot3d import Axes3D
+
+
+def norm(x, y, z):
+    return m.sqrt(x*x + y*y + z*z)
+
+
+def normalize(x, y, z):
+    n = norm(x, y, z)
+    return (x/n, y/n, z/n)
+
+
+def normalize_and_scale(x, y, z):
+    s = r.random()
+    normalized = normalize(x, y, z)
+    return (normalized[0]*s,
+            normalized[1]*s,
+            normalized[2]*s)
+
+
+
+def make_colors(xs, yz, zs):
+    def make_RBGA_string(x, y, z):
+        return "#%02hx%02hx%02hx" % tuple([int(v*255) for v in (x, y, z)])
+    return [make_RBGA_string(x, y, z) for (x, y, z) in zip(xs, ys, zs)]
+
+
+
+def make_scatterplot(xs, ys, zs):
+    fig = plt.figure()
+    ax = fig.add_subplot(111, projection='3d')
+    ax.set_xlabel('X')
+    ax.set_ylabel('Y')
+    ax.set_zlabel('Z')
+
+    ax.scatter(xs, ys, zs, s=50)#, c=make_colors(xs, ys, zs))
+    plt.show()
+    
+    
+
+
+
+
+if __name__ == '__main__':    
+    N = 64
+
+    xs, ys, zs = [], [], []
+
+    for i in range(N):
+        x =  r.uniform(0, 1) 
+        y =  r.uniform(0, 1) 
+        z =  r.uniform(0, 1) 
+
+        print x, y, z
+        sx, sy, sz = x, y, z #normalize_and_scale(x, y, z)
+        xs.append(sx)
+        ys.append(sy)
+        zs.append(sz)
+        
+    
+    make_scatterplot(xs, ys, xs)

python/img_to_vectors.py

+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+
+from PIL import Image
+import numpy as np
+import matplotlib.pyplot as plt
+from mpl_toolkits.mplot3d import Axes3D
+from pprint import pprint
+
+
+
+    
+
+
+def make_colors(xs, yz, zs):
+    def make_RBGA_string(x, y, z):
+        return "#%02hx%02hx%02hx" % tuple([int(v*255) for v in (x, y, z)])
+    return [make_RBGA_string(x, y, z) for (x, y, z) in zip(xs, ys, zs)]
+
+
+
+def make_scatterplot(xs, ys, zs):
+    fig = plt.figure()
+    ax = fig.add_subplot(111, projection='3d')
+    ax.set_xlabel('X')
+    ax.set_ylabel('Y')
+    ax.set_zlabel('Z')
+
+    ax.scatter(xs, ys, zs, s=50, c=make_colors(xs, ys, zs))
+    plt.show()
+    
+    
+    
+    
+if __name__ == '__main__':
+    img_file = "regularSphereJittered4.png"
+    img = Image.open(img_file)
+
+    img_data = np.asarray(img)
+    
+    #plt.imshow(img_data, interpolation='nearest')
+    #plt.show()
+    
+    
+    img_data = (img_data.astype('float')) / 255
+
+    dimensions = np.asarray([img_data[:,:,i] for i in (0,1,2)])
+    
+
+    xs, ys, zs = [arr.reshape((16)) for arr in dimensions]
+
+
+    print "float3 sphereVectors[%d] { " % len(xs)
+    for (x, y, z) in zip(xs, ys, zs):
+        print "    float3(%f, %f, %f)," % (x,y,z)
+    print "};"
+
+
+    for (x, y, z) in zip(xs, ys, zs):
+        print 
+    
+    make_scatterplot(xs, ys, zs)

python/range_is_valid.py

+
+
+import numpy as np
+import matplotlib.pyplot as plt
+from mpl_toolkits.mplot3d import Axes3D
+from pprint import pprint
+from scipy.weave import inline, converters
+
+
+
+
+def saturate(xs, ys):
+    num_samples = xs.shape[0]
+    zs = np.zeros((num_samples, num_samples))
+
+    print zs
+    
+    code = """
+
+    for (int i=0; i<num_samples; ++i)
+    {
+        float frag = xs(i);
+        for (int j=0; j<num_samples; ++j)
+        {
+            float sample = ys(j);
+
+            float val = (frag - sample) / RADIUS;
+            
+            if(val < 0.0f)
+                val = 0.0f;
+            else if(val > 1.0f)
+                val = 1.0f;
+            zs(i, j) = val;
+        }
+    }
+
+    
+    """
+
+    RADIUS =  50
+    
+    inline(code, ['xs', 'ys', 'zs', 'RADIUS', 'num_samples'],
+           type_converters=converters.blitz,
+           compiler = 'gcc',
+           verbose = 1)
+
+    return zs
+
+
+
+
+if __name__ == '__main__':
+    near_clip_distance = 0.05
+    far_clip_distance = 200
+
+    num_samples = 100
+    xs = np.linspace(near_clip_distance, far_clip_distance, num_samples)
+    ys = np.linspace(near_clip_distance, far_clip_distance, num_samples)
+
+    zs = saturate(xs, ys)
+
+    print zs
+
+    
+    fig = plt.figure()
+    ax = fig.add_subplot(111, projection='3d')
+    ax.set_xlabel('frag')
+    ax.set_ylabel('sample')
+    ax.set_zlabel('saturate')
+
+
+    X, Y = np.meshgrid(xs, ys)
+    #x.plot_surface(X, Y, zs)
+    ax.scatter(xs, ys, zs)
+
+    
+    plt.show()
+    print xs
+    print ys
+    print zs
+    
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.