public void LoadPNGImageWithAlpha() { //load a ppm var png = PNGImage.LoadPNGFromPath("../../../../../textures/testTextureWithSomeAlpha.png"); var ppm = new ppmImage(512, 512, 255); ppm.Colors = png.Colors; Assert.AreEqual(png.Colors.Where(x => x == Color.FromArgb(255, 216, 216, 216)).Count(), 11016); var savePath = "../../../../../testTextureWithSomeAlpha.ppm"; System.IO.File.WriteAllBytes(savePath, ppm.toByteArray()); }
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() { var cameraPos = new Vector3(0, 2, 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 normalMap = PNGImage.LoadPNGFromPath("../../../../../textures/testMaps/gridnormalmap.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("../../../perspectiveTestNormal.ppm", image.toByteArray()); Assert.AreEqual(1002520, 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()); }