private void AddLights(RayTracer_552.SceneDatabase rtScene) { UWB_XNAGraphicsDevice.m_TheAPI.LightManager.ResetAllLights(); for (int l = 0; l < rtScene.GetNumLights(); l++) { RTLight lgt = rtScene.GetLight(l); Vector4 useColor = new Vector4(lgt.GetColor(new Vector3(0, 0, 0)), 1f); UWB_XNALight theLight = null; if (lgt.GetLightSourceType() == RTLightType.RTLightSourceType.RTLightSourceTypeDirection) { theLight = UWB_XNAGraphicsDevice.m_TheAPI.LightManager.CreateDirectionalLight(); } else if (lgt.GetLightSourceType() == RTLightType.RTLightSourceType.RTLightSourceTypeSpot) { theLight = UWB_XNAGraphicsDevice.m_TheAPI.LightManager.CreateSpotLight(); } else { theLight = UWB_XNAGraphicsDevice.m_TheAPI.LightManager.CreatePointLight(); } theLight.Ambient = Vector4.Zero; theLight.Diffuse = useColor; theLight.Specular = useColor; theLight.Position = lgt.GetLightPosition(); theLight.Direction = -lgt.GetNormalizedDirection(Vector3.Zero); theLight.Color = useColor; theLight.Attenuation = new Vector3(1f, 0.0f, 0.0f); theLight.Range = 10000f; theLight.SwitchOnLight(); UWB_Primitive prim = CreateSphereMesh(); SetMeshMaterial(prim, rtScene.GetMaterial(0)); float scale = 0.25f; CreateNode(lgt.GetLightPosition(), scale, scale, scale, prim); } }
internal void AddRTScene(RayTracer_552.RTCamera c, RayTracer_552.SceneDatabase rtScene) { UWB_Primitive prim; NewSceneDatabase(); SceneResource <RTGeometry> allGeom = rtScene.GetAllGeom(); for (int i = 0; i < allGeom.Count; i++) { RTGeometry g = (RTGeometry)allGeom.ResourceLookup(i); switch (g.GeomType()) { case RTGeometry.RTGeometryType.Sphere: RTSphere s = (RTSphere)g; prim = CreateSphereMesh(); SetMeshMaterial(prim, rtScene.GetMaterial(s.GetMaterialIndex())); float scale = s.Radius / 2f; CreateNode(s.Center, scale, scale, scale, prim); break; case RTGeometry.RTGeometryType.Rectangle: RTRectangle r = (RTRectangle)g; prim = CreateRectangle(r); SetMeshMaterial(prim, rtScene.GetMaterial(r.GetMaterialIndex())); UWB_SceneNode node = CreateNode(r.GetCenter(), r.GetUSize() / 2f, 1f, r.GetVSize() / 2f, prim); // now rotate the y-vector of node to point towards r.Normal; float dot = (float)Math.Abs(Vector3.Dot(Vector3.UnitY, r.GetNormal())); if (dot < 0.9999f) { float angle = (float)Math.Acos(dot); Vector3 axis = Vector3.Cross(Vector3.UnitY, r.GetNormal()); axis.Normalize(); Quaternion q = Quaternion.CreateFromAxisAngle(axis, angle); UWB_XFormInfo xf = node.getXFormInfo(); xf.SetRotationQuat(q); node.setXFormInfo(xf); } break; case RTGeometry.RTGeometryType.Triangle: RTTriangle t = (RTTriangle)g; Vector3[] v = t.GetVertices(); prim = new UWB_PrimitiveTriangle(v[0], v[1], v[2]); prim.EnableLighting(true); prim.EnableTexturing(false); SetMeshMaterial(prim, rtScene.GetMaterial(t.GetMaterialIndex())); CreateNode(Vector3.Zero, 1f, 1f, 1f, prim); break; } } AddCamera(c); AddLights(rtScene); // to show ray list mShownRayX = mShownRayY = 0; mRaysToShow = new UWB_PrimitiveList(); mDebugInfo = new UWB_SceneNode(); mDebugInfo.setPrimitive(mRaysToShow); mDebugInfo.insertChildNode(mPixelsToShow.GetAllPixels()); mDebugInfo.insertChildNode(mPixelInWorld.GetAllPixels()); }