public Light(Camera camera, RgbaFloat color, float intensity, float attenuation, Vector4 parameters) { LightCam = camera; _color = color.ToVector4(); _color.W = intensity; var lookAt = camera.LookDirection; var direction = new Vector4(lookAt.X, lookAt.Y, lookAt.Z, attenuation); _direction = direction; _parameters = parameters; }
internal static bool DrawRgbaFloat(string label, ref RgbaFloat obj, RenderContext rc) { var color = obj.ToVector4(); bool result = ImGui.ColorEdit4(label, ref color, true); if (result) { obj = new RgbaFloat(color.X, color.Y, color.Z, color.W); } return(result); }
public static Mesh <VertexPositionColor> GenerateCubeColor(bool indexed, RgbaFloat color) { VertexPositionColor[] cubeVerticies = new VertexPositionColor[] { // Top new VertexPositionColor(new Vector3(-1.0f, +1.0f, -1.0f), color.ToVector4()), new VertexPositionColor(new Vector3(+1.0f, +1.0f, -1.0f), color.ToVector4()), new VertexPositionColor(new Vector3(+1.0f, +1.0f, +1.0f), color.ToVector4()), new VertexPositionColor(new Vector3(-1.0f, +1.0f, +1.0f), color.ToVector4()), // Bottom new VertexPositionColor(new Vector3(-1.0f, -1.0f, +1.0f), color.ToVector4()), new VertexPositionColor(new Vector3(+1.0f, -1.0f, +1.0f), color.ToVector4()), new VertexPositionColor(new Vector3(+1.0f, -1.0f, -1.0f), color.ToVector4()), new VertexPositionColor(new Vector3(-1.0f, -1.0f, -1.0f), color.ToVector4()), // Left new VertexPositionColor(new Vector3(-1.0f, +1.0f, -1.0f), color.ToVector4()), new VertexPositionColor(new Vector3(-1.0f, +1.0f, +1.0f), color.ToVector4()), new VertexPositionColor(new Vector3(-1.0f, -1.0f, +1.0f), color.ToVector4()), new VertexPositionColor(new Vector3(-1.0f, -1.0f, -1.0f), color.ToVector4()), // Right new VertexPositionColor(new Vector3(+1.0f, +1.0f, +1.0f), color.ToVector4()), new VertexPositionColor(new Vector3(+1.0f, +1.0f, -1.0f), color.ToVector4()), new VertexPositionColor(new Vector3(+1.0f, -1.0f, -1.0f), color.ToVector4()), new VertexPositionColor(new Vector3(+1.0f, -1.0f, +1.0f), color.ToVector4()), // Back new VertexPositionColor(new Vector3(+1.0f, +1.0f, -1.0f), color.ToVector4()), new VertexPositionColor(new Vector3(-1.0f, +1.0f, -1.0f), color.ToVector4()), new VertexPositionColor(new Vector3(-1.0f, -1.0f, -1.0f), color.ToVector4()), new VertexPositionColor(new Vector3(+1.0f, -1.0f, -1.0f), color.ToVector4()), // Front new VertexPositionColor(new Vector3(-1.0f, +1.0f, +1.0f), color.ToVector4()), new VertexPositionColor(new Vector3(+1.0f, +1.0f, +1.0f), color.ToVector4()), new VertexPositionColor(new Vector3(+1.0f, -1.0f, +1.0f), color.ToVector4()), new VertexPositionColor(new Vector3(-1.0f, -1.0f, +1.0f), color.ToVector4()), }; return(indexed ? new Mesh <VertexPositionColor>(cubeVerticies, generateCubeIndicies_TriangleList_CW()) : new Mesh <VertexPositionColor>(cubeVerticies)); }
public static RgbaFloat Multiply(this RgbaFloat source, float value) { var v = source.ToVector4() * value; return(new RgbaFloat(v.X, v.Y, v.Z, v.W)); }
public VertexPositionTextureColor(Vector2 position, Vector2 tex, RgbaFloat color) { Position = position; TexCoords = tex; Color = color.ToVector4(); }
override protected void CreateResources() { // RgbaFloat lightColor = RgbaFloat.Orange; RgbaFloat lightColor = RgbaFloat.Blue; //RgbaFloat lightColor = RgbaFloat.LightGrey; var spotLightPos = new Vector4(0.0f, 5.0f, 7.0f, 1.0f); var lightLookAt = spotLightPos - Light.DEFAULT_POSITION; var lightCam = new OrthographicCamera(35, 35, Light.DEFAULT_POSITION, lightLookAt); var spotLightCam = new OrthographicCamera(RenderResoultion.Horizontal, RenderResoultion.Vertical, spotLightPos, Light.DEFAULT_LOOKAT); // RgbaFloat lightColor = new RgbaFloat(1.0f,0.36f,0.0f,0.2f); _sceneRuntimeState.Light = new Light(lightCam, lightColor, 0.1f); _sceneRuntimeState.Camera = Camera; _sceneRuntimeState.SpotLight = new Light( spotLightCam, RgbaFloat.DarkRed, 1.0f, 0.02f, new Vector4(Math.Cos(17.5f.ToRadians()).ToFloat(), Math.Cos(12.5f.ToRadians()).ToFloat(), 0.0f, 1.0f)); // Sun //TODO: Make this VertexPositionNormalColor _sun = new Model <VertexPositionNormal, RealtimeMaterial>(String.Empty, GeometryFactory.GenerateSphereNormal(100, 100, 1), new RealtimeMaterial()); var sunMeshZero = _sun.GetMesh(0); var sunMaterialZero = _sun.GetMaterial(0); // _sun.meshes[0].TryGetMaterial().ambient = new Vector4(0.0f,0.0f,0.0f,0.0f); sunMaterialZero.ambient = lightColor.ToVector4(); Vector4 lightPos = _sceneRuntimeState.Light.LightPos; Vector3 newTranslation = new Vector3(lightPos.X, lightPos.Y, lightPos.Z); _sun.SetNewWorldTranslation(ref newTranslation, true); //TODO: This geometry will cause problems for shadow mapping. Has to be ignored in the shadowmap generation process. var sunRuntimeState = new ModelRuntimeDescriptor <VertexPositionNormal>(_sun, "Phong", "PhongNoShadow", VertexRuntimeTypes.VertexPositionNormal, PrimitiveTopology.TriangleList, new RenderDescription(RenderFlags.NORMAL), new InstancingRenderDescription(RenderFlags.NONE, InstancingDataFlags.EMPTY)); sunRuntimeState.CallVertexLayoutGeneration += ResourceGenerator.GenerateVertexLayoutForPN; _modelPNDescriptorList.Add(sunRuntimeState); var spotlight = new Model <VertexPositionNormal, RealtimeMaterial>(String.Empty, GeometryFactory.GenerateSphereNormal(100, 100, 1), new RealtimeMaterial()); var spotlightMeshZero = spotlight.GetMesh(0); var spotlightMaterialZero = spotlight.GetMaterial(0); //TODO: @Bug: Seems to be an issue with ambient selecting the wrong color spotlightMaterialZero.ambient = _sceneRuntimeState.SpotLight.Color_DontMutate; // spotlight.meshes[0].TryGetMaterial().ambient = new Vector4(1.0f,1.0f,1.0f,1.0f); // _sun.meshes[0].TryGetMaterial().ambient = lightColor.ToVector4(); Vector4 lightPosSpot = _sceneRuntimeState.SpotLight.LightPos; Vector3 newTranslationSpot = new Vector3(lightPosSpot.X, lightPosSpot.Y, lightPosSpot.Z); spotlight.SetNewWorldTranslation(ref newTranslationSpot, true); var spotLightRuntimeState = new ModelRuntimeDescriptor <VertexPositionNormal>(spotlight, "Phong", "PhongNoShadow", VertexRuntimeTypes.VertexPositionNormal, PrimitiveTopology.TriangleList, new RenderDescription(RenderFlags.NORMAL | RenderFlags.SHADOW_MAP), new InstancingRenderDescription(RenderFlags.NONE, InstancingDataFlags.EMPTY)); spotLightRuntimeState.CallVertexLayoutGeneration += ResourceGenerator.GenerateVertexLayoutForPN; _modelPNDescriptorList.Add(spotLightRuntimeState); // Colored Quad // var offsets = new Vector3[] {new Vector3(-1.0f,0.0f,0f),new Vector3(1.0f,0.0f,0.0f)}; // // var offsets = new Vector3[] {new Vector3(0.0f,0.0f,0.0f)}; // var instancingData = new InstancingData {Positions = offsets}; // var floor = new Model<VertexPositionColor>(String.Empty,GeometryFactory.GenerateColorQuad(RgbaFloat.Red,RgbaFloat.Yellow,RgbaFloat.Green,RgbaFloat.LightGrey)); // var floorRuntimeState = new ModelRuntimeDescriptor<VertexPositionColor>(floor,"OffsetColor","Color",VertexTypes.VertexPositionColor,PrimitiveTopology.TriangleStrip); // floorRuntimeState.TotalInstanceCount = offsets.Length.ToUnsigned(); // floorRuntimeState.CallVertexLayoutGeneration+=ResourceGenerator.GenerateVertexLayoutForPC; // floorRuntimeState.CallVertexInstanceLayoutGeneration+=ResourceGenerator.GenerateVertexInstanceLayoutForPC; // _modelPCDescriptorList.Add(floorRuntimeState); //Quad Textured // var offsets = new Vector3[] {new Vector3(-1.0f,0.0f,0f),new Vector3(1.0f,0.0f,0.0f)}; // // var offsets = new Vector3[] {new Vector3(0.0f,0.0f,0.0f)}; // var instancingData = new InstancingData {Positions = offsets}; // var floor = new Model<VertexPositionTexture>("paving",GeometryFactory.GenerateTexturedQuad()); // floor.meshes[0].TryGetMaterial().textureDiffuse="pavingColor.jpg"; // var floorRuntimeState = new ModelRuntimeDescriptor<VertexPositionTexture>(floor,"PositionOffsetTexture","Texture",VertexTypes.VertexPositionTexture,PrimitiveTopology.TriangleStrip); // floorRuntimeState.TotalInstanceCount = offsets.Length.ToUnsigned(); // floorRuntimeState.CallVertexLayoutGeneration+=ResourceGenerator.GenerateVertexLayoutForPT; // floorRuntimeState.CallVertexInstanceLayoutGeneration+=ResourceGenerator.GenerateVertexInstanceLayoutForPositionOffset; // floorRuntimeState.CallTextureResourceLayoutGeneration+=ResourceGenerator.GenerateTextureResourceLayoutForDiffuseMapping; // floorRuntimeState.CallTextureResourceSetGeneration+=ResourceGenerator.GenerateTextureResourceSetForDiffuseMapping; // floorRuntimeState.CallSamplerGeneration+=ResourceGenerator.GenerateLinearSampler; // _modelPTDescriptorList.Add(floorRuntimeState); // floor // var offsets = new Vector3[] {new Vector3(-1.0f,0.0f,0f),new Vector3(1.0f,0.0f,0.0f)}; // var offsets = new Vector3[] {new Vector3(0.0f,0.0f,0.0f)}; var offsets = GeometryUtils.CreateTilingList_XZ(-20, 20, -10, 10, 0, GeometryFactory.QUAD_WIDTH, GeometryFactory.QUAD_HEIGHT); // var offsets = GeometryUtils.CreateTilingList_XZ(-1,1,0,0,0,GeometryFactory.QUAD_WIDTH,GeometryFactory.QUAD_HEIGHT); var instancingData = new InstanceData { Flag = InstancingDataFlags.POSITION, Positions = offsets }; var floor = new Model <VertexPositionNormalTextureTangentBitangent, RealtimeMaterial>("paving/", GeometryFactory.GenerateQuadPNTTB_XZ(), new RealtimeMaterial()); var floorMeshZero = floor.GetMesh(0); var flootMaterialZero = floor.GetMaterial(0); flootMaterialZero.textureDiffuse = "pavingColor.jpg"; flootMaterialZero.textureNormal = "pavingNorm.jpg"; flootMaterialZero.ambient = new Vector4(0.3f, 0.3f, 0.3f, 1.0f); var floorTranslation = new Vector3(0.0f, -2.0f, 0.0f); floor.SetNewWorldTranslation(ref floorTranslation, true); var floorRuntimeState = new ModelRuntimeDescriptor <VertexPositionNormalTextureTangentBitangent>(floor, "PositionOffsetPhongBitangentTexture", "PhongBitangentTexture", VertexRuntimeTypes.VertexPositionNormalTextureTangentBitangent, PrimitiveTopology.TriangleStrip, new RenderDescription(RenderFlags.NORMAL | RenderFlags.SHADOW_MAP), new InstancingRenderDescription(RenderFlags.SHADOW_MAP, InstancingDataFlags.POSITION)); floorRuntimeState.TotalInstanceCount = offsets.Length.ToUnsigned(); //TODO: Test ViewMatrix Instancing // Matrix4x4 test = Camera.ViewMatrix; // Matrix4x4 test2 = Camera.ViewMatrix; // test.Translation = new Vector3(0,1,-10); // test2.Translation = new Vector3(0,0,-10); // var viewMatrices = new Matrix4x4[] {test2, test}; // var viewInstancingData = new InstancingData{ // Types = InstancingTypes.ViewMatricies, // ViewMatrices = viewMatrices // }; // var floorRuntimeState = new ModelRuntimeDescriptor<VertexPositionNormalTextureTangentBitangent>(floor, "ViewMatInstancePhongBitangentTexture", "PhongBitangentTexture", VertexRuntimeTypes.VertexPositionNormalTextureTangentBitangent, PrimitiveTopology.TriangleStrip, RenderFlags.NORMAL | RenderFlags.SHADOW_MAP); //floorRuntimeState.TotalInstanceCount = viewMatrices.Length.ToUnsigned(); floorRuntimeState.CallVertexLayoutGeneration += ResourceGenerator.GenerateVertexLayoutForPNTTB; floorRuntimeState.AddVertexInstanceDelegate(InstancingDataFlags.POSITION, ResourceGenerator.GenerateVertexInstanceLayoutForPositionOffset); floorRuntimeState.AddPreEffectsVertexInstanceDelegate(RenderFlags.SHADOW_MAP, ResourceGenerator.GenerateVertexLayoutForPNTTB); //floorRuntimeState.CallVertexInstanceLayoutGeneration+=ResourceGenerator.GenerateVertexInstanceLayoutForViewMatrixOffset; //viewMatInstance floorRuntimeState.CallTextureResourceLayoutGeneration += ResourceGenerator.GenerateTextureResourceLayoutForNormalMapping; floorRuntimeState.CallTextureResourceSetGeneration += ResourceGenerator.GenerateTextureResourceSetForNormalMapping; floorRuntimeState.CallSamplerGeneration += ResourceGenerator.GenerateTriLinearSampler; _modelPNTTBDescriptorList.Add(floorRuntimeState); InstanceData[] instancingDataPN = { InstanceData.NO_DATA }; InstanceData[] instancingDataPNTTB = { instancingData }; foreach (var modelDescriptor in _modelPNDescriptorList) { FillRuntimeDescriptor(modelDescriptor, _sceneRuntimeState, instancingDataPN); PNRuntimeGeometry.AddModel(modelDescriptor); } // foreach(var modelDescriptor in _modelPTDescriptorList){ // FillRuntimeDescriptor(modelDescriptor,_sceneRuntimeState,InstancingData.NO_DATA); // } foreach (var modelDescriptor in _modelPNTTBDescriptorList) { FillRuntimeDescriptor(modelDescriptor, _sceneRuntimeState, instancingDataPNTTB); PNTTBRuntimeGeometry.AddModel(modelDescriptor); } }
public VertexPositionColorTexture(Vector3 position, RgbaFloat color, Vector2 texCoordinates) { Position = position; Color = color.ToVector4(); TexCoordinates = texCoordinates; }
internal void SetColor(RgbaFloat color) { _modelColor = color.ToVector4(); }
public Light(Camera camera, RgbaFloat color, float intensity) { LightCam = camera; _color = color.ToVector4(); _color.W = intensity; }
public Light(Camera camera, RgbaFloat color, Vector4 attenuation) { LightCam = camera; _color = color.ToVector4(); _attenuation = attenuation; }
public Light(Camera camera, RgbaFloat color) { LightCam = camera; _color = color.ToVector4(); }
override protected void CreateResources() { RgbaFloat lightColor = RgbaFloat.White; // RgbaFloat lightColor = RgbaFloat.LightGrey; //var lightPos = new Vector4(-0.5f,0.1f,10,1); var lightPos = new Vector4(0.0f, 0.0f, 0, 1); var lookAt = new Vector4(0, 0, 0, 1) - new Vector4(0, 1, 0, 1); //var lightCam = new OrthographicCamera(50.0f, 50.0f, lightPos, lookAt); //_sceneRuntimeState.Light = new Light(lightCam,lightColor,0.1f); _sceneRuntimeState.Camera = Camera; _sceneRuntimeState.SpotLight = Light.NO_POINTLIGHT; var omniCameras = CubeMap.GenerateOmniCameras(lightPos, 1024, 1024); _sceneRuntimeState.OmniLights = Light.GenerateOmniLights(omniCameras, lightColor, 0.1f); // string filePath = Path.Combine(AppContext.BaseDirectory, "armor/armor.dae"); // string filePath = Path.Combine(AppContext.BaseDirectory, "nanosuit/nanosuit.obj"); var scale = Matrix4x4.CreateScale(0.05f, 0.05f, 0.05f); //var scale = Matrix4x4.CreateScale(1.00f,1.00f,1.00f); string filePath = "models/chinesedragon.dae"; // string filePath = "Models/Box.dae"; var model = AssimpLoader.LoadFromFileWithRealtimeMaterial <VertexPositionNormal>(AppContext.BaseDirectory, filePath, VertexPositionNormal.HenzaiType); var newModelTranslation = Matrix4x4.CreateTranslation(new Vector3(0, 20, 0)); var modelRuntimeState = new ModelRuntimeDescriptor <VertexPositionNormal>(model, "PhongOmni", "PhongOmni", VertexRuntimeTypes.VertexPositionNormal, PrimitiveTopology.TriangleList, new RenderDescription(RenderFlags.NORMAL | RenderFlags.OMNI_SHADOW_MAPS), new InstancingRenderDescription(RenderFlags.NONE, InstancingDataFlags.EMPTY)); modelRuntimeState.CallVertexLayoutGeneration += ResourceGenerator.GenerateVertexLayoutForPN; model.SetNewWorldTransformation(ref newModelTranslation, true); //TODO: Write method to remove ambient terms var sponzaModels = AssimpLoader.LoadRealtimeModelsFromFile(AppContext.BaseDirectory, "sponza/sponza.obj"); var sponzaPNTTB = sponzaModels.modelPNTTB; var sponzaPC = sponzaModels.modelPC; for (int i = 0; i < sponzaPNTTB.MaterialCount; i++) { sponzaPNTTB.GetMaterial(i).ambient = new Vector4(0.3f, 0.3f, 0.3f, 1.0f); } for (int i = 0; i < sponzaPC.MaterialCount; i++) { sponzaPC.GetMaterial(i).ambient = new Vector4(0.3f, 0.3f, 0.3f, 1.0f); } sponzaPNTTB.SetNewWorldTransformation(ref scale, true); sponzaPC.SetNewWorldTransformation(ref scale, true); var sponzaRuntimeState //TOOD: Omni Fragment shader produces a runtime error = new ModelRuntimeDescriptor <VertexPositionNormalTextureTangentBitangent>(sponzaPNTTB, "PhongBitangentTextureOmni", "PhongBitangentTextureOmni", VertexRuntimeTypes.VertexPositionNormalTextureTangentBitangent, PrimitiveTopology.TriangleList, new RenderDescription(RenderFlags.NORMAL | RenderFlags.OMNI_SHADOW_MAPS), new InstancingRenderDescription(RenderFlags.NONE, InstancingDataFlags.EMPTY)); sponzaRuntimeState.CallVertexLayoutGeneration += ResourceGenerator.GenerateVertexLayoutForPNTTB; sponzaRuntimeState.CallSamplerGeneration += ResourceGenerator.GenerateTriLinearSampler; sponzaRuntimeState.CallTextureResourceLayoutGeneration += ResourceGenerator.GenerateTextureResourceLayoutForNormalMapping; sponzaRuntimeState.CallTextureResourceSetGeneration += ResourceGenerator.GenerateTextureResourceSetForNormalMapping; var sponzaRuntimeStateColorOnly = new ModelRuntimeDescriptor <VertexPositionColor>(sponzaPC, "Color", "Color", VertexRuntimeTypes.VertexPositionColor, PrimitiveTopology.TriangleList, new RenderDescription(RenderFlags.NORMAL | RenderFlags.OMNI_SHADOW_MAPS), new InstancingRenderDescription(RenderFlags.NONE, InstancingDataFlags.EMPTY)); sponzaRuntimeStateColorOnly.CallVertexLayoutGeneration += ResourceGenerator.GenerateVertexLayoutForPC; /// var floor = new Model <VertexPositionNormalTextureTangentBitangent, RealtimeMaterial>("paving/", GeometryFactory.GenerateQuadPNTTB_XY(), new RealtimeMaterial()); var floorMeshZero = floor.GetMesh(0); var flootMaterialZero = floor.GetMaterial(0); flootMaterialZero.textureDiffuse = "pavingColor.jpg"; flootMaterialZero.textureNormal = "pavingNorm.jpg"; flootMaterialZero.ambient = new Vector4(0.3f, 0.3f, 0.3f, 1.0f); var floorTranslation = Matrix4x4.CreateTranslation(-6, 0, -7); var floorScale = Matrix4x4.CreateScale(100.0f, 100.0f, 1); var newTrans = Matrix4x4.Multiply(floorScale, floorTranslation); floor.SetNewWorldTransformation(ref floorTranslation, true); var floorRuntimeState = new ModelRuntimeDescriptor <VertexPositionNormalTextureTangentBitangent>(floor, "PhongBitangentTextureOmni", "PhongBitangentTextureOmni", VertexRuntimeTypes.VertexPositionNormalTextureTangentBitangent, PrimitiveTopology.TriangleStrip, new RenderDescription(RenderFlags.NORMAL | RenderFlags.OMNI_SHADOW_MAPS), new InstancingRenderDescription(RenderFlags.NONE, InstancingDataFlags.EMPTY)); floorRuntimeState.CallVertexLayoutGeneration += ResourceGenerator.GenerateVertexLayoutForPNTTB; floorRuntimeState.CallTextureResourceLayoutGeneration += ResourceGenerator.GenerateTextureResourceLayoutForNormalMapping; floorRuntimeState.CallTextureResourceSetGeneration += ResourceGenerator.GenerateTextureResourceSetForNormalMapping; floorRuntimeState.CallSamplerGeneration += ResourceGenerator.GenerateTriLinearSampler; ///// var floor2 = new Model <VertexPositionNormalTextureTangentBitangent, RealtimeMaterial>("paving/", GeometryFactory.GenerateQuadPNTTB_XZ(), new RealtimeMaterial()); var floorMeshZero2 = floor2.GetMesh(0); var flootMaterialZero2 = floor2.GetMaterial(0); flootMaterialZero2.textureDiffuse = "pavingColor.jpg"; flootMaterialZero2.textureNormal = "pavingNorm.jpg"; flootMaterialZero2.ambient = new Vector4(0.3f, 0.3f, 0.3f, 1.0f); var floorTranslation2 = Matrix4x4.CreateTranslation(0, -5, 0); var floorScale2 = Matrix4x4.CreateScale(100.0f, 1.0f, 100.0f); var newTrans2 = Matrix4x4.Multiply(floorScale2, floorTranslation2); floor2.SetNewWorldTransformation(ref newTrans2, true); var floorRuntimeState2 = new ModelRuntimeDescriptor <VertexPositionNormalTextureTangentBitangent>(floor2, "PhongBitangentTextureOmni", "PhongBitangentTextureOmni", VertexRuntimeTypes.VertexPositionNormalTextureTangentBitangent, PrimitiveTopology.TriangleStrip, new RenderDescription(RenderFlags.NORMAL | RenderFlags.OMNI_SHADOW_MAPS), new InstancingRenderDescription(RenderFlags.NONE, InstancingDataFlags.EMPTY)); floorRuntimeState2.CallVertexLayoutGeneration += ResourceGenerator.GenerateVertexLayoutForPNTTB; floorRuntimeState2.CallTextureResourceLayoutGeneration += ResourceGenerator.GenerateTextureResourceLayoutForNormalMapping; floorRuntimeState2.CallTextureResourceSetGeneration += ResourceGenerator.GenerateTextureResourceSetForNormalMapping; floorRuntimeState2.CallSamplerGeneration += ResourceGenerator.GenerateTriLinearSampler; // var skyBox = new Model <VertexPosition, RealtimeMaterial>("cloudtop", GeometryFactory.GenerateCube(true), new RealtimeMaterial()); var skyBoxMaterial = skyBox.GetMaterial(0); skyBoxMaterial.AssignCubemapPaths("cloudtop_ft.png", "cloudtop_bk.png", "cloudtop_lf.png", "cloudtop_rt.png", "cloudtop_up.png", "cloudtop_dn.png"); _skyBoxRuntimeState = new ModelRuntimeDescriptor <VertexPosition>(skyBox, "Skybox", "Skybox", VertexRuntimeTypes.VertexPosition, PrimitiveTopology.TriangleList, new RenderDescription(RenderFlags.NORMAL), new InstancingRenderDescription(RenderFlags.NONE, InstancingDataFlags.EMPTY)); _skyBoxRuntimeState.CallVertexLayoutGeneration += ResourceGenerator.GenerateVertexLayoutForP; _skyBoxRuntimeState.CallSamplerGeneration += ResourceGenerator.GenerateBiLinearSampler; _skyBoxRuntimeState.CallTextureResourceLayoutGeneration += ResourceGenerator.GenerateTextureResourceLayoutForCubeMapping; _skyBoxRuntimeState.CallTextureResourceSetGeneration += ResourceGenerator.GenerateTextureResourceSetForCubeMapping; _sun = new Model <VertexPositionNormal, RealtimeMaterial>(string.Empty, GeometryFactory.GenerateSphereNormal(100, 100, 0.3f), new RealtimeMaterial()); _sun.GetMaterial(0).ambient = lightColor.ToVector4(); Vector3 newTranslation = new Vector3(lightPos.X, lightPos.Y, lightPos.Z); _sun.SetNewWorldTranslation(ref newTranslation, true); var sunRuntimeState = new ModelRuntimeDescriptor <VertexPositionNormal>(_sun, "PhongNoShadow", "PhongNoShadow", VertexRuntimeTypes.VertexPositionNormal, PrimitiveTopology.TriangleList, new RenderDescription(RenderFlags.NORMAL), new InstancingRenderDescription(RenderFlags.NONE, InstancingDataFlags.EMPTY)); sunRuntimeState.CallVertexLayoutGeneration += ResourceGenerator.GenerateVertexLayoutForPN; var _sun2 = new Model <VertexPositionNormal, RealtimeMaterial>(string.Empty, GeometryFactory.GenerateSphereNormal(100, 100, 0.5f), new RealtimeMaterial()); _sun2.GetMaterial(0).ambient = lightColor.ToVector4(); Vector3 newTranslation2 = new Vector3(5, -2, 1); _sun2.SetNewWorldTranslation(ref newTranslation2, true); var sunRuntimeState2 = new ModelRuntimeDescriptor <VertexPositionNormal>(_sun2, "PhongOmni", "PhongOmni", VertexRuntimeTypes.VertexPositionNormal, PrimitiveTopology.TriangleList, new RenderDescription(RenderFlags.NORMAL | RenderFlags.OMNI_SHADOW_MAPS), new InstancingRenderDescription(RenderFlags.NONE, InstancingDataFlags.EMPTY)); sunRuntimeState2.CallVertexLayoutGeneration += ResourceGenerator.GenerateVertexLayoutForPN; var _sun3 = new Model <VertexPositionNormal, RealtimeMaterial>(string.Empty, GeometryFactory.GenerateSphereNormal(100, 100, 0.5f), new RealtimeMaterial()); _sun3.GetMaterial(0).ambient = lightColor.ToVector4(); Vector3 newTranslation3 = new Vector3(-5, 0, -3.0f); _sun3.SetNewWorldTranslation(ref newTranslation3, true); var sunRuntimeState3 = new ModelRuntimeDescriptor <VertexPositionNormal>(_sun3, "PhongOmni", "PhongOmni", VertexRuntimeTypes.VertexPositionNormal, PrimitiveTopology.TriangleList, new RenderDescription(RenderFlags.NORMAL | RenderFlags.OMNI_SHADOW_MAPS), new InstancingRenderDescription(RenderFlags.NONE, InstancingDataFlags.EMPTY)); sunRuntimeState3.CallVertexLayoutGeneration += ResourceGenerator.GenerateVertexLayoutForPN; var _sun4 = new Model <VertexPositionNormal, RealtimeMaterial>(string.Empty, GeometryFactory.GenerateSphereNormal(100, 100, 0.2f), new RealtimeMaterial()); _sun4.GetMaterial(0).ambient = lightColor.ToVector4(); Vector3 newTranslation4 = new Vector3(0, -2, 0.0f); _sun4.SetNewWorldTranslation(ref newTranslation4, true); var sunRuntimeState4 = new ModelRuntimeDescriptor <VertexPositionNormal>(_sun4, "PhongOmni", "PhongOmni", VertexRuntimeTypes.VertexPositionNormal, PrimitiveTopology.TriangleList, new RenderDescription(RenderFlags.NORMAL | RenderFlags.OMNI_SHADOW_MAPS), new InstancingRenderDescription(RenderFlags.NONE, InstancingDataFlags.EMPTY)); sunRuntimeState4.CallVertexLayoutGeneration += ResourceGenerator.GenerateVertexLayoutForPN; //TODO: Automate this //_modelPNTTBDescriptorList.Add(sponzaRuntimeState); _modelPNTTBDescriptorList.Add(floorRuntimeState); //Rendering this seems to crate aretfacts on the other floor _modelPNTTBDescriptorList.Add(floorRuntimeState2); //_modelPCDescriptorList.Add(sponzaRuntimeStateColorOnly); //_modelPDescriptorList.Add(_skyBoxRuntimeState); _modelPNDescriptorList.Add(sunRuntimeState3); _modelPNDescriptorList.Add(sunRuntimeState); _modelPNDescriptorList.Add(sunRuntimeState2); _modelPNDescriptorList.Add(sunRuntimeState4); //_modelPNDescriptorList.Add(modelRuntimeState); InstanceData[] instancingData = { InstanceData.NO_DATA }; //TODO: Abstrct this foreach (var modelDescriptor in _modelPNTTBDescriptorList) { FillRuntimeDescriptor(modelDescriptor, _sceneRuntimeState, instancingData); PNTTBRuntimeGeometry.AddModel(modelDescriptor); } foreach (var modelDescriptor in _modelPNDescriptorList) { FillRuntimeDescriptor(modelDescriptor, _sceneRuntimeState, instancingData); PNRuntimeGeometry.AddModel(modelDescriptor); } foreach (var modelDescriptor in _modelPTDescriptorList) { FillRuntimeDescriptor(modelDescriptor, _sceneRuntimeState, instancingData); PTRuntimeGeometry.AddModel(modelDescriptor); } foreach (var modelDescriptor in _modelPCDescriptorList) { FillRuntimeDescriptor(modelDescriptor, _sceneRuntimeState, instancingData); PCRuntimeGeometry.AddModel(modelDescriptor); } foreach (var modelDescriptor in _modelPDescriptorList) { FillRuntimeDescriptor(modelDescriptor, _sceneRuntimeState, instancingData); PRuntimeGeometry.AddModel(modelDescriptor); } }
override protected void CreateResources() { // RgbaFloat lightColor = RgbaFloat.Orange; RgbaFloat lightColor = RgbaFloat.LightGrey; var lightPos = new Vector4(10, 20, 0, 1); var meshPos = new Vector4(0, 0, 0, 1); var lookAt = meshPos - lightPos; //TODO: Position seems to be buggy var lightCam = new OrthographicCamera(50, 50, lightPos, lookAt); _sceneRuntimeState.Light = new Light(lightCam, lightColor, 0.1f); _sceneRuntimeState.Camera = Camera; _sceneRuntimeState.SpotLight = Light.NO_POINTLIGHT; // string filePath = Path.Combine(AppContext.BaseDirectory, "armor/armor.dae"); // string filePath = Path.Combine(AppContext.BaseDirectory, "nanosuit/nanosuit.obj"); _nanosuit = AssimpLoader.LoadFromFileWithRealtimeMaterial <VertexPositionNormalTextureTangentBitangent>(AppContext.BaseDirectory, "nanosuit/nanosuit.obj", VertexPositionNormalTextureTangentBitangent.HenzaiType); // _nanosuit.SetAmbientForAllMeshes(new Vector4(0.1f,0.1f,0.1f,1.0f)); // _model = AssimpLoader.LoadFromFile<VertexPositionNormalTextureTangentBitangent>(AppContext.BaseDirectory,"sponza/sponza.obj",VertexPositionNormalTextureTangentBitangent.HenzaiType); GeometryUtils.GenerateTangentAndBitagentSpaceFor(_nanosuit); // GeometryUtils.CheckTBN(_model); // var sun = new Model<VertexPositionNormalTextureTangentBitangent>("water",GeometryFactory.generateSphereTangentBitangent(100,100,1)); _sun = new Model <VertexPositionNormal, RealtimeMaterial>(string.Empty, GeometryFactory.GenerateSphereNormal(100, 100, 1), new RealtimeMaterial()); var meshZero = _sun.GetMesh(0); var materialZero = _sun.GetMaterial(0); materialZero.textureDiffuse = "Water.jpg"; materialZero.textureNormal = "WaterNorm.jpg"; materialZero.ambient = lightColor.ToVector4(); // _sun.meshes[0].TryGetMaterial().ambient = lightColor.ToVector4(); Vector3 newTranslation = new Vector3(lightPos.X, lightPos.Y, lightPos.Z); _sun.SetNewWorldTranslation(ref newTranslation, true); var nanoSuitRuntimeState = new ModelRuntimeDescriptor <VertexPositionNormalTextureTangentBitangent>(_nanosuit, "PhongBitangentTexture", "PhongBitangentTexture", VertexRuntimeTypes.VertexPositionNormalTextureTangentBitangent, PrimitiveTopology.TriangleList, new RenderDescription(RenderFlags.NORMAL | RenderFlags.SHADOW_MAP), new InstancingRenderDescription(RenderFlags.NONE, InstancingDataFlags.EMPTY)); nanoSuitRuntimeState.CallVertexLayoutGeneration += ResourceGenerator.GenerateVertexLayoutForPNTTB; nanoSuitRuntimeState.CallSamplerGeneration += ResourceGenerator.GenerateTriLinearSampler; nanoSuitRuntimeState.CallTextureResourceLayoutGeneration += ResourceGenerator.GenerateTextureResourceLayoutForNormalMapping; nanoSuitRuntimeState.CallTextureResourceSetGeneration += ResourceGenerator.GenerateTextureResourceSetForNormalMapping; // var sunRuntimeState = new ModelRuntimeState<VertexPositionNormalTextureTangentBitangent>(sun,"PhongBitangentTexture","PhongBitangentTexture"); // sunRuntimeState.CallVertexLayoutGeneration+=ResourceGenerator.GenerateVertexLayoutForPNTTB; // sunRuntimeState.CallSamplerGeneration+=ResourceGenerator.GenerateLinearSampler; // sunRuntimeState.CallTextureResourceLayoutGeneration+=ResourceGenerator.GenerateTextureResourceLayoutForNormalMapping; // sunRuntimeState.CallTextureResourceSetGeneration+=ResourceGenerator.GenerateTextureResourceSetForNormalMapping; // _modelStatesList.Add(sunRuntimeState); var sunRuntimeState = new ModelRuntimeDescriptor <VertexPositionNormal>(_sun, "Phong", "PhongNoShadow", VertexRuntimeTypes.VertexPositionNormal, PrimitiveTopology.TriangleList, new RenderDescription(RenderFlags.NORMAL), new InstancingRenderDescription(RenderFlags.NONE, InstancingDataFlags.EMPTY)); sunRuntimeState.CallVertexLayoutGeneration += ResourceGenerator.GenerateVertexLayoutForPN; var plane = new Model <VertexPositionNormal, RealtimeMaterial>(String.Empty, GeometryFactory.GenerateQuadPN_XZ(), new RealtimeMaterial()); var newPlaneTranslation = Matrix4x4.CreateTranslation(new Vector3(0, 0, 0)); var newPlaneScale = Matrix4x4.CreateScale(new Vector3(100, 1, 100)); var trafo = newPlaneScale * newPlaneTranslation; plane.SetNewWorldTransformation(ref trafo, true); var planeRuntimeState = new ModelRuntimeDescriptor <VertexPositionNormal>(plane, "Phong", "Phong", VertexRuntimeTypes.VertexPositionNormal, PrimitiveTopology.TriangleStrip, new RenderDescription(RenderFlags.NORMAL | RenderFlags.SHADOW_MAP), new InstancingRenderDescription(RenderFlags.NONE, InstancingDataFlags.EMPTY)); planeRuntimeState.CallVertexLayoutGeneration += ResourceGenerator.GenerateVertexLayoutForPN; _modelPNTTBDescriptorList.Add(nanoSuitRuntimeState); _modelPNDescriptorList.Add(planeRuntimeState); _modelPNDescriptorList.Add(sunRuntimeState); InstanceData[] instancingData = { InstanceData.NO_DATA }; foreach (var modelDescriptor in _modelPNTTBDescriptorList) { FillRuntimeDescriptor(modelDescriptor, _sceneRuntimeState, instancingData); PNTTBRuntimeGeometry.AddModel(modelDescriptor); } foreach (var modelDescriptor in _modelPNDescriptorList) { FillRuntimeDescriptor(modelDescriptor, _sceneRuntimeState, instancingData); PNRuntimeGeometry.AddModel(modelDescriptor); } }
override protected void CreateResources() { RgbaFloat lightColor = RgbaFloat.White; // RgbaFloat lightColor = RgbaFloat.LightGrey; var lightPos = new Vector4(0, 100, 0, 1); var lookAt = new Vector4(0, 0, 0, 1) - new Vector4(0, 50, 0, 1); var lightCam = new OrthographicCamera(50.0f, 50.0f, lightPos, lookAt); _sceneRuntimeState.Light = new Light(lightCam, lightColor, 0.1f); _sceneRuntimeState.Camera = Camera; _sceneRuntimeState.SpotLight = Light.NO_POINTLIGHT; // string filePath = Path.Combine(AppContext.BaseDirectory, "armor/armor.dae"); // string filePath = Path.Combine(AppContext.BaseDirectory, "nanosuit/nanosuit.obj"); var scale = Matrix4x4.CreateScale(0.05f, 0.05f, 0.05f); //var scale = Matrix4x4.CreateScale(1.00f,1.00f,1.00f); string filePath = "models/chinesedragon.dae"; // string filePath = "Models/Box.dae"; var model = AssimpLoader.LoadFromFileWithRealtimeMaterial <VertexPositionNormal>(AppContext.BaseDirectory, filePath, VertexPositionNormal.HenzaiType); var newModelTranslation = Matrix4x4.CreateTranslation(new Vector3(0, 20, 0)); var modelRuntimeState = new ModelRuntimeDescriptor <VertexPositionNormal>(model, "Phong", "Phong", VertexRuntimeTypes.VertexPositionNormal, PrimitiveTopology.TriangleList, new RenderDescription(RenderFlags.NORMAL | RenderFlags.SHADOW_MAP), new InstancingRenderDescription(RenderFlags.NONE, InstancingDataFlags.EMPTY)); modelRuntimeState.CallVertexLayoutGeneration += ResourceGenerator.GenerateVertexLayoutForPN; model.SetNewWorldTransformation(ref newModelTranslation, true); var plane = new Model <VertexPositionNormal, RealtimeMaterial>(String.Empty, GeometryFactory.GenerateQuadPN_XZ(), new RealtimeMaterial()); var newPlaneTranslation = Matrix4x4.CreateTranslation(new Vector3(0, 10, 0)); var newPlaneScale = Matrix4x4.CreateScale(new Vector3(30, 1, 30)); var trafo = newPlaneScale * newPlaneTranslation; plane.SetNewWorldTransformation(ref trafo, true); var planeRuntimeState = new ModelRuntimeDescriptor <VertexPositionNormal>(plane, "Phong", "Phong", VertexRuntimeTypes.VertexPositionNormal, PrimitiveTopology.TriangleStrip, new RenderDescription(RenderFlags.NORMAL | RenderFlags.SHADOW_MAP), new InstancingRenderDescription(RenderFlags.NONE, InstancingDataFlags.EMPTY)); planeRuntimeState.CallVertexLayoutGeneration += ResourceGenerator.GenerateVertexLayoutForPN; //TODO: Write method to remove ambient terms var sponzaModels = AssimpLoader.LoadRealtimeModelsFromFile(AppContext.BaseDirectory, "sponza/sponza.obj"); var sponzaPNTTB = sponzaModels.modelPNTTB; var sponzaPC = sponzaModels.modelPC; for (int i = 0; i < sponzaPNTTB.MaterialCount; i++) { sponzaPNTTB.GetMaterial(i).ambient = new Vector4(0.3f, 0.3f, 0.3f, 1.0f); } for (int i = 0; i < sponzaPC.MaterialCount; i++) { sponzaPC.GetMaterial(i).ambient = new Vector4(0.3f, 0.3f, 0.3f, 1.0f); } sponzaPNTTB.SetNewWorldTransformation(ref scale, true); sponzaPC.SetNewWorldTransformation(ref scale, true); var sponzaRuntimeState = new ModelRuntimeDescriptor <VertexPositionNormalTextureTangentBitangent>(sponzaPNTTB, "PhongBitangentTexture", "PhongBitangentTexture", VertexRuntimeTypes.VertexPositionNormalTextureTangentBitangent, PrimitiveTopology.TriangleList, new RenderDescription(RenderFlags.NORMAL | RenderFlags.SHADOW_MAP), new InstancingRenderDescription(RenderFlags.NONE, InstancingDataFlags.EMPTY)); sponzaRuntimeState.CallVertexLayoutGeneration += ResourceGenerator.GenerateVertexLayoutForPNTTB; sponzaRuntimeState.CallSamplerGeneration += ResourceGenerator.GenerateTriLinearSampler; sponzaRuntimeState.CallTextureResourceLayoutGeneration += ResourceGenerator.GenerateTextureResourceLayoutForNormalMapping; sponzaRuntimeState.CallTextureResourceSetGeneration += ResourceGenerator.GenerateTextureResourceSetForNormalMapping; // var sponzaRuntimeStateTexOnly = new ModelRuntimeDescriptor<VertexPositionTexture>(sponzaPT,"Texture","Texture", VertexTypes.VertexPositionTexture,PrimitiveTopology.TriangleList); // sponzaRuntimeStateTexOnly.CallVertexLayoutGeneration+=ResourceGenerator.GenerateVertexLayoutForPT; // sponzaRuntimeStateTexOnly.CallSamplerGeneration+=ResourceGenerator.GenerateTriLinearSampler; // sponzaRuntimeStateTexOnly.CallTextureResourceLayoutGeneration+=ResourceGenerator.GenerateTextureResourceLayoutForDiffuseMapping; // sponzaRuntimeStateTexOnly.CallTextureResourceSetGeneration+=ResourceGenerator.GenerateTextureResourceSetForDiffuseMapping; var sponzaRuntimeStateColorOnly = new ModelRuntimeDescriptor <VertexPositionColor>(sponzaPC, "Color", "Color", VertexRuntimeTypes.VertexPositionColor, PrimitiveTopology.TriangleList, new RenderDescription(RenderFlags.NORMAL | RenderFlags.SHADOW_MAP), new InstancingRenderDescription(RenderFlags.NONE, InstancingDataFlags.EMPTY)); sponzaRuntimeStateColorOnly.CallVertexLayoutGeneration += ResourceGenerator.GenerateVertexLayoutForPC; // var sunRuntimeState = new ModelRuntimeState<VertexPositionNormalTextureTangentBitangent>(sun,"PhongBitangentTexture","PhongBitangentTexture"); // sunRuntimeState.CallVertexLayoutGeneration+=ResourceGenerator.GenerateVertexLayoutForPNTTB; // sunRuntimeState.CallSamplerGeneration+=ResourceGenerator.GenerateLinearSampler; // sunRuntimeState.CallTextureResourceLayoutGeneration+=ResourceGenerator.GenerateTextureResourceLayoutForNormalMapping; // sunRuntimeState.CallTextureResourceSetGeneration+=ResourceGenerator.GenerateTextureResourceSetForNormalMapping; var skyBox = new Model <VertexPosition, RealtimeMaterial>("cloudtop", GeometryFactory.GenerateCube(true), new RealtimeMaterial()); var skyBoxMaterial = skyBox.GetMaterial(0); skyBoxMaterial.AssignCubemapPaths("cloudtop_ft.png", "cloudtop_bk.png", "cloudtop_lf.png", "cloudtop_rt.png", "cloudtop_up.png", "cloudtop_dn.png"); _skyBoxRuntimeState = new ModelRuntimeDescriptor <VertexPosition>(skyBox, "Skybox", "Skybox", VertexRuntimeTypes.VertexPosition, PrimitiveTopology.TriangleList, new RenderDescription(RenderFlags.NORMAL), new InstancingRenderDescription(RenderFlags.NONE, InstancingDataFlags.EMPTY)); _skyBoxRuntimeState.CallVertexLayoutGeneration += ResourceGenerator.GenerateVertexLayoutForP; _skyBoxRuntimeState.CallSamplerGeneration += ResourceGenerator.GenerateBiLinearSampler; _skyBoxRuntimeState.CallTextureResourceLayoutGeneration += ResourceGenerator.GenerateTextureResourceLayoutForCubeMapping; _skyBoxRuntimeState.CallTextureResourceSetGeneration += ResourceGenerator.GenerateTextureResourceSetForCubeMapping; _sun = new Model <VertexPositionNormal, RealtimeMaterial>(string.Empty, GeometryFactory.GenerateSphereNormal(100, 100, 1), new RealtimeMaterial()); _sun.GetMaterial(0).ambient = lightColor.ToVector4(); // _sun.meshes[0].TryGetMaterial().ambient = lightColor.ToVector4(); Vector3 newTranslation = new Vector3(lightPos.X, lightPos.Y, lightPos.Z); _sun.SetNewWorldTranslation(ref newTranslation, true); var sunRuntimeState = new ModelRuntimeDescriptor <VertexPositionNormal>(_sun, "Phong", "PhongNoShadow", VertexRuntimeTypes.VertexPositionNormal, PrimitiveTopology.TriangleList, new RenderDescription(RenderFlags.NORMAL), new InstancingRenderDescription(RenderFlags.NONE, InstancingDataFlags.EMPTY)); sunRuntimeState.CallVertexLayoutGeneration += ResourceGenerator.GenerateVertexLayoutForPN; //TODO: Automate this _modelPNTTBDescriptorList.Add(sponzaRuntimeState); _modelPCDescriptorList.Add(sponzaRuntimeStateColorOnly); _modelPDescriptorList.Add(_skyBoxRuntimeState); // _modelPTDescriptorList.Add(sponzaRuntimeStateTexOnly); // _modelStatesList.Add(sunRuntimeState); _modelPNDescriptorList.Add(sunRuntimeState); _modelPNDescriptorList.Add(modelRuntimeState); //_modelPNDescriptorList.Add(planeRuntimeState); InstanceData[] instancingData = { InstanceData.NO_DATA }; //TODO: Abstrct this foreach (var modelDescriptor in _modelPNTTBDescriptorList) { FillRuntimeDescriptor(modelDescriptor, _sceneRuntimeState, instancingData); PNTTBRuntimeGeometry.AddModel(modelDescriptor); } foreach (var modelDescriptor in _modelPNDescriptorList) { FillRuntimeDescriptor(modelDescriptor, _sceneRuntimeState, instancingData); PNRuntimeGeometry.AddModel(modelDescriptor); } foreach (var modelDescriptor in _modelPTDescriptorList) { FillRuntimeDescriptor(modelDescriptor, _sceneRuntimeState, instancingData); PTRuntimeGeometry.AddModel(modelDescriptor); } foreach (var modelDescriptor in _modelPCDescriptorList) { FillRuntimeDescriptor(modelDescriptor, _sceneRuntimeState, instancingData); PCRuntimeGeometry.AddModel(modelDescriptor); } foreach (var modelDescriptor in _modelPDescriptorList) { FillRuntimeDescriptor(modelDescriptor, _sceneRuntimeState, instancingData); PRuntimeGeometry.AddModel(modelDescriptor); } }
public HexColor(RgbaFloat value) { Vector4 = value.ToVector4(); }