//------------------------------------------------------------------------------------------
        //------------------------------------------------------------------------------------------
        public ResourceItem Convert(object input, String collection)
        {
            MaterialItem ret = new MaterialItem();
            MaterialObject obj = (MaterialObject) input;

            ret.Properties = new Dictionary<string, PropertyItem>();

            obj.Properties.ForEach(delegate(PropertyObject value) {
                PropertyItem property = new PropertyItem();

                if(value.Type == ColorType) {
                    property.Type = ColorType;
                    property.Value = value.Value.Split(new RegularExpression("[^0-9.]+"));
                } else if(value.Type == FloatType) {
                    property.Type = FloatType;
                    property.Value = float.Parse(value.Value);
                } else if (value.Type == TextureHandleType) {
                    Handle handle = new Handle();

                    handle.Id = value.Value;
                    handle.Collection = collection;

                    property.Type = TextureHandleType;
                    property.Value = handle;
                }

                ret.Properties[value.Name] = property;
            });

            ret.Shader = obj.Shader;

            return ret;
        }
Beispiel #2
0
        public static Handle Create(String library, String id)
        {
            Handle ret = new Handle();

            ret.Collection = library;
            ret.Id = id;

            return ret;
        }
Beispiel #3
0
        //------------------------------------------------------------------------------------------
        //------------------------------------------------------------------------------------------
        public void Initialize(float fov, float zNear, float zFar)
        {
            this.DisplayDebugInformation();
            WebGLGraphics that = this;

            /*render texture dimensions*/
            this._renderTextureDim = this.SmallestPowerOfTwo(_canvas.Width);
            this._renderViewport =
                SystemCore.Environment.CreateFloat32ArrayFromArray(new float[] { _renderTextureDim, _renderTextureDim, });

            this._shaderGroups = new Dictionary<string, ShaderGroup>();

            /*rendering shaders*/
            ShaderGroup phongShaderGroup = new ShaderGroup();
            phongShaderGroup.Name = "phong";
            phongShaderGroup.ShaderBinder = new PhongBinder(that.Library, that._context, phongShaderGroup);

            SystemCore.ResourceManager.GetResource("/Data/Shader/phong_pass_geom.shader", null).ResourceChanged.Subscribe(
                delegate(object sender, object args) {
                Resource resource = (Resource) sender;

                if (resource.Finished) {
                    phongShaderGroup.GeometryPassShader = (CompiledShader) resource.Data;
                }
            }, null);

            SystemCore.ResourceManager.GetResource("/Data/Shader/phong_pass_prepost.shader", null).ResourceChanged.Subscribe(
                delegate(object sender, object args) {
                Resource resource = (Resource)sender;

                if (resource.Finished) {
                    phongShaderGroup.PrePostProcessPassShader = (CompiledShader)resource.Data;
                }
            }, null);

            SystemCore.ResourceManager.GetResource("/Data/Shader/phong_pass_light.shader", null).ResourceChanged.Subscribe(
                delegate(object sender, object args) {
                Resource resource = (Resource)sender;

                if (resource.Finished) {
                    phongShaderGroup.LightPassShader = (CompiledShader)resource.Data;
                }
            }, null);

            SystemCore.ResourceManager.GetResource("/Data/Shader/phong_pass_final.shader", null).ResourceChanged.Subscribe(
                delegate(object sender, object args) {
                Resource resource = (Resource)sender;

                if (resource.Finished) {
                    phongShaderGroup.FinalPassShader = (CompiledShader)resource.Data;
                }
            }, null);

            this.AddShaderGroup(phongShaderGroup);
            this.ActiveShaderGroup = "phong";

            /*core library - which contain things like light bounding meshes*/
            Library.LoadLibrary("/Data/JSON/core.json").Finished.Subscribe(delegate(object sender, object args) {
                Handle sphereHandle = new Handle();
                sphereHandle.Collection = "core";
                sphereHandle.Id = "point_light_sphere-lib";

                that._lightSphereVolume = ((MeshItem)Library.GetResource(sphereHandle));
            }, true);

            /*enable webGL float texture extension*/
            SystemCore.Logger.Log(this._context.GetExtension("OES_texture_float").ToString());

            this.SetupFrameBuffers();

            /*webgl render queues*/
            this._opaqueMeshQueue = new List<List<Node>>();
            this._transparentMeshQueue = new List<List<Node>>();
            this._lightQueue = new Dictionary<int, List<Node>>();

            /*camera*/
            this._camera = new Node();
            this._camera.AddComponent(new CameraComponent());

            /*perspective*/
            this._scaleMatrix = new Matrix4X4(null);
            this._mvMatrix = new Matrix4X4(null);
            this._vMatrix = new Matrix4X4(null);
            this._nMatrix = new Matrix4X4(null);
            this._pMatrix = Matrix4X4.MakePerspective(fov, 800.0f / 600.0f, zNear, zFar);

            this._context.Viewport(0, 0, this._renderTextureDim, this._renderTextureDim);
            this._context.EnableVertexAttribArray(0);
            this._context.EnableVertexAttribArray(1);
            this._context.EnableVertexAttribArray(2);

            this._context.Enable(WebGLE.DepthTest);
            this._context.Enable(WebGLE.CullFace);
            this._context.BlendFunc(WebGLE.SrcAlpha, WebGLE.One);

            /*occlusion*/
            this._cullInfo = new CullInfo();

            /*post process effects*/
            this._effects = new List<IPostProcessEffect>();

            /*active texture targets*/
            this._activeTextureTarget = new List<int>();
            this._activeTextureTarget[0] = WebGLE.Texture0;
            this._activeTextureTarget[1] = WebGLE.Texture1;
            this._activeTextureTarget[2] = WebGLE.Texture2;
            /*I don't need any more for now*/
        }
Beispiel #4
0
        //------------------------------------------------------------------------------------------
        //------------------------------------------------------------------------------------------
        public ResourceItem GetResource(Handle handle)
        {
            if(this._collections[handle.Collection] == null)
                return null;

            ResourceItem resource = this._collections[handle.Collection].Resources[handle.Id];

            if (resource == null)
                return null;

            if(!resource.Alocated) {
                if(resource.Readlocate())
                    this._alocatedItems.Add(resource);
            }

            resource.LastAccessed = this._lastUpdated;

            return resource;
        }