public LCC3ShaderUniform AddUniformOverrideForUniform(LCC3ShaderUniform uniform)
        {
            if (uniform != null)
            {
                LCC3ShaderUniform newUniform = uniform.CloneVariable<LCC3ShaderUniformOverride>();
                _uniformsByName[newUniform.Name] = newUniform;
                _uniforms.Add(newUniform);

                return newUniform;
            }

            return null;
        }
        public bool PopulateUniformWithVisitor(LCC3ShaderUniform uniform, LCC3NodeDrawingVisitor visitor)
        {
            if (uniform.Program != _program)
            {
                return false;
            }

            foreach(LCC3ShaderUniform currentUniform in _uniforms)
            {
                if (currentUniform.Location == uniform.Location)
                {
                    uniform.SetValueFromUniform(currentUniform);
                    return true;
                }
            }

            return false;
        }
Пример #3
0
 public void SetValueFromUniform(LCC3ShaderUniform uniform)
 {
     _varValue = uniform.VarValue;
 }
Пример #4
0
 public void PopulateFrom(LCC3ShaderUniform uniform)
 {
     base.PopulateFrom(uniform);
 }
        public bool PopulateUniformWithVisitor(LCC3ShaderUniform uniform, LCC3NodeDrawingVisitor visitor)
        {
            LCC3Semantic semantic = uniform.Semantic;
            uint semanticIndex = uniform.SemanticIndex;
            LCC3Material material;
            uint numOfTextures = (uint)visitor.CurrentMaterial.TextureCount();
            bool isInverted;

            switch (semantic)
            {
                #region Attribute Qualifiers

                case LCC3Semantic.SemanticVertexNormal:
                    uniform.SetValue(visitor.CurrentMesh.HasVertexNormals);
                    return true;
                case LCC3Semantic.SemanticShouldNormalizeVertexNormal:
                    uniform.SetValue(visitor.CurrentMeshNode.EffectiveNormalScalingMethod == LCC3NormalScaling.CC3NormalScalingNormalize);
                    return true;
                case LCC3Semantic.SemanticShouldRescaleVertexNormal:
                    uniform.SetValue(visitor.CurrentMeshNode.EffectiveNormalScalingMethod == LCC3NormalScaling.CC3NormalScalingRescale);
                    return true;
                case LCC3Semantic.SemanticHasVertexTangent:
                    uniform.SetValue(visitor.CurrentMesh.HasVertexTangents);
                    return true;
                case LCC3Semantic.SemanticHasVertexBitangent:
                    uniform.SetValue(visitor.CurrentMesh.HasVertexBitangents);
                    return true;
                case LCC3Semantic.SemanticHasVertexColor:
                    uniform.SetValue(visitor.CurrentMesh.HasVertexColors);
                    return true;
                case LCC3Semantic.SemanticHasVertexWeight:
                    uniform.SetValue(visitor.CurrentMesh.HasVertexWeights);
                    return true;
                case LCC3Semantic.SemanticHasVertexMatrixIndex:
                    uniform.SetValue(visitor.CurrentMesh.HasVertexMatrixIndices);
                    return true;
                case LCC3Semantic.SemanticHasVertexTextureCoordinate:
                    uniform.SetValue(visitor.CurrentMesh.HasVertexTextureCoordinates);
                    return true;
                case LCC3Semantic.SemanticHasVertexPointSize:
                    uniform.SetValue(visitor.CurrentMesh.HasVertexPointSizes);
                    return true;
                case LCC3Semantic.SemanticIsDrawingPoints:
                    uniform.SetValue(false); // XNA doesn't support drawing mode by points
                    return true;

                #endregion Attribute Qualifiers

                #region Environment semantics

                case LCC3Semantic.SemanticEyePosition:
                    uniform.SetValue(visitor.ViewMatrix.Inverse().TranslationOfTransformMatrix());
                    return true;
                case LCC3Semantic.SemanticModelMatrix:
                    uniform.SetValue(visitor.ModelMatrix);
                    return true;
                case LCC3Semantic.SemanticModelViewMatrix:
                    uniform.SetValue(visitor.ModelViewMatrix);
                    return true;
                case LCC3Semantic.SemanticModelViewProjMatrix:
                    uniform.SetValue(visitor.ModelViewProjMatrix);
                    return true;
                case LCC3Semantic.SemanticViewMatrix:
                    uniform.SetValue(visitor.ViewMatrix);
                    return true;
                case LCC3Semantic.SemanticProjMatrix:
                    uniform.SetValue(visitor.ProjMatrix);
                    return true;
                case LCC3Semantic.SemanticModelViewMatrixInvTran:
                    uniform.SetValue(visitor.ModelViewMatrix.InverseAdjointTranspose());
                    return true;
                case LCC3Semantic.SemanticModelMatrixInvTran:
                    uniform.SetValue(visitor.ModelMatrix.Transpose().Inverse());
                    return true;

                #endregion Environment semantics

                #region Setting material semantics

                case LCC3Semantic.SemanticColor:
                    uniform.SetValue(visitor.CurrentColor.ToVector4());
                    return true;
                case LCC3Semantic.SemanticMaterialColorAmbient:
                    uniform.SetValue(visitor.CurrentMaterial.EffectiveAmbientColor.ToVector4());
                    return true;
                case LCC3Semantic.SemanticMaterialColorDiffuse:
                    uniform.SetValue(visitor.CurrentMaterial.EffectiveDiffuseColor.ToVector4());
                    return true;
                case LCC3Semantic.SemanticMaterialColorSpecular:
                    uniform.SetValue(visitor.CurrentMaterial.EffectiveSpecularColor.ToVector4());
                    return true;
                case LCC3Semantic.SemanticMaterialColorEmission:
                    uniform.SetValue(visitor.CurrentMaterial.EffectiveEmissionColor.ToVector4());
                    return true;
                case LCC3Semantic.SemanticMaterialOpacity:
                    uniform.SetValue(visitor.CurrentMaterial.EffectiveDiffuseColor.A);
                    return true;
                case LCC3Semantic.SemanticMaterialShininess:
                    uniform.SetValue(visitor.CurrentMaterial.Shininess);
                    return true;
                case LCC3Semantic.SemanticMaterialReflectivity:
                    uniform.SetValue(visitor.CurrentMaterial.Reflectivity);
                    return true;
                case LCC3Semantic.SemanticMinimumDrawnAlpha:
                    material = visitor.CurrentMaterial;
                    uniform.SetValue(material.ShouldDrawLowAlpha ? 0.0f : material.AlphaTestReference);
                    return true;

                #endregion Setting material semantics

                #region Textures

                case LCC3Semantic.SemanticTextureCount:
                    uniform.SetValue(visitor.CurrentMaterial.TextureCount());
                    return true;
                case LCC3Semantic.SemanticTexUnitMode:
                    if(semanticIndex < numOfTextures)
                    {
                        LCC3TextureUnitMode texUnitMode = visitor.CurrentMaterial.TextureForTextureUnit(semanticIndex).TextureUnitMode;
                        uniform.SetValue((int)texUnitMode);
                    }
                    else
                    {
                        uniform.SetValue(0);
                    }
                    return true;
                case LCC3Semantic.SemanticVertexTexture:
                    if(semanticIndex < numOfTextures)
                    {
                        LCC3Texture texture = visitor.CurrentMaterial.TextureForTextureUnit(semanticIndex);
                        LCC3GraphicsTexture2D tex2D = texture.GraphicsTexture as LCC3GraphicsTexture2D;
                        uniform.SetValue(tex2D);
                    }
                    else
                    {
                        uniform.SetValue(null);
                    }
                    return true;
                case LCC3Semantic.SemanticTexUnitConstantColor:
                    if(semanticIndex < numOfTextures)
                    {
                        LCC3Texture texture = visitor.CurrentMaterial.TextureForTextureUnit(semanticIndex);
                        uniform.SetValue(texture.TextureUnitConstantColor.ToVector4());
                    }
                    else
                    {
                        uniform.SetValue(LCC3Vector4.CC3Vector4One);
                    }
                    return true;

                #endregion Textures

                #region Light semantics

                case LCC3Semantic.SemanticIsUsingLighting:
                    uniform.SetValue(visitor.CurrentNode.ShouldUseLighting);
                    return true;
                case LCC3Semantic.SemanticSceneLightColorAmbient:
                    uniform.SetValue(visitor.Scene.AmbientLight.ToVector4());
                    return true;
                case LCC3Semantic.SemanticLightIsEnabled:
                    for (uint i = 0; i < uniform.Size; i++)
                    {
                        LCC3Light light = visitor.LightAtIndex(uniform.SemanticIndex + i);
                        uniform.SetValueAtIndex(light.Visible, i);
                    }
                    return true;
                case LCC3Semantic.SemanticLightInvertedPositionEyeSpace:
                    isInverted = true;
                    goto case LCC3Semantic.SemanticLightPositionEyeSpace;
                case LCC3Semantic.SemanticLightPositionEyeSpace:
                    for (uint i = 0; i < uniform.Size; i++)
                    {
                        LCC3Light light = visitor.LightAtIndex(uniform.SemanticIndex + i);
                        LCC3Vector4 ltPos = light.GlobalHomogeneousPosition;
                        if (isInverted == true)
                        {
                            ltPos = ltPos.HomogeneousNegate();
                        }

                        // Transform global position/direction to eye space and normalize if direction
                        ltPos = visitor.ViewMatrix.TransformCC3Vector4(ltPos);
                        if (light.IsDirectionalOnly == true)
                        {
                            ltPos = ltPos.NormalizedVector();
                        }

                        uniform.SetValueAtIndex(ltPos, i);
                    }
                    return true;
                case LCC3Semantic.SemanticLightDirection:
                    for (uint i = 0; i < uniform.Size; i++)
                    {
                        LCC3Light light = visitor.LightAtIndex(uniform.SemanticIndex + i);
                        uniform.SetValueAtIndex(light.Location, i);
                    }
                    return true;

                case LCC3Semantic.SemanticLightColorDiffuse:
                    for (uint i = 0; i < uniform.Size; i++)
                    {
                        LCC3Light light = visitor.LightAtIndex(uniform.SemanticIndex + i);
                        CCColor4F ltColor = light.Visible ? light.DiffuseColor : LCC3ColorUtil.CCC4FBlackTransparent;
                        uniform.SetValueAtIndex(ltColor.ToVector4(), i);
                    }
                    return true;
                case LCC3Semantic.SemanticLightColorAmbient:
                    for (uint i = 0; i < uniform.Size; i++)
                    {
                        LCC3Light light = visitor.LightAtIndex(uniform.SemanticIndex + i);
                        CCColor4F ltColor = light.Visible ? light.AmbientColor : LCC3ColorUtil.CCC4FBlackTransparent;
                        uniform.SetValueAtIndex(ltColor.ToVector4(), i);
                    }
                    return true;
                case LCC3Semantic.SemanticLightColorSpecular:
                    for (uint i = 0; i < uniform.Size; i++)
                    {
                        LCC3Light light = visitor.LightAtIndex(uniform.SemanticIndex + i);
                        CCColor4F ltColor = light.Visible ? light.SpecularColor : LCC3ColorUtil.CCC4FBlackTransparent;
                        uniform.SetValueAtIndex(ltColor.ToVector4(), i);
                    }
                    return true;

                #endregion Light semantics

            }

            return false;
        }
Пример #6
0
 public bool PopulateUniformWithVisitor(LCC3ShaderUniform uniform, LCC3NodeDrawingVisitor visitor)
 {
     return false;
 }
Пример #7
0
        internal void UpdateUniformValue(LCC3ShaderUniform uniform)
        {
            EffectParameter _xnaEffectParam = _xnaShaderEffect.Parameters[uniform.Name];

            if (_xnaEffectParam != null && uniform.VarValue != null)
            {
                switch (uniform.Type)
                {
                    case LCC3ElementType.Float3x3:
                    case LCC3ElementType.Float4x4:
                        _xnaEffectParam.SetValue(uniform.XnaMatrix);
                        break;
                    case LCC3ElementType.Texture2D:
                        _xnaEffectParam.SetValue(uniform.XnaTexture2D);
                        break;
                    case LCC3ElementType.Vector4:
                        _xnaEffectParam.SetValue(uniform.XnaVector4);
                        break;
                    case LCC3ElementType.Vector3:
                        _xnaEffectParam.SetValue(uniform.XnaVector3);
                        break;
                    case LCC3ElementType.Float:
                        _xnaEffectParam.SetValue(uniform.FloatValue);
                        break;
                    case LCC3ElementType.Int:
                        _xnaEffectParam.SetValue(uniform.IntValue);
                        break;
                    case LCC3ElementType.Boolean:
                        _xnaEffectParam.SetValue(uniform.BoolValue);
                        break;
                    case LCC3ElementType.BooleanArray:
                        bool[] boolArray = uniform.BoolArrayValue;

                        for (int i = 0; i < boolArray.Length; i++)
                        {
                            _xnaEffectParam.Elements[i].SetValue(boolArray[i]);
                        }
                        break;
                    case LCC3ElementType.FloatArray:
                        float[] floatArray = uniform.FloatArrayValue;
                        for (int i = 0; i < floatArray.Length; i++)
                        {
                            _xnaEffectParam.Elements[i].SetValue(floatArray[i]);
                        }
                        break;
                    case LCC3ElementType.Vector4Array:
                        _xnaEffectParam.SetValue(uniform.XnaVector4Array);
                        break;
                }
            }
        }
Пример #8
0
 public void AddUniform(LCC3ShaderUniform uniform)
 {
     switch (uniform.Scope)
     {
         case LCC3ShaderVariableScope.ScopeScene:
             _uniformsSceneScope.Add(uniform);
             break;
         case LCC3ShaderVariableScope.ScopeDraw:
             _uniformsDrawScope.Add(uniform);
             break;
         default:
             _uniformsNodeScope.Add(uniform);
             break;
     }
 }
        public void RemoveUniformOverride(LCC3ShaderUniform uniform)
        {
            _uniforms.Remove(uniform);
            _uniformsByName.Remove(uniform.Name);

            if (_uniforms.Count == 0)
            {
                this.RemoveAllOverrides();
            }
        }