public void Prespective_Tex_Map() { var cameraPos = new Vector3(0, 0, 2); var target = new Vector3(0, 0, 0); var width = 1024; var height = 1024; var view = Matrix4x4.CreateLookAt(cameraPos, target, Vector3.UnitY); var proj = Matrix4x4.CreatePerspective(4, 4, 1, 10); var viewport = MatrixExtensions.CreateViewPortMatrix(0, 0, 255, width, height); var mesh = ObjFileLoader.LoadMeshFromObjAtPath(new System.IO.FileInfo("../../../../../geometry_models/knot3/knot3.obj")); var diffuseTex = new ppmImage("../../../../../textures/testTexture2.ppm"); var renderable = new Renderable <Mesh>( new DiffuseMaterial() { Shader = new TextureShader(view, proj, viewport), DiffuseTexture = new Texture2d(diffuseTex.Width, diffuseTex.Height, diffuseTex.Colors) }, mesh); var renderer = new Renderer3dGeneric <Mesh>(width, height, Color.White, new List <IEnumerable <Renderable <Mesh> > > { new List <Renderable <Mesh> > { renderable } }); var image = new ppmImage(width, height, 255); image.Colors = renderer.Render(); System.IO.File.WriteAllBytes("../../../perspectiveTestDiffuse.ppm", image.toByteArray()); Assert.AreEqual(847497, image.Colors.Where(x => x == Color.White).Count()); }
public void MeshRenderPerspProjectionShader() { var cameraPos = new Vector3(0, 0, 4); var target = new Vector3(0, 0, 0); var view = Matrix4x4.CreateLookAt(cameraPos, target, Vector3.UnitY); var proj = Matrix4x4.CreatePerspective(4, 3, 1, 10); var viewport = MatrixExtensions.CreateViewPortMatrix(0, 0, 255, 640, 480); var mesh = ObjFileLoader.LoadMeshFromObjAtPath(new System.IO.FileInfo("../../../../../geometry_models/knot3/knot3.obj")); var renderable = new Renderable <Mesh>( new Material() { Shader = new Base3dShader(view, proj, viewport) }, mesh); var renderer = new Renderer3dGeneric <Mesh>(640, 480, Color.White, new List <IEnumerable <Renderable <Mesh> > > { new List <Renderable <Mesh> > { renderable } }); var image = new ppmImage(640, 480, 255); image.Colors = renderer.Render(); System.IO.File.WriteAllBytes("../../../perspectiveTest1.ppm", image.toByteArray()); Assert.AreEqual(300249, image.Colors.Where(x => x == Color.White).Count()); }
public void Prespective_Normal_Map_TinyRenderReferenceAnimation() { var cameraPos = new Vector3(-.6f, .6f, 3); var target = new Vector3(0, 0, 0); var width = 480; var height = 480; var view = Matrix4x4.CreateLookAt(cameraPos, target, Vector3.UnitY); var proj = Matrix4x4.CreatePerspective(1, 1, 1, 10); var viewport = MatrixExtensions.CreateViewPortMatrix(0, 0, 255, width, height); var mesh = ObjFileLoader.LoadMeshFromObjAtPath(new System.IO.FileInfo(Path.Combine(root, "geometry_models/tiny_renderer_sample_models/african_head.obj"))); var diffuseTex = PNGImage.LoadPNGFromPath(Path.Combine(root, "geometry_models/tiny_renderer_sample_models/african_head_diffuse2.png")); var normalMap = PNGImage.LoadPNGFromPath(Path.Combine(root, "geometry_models/tiny_renderer_sample_models/african_head_nm_tangent.png")); var lightvals = Enumerable.Range(0, 11).Select(x => (x / 5.0) - 1.0).ToList(); var renderable = new Renderable <Mesh>( new NormalMaterial() { Shader = new NormalShader(view, proj, viewport) { ambientCoef = 10, LightDirection = new Vector3(0, 0, 1) }, DiffuseTexture = new Texture2d(diffuseTex.Width, diffuseTex.Height, diffuseTex.Colors), NormalMap = new Texture2d(normalMap.Width, normalMap.Height, normalMap.Colors) }, mesh); var renderer = new Renderer3dGeneric <Mesh>(width, height, Color.White, new List <IEnumerable <Renderable <Mesh> > > { new List <Renderable <Mesh> > { renderable } }); for (var i = 0; i < lightvals.Count; i++) { var mat = Matrix4x4.CreateRotationY(0.174533f * 3f); var transformedLightDir = Vector3.Transform(renderable.material.Shader.LightDirection, Matrix4x4.Transpose(mat)); renderable.material.Shader.LightDirection = transformedLightDir; var image = new ppmImage(width, height, 255); image.Colors = renderer.Render(); image.Flip(); var path = $"../../../animation1/perspectiveTestNormalHead{i}.ppm"; System.IO.FileInfo file = new System.IO.FileInfo(path); file.Directory.Create(); System.IO.File.WriteAllBytes(path, image.toByteArray()); } }
public void Prespective_Normal_Map_ZbrushMando1() { var cameraPos = new Vector3(-2f, 1, 4f); var target = new Vector3(0, 0, 0); var width = 2048; var height = 2048; var view = Matrix4x4.CreateLookAt(cameraPos, target, Vector3.UnitY); var proj = Matrix4x4.CreatePerspective(1, 1, 1, 10); var viewport = MatrixExtensions.CreateViewPortMatrix(0, 0, 255, width, height); var mesh = ObjFileLoader.LoadMeshFromObjAtPath(new System.IO.FileInfo(Path.Combine(root, "geometry_models/mandohead/mandoclean.OBJ"))); var diffuseTex = PNGImage.LoadPNGFromPath(Path.Combine(root, "geometry_models/mandohead/mandocleandiffuse6.png")); var normalMap = PNGImage.LoadPNGFromPath(Path.Combine(root, "geometry_models/mandohead/mandocleannormal1.png")); var renderable = new Renderable <Mesh>( new NormalMaterial() { Shader = new NormalShader(view, proj, viewport) { ambientCoef = 30, LightDirection = new Vector3(0, 0, 1f) }, DiffuseTexture = new Texture2d(diffuseTex.Width, diffuseTex.Height, diffuseTex.Colors), NormalMap = new Texture2d(normalMap.Width, normalMap.Height, normalMap.Colors) }, mesh); var renderer = new Renderer3dGeneric <Mesh>(width, height, Color.White, new List <IEnumerable <Renderable <Mesh> > > { new List <Renderable <Mesh> > { renderable } }); var image = new ppmImage(width, height, 255); image.Colors = renderer.Render(); image.Flip(); System.IO.File.WriteAllBytes("../../../perspectiveTestNormalMandoonecolorfront.ppm", image.toByteArray()); Assert.AreEqual(3248415, image.Colors.Where(x => x == Color.White).Count()); }
public void Prespective_Normal_Map_TinyRenderReference() { var cameraPos = new Vector3(-.6f, .6f, 3); var target = new Vector3(0, 0, 0); var width = 2048; var height = 2048; var view = Matrix4x4.CreateLookAt(cameraPos, target, Vector3.UnitY); var proj = Matrix4x4.CreatePerspective(1, 1, 1, 10); var viewport = MatrixExtensions.CreateViewPortMatrix(0, 0, 255, width, height); var mesh = ObjFileLoader.LoadMeshFromObjAtPath(new System.IO.FileInfo("../../../../../geometry_models/tiny_renderer_sample_models/african_head.obj")); var diffuseTex = PNGImage.LoadPNGFromPath("../../../../../geometry_models/tiny_renderer_sample_models/african_head_diffuse2.png"); var normalMap = PNGImage.LoadPNGFromPath("../../../../../geometry_models/tiny_renderer_sample_models/african_head_nm_tangent.png"); var renderable = new Renderable <Mesh>( new NormalMaterial() { Shader = new NormalShader(view, proj, viewport) { ambientCoef = 10, LightDirection = new Vector3(0, 0, 1) }, DiffuseTexture = new Texture2d(diffuseTex.Width, diffuseTex.Height, diffuseTex.Colors), NormalMap = new Texture2d(normalMap.Width, normalMap.Height, normalMap.Colors) }, mesh); var renderer = new Renderer3dGeneric <Mesh>(width, height, Color.White, new List <IEnumerable <Renderable <Mesh> > > { new List <Renderable <Mesh> > { renderable } }); var image = new ppmImage(width, height, 255); image.Colors = renderer.Render(); System.IO.File.WriteAllBytes("../../../perspectiveTestNormalHead.ppm", image.toByteArray()); Assert.AreEqual(3362439, image.Colors.Where(x => x == Color.White).Count()); }
public void RenderIsFlippedCorrectly() { var cameraPos = new Vector3(-.6f, .6f, 5); var target = new Vector3(0, 0, 0); var width = 2048; var height = 2048; var view = Matrix4x4.CreateLookAt(cameraPos, target, Vector3.UnitY); var proj = Matrix4x4.CreatePerspective(1, 1, 1, 10); var viewport = MatrixExtensions.CreateViewPortMatrix(0, 0, 255, width, height); var mesh = ObjFileLoader.LoadMeshFromObjAtPath(new System.IO.FileInfo(System.IO.Path.Combine(root, "geometry_models/head_asymmetric/head.OBJ"))); var diffuseTex = PNGImage.LoadPNGFromPath(System.IO.Path.Combine(root, "geometry_models/head_asymmetric/head.png")); var renderable = new Renderable <Mesh>( new DiffuseMaterial() { Shader = new TextureShader(view, proj, viewport) { LightDirection = new Vector3(0, 0, 1) }, DiffuseTexture = new Texture2d(diffuseTex.Width, diffuseTex.Height, diffuseTex.Colors), }, mesh); var renderer = new Renderer3dGeneric <Mesh>(width, height, Color.White, new List <IEnumerable <Renderable <Mesh> > > { new List <Renderable <Mesh> > { renderable } }); var image = new ppmImage(width, height, 255); image.Colors = renderer.Render(); image.Flip(); System.IO.File.WriteAllBytes("../../../asymmetricHead.ppm", image.toByteArray()); Assert.AreEqual(3528584, image.Colors.Where(x => x == Color.White).Count()); }