private static List <LightBase> GetSpotLights() { var list = new List <LightBase>(); double radian = 120.0 / 180.0 * Math.PI / 2.0; { var light = new CSharpGL.SpotLight(new vec3(3, 3, 3), new vec3(), (float)Math.Cos(radian), new Attenuation(1, 0, 0)); light.Diffuse = new vec3(1, 1, 1); light.Specular = new vec3(1, 1, 1); list.Add(light); } //{ // var light = new CSharpGL.SpotLight(new vec3(3, 3, 3), new vec3(), (float)Math.Cos(radian), new Attenuation(2, 0, 0)); // light.Diffuse = new vec3(0, 1, 0); // light.Specular = new vec3(0, 1, 0); // list.Add(light); //} //{ // var light = new CSharpGL.SpotLight(new vec3(3, 3, 3), new vec3(), (float)Math.Cos(radian), new Attenuation(2, 0, 0)); // light.Diffuse = new vec3(0, 0, 1); // light.Specular = new vec3(0, 0, 1); // list.Add(light); //} return(list); }
private static mat4 GetProjectionMatrix(this SpotLight light) { var angle = Math.Acos(light.CutOff) * 2; // in radians const float aspectRatio = 1.0f; // TODO: how to get a precise projection? mat4 projection = glm.perspective((float)angle, aspectRatio, 0.1f, 50); return(projection); }
private static mat4 GetViewMatrix(this SpotLight light) { vec3 up = new vec3(0, 1, 0); //if(light.Direction.dot(up) < 0.01f) { //up = } mat4 view = glm.lookAt(light.Position, light.Target, up); return(view); }
private static void SetUniforms(this SpotLight light, ShaderProgram program) { program.SetUniform("light.position", light.Position); program.SetUniform("light.diffuse", light.Diffuse); program.SetUniform("light.specular", light.Specular); program.SetUniform("light.constant", light.Attenuation.Constant); program.SetUniform("light.linear", light.Attenuation.Linear); program.SetUniform("light.quadratic", light.Attenuation.Exp); program.SetUniform("light.direction", light.Position - light.Target); program.SetUniform("light.cutOff", light.CutOff); const int lightUpRoutine = 2; program.SetUniform("lightUpRoutine", lightUpRoutine); }
private void FormMain_Load(object sender, EventArgs e) { var position = new vec3(1, 0.6f, 1) * 14; var center = new vec3(0, 0, 0); var up = new vec3(0, 1, 0); var camera = new Camera(position, center, up, CameraType.Perspective, this.winGLCanvas1.Width, this.winGLCanvas1.Height); this.scene = new Scene(camera) ; string folder = System.Windows.Forms.Application.StartupPath; string objFilename = System.IO.Path.Combine(folder + @"\..\..\..\..\Infrastructure\CSharpGL.Models", "vnfHanoiTower.obj_"); var parser = new ObjVNFParser(false); ObjVNFResult result = parser.Parse(objFilename); if (result.Error != null) { MessageBox.Show(result.Error.ToString()); } else { double radian = 120.0 / 180.0 * Math.PI / 2.0; var light = new CSharpGL.SpotLight(new vec3(1, 1, 1), new vec3(), (float)Math.Cos(radian)); var model = new ObjVNF(result.Mesh); this.node = SpotLightNode.Create(light, model, ObjVNF.strPosition, ObjVNF.strNormal, model.GetSize()); float max = node.ModelSize.max(); this.node.Scale *= 16.0f / max; this.lightNode = LightPostionNode.Create(); lightNode.SetLight(light); lightNode.WorldPosition = new vec3(1, 1, 1) * 4; var groupNode = new GroupNode(node, lightNode); this.scene.RootNode = groupNode; (new FormProperyGrid(groupNode)).Show(); } var list = new ActionList(); var transformAction = new TransformAction(scene); list.Add(transformAction); var renderAction = new RenderAction(scene); list.Add(renderAction); this.actionList = list; var manipulater = new FirstPerspectiveManipulater(); manipulater.Bind(camera, this.winGLCanvas1); }
private void FormMain_Load(object sender, EventArgs e) { var position = new vec3(1, 0.6f, 1) * 14; var center = new vec3(0, 0, 0); var up = new vec3(0, 1, 0); var camera = new Camera(position, center, up, CameraType.Perspecitive, this.winGLCanvas1.Width, this.winGLCanvas1.Height); this.scene = new Scene(camera, this.winGLCanvas1); string objFilename = "nanosuit.obj_"; var parser = new ObjVNFParser(false); ObjVNFResult result = parser.Parse(objFilename); if (result.Error != null) { MessageBox.Show(result.Error.ToString()); } else { var light = new CSharpGL.SpotLight(new vec3(1, 1, 1), new vec3(), 60); var model = new ObjVNF(result.Mesh); this.node = SpotLightNode.Create(light, model, ObjVNF.strPosition, ObjVNF.strNormal, model.GetSize()); float max = node.ModelSize.max(); this.node.Scale *= 16.0f / max; this.lightNode = LightPostionNode.Create(); lightNode.SetLight(light); lightNode.WorldPosition = new vec3(1, 1, 1) * 4; var groupNode = new GroupNode(node, lightNode); this.scene.RootElement = groupNode; (new FormProperyGrid(groupNode)).Show(); } var list = new ActionList(); var transformAction = new TransformAction(scene); list.Add(transformAction); var renderAction = new RenderAction(scene); list.Add(renderAction); this.actionList = list; var manipulater = new FirstPerspectiveManipulater(); manipulater.Bind(camera, this.winGLCanvas1); }
/// <summary> /// /// </summary> /// <param name="model"></param> /// <param name="position"></param> /// <param name="normal"></param> /// <param name="size"></param> /// <returns></returns> public static SpotLightNode Create(CSharpGL.SpotLight light, IBufferSource model, string position, string normal, vec3 size) { var vs = new VertexShader(spotLightVert); var fs = new FragmentShader(spotLightFrag); var provider = new ShaderArray(vs, fs); var map = new AttributeMap(); map.Add(inPosition, position); map.Add(inNormal, normal); var builder = new RenderMethodBuilder(provider, map); var node = new SpotLightNode(model, position, builder); node.light = light; node.ModelSize = size; node.Children.Add(new LegacyBoundingBoxNode(size)); node.Initialize(); return node; }
public void SetLight(CSharpGL.SpotLight light) { this.light = light; }
private void FormMain_Load(object sender, EventArgs e) { var rootElement = GetRootElement(); //var teapot = ShadowMappingRenderer.Create(); //var rootElement = teapot; var position = new vec3(5, 3, 5) * 3; var center = new vec3(0, 0, 0); var up = new vec3(0, 1, 0); var camera = new Camera(position, center, up, CameraType.Perspecitive, this.winGLCanvas1.Width, this.winGLCanvas1.Height); this.scene = new Scene(camera) { RootNode = rootElement, ClearColor = Color.SkyBlue.ToVec4(), }; { // add lights. var list = new List <LightBase>(); double radian = 120.0 / 180.0 * Math.PI; { var light = new CSharpGL.SpotLight(new vec3(3, 3, 3), new vec3(), (float)Math.Cos(radian), new Attenuation(2, 0, 0)); light.Diffuse = new vec3(1, 0, 0); light.Specular = new vec3(1, 0, 0); list.Add(light); } { var light = new CSharpGL.SpotLight(new vec3(3, 3, 3), new vec3(), (float)Math.Cos(radian), new Attenuation(2, 0, 0)); light.Diffuse = new vec3(0, 1, 0); light.Specular = new vec3(0, 1, 0); list.Add(light); } { var light = new CSharpGL.SpotLight(new vec3(3, 3, 3), new vec3(), (float)Math.Cos(radian), new Attenuation(2, 0, 0)); light.Diffuse = new vec3(0, 0, 1); light.Specular = new vec3(0, 0, 1); list.Add(light); } for (int i = 0; i < list.Count; i++) { var light = list[i]; var node = LightPositionNode.Create(light, i * 360.0f / list.Count); this.scene.Lights.Add(light); this.scene.RootNode.Children.Add(node); } } Match(this.trvScene, scene.RootNode); this.trvScene.ExpandAll(); var tansformAction = new TransformAction(scene); this.shadowMappingAction = new ShadowMappingAction(scene); var renderAction = new RenderAction(scene); var actionList = new ActionList(); actionList.Add(tansformAction); actionList.Add(shadowMappingAction); actionList.Add(renderAction); this.actionList = actionList; (new FormProperyGrid(shadowMappingAction)).Show(); var manipulater = new FirstPerspectiveManipulater(); manipulater.Bind(camera, this.winGLCanvas1); }