public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
        {
            var result = new GetNewLightsResponse();

            while (reader.Read())
            {
                if (reader.TokenType == JsonToken.PropertyName && reader.Value.ToString().Equals("lastscan"))
                {
                    reader.Read();
                    if (reader.Value.ToString().Equals("none"))
                    {
                        result.LastScan = DateTime.MinValue;
                    }
                    else if (reader.Value.ToString().Equals("active"))
                    {
                        result.LastScan = DateTime.MaxValue;
                    }
                    else
                    {
                        result.LastScan = DateTime.Parse(reader.Value.ToString());
                    }
                }
                else if (reader.TokenType == JsonToken.PropertyName)
                {
                    var newBasicLight = new BasicLight();
                    newBasicLight.Id = Convert.ToInt32(reader.Value);
                    reader.Read();
                    newBasicLight.Name = reader.Value.ToString();
                    result.Add(newBasicLight);
                }
            }
            return(result);
        }
示例#2
0
        protected override void Initialize()
        {
            string rayGenPath = shaderPath;

            /*-----------------------------------------------
             * Create the Optix context
             *-----------------------------------------------*/
            OptixContext = new Context();
            OptixContext.RayTypeCount    = 2;
            OptixContext.EntryPointCount = 1;
            OptixContext.SetStackSize(4096);

            /* Create the ray-generation and exception programs
             *-----------------------------------------------*/
            var rayGen    = new OptixProgram(OptixContext, rayGenPath, mTutorial < 11 ? "pinhole_camera" : "env_camera");
            var exception = new OptixProgram(OptixContext, rayGenPath, "exception");
            var miss      = new OptixProgram(OptixContext, rayGenPath, mTutorial < 5 ? "miss" : "envmap_miss");

            OptixContext["bg_color"].Set(100 / 255.0f, 149 / 255.0f, 237 / 255.0f);
            OptixContext["bad_color"].Set(1.0f, 0.0f, 0.0f);

            OptixContext.SetRayGenerationProgram(0, rayGen);
            OptixContext.SetExceptionProgram(0, exception);
            OptixContext.SetRayMissProgram(0, miss);

            /*-----------------------------------------------
             * Create lights
             *-----------------------------------------------*/
            BasicLight[] lights = new BasicLight[1];
            lights[0].Position    = new Vector3(-5.0f, 60.0f, -16.0f);
            lights[0].Color       = new Vector3(1.0f, 1.0f, 1.0f);
            lights[0].CastsShadow = 1;

            BufferDesc desc = new BufferDesc()
            {
                Width    = (uint)lights.Length,
                Format   = Format.User,
                Type     = BufferType.Input,
                ElemSize = (uint)Marshal.SizeOf(typeof(BasicLight))
            };
            Buffer lightsBuffer = new Buffer(OptixContext, desc);

            lightsBuffer.SetData <BasicLight>(lights);

            OptixContext["lights"].Set(lightsBuffer);

            /*-----------------------------------------------
             * Create noise texture
             *-----------------------------------------------*/
            if (mTutorial >= 8)
            {
                uint noiseTexDim = 64;
                desc = new BufferDesc()
                {
                    Width = noiseTexDim, Height = noiseTexDim, Depth = noiseTexDim, Format = Format.Float, Type = BufferType.Input
                };
                Buffer noiseBuffer = new Buffer(OptixContext, desc);

                Random       rand   = new Random();
                BufferStream stream = noiseBuffer.Map();
                for (int i = 0; i < noiseTexDim * noiseTexDim * noiseTexDim; i++)
                {
                    stream.Write <float>((float)rand.NextDouble());
                }
                noiseBuffer.Unmap();

                TextureSampler noiseTex = new TextureSampler(OptixContext, TextureSamplerDesc.GetDefault(WrapMode.Repeat));
                noiseTex.SetBuffer(noiseBuffer);

                OptixContext["noise_texture"].Set(noiseTex);
            }

            /*-----------------------------------------------
             * Load enivronment map texture
             *-----------------------------------------------*/
            LoadEnvMap();

            /*-----------------------------------------------
             * Load the geometry
             *-----------------------------------------------*/
            CreateGeometry();

            /*-----------------------------------------------
             * Create the output buffer
             *-----------------------------------------------*/
            CreateOutputBuffer(Format.UByte4);
            OptixContext["output_buffer"].Set(OutputBuffer);

            /*-----------------------------------------------
             * Finally compile the optix context, and build the accel tree
             *-----------------------------------------------*/
            SetCamera();

            OptixContext["max_depth"].Set(100);
            OptixContext["radiance_ray_type"].Set(0u);
            OptixContext["shadow_ray_type"].Set(1u);
            OptixContext["frame_number"].Set(0u);
            OptixContext["scene_epsilon"].Set(.001f);
            OptixContext["importance_cutoff"].Set(0.01f);
            OptixContext["ambient_light_color"].Set(0.31f, 0.33f, 0.28f);

            OptixContext.Compile();
            OptixContext.BuildAccelTree();

            //very loose calculation of number of rays
            float numSecondaryRays = 0;

            if (mTutorial >= 9)
            {
                numSecondaryRays = 2.5f; //only convex hull casts refraction rays
            }
            else if (mTutorial >= 8)
            {
                numSecondaryRays = 2;
            }
            else if (mTutorial >= 4)
            {
                numSecondaryRays = 1.5f; //only the floor casts reflection rays, so give aproximate
            }
            else if (mTutorial >= 3)
            {
                numSecondaryRays = 1;
            }

            RaysTracedPerFrame = (int)(Width * Height * (numSecondaryRays + 1));
        }