Beispiel #1
0
        public ShaderSource Generate(MaterialGeneratorContext context)
        {
            // Generate unique keys because this mixin can be used more than once per shader and we want their constants to be independent.
            var uniqueHardnessReciprocalKey = (ValueParameterKey <float>)context.GetParameterKey(HardnessReciprocalParameterKey);
            var uniqueBoundaryShiftKey      = (ValueParameterKey <float>)context.GetParameterKey(BoundaryShiftParameterKey);

            context.Parameters.Set(uniqueHardnessReciprocalKey, 1.0f / Hardness);
            context.Parameters.Set(uniqueBoundaryShiftKey, BoundaryShift);

            return(new ShaderClassSource("MaterialHairLightAttenuationFunctionDirectional", (int)SelectedNormalMode, uniqueHardnessReciprocalKey, uniqueBoundaryShiftKey));
        }
Beispiel #2
0
        public static void SetMaterialPassParameters(MaterialGeneratorContext context, ShaderMixinSource shaderSource, float alphaThreshold)
        {
            const string functionName = "hairDiscardFunction";

            // Generate a key because the mixin can be used more than once per shader and therefore we want their constants to be independent.
            var uniqueAlphaThresholdKey = (ValueParameterKey <float>)context.GetParameterKey(HairAlphaThresholdKey);

            context.Parameters.Set(uniqueAlphaThresholdKey, alphaThreshold);

            switch (context.PassIndex)
            {
            case (int)PassID.OpaqueBackAndFront:
                context.MaterialPass.BlendState      = BlendStates.Opaque; // Render as opaque.
                context.MaterialPass.HasTransparency = false;              // Render as opaque.
                context.MaterialPass.CullMode        = CullMode.None;      // Render both faces
                shaderSource.AddComposition(functionName, new MaterialHairDiscardFunctionOpaquePass().Generate(context, uniqueAlphaThresholdKey));
                break;

            case (int)PassID.TransparentBack:
                context.MaterialPass.BlendState      = BlendStates.NonPremultiplied; // TODO: Is this the correct blend mode?
                context.MaterialPass.HasTransparency = true;                         // Render as a transparent.
                context.MaterialPass.CullMode        = CullMode.Front;               // Only draw back faces.
                shaderSource.AddComposition(functionName, new MaterialHairDiscardFunctionTransparentPass().Generate(context, uniqueAlphaThresholdKey));
                break;

            case (int)PassID.TransparentFront:
                context.MaterialPass.BlendState      = BlendStates.NonPremultiplied; // TODO: Is this the correct blend mode?
                context.MaterialPass.HasTransparency = true;                         // Render as a transparent.
                context.MaterialPass.CullMode        = CullMode.Back;                // Only draw front faces.
                shaderSource.AddComposition(functionName, new MaterialHairDiscardFunctionTransparentPass().Generate(context, uniqueAlphaThresholdKey));
                break;
            }
        }
Beispiel #3
0
        public ShaderSource Generate(MaterialGeneratorContext context)
        {
            // Generate a unique key because this mixin can be used more than once per shader and we want their constants to be independent.
            var uniqueExtinctionStrengthKey = (ValueParameterKey <float>)context.GetParameterKey(ExtinctionStrengthKey);

            context.MaterialPass.Parameters.Set(uniqueExtinctionStrengthKey, ExtinctionStrength);

            return(new ShaderClassSource("MaterialHairShadowingFunctionScattering", uniqueExtinctionStrengthKey));
        }