public override void Render() { // render all tri strips device.VertexFormat = CustomVertex.PositionNormal.Format; device.RenderState.Lighting = false; device.RenderState.DiffuseMaterialSource = ColorSource.Material; Material m = new Material(); m.DiffuseColor = ColorValue.FromColor(Color.SeaGreen); device.Material = m; for (int strip = 0; strip < triStrips.Length; strip++) { // fronts device.SetStreamSource(0, triStrips[strip], 0); device.DrawPrimitives(PrimitiveType.TriangleStrip, 0, triStripSizes[strip]); //device.RenderState.CullMode = Cull.CounterClockwise; // backs //device.SetStreamSource(0, triStripsMirrored[strip], 0); //device.DrawPrimitives(PrimitiveType.TriangleStrip, 0, triStripSizes[strip]); //device.RenderState.CullMode = Cull.Clockwise; } Matrix world = device.Transform.World * Matrix.Identity; foreach (NuSceneBuffer3D.NuBufferMeshItem mesh in sbLocalCopy.meshes) { device.Transform.World = Matrix.Translation(mesh.translation) * world; mesh.mesh.DrawSubset(0); } }
public override void Render() { //BackgroundColor D3DDevice.Instance.Device.Clear(ClearFlags.Target | ClearFlags.ZBuffer, Color.Black, 1.0f, 0); D3DDevice.Instance.Device.BeginScene(); ClearTextures(); //Cargar variables shader mesh.Effect.SetValue("ambientColor", ColorValue.FromColor(Color.Gray)); mesh.Effect.SetValue("diffuseColor", ColorValue.FromColor(Color.LightBlue)); mesh.Effect.SetValue("specularColor", ColorValue.FromColor(Color.White)); mesh.Effect.SetValue("specularExp", 10f); mesh.Effect.SetValue("lightPosition", lightPos); mesh.Effect.SetValue("eyePosition", TgcParserUtils.vector3ToFloat4Array(Camara.Position)); mesh.rotateY(-ElapsedTime / 2); mesh.render(); textHelp.render(); //Help if (Input.keyPressed(Key.H)) { helpForm.ShowDialog(); } PostRender(); }
protected override void InitializeSettings(ParticleSettings settings) { settings.TextureName = "explosion"; settings.MaxParticles = 100; settings.Duration = TimeSpan.FromSeconds(2); settings.DurationRandomness = 1; settings.MinHorizontalVelocity = 20; settings.MaxHorizontalVelocity = 30; settings.MinVerticalVelocity = -20; settings.MaxVerticalVelocity = 20; settings.EndVelocity = 0; settings.MinColor = ColorValue.FromColor(Color.DarkGray); settings.MaxColor = ColorValue.FromColor(Color.Gray); settings.MinRotateSpeed = -1; settings.MaxRotateSpeed = 1; settings.MinStartSize = 10; settings.MaxStartSize = 10; settings.MinEndSize = 100; settings.MaxEndSize = 200; // Use additive blending. settings.SourceBlend = Blend.SourceAlpha; settings.DestinationBlend = Blend.One; }
public void ProcesarLuces() { if (camara == null) { return; } var lightDir = new Vector3(20, 0, 0); lightDir.Normalize(); foreach (var mesh in lstMeshes) { Vector3 posicionCamara = camara.Position; Vector3 posicionLuz = new Vector3(0, 30, 0); mesh.Effect.SetValue("lightColor", ColorValue.FromColor((Color.White))); mesh.Effect.SetValue("lightPosition", TgcParserUtils.vector3ToVector4(posicionLuz)); mesh.Effect.SetValue("eyePosition", TgcParserUtils.vector3ToFloat4Array(posicionCamara)); mesh.Effect.SetValue("spotLightDir", TgcParserUtils.vector3ToFloat3Array(lightDir)); mesh.Effect.SetValue("lightIntensity", 200f); mesh.Effect.SetValue("lightAttenuation", 0.1f); mesh.Effect.SetValue("spotLightAngleCos", 55); mesh.Effect.SetValue("spotLightExponent", 7f); //Cargar variables de shader de Material. El Material en realidad deberia ser propio de cada mesh. Pero en este ejemplo se simplifica con uno comun para todos mesh.Effect.SetValue("materialEmissiveColor", ColorValue.FromColor((Color.Gray))); mesh.Effect.SetValue("materialAmbientColor", ColorValue.FromColor((Color.White))); mesh.Effect.SetValue("materialDiffuseColor", ColorValue.FromColor((Color.White))); mesh.Effect.SetValue("materialSpecularColor", ColorValue.FromColor((Color.White))); mesh.Effect.SetValue("materialSpecularExp", 1f); mesh.render(); } }
public override void Update() { lightBox.Transform = TGCMatrix.Translation(lightPositionModifier.Value); effect.SetValue("ambientColor", ColorValue.FromColor(ambientColorModifier.Value)); effect.SetValue("diffuseColor", ColorValue.FromColor(diffuseColorModifier.Value)); effect.SetValue("specularColor", ColorValue.FromColor(specularColorModifier.Value)); effect.SetValue("KAmbient", ambientModifier.Value); effect.SetValue("KDiffuse", diffuseModifier.Value); effect.SetValue("KSpecular", specularModifier.Value); effect.SetValue("shininess", specularPowerModifier.Value); effect.SetValue("lightPosition", TGCVector3.TGCVector3ToFloat3Array(lightPositionModifier.Value)); effect.SetValue("eyePosition", TGCVector3.TGCVector3ToFloat3Array(Camera.Position)); if (!toggleBlinn.Value.Equals(previousValue)) { if (toggleBlinn.Value) { planes[0].Technique = "Blinn"; } else { planes[0].Technique = "Phong"; } previousValue = toggleBlinn.Value; } }
public void setShadersValues() { Vector3 lightPosition = new Vector3(-100, 140, 3000);// (Vector3)GuiController.Instance.Modifiers["LightPosition"]; efectoOlas.SetValue("llueve", (Boolean)GuiController.Instance.Modifiers["lluvia"]); efectoOlas.SetValue("time", (float)GuiController.Instance.UserVars.getValue("time")); efectoOlas.SetValue("fvLightPosition", TgcParserUtils.vector3ToFloat3Array(lightPosition)); efectoOlas.SetValue("k_la", (float)GuiController.Instance.Modifiers["Ambient"]); efectoOlas.SetValue("fSpecularPower", 20.0f);//(float)GuiController.Instance.Modifiers["SpecularPower"]); efectoOlas.SetValue("blendAmount", (float)GuiController.Instance.Modifiers["blending"]); efectoOlas.SetValue("fvEyePosition", TgcParserUtils.vector3ToFloat3Array(GuiController.Instance.CurrentCamera.getPosition())); efectoOlas.SetValue("fogColor", ColorValue.FromColor((Color)GuiController.Instance.Modifiers["fog color"])); efectoOlas.SetValue("fogStart", (float)GuiController.Instance.Modifiers["fog start"]); efectoOlas.SetValue("blendStart", (float)GuiController.Instance.Modifiers["blend start"]); efectoOlas.SetValue("camara3p", (Boolean)GuiController.Instance.Modifiers["camaraEnBarco"]); efectoOlas.SetValue("rayo", rayo); efectoOlas.SetValue("delta", 150.0f);//(float)GuiController.Instance.Modifiers["delta"]); efectoOlas.SetValue("reflection", (float)GuiController.Instance.Modifiers["reflection"]); //CubeMap efectoOlas.SetValue("texCubeMap", cubeMap); efectoCascada.SetValue("time", (float)GuiController.Instance.UserVars.getValue("time")); efectoCascada.SetValue("fvEyePosition", TgcParserUtils.vector3ToFloat3Array(GuiController.Instance.CurrentCamera.getPosition())); efectoCascada.SetValue("fvLightPosition", TgcParserUtils.vector3ToFloat3Array(lightPosition)); efectoCascada.SetValue("camara3p", (Boolean)GuiController.Instance.Modifiers["camaraEnBarco"]); efectoCascada.SetValue("texCubeMap", cubeMap); efectoCascada.SetValue("reflection", (float)GuiController.Instance.Modifiers["reflection"]); efectoCascada.SetValue("blendAmount", (float)GuiController.Instance.Modifiers["blending"]); efectoCascada.SetValue("k_la", (float)GuiController.Instance.Modifiers["Ambient"]); }
private void SetValuesToMesh() { Vector3 eyePosition = GuiController.Instance.FpsCamera.getPosition(); //Cargar variables shader de la luz try { meshDeAuto.Effect.SetValue("lightColor", ColorValue.FromColor(Color.White)); meshDeAuto.Effect.SetValue("lightPosition", TgcParserUtils.vector3ToFloat4Array(new Vector3(-10000, 700, 11880))); meshDeAuto.Effect.SetValue("eyePosition", TgcParserUtils.vector3ToFloat4Array(eyePosition)); meshDeAuto.Effect.SetValue("lightIntensity", (float)4500); meshDeAuto.Effect.SetValue("lightAttenuation", (float)0.9f); meshDeAuto.Effect.SetValue("bumpiness", (float)1f); meshDeAuto.Effect.SetValue("materialSpecularExp", 9f); meshDeAuto.Effect.SetValue("materialEmissiveColor", ColorValue.FromColor(Color.Gray)); meshDeAuto.Effect.SetValue("materialAmbientColor", ColorValue.FromColor(Color.White)); meshDeAuto.Effect.SetValue("materialDiffuseColor", ColorValue.FromColor(Color.White)); meshDeAuto.Effect.SetValue("materialSpecularColor", ColorValue.FromColor(Color.White)); } catch (Exception e) { //No tiro ninguna excepciĆ³n especĆfica } }
public void render() { Device d3dDevice = GuiController.Instance.D3dDevice; Effect effect = GuiController.Instance.Shaders.TgcMeshPhongShader; effect.Technique = "DIFFUSE_MAP"; GuiController.Instance.Shaders.setShaderMatrix(effect, transform); //Cargar variables shader effect.SetValue("ambientColor", ColorValue.FromColor(Color.Gray)); effect.SetValue("diffuseColor", ColorValue.FromColor(Color.LightBlue)); effect.SetValue("specularColor", ColorValue.FromColor(Color.White)); effect.SetValue("specularExp", 10f); //Iniciar Shader e iterar sobre sus Render Passes int numPasses = effect.Begin(0); for (int n = 0; n < numPasses; n++) { //Dibujar cada subset con su DiffuseMap correspondiente for (int i = 0; i < meshMaterials.Length; i++) { //Setear textura en shader effect.SetValue("texDiffuseMap", meshTextures[i]); //Iniciar pasada de shader effect.BeginPass(n); mesh.DrawSubset(i); effect.EndPass(); } } //Finalizar shader effect.End(); }
public Sol() { colorDeLuz = ColorValue.FromColor(Color.LightYellow); intensidadDeLuzSol = 1000f; atenuacionDeLuz = 0.1f; alturaPuestaSol = 0; }
protected override void InitializeSettings(ParticleSettings settings) { settings.TextureName = "smoke"; settings.MaxParticles = 200; settings.Duration = TimeSpan.FromSeconds(4); settings.MinHorizontalVelocity = 0; settings.MaxHorizontalVelocity = 50; settings.MinVerticalVelocity = -10; settings.MaxVerticalVelocity = 50; settings.Gravity = new Vector3(0, -20, 0); settings.EndVelocity = 0; settings.MinColor = ColorValue.FromColor(Color.LightGray); settings.MaxColor = ColorValue.FromColor(Color.White); settings.MinRotateSpeed = -2; settings.MaxRotateSpeed = 2; settings.MinStartSize = 10; settings.MaxStartSize = 10; settings.MinEndSize = 100; settings.MaxEndSize = 200; }
public override int BeginApply() { //update texture transforms (animations) base.BeginApply(); if (technique == null) { return(1); } else { effect.SetValue(cameraHandle, new Vector4(MdxRender.Camera.Position.X, MdxRender.Camera.Position.Y, MdxRender.Camera.Position.Z, 1.0f)); effect.SetValue(worldHandle, MdxRender.Device.Transform.World); effect.SetValue(wvpHandle, MdxRender.Device.Transform.World * MdxRender.Device.Transform.View * MdxRender.Device.Transform.Projection); effect.SetValue(illuminationValueHandle, Animate(shaderModelValues.AnimationFunction.Value, shaderModelValues.AnimationPeriod.Value, 0.0f)); effect.SetValue(fogStartHandle, MdxRender.Device.RenderState.FogStart); effect.SetValue(fogEndHandle, MdxRender.Device.RenderState.FogEnd); effect.SetValue(fogDensityHandle, MdxRender.Device.RenderState.FogDensity); effect.SetValue(ambientColorHandle, ColorValue.FromColor(MdxRender.Device.Material.Diffuse)); if (lightmap == null) { effect.SetValue(lightmapHandle, default2d[Multiplicative]); } else { effect.SetValue(lightmapHandle, lightmap); } effect.CommitChanges(); return(effect.Begin(FX.DoNotSaveState)); } }
public override void Render() { //BackgroundColor D3DDevice.Instance.Device.Clear(ClearFlags.Target | ClearFlags.ZBuffer, Color.Black, 1.0f, 0); BeginScene(); ClearTextures(); //Cargar variables shader mesh.Effect.SetValue("ambientColor", ColorValue.FromColor(Color.Gray)); mesh.Effect.SetValue("diffuseColor", ColorValue.FromColor(Color.LightBlue)); mesh.Effect.SetValue("specularColor", ColorValue.FromColor(Color.White)); mesh.Effect.SetValue("specularExp", 10f); mesh.Effect.SetValue("lightPosition", lightPos); mesh.Effect.SetValue("eyePosition", TGCVector3.Vector3ToFloat4Array(Camara.Position)); mesh.RotateY(-ElapsedTime / 2); mesh.Transform = TGCMatrix.Scaling(mesh.Scale) * TGCMatrix.RotationYawPitchRoll(mesh.Rotation.Y, mesh.Rotation.X, mesh.Rotation.Z) * TGCMatrix.Translation(mesh.Position); mesh.Render(); textHelp.render(); //Help if (Input.keyPressed(Key.H)) { helpForm.ShowDialog(); } PostRender(); }
public void updatearMiPropiaLuz(Escenario escenario, Personaje personaje) { Microsoft.DirectX.Direct3D.Effect currentShader; currentShader = TGCShaders.Instance.TgcMeshPointLightShader; TGCVector3 radioDeLuz = new TGCVector3(50, 0, 50); radioDeLuz += unEscondite.BoundingBox.PMin; var listMeshesCercanos = escenario.tgcScene.Meshes.FindAll(unMesh => unMesh.BoundingBox.PMin.X < radioDeLuz.X && unMesh.BoundingBox.PMin.Z < radioDeLuz.Z); foreach (TgcMesh mesh in listMeshesCercanos) { mesh.Effect = currentShader; mesh.Technique = TGCShaders.Instance.GetTGCMeshTechnique(mesh.RenderType); // Estos son paramentros del current shader, si cambias el shader chequear los parametros o rompe mesh.Effect.SetValue("materialEmissiveColor", ColorValue.FromColor(Color.Black)); mesh.Effect.SetValue("materialAmbientColor", ColorValue.FromColor(Color.White)); mesh.Effect.SetValue("materialDiffuseColor", ColorValue.FromColor(Color.White)); mesh.Effect.SetValue("materialSpecularColor", ColorValue.FromColor(Color.White)); mesh.Effect.SetValue("materialSpecularExp", 9f); mesh.Effect.SetValue("eyePosition", TGCVector3.Vector3ToFloat4Array(personaje.eye)); mesh.Effect.SetValue("lightAttenuation", 0.3f); mesh.Effect.SetValue("lightColor", ColorValue.FromColor(Color.Blue)); mesh.Effect.SetValue("lightIntensity", 50f); mesh.Effect.SetValue("lightPosition", TGCVector3.Vector3ToFloat4Array(radioDeLuz)); } }
protected override void InitializeSettings(ParticleSettings settings) { settings.TextureName = "smoke"; settings.MaxParticles = 1000; settings.Duration = TimeSpan.FromSeconds(3); settings.DurationRandomness = 1.5f; settings.EmitterVelocitySensitivity = 0.1f; settings.MinHorizontalVelocity = 0; settings.MaxHorizontalVelocity = 1; settings.MinVerticalVelocity = -1; settings.MaxVerticalVelocity = 1; settings.MinColor = ColorValue.FromColor(Color.FromArgb(255, 64, 96, 128)); settings.MaxColor = ColorValue.FromColor(Color.FromArgb(128, 255, 255, 255)); settings.MinRotateSpeed = -4; settings.MaxRotateSpeed = 4; settings.MinStartSize = 2; settings.MaxStartSize = 4; settings.MinEndSize = 5; settings.MaxEndSize = 15; }
/// <summary> /// Initializes a Material structure, setting the diffuse and ambient /// colors. It does not set emissive or specular colors. /// </summary> /// <param name="c">The ambient and diffuse color</param> /// <returns>A defined material</returns> public static Direct3D.Material InitMaterial(System.Drawing.Color c) { Material mtrl = new Material(); mtrl.AmbientColor = mtrl.DiffuseColor = ColorValue.FromColor(c); return(mtrl); }
public void setValues(TgcMesh mesh, Vector3 posicionCamara) { Effect currentShader; currentShader = TgcShaders.Instance.TgcMeshSpotLightShader; mesh.Effect = currentShader; var direccionLuz = lightDir; mesh.Technique = "DIFFUSE_MAP";//TgcShaders.Instance.getTgcMeshTechnique(mesh.RenderType); mesh.Effect = TgcShaders.Instance.TgcMeshSpotLightShader; //El Technique depende del tipo RenderType del mesh mesh.Technique = TgcShaders.Instance.getTgcMeshTechnique(mesh.RenderType); mesh.Effect.SetValue("lightColor", ColorValue.FromColor(Color.Violet)); mesh.Effect.SetValue("lightPosition", TgcParserUtils.vector3ToFloat4Array(lightPos)); mesh.Effect.SetValue("eyePosition", TgcParserUtils.vector3ToFloat4Array(posicionCamara)); mesh.Effect.SetValue("spotLightDir", TgcParserUtils.vector3ToFloat3Array(direccionLuz)); mesh.Effect.SetValue("lightIntensity", lightIntensity); mesh.Effect.SetValue("lightAttenuation", 0.3f); mesh.Effect.SetValue("spotLightAngleCos", FastMath.ToRad(45f)); mesh.Effect.SetValue("spotLightExponent", 20f); mesh.Effect.SetValue("materialEmissiveColor", ColorValue.FromColor(Color.Gray)); mesh.Effect.SetValue("materialAmbientColor", ColorValue.FromColor(Color.White)); mesh.Effect.SetValue("materialDiffuseColor", ColorValue.FromColor(Color.White)); mesh.Effect.SetValue("materialSpecularColor", ColorValue.FromColor(Color.White)); mesh.Effect.SetValue("materialSpecularExp", 10f); }
public override void render(float elapsedTime) { Device device = GuiController.Instance.D3dDevice; Vector3 lightPosition = (Vector3)GuiController.Instance.Modifiers["LightPosition"]; //Cargar variables de shader globales a todos los objetos mesh.Effect.SetValue("fvLightPosition", TgcParserUtils.vector3ToFloat3Array(lightPosition)); mesh.Effect.SetValue("fvEyePosition", TgcParserUtils.vector3ToFloat3Array(GuiController.Instance.RotCamera.getPosition())); mesh.Effect.SetValue("fvAmbient", ColorValue.FromColor((Color)GuiController.Instance.Modifiers["AmbientColor"])); mesh.Effect.SetValue("fvDiffuse", ColorValue.FromColor((Color)GuiController.Instance.Modifiers["DiffuseColor"])); mesh.Effect.SetValue("fvSpecular", ColorValue.FromColor((Color)GuiController.Instance.Modifiers["SpecularColor"])); mesh.Effect.SetValue("fSpecularPower", (float)GuiController.Instance.Modifiers["SpecularPower"]); //Mover mesh que representa la luz lightBox.Position = lightPosition; //Mover mesh Vector3 meshPos = (Vector3)GuiController.Instance.Modifiers["MeshPos"]; mesh.Position = meshPos; mesh.render(); lightBox.render(); }
public override void Render(float elapsedTime) { if (muzzle.TIME_RENDER > 0) { muzzle.renderFlash(); mesh.Effect = currentShader; //El Technique depende del tipo RenderType del mesh mesh.Technique = GuiController.Instance.Shaders.getTgcMeshTechnique(mesh.RenderType); mesh.Effect.SetValue("lightColor", ColorValue.FromColor(Color.White)); mesh.Effect.SetValue("lightPosition", TgcParserUtils.vector3ToFloat4Array(muzzle.getPosicion())); mesh.Effect.SetValue("eyePosition", TgcParserUtils.vector3ToFloat4Array(CustomFpsCamera.Instance.getPosition())); mesh.Effect.SetValue("lightIntensity", 2000); mesh.Effect.SetValue("lightAttenuation", 0.3f); //Cargar variables de shader de Material. El Material en realidad deberia ser propio de cada mesh. Pero en este ejemplo se simplifica con uno comun para todos mesh.Effect.SetValue("materialEmissiveColor", ColorValue.FromColor(Color.Black)); mesh.Effect.SetValue("materialAmbientColor", ColorValue.FromColor(Color.White)); mesh.Effect.SetValue("materialDiffuseColor", ColorValue.FromColor(Color.White)); mesh.Effect.SetValue("materialSpecularColor", ColorValue.FromColor(Color.Khaki)); mesh.Effect.SetValue("materialSpecularExp", 9); } mesh.render(); mesh.Effect = GuiController.Instance.Shaders.TgcMeshShader; }
protected override void InitializeSettings(ParticleSettings settings) { settings.TextureName = "fire"; settings.MaxParticles = 2400; settings.Duration = TimeSpan.FromSeconds(1.8); //1.8 settings.DurationRandomness = 1f; settings.MinHorizontalVelocity = 0; settings.MaxHorizontalVelocity = 1.0f; settings.MinVerticalVelocity = -2; settings.MaxVerticalVelocity = 2; // Set gravity upside down, so the flames will 'fall' upward. settings.Gravity = new Vector3(0, 6.5f, 0); settings.MinColor = ColorValue.FromColor(Color.FromArgb(10, 255, 255, 255)); settings.MaxColor = ColorValue.FromColor(Color.FromArgb(40, 255, 255, 255)); settings.MinStartSize = 1f; settings.MaxStartSize = 2f; settings.MinEndSize = 2; settings.MaxEndSize = 8; // Use additive blending. settings.SourceBlend = Blend.SourceAlpha; settings.DestinationBlend = Blend.One; }
public override void SetupDx(Microsoft.DirectX.Direct3D.Light light) { light.DiffuseColor = ColorValue.FromColor(clr); light.Direction = direction; light.Type = LightType.Directional; light.Enabled = true; //light.Update(); }
public override void render(float elapsedTime) { Device device = GuiController.Instance.D3dDevice; //Actualzar posiciĆ³n de la luz Vector3 lightPos = (Vector3)GuiController.Instance.Modifiers["lightPos"]; lightMesh.Position = lightPos; Vector3 eyePosition = GuiController.Instance.FpsCamera.getPosition(); //Renderizar meshes foreach (TgcMeshBumpMapping mesh in meshes) { //Cargar variables shader de la luz mesh.Effect.SetValue("lightColor", ColorValue.FromColor((Color)GuiController.Instance.Modifiers["lightColor"])); mesh.Effect.SetValue("lightPosition", TgcParserUtils.vector3ToFloat4Array(lightPos)); mesh.Effect.SetValue("eyePosition", TgcParserUtils.vector3ToFloat4Array(eyePosition)); mesh.Effect.SetValue("lightIntensity", (float)GuiController.Instance.Modifiers["lightIntensity"]); mesh.Effect.SetValue("lightAttenuation", (float)GuiController.Instance.Modifiers["lightAttenuation"]); mesh.Effect.SetValue("bumpiness", (float)GuiController.Instance.Modifiers["bumpiness"]); //Material mesh.Effect.SetValue("materialEmissiveColor", ColorValue.FromColor((Color)GuiController.Instance.Modifiers["mEmissive"])); mesh.Effect.SetValue("materialAmbientColor", ColorValue.FromColor((Color)GuiController.Instance.Modifiers["mAmbient"])); mesh.Effect.SetValue("materialDiffuseColor", ColorValue.FromColor((Color)GuiController.Instance.Modifiers["mDiffuse"])); mesh.Effect.SetValue("materialSpecularColor", ColorValue.FromColor((Color)GuiController.Instance.Modifiers["mSpecular"])); mesh.Effect.SetValue("materialSpecularExp", (float)GuiController.Instance.Modifiers["specularEx"]); //Renderizar modelo mesh.render(); } //Renderizar mesh de luz lightMesh.render(); //Dibujar flechas de debug bool showNormals = (bool)GuiController.Instance.Modifiers["showNormals"]; bool showTangents = (bool)GuiController.Instance.Modifiers["showTangents"]; bool showBinormals = (bool)GuiController.Instance.Modifiers["showBinormals"]; for (int i = 0; i < normals.Count; i++) { if (showNormals) { normals[i].render(); } if (showTangents) { tangents[i].render(); } if (showBinormals) { binormals[i].render(); } } }
public void SetColor(Dx3D.Effect shader, Color color) { if (shader == _LightShader) { shader.SetValue("materialAmbientColor", ColorValue.FromColor(color)); shader.SetValue("materialDiffuseColor", ColorValue.FromColor(color)); shader.SetValue("materialSpecularColor", ColorValue.FromColor(color)); } }
private void SetUpLighting() { var effect = TgcShaders.Instance.TgcMeshPointLightShader; effect.SetValue("ambientColor", ColorValue.FromColor(Color.FromArgb(255, 85, 85, 85))); effect.SetValue("diffuseColor", ColorValue.FromColor(Color.WhiteSmoke)); effect.SetValue("specularColor", ColorValue.FromColor(Color.FromArgb(255, 255, 255, 255))); effect.SetValue("specularExp", 200f); }
public override void render(float elapsedTime) { Device device = GuiController.Instance.D3dDevice; //Habilitar luz bool lightEnable = (bool)GuiController.Instance.Modifiers["lightEnable"]; Effect currentShader; if (lightEnable) { //Con luz: Cambiar el shader actual por el shader default que trae el framework para iluminacion dinamica con PointLight para Skeletal Mesh currentShader = GuiController.Instance.Shaders.TgcSkeletalMeshPointLightShader; } else { //Sin luz: Restaurar shader default currentShader = GuiController.Instance.Shaders.TgcSkeletalMeshShader; } //Aplicar al mesh el shader actual mesh.Effect = currentShader; //El Technique depende del tipo RenderType del mesh mesh.Technique = GuiController.Instance.Shaders.getTgcSkeletalMeshTechnique(mesh.RenderType); //Actualzar posiciĆ³n de la luz Vector3 lightPos = (Vector3)GuiController.Instance.Modifiers["lightPos"]; lightMesh.Position = lightPos; //Renderizar mesh if (lightEnable) { //Cargar variables shader de la luz mesh.Effect.SetValue("lightColor", ColorValue.FromColor((Color)GuiController.Instance.Modifiers["lightColor"])); mesh.Effect.SetValue("lightPosition", TgcParserUtils.vector3ToFloat4Array(lightPos)); mesh.Effect.SetValue("eyePosition", TgcParserUtils.vector3ToFloat4Array(GuiController.Instance.FpsCamera.getPosition())); mesh.Effect.SetValue("lightIntensity", (float)GuiController.Instance.Modifiers["lightIntensity"]); mesh.Effect.SetValue("lightAttenuation", (float)GuiController.Instance.Modifiers["lightAttenuation"]); //Cargar variables de shader de Material. El Material en realidad deberia ser propio de cada mesh. Pero en este ejemplo se simplifica con uno comun para todos mesh.Effect.SetValue("materialEmissiveColor", ColorValue.FromColor((Color)GuiController.Instance.Modifiers["mEmissive"])); mesh.Effect.SetValue("materialAmbientColor", ColorValue.FromColor((Color)GuiController.Instance.Modifiers["mAmbient"])); mesh.Effect.SetValue("materialDiffuseColor", ColorValue.FromColor((Color)GuiController.Instance.Modifiers["mDiffuse"])); mesh.Effect.SetValue("materialSpecularColor", ColorValue.FromColor((Color)GuiController.Instance.Modifiers["mSpecular"])); mesh.Effect.SetValue("materialSpecularExp", (float)GuiController.Instance.Modifiers["specularEx"]); } mesh.animateAndRender(); //Renderizar mesh de luz lightMesh.render(); }
public void Render(Device device) { if (Geometry.Clr != -1) { device.RenderState.Lighting = true; Microsoft.DirectX.Direct3D.Material mt = new Microsoft.DirectX.Direct3D.Material(); mt.AmbientColor = ColorValue.FromArgb(Geometry.Clr); mt.DiffuseColor = ColorValue.FromArgb(Geometry.Clr); device.RenderState.DiffuseMaterialSource = ColorSource.Material; device.Material = mt; device.RenderState.AmbientColor = Geometry.Clr; } device.VertexFormat = vFormat; device.SetStreamSource(0, vBuffer, 0); if (matIBuffers != null) { for (int mat = 0; mat < MaterialIndices.Length; mat++) { Microsoft.DirectX.Direct3D.Material oMat = device.Material; if (MaterialIndices[mat].Material.Texture == null) { Microsoft.DirectX.Direct3D.Material material = new Microsoft.DirectX.Direct3D.Material(); material.AmbientColor = ColorValue.FromColor(System.Drawing.Color.FromArgb(MaterialIndices[mat].Material.Ambient.A, MaterialIndices[mat].Material.Ambient.R, MaterialIndices[mat].Material.Ambient.G, MaterialIndices[mat].Material.Ambient.B)); material.DiffuseColor = ColorValue.FromColor(System.Drawing.Color.FromArgb(MaterialIndices[mat].Material.Diffuse.A, MaterialIndices[mat].Material.Diffuse.R, MaterialIndices[mat].Material.Diffuse.G, MaterialIndices[mat].Material.Diffuse.B)); device.Material = material; } else { device.SetTexture(0, MaterialIndices[mat].Material.Texture); } device.Indices = matIBuffers[mat]; device.DrawIndexedPrimitives(Geometry.PrimType, 0, 0, Geometry.Vertices.Length, 0, MaterialIndices[mat].PrimCount); device.Material = oMat; } } else if (iBuffer != null) { device.Indices = iBuffer; device.DrawIndexedPrimitives(Geometry.PrimType, 0, 0, Geometry.Vertices.Length, 0, numPrimitives); } else { device.Indices = null; device.DrawPrimitives(Geometry.PrimType, 0, numPrimitives); } }
/// <summary> /// Gets a dynamic color defined by a function in the dynamic object contained by this instance. /// </summary> /// <param name="source">color source to retrieve from</param> public ColorValue GetDynamicColor(int source) { if (source < 0) { return(ColorValue.FromColor(Color.White)); } else { return(colorProvider.GetCurrentColor(source)); } }
private void updateShaders() { Device device = GuiController.Instance.D3dDevice; //Cargar variables Phong shader plane.Effect.SetValue("lightPosition", TgcParserUtils.vector3ToFloat4Array((Vector3)GuiController.Instance.Modifiers["lightPos"])); plane.Effect.SetValue("eyePosition", TgcParserUtils.vector3ToFloat4Array(GuiController.Instance.CurrentCamera.getPosition())); plane.Effect.SetValue("ambientColor", ColorValue.FromColor(Color.White)); plane.Effect.SetValue("diffuseColor", ColorValue.FromColor(Color.Wheat)); plane.Effect.SetValue("specularColor", ColorValue.FromColor(Color.White)); plane.Effect.SetValue("specularExp", specularEx); //variables Fuego // dibujo la escena una textura // guardo el Render target anterior y seteo la textura como render target Surface pOldRT = device.GetRenderTarget(0); Surface pSurf = g_pRenderTargetFuego.GetSurfaceLevel(0); device.SetRenderTarget(0, pSurf); // hago lo mismo con el depthbuffer, necesito el que no tiene multisampling Surface pOldDS = device.DepthStencilSurface; device.DepthStencilSurface = g_pDepthStencil; device.Clear(ClearFlags.Target | ClearFlags.ZBuffer, Color.Black, 1.0f, 0); device.BeginScene(); efFuego.Technique = "Fire"; efFuego.SetValue("fire_base_Tex", fuegoBase.D3dTexture); efFuego.SetValue("fire_distortion_Tex", fuegoDistorsion.D3dTexture); efFuego.SetValue("fire_opacity_Tex", fuegoOpacidad.D3dTexture); efFuego.SetValue("time", totalTime); device.VertexFormat = vertexFuego.Format; device.SetStreamSource(0, g_pVBV3D, 0); efFuego.Begin(FX.None); efFuego.BeginPass(0); device.DrawPrimitives(PrimitiveType.TriangleStrip, 0, 2); efFuego.EndPass(); efFuego.End(); device.EndScene(); pSurf.Dispose(); // restuaro el render target y el stencil device.DepthStencilSurface = pOldDS; device.SetRenderTarget(0, pOldRT); exhaust.DiffuseMaps[0] = new TgcTexture("", "", g_pRenderTargetFuego, false); }
private void updateLighting() { Microsoft.DirectX.Direct3D.Effect currentShader; TgcMesh unPoste; //Con luz: Cambiar el shader actual por el shader default que trae el framework para iluminacion dinamica con PointLight if (personaje.tieneLuz) { currentShader = TGCShaders.Instance.TgcMeshSpotLightShader; } else { currentShader = TGCShaders.Instance.TgcMeshPointLightShader; } //Aplicar a cada mesh el shader actual foreach (TgcMesh mesh in escenario.tgcScene.Meshes) { mesh.Effect = currentShader; mesh.Technique = TGCShaders.Instance.GetTGCMeshTechnique(mesh.RenderType); // Estos son paramentros del current shader, si cambias el shader chequear los parametros o rompe mesh.Effect.SetValue("materialEmissiveColor", ColorValue.FromColor(Color.Black)); mesh.Effect.SetValue("materialAmbientColor", ColorValue.FromColor(Color.White)); mesh.Effect.SetValue("materialDiffuseColor", ColorValue.FromColor(Color.White)); mesh.Effect.SetValue("materialSpecularColor", ColorValue.FromColor(Color.White)); mesh.Effect.SetValue("materialSpecularExp", 9f); mesh.Effect.SetValue("eyePosition", TGCVector3.Vector3ToFloat4Array(personaje.eye)); mesh.Effect.SetValue("lightAttenuation", personaje.itemEnMano.getValorAtenuacion()); mesh.Effect.SetValue("lightColor", ColorValue.FromColor(Color.White)); unPoste = escenario.listaDePostes.OrderBy(poste => this.DistanciaA2(poste)).First(); if (DistanciaA2(unPoste) < 2000) { //Se prende el farol mas cercano mesh.Effect.SetValue("lightColor", ColorValue.FromColor(Color.White)); mesh.Effect.SetValue("lightIntensity", 50f); mesh.Effect.SetValue("lightPosition", TGCVector3.Vector3ToFloat4Array(unPoste.BoundingBox.PMin)); } else { if (personaje.tieneLuz) { this.AplicarShaderSpotLight(mesh); } else { mesh.Effect.SetValue("lightIntensity", 50f); mesh.Effect.SetValue("lightPosition", TGCVector3.Vector3ToFloat4Array(personaje.getPosition())); } } } }
private void _LoadShaders() { //Cargar variables shader de la luz _LightShader.SetValue("lightColor", ColorValue.FromColor(Color.White)); _LightShader.SetValue("eyePosition", TgcParserUtils.vector3ToFloat4Array(GuiController.Instance.ThirdPersonCamera.getPosition())); _LightShader.SetValue("lightAttenuation", 1); //Cargar variables de shader de Material. El Material en realidad deberia ser propio de cada mesh. Pero en este ejemplo se simplifica con uno comun para todos _LightShader.SetValue("materialEmissiveColor", ColorValue.FromColor(Color.Black)); _LightShader.SetValue("materialAmbientColor", ColorValue.FromColor(Color.White)); _LightShader.SetValue("materialDiffuseColor", ColorValue.FromColor(Color.White)); _LightShader.SetValue("materialSpecularColor", ColorValue.FromColor(Color.White)); _LightShader.SetValue("materialSpecularExp", 10f); }
public void Render() { shader.SetValue("materialEmissiveColor", ColorValue.FromColor(Color.FromArgb(0, candlesPlaced < 6?0:(candlesPlaced - 6), 0, 0))); shader.SetValue("eyePosition", TGCVector3.Vector3ToFloat4Array(g.camera.eyePosition)); shader.SetValue("lightIntensityEye", 50f + (g.hands.state > 0? (g.hands.state == 1? 250f + Random.Next(-50, 50) : 250f + Random.Next(-50, 50) + 250f + Random.Next(-50, 50)) :0)); for (int i = 0; i < lightCount; i++) { //lightPos del frame anterior shader.SetValue("lightPosition[" + i.ToString() + "]", TGCVector3.Vector3ToFloat4Array(lightPosition[i])); shader.SetValue("lightIntensity[" + i.ToString() + "]", 250f + Random.Next(-50, 50)); //de paso limpio la lightpos para cargar las de este frame lightPosition[i] = TGCVector3.One * float.MaxValue; } lightIndex = 0; sky.Render(); if (renderCandlePlace) { renderCandles(); } g.chunks.render(); if (GameModel.debugColission) { g.chunks.fromCoordinates(g.camera.eyePosition).renderDebugColission(); TGCVector3 ray = g.camera.horx.Origin + TGCVector3.Down * 200f; TGCVector3 end = ray + g.camera.horx.Direction * 200f; TgcLine.fromExtremes(ray, end).Render(); ray = g.camera.horz.Origin + TGCVector3.Down * 200f; end = ray + g.camera.horz.Direction * 200f; TgcLine.fromExtremes(ray, end).Render(); } g.terrain.Render(); deforming += g.game.ElapsedTime * 0.1f; //Console.WriteLine(deforming); }