Beispiel #1
0
        private void SetVectors(UniformBlock uniformBlock)
        {
            // Use a 16 byte type to avoid alignment issues.
            var customVectors = new Vector4[64];

            customVectors[3]  = Vector4.One;
            customVectors[6]  = new Vector4(1, 1, 0, 0);
            customVectors[8]  = Vector4.One;
            customVectors[13] = Vector4.One;
            customVectors[18] = Vector4.One;
            customVectors[31] = new Vector4(1, 1, 0, 0);
            customVectors[32] = new Vector4(1, 1, 0, 0);

            // Set values from the material.
            foreach (var param in vec4ByParamId)
            {
                customVectors[param.Key.ToVectorIndex()] = param.Value;
            }

            // Override the defaults or material values with animation data.
            foreach (var param in Vec4ParamsMaterialAnimation)
            {
                customVectors[param.Key.ToVectorIndex()] = param.Value;
            }

            uniformBlock.SetValues("CustomVector", customVectors);
        }
Beispiel #2
0
        public void Render(Camera camera, RSkeleton Skeleton = null)
        {
            Shader shader = ShaderContainer.GetCurrentRModelShader();

            if (!shader.LinkStatusIsOk)
            {
                return;
            }

            shader.UseProgram();

            SetRenderSettingsUniforms(shader);
            SetCameraUniforms(camera, shader);

            // Bones
            if (boneUniformBuffer != null)
            {
                boneUniformBuffer.BindBlock(shader);
                if (Skeleton != null)
                {
                    boneBinds = Skeleton.GetAnimationTransforms();
                }
                boneUniformBuffer.SetValues("transforms", boneBinds);
            }

            DrawMeshes(Skeleton, shader);
        }
Beispiel #3
0
        private void SetFloats(UniformBlock uniformBlock)
        {
            // Use a 16 byte type to avoid alignment issues.
            var customFloatData = new Vector4[20];

            foreach (var param in floatByParamId)
            {
                customFloatData[param.Key.ToFloatIndex()] = new Vector4(param.Value, 0f, 0f, 0f);
            }
            uniformBlock.SetValues("CustomFloat", customFloatData);
        }
Beispiel #4
0
        public static void DrawMesh(RMesh m, RSkeleton?skeleton, Shader currentShader, RMaterial?previousMaterial, UniformBlock?boneUniformBuffer, RSkeleton?previousSkeleton)
        {
            // Check if the uniform values have already been set for this shader.
            if (previousMaterial == null || (m.Material != null && m.Material.MaterialLabel != previousMaterial.MaterialLabel))
            {
                m.Material?.SetMaterialUniforms(currentShader, previousMaterial);
                m.Material?.SetRenderState(previousMaterial);
            }

            if (skeleton != null && skeleton != previousSkeleton)
            {
                var boneBinds = skeleton.GetAnimationTransforms();
                boneUniformBuffer?.SetValues("transforms", boneBinds);
            }

            m.Draw(currentShader, skeleton);
        }
Beispiel #5
0
        private void SetBooleans(UniformBlock uniformBlock)
        {
            // Use a 16 byte type to avoid alignment issues.
            var customBooleans = new IVec4[20];

            customBooleans[1] = new IVec4 {
                X = 1
            };
            customBooleans[2] = new IVec4 {
                X = 0
            };
            customBooleans[3] = new IVec4 {
                X = 1
            };
            customBooleans[4] = new IVec4 {
                X = 1
            };
            customBooleans[5] = new IVec4 {
                X = 0
            };
            customBooleans[6] = new IVec4 {
                X = 0
            };
            customBooleans[9] = new IVec4 {
                X = 0
            };
            customBooleans[11] = new IVec4 {
                X = 1
            };

            foreach (var param in boolByParamId)
            {
                customBooleans[param.Key.ToBooleanIndex()] = new IVec4 {
                    X = param.Value ? 1 : 0
                };
            }
            uniformBlock.SetValues("CustomBoolean", customBooleans);
        }
Beispiel #6
0
        public void InvalidName()
        {
            var uniformBlock = new UniformBlock(shader, "UniformBlockA");

            Assert.IsFalse(uniformBlock.SetValues("ಠ_ಠ", new float[4]));
        }
Beispiel #7
0
 public void ValidNameLargerThanBlock()
 {
     var uniformBlock = new UniformBlock(shader, "UniformBlockA");
     var e            = Assert.ThrowsException <ArgumentOutOfRangeException>(() =>
                                                                             uniformBlock.SetValues("blockAVec4", new float[100]));
 }
Beispiel #8
0
        public void ValidName()
        {
            var uniformBlock = new UniformBlock(shader, "UniformBlockA");

            Assert.IsTrue(uniformBlock.SetValues("blockAVec4", new float[4]));
        }