Пример #1
0
    // switch between shader types
    /// <param name = "newShader"> The state to switch to</param>
    private void ChangeShader(ShaderState newShader)
    {
        switch (newShader)
        {
        // translate depth into
        case ShaderState.Color:     // ...color
            DepthMapMaterial.SetInt("_Equation", 6);
            mappingMaterial.DrawVisualMeshes = true;
            break;

        case ShaderState.Transparency:     // ... transparency/alpha values
            DepthMapMaterial.SetInt("_Equation", 9);
            mappingMaterial.DrawVisualMeshes = true;
            break;

        case ShaderState.Pulse:     // ... frequency
            DepthMapMaterial.SetInt("_Equation", 10);
            mappingMaterial.DrawVisualMeshes = true;
            break;

        case ShaderState.AdjustHoloLens:     // white shader to adjust the HoloLens
            DepthMapMaterial.SetInt("_Equation", 12);
            mappingMaterial.DrawVisualMeshes = true;
            break;

        case ShaderState.Off:     // white shader to adjust the HoloLens
            mappingMaterial.DrawVisualMeshes = false;
            break;

        default:
            break;
        }
        currentShader = newShader;
        Debug.Log("The new shader STATE is: " + newShader);
    }
Пример #2
0
        protected Shader(string vertexSource, string fragmentSource, string geometrySource, ShaderState state)
        {
            VertexShader = GL.CreateShader(OpenTK.Graphics.OpenGL.ShaderType.VertexShader);
            GL.ShaderSource(VertexShader, vertexSource);
            GL.CompileShader(VertexShader);

            FragmentShader = GL.CreateShader(OpenTK.Graphics.OpenGL.ShaderType.FragmentShader);
            GL.ShaderSource(FragmentShader, fragmentSource);
            GL.CompileShader(FragmentShader);

            if (geometrySource != null)
            {
                GeometryShader = GL.CreateShader(OpenTK.Graphics.OpenGL.ShaderType.GeometryShader);
                GL.ShaderSource(GeometryShader, geometrySource);
                GL.CompileShader(GeometryShader);
            }

            ShaderProgram = GL.CreateProgram();
            GL.AttachShader(ShaderProgram, VertexShader);
            GL.AttachShader(ShaderProgram, FragmentShader);
            if (geometrySource != null) GL.AttachShader(ShaderProgram, GeometryShader);

            GL.BindFragDataLocation(ShaderProgram, 0, "color"); // TODO: remove
            GL.BindAttribLocation(ShaderProgram, 0, "vertex");
            GL.BindAttribLocation(ShaderProgram, 1, "textureCoordinate");
            GL.BindAttribLocation(ShaderProgram, 2, "normal");

            GL.LinkProgram(ShaderProgram);

            _parameters = new Dictionary<string, int>();
            _textures = new Dictionary<string, int>();

            State = state;
            Initialized = false;
        }
Пример #3
0
        private static void UpdateMaterials(ShaderState shaderState, Color planColor, Color supportedPlanColor, float transparency, Material[] sharedMaterials)
        {
            for (int j = 0; j < sharedMaterials.Length; j++)
            {
                Material originalMaterial = sharedMaterials[j];
                Material material         = new Material(originalMaterial)
                {
                    name = originalMaterial.name
                };
                if (!originalMaterialDict.ContainsKey(material.name))
                {
                    originalMaterialDict[material.name] = originalMaterial;
                }
                switch (shaderState)
                {
                case ShaderState.Skuld:
                    material = originalMaterialDict[originalMaterial.name];
                    break;

                default:
                    material.SetOverrideTag("RenderType", "Transparent");
                    material.shader = planShader;
                    Color color = (shaderState == ShaderState.Supported ? supportedPlanColor : planColor);
                    color.a       *= transparency;
                    material.color = color;
                    material.EnableKeyword("_EMISSION");
                    material.DisableKeyword("DIRECTIONAL");
                    break;
                }
                sharedMaterials[j] = material;
            }
        }
Пример #4
0
        public static void UpdateTextures(GameObject m_placementplan, ShaderState shaderState)
        {
            Color unsupportedColor = unsupportedColorConfig.Value;
            Color supportedColor   = supportedPlanColorConfig.Value;
            float transparency     = transparencyConfig.Value;

            transparency *= transparency; //x² mapping for finer control
            MeshRenderer[] meshRenderers = m_placementplan.GetComponentsInChildren <MeshRenderer>();
            foreach (MeshRenderer meshRenderer in meshRenderers)
            {
                if (!(meshRenderer.sharedMaterial == null))
                {
                    Material[] sharedMaterials = meshRenderer.sharedMaterials;
                    UpdateMaterials(shaderState, unsupportedColor, supportedColor, transparency, sharedMaterials);

                    meshRenderer.sharedMaterials   = sharedMaterials;
                    meshRenderer.shadowCastingMode = ShadowCastingMode.Off;
                }
            }

            SkinnedMeshRenderer[] skinnedMeshRenderers = m_placementplan.GetComponentsInChildren <SkinnedMeshRenderer>();
            foreach (SkinnedMeshRenderer meshRenderer in skinnedMeshRenderers)
            {
                if (!(meshRenderer.sharedMaterial == null))
                {
                    Material[] sharedMaterials = meshRenderer.sharedMaterials;
                    UpdateMaterials(shaderState, unsupportedColor, supportedColor, transparency, sharedMaterials);

                    meshRenderer.sharedMaterials   = sharedMaterials;
                    meshRenderer.shadowCastingMode = ShadowCastingMode.Off;
                }
            }
        }
Пример #5
0
    public static float toFloat(this ShaderState state)
    {
        switch (state)
        {
        case ShaderState.None:
            return(0.1f);

        case ShaderState.Half:
            return(0.4f);

        case ShaderState.Complete:
            return(1f);

        default:
            throw new ArgumentOutOfRangeException(nameof(state), state, null);
        }
    }
Пример #6
0
        void EnterState(ShaderState s)
        {
            if (st == s)
            {
                return;
            }
            switch (s)
            {
            case ShaderState.eStart:
            {
                shaderintf.SetObjectSelected(true);
                shaderintf.SetObjectColor(Color.black);
            }
            break;

            case ShaderState.eStep1:
            {
                shaderintf.SetObjectColor(Color.yellow);
            }
            break;

            case ShaderState.eStep2:
            {
                shaderintf.SetObjectColor(Color.cyan);
            }
            break;

            case ShaderState.eStep3:
            {
                shaderintf.SetObjectColor(Color.red);
            }
            break;

            case ShaderState.eEnd:
            {
                shaderintf.OnButtonClicked();
                shaderintf.SetObjectSelected(false);
            }
            break;
            }
            st = s;
        }
Пример #7
0
        public Shader(string vertexSource, string fragmentSource, ShaderState state)
        {
            State       = state;
            Initialized = false;

            VertexShader = GL.CreateShader(ShaderType.VertexShader);
            GL.ShaderSource(VertexShader, vertexSource);
            GL.CompileShader(VertexShader);

            FragmentShader = GL.CreateShader(ShaderType.FragmentShader);
            GL.ShaderSource(FragmentShader, fragmentSource);
            GL.CompileShader(FragmentShader);

            ShaderProgram = GL.CreateProgram();
            GL.AttachShader(ShaderProgram, VertexShader);
            GL.AttachShader(ShaderProgram, FragmentShader);

            GL.BindAttribLocation(ShaderProgram, 0, "vertex");
            GL.BindAttribLocation(ShaderProgram, 1, "color");
            GL.BindAttribLocation(ShaderProgram, 2, "textureCoordinate");
            GL.BindAttribLocation(ShaderProgram, 3, "normal");

            GL.LinkProgram(ShaderProgram);
        }
Пример #8
0
 protected Shader(string vertexSource, string fragmentSource, ShaderState state)
     : this(vertexSource, fragmentSource, null, state)
 {
 }
Пример #9
0
 public string GetVertexShader()
 {
     return(ShaderState.Singleton().VertexShader);
 }
Пример #10
0
 public string GetFragmentShader()
 {
     return(ShaderState.Singleton().FragmentShader);
 }
Пример #11
0
            private void SetupShaderStage(SerializedProperty serializedProperty)
            {
                var stateProp = serializedProperty.FindPropertyRelative("m_State");

                this.state = new ShaderState(stateProp);
            }
Пример #12
0
 public void SaveShaders([FromBody] JObject shaders)
 {
     ShaderState.Singleton().VertexShader   = shaders["vertexshader"].ToString();
     ShaderState.Singleton().FragmentShader = shaders["fragmentshader"].ToString();
 }