Beispiel #1
0
        protected override HighLevelGpuProgramSharedPtr setupUnifiedVertex(String name, TextureMaps maps, MaterialDescription description)
        {
            var program = HighLevelGpuProgramManager.Instance.createProgram(name, ResourceGroupName, "glsles", GpuProgramType.GPT_VERTEX_PROGRAM);

            program.Value.SourceFile = UnifiedShaderBase + "MainVP.glsl";

            program.Value.SkeletalAnimationIncluded = description.NumHardwareBones > 0;
            program.Value.NumberOfPoses             = (ushort)description.NumHardwarePoses;
            program.Value.setParam("preprocessor_defines", DetermineVertexPreprocessorDefines(maps, description.NumHardwareBones, description.NumHardwarePoses, description.Parity));
            program.Value.load();

            using (var defaultParams = program.Value.getDefaultParameters())
            {
                if (description.NumHardwareBones > 0 || description.NumHardwarePoses > 0)
                {
                    defaultParams.Value.setNamedAutoConstant("eyePosition", AutoConstantType.ACT_CAMERA_POSITION_OBJECT_SPACE);
                    defaultParams.Value.setNamedAutoConstant("lightAttenuation", AutoConstantType.ACT_LIGHT_ATTENUATION, 0);
                    defaultParams.Value.setNamedAutoConstant("lightPosition", AutoConstantType.ACT_LIGHT_POSITION_OBJECT_SPACE, 0);

                    defaultParams.Value.setNamedAutoConstant("worldMatrix3x4Array", AutoConstantType.ACT_WORLD_MATRIX_ARRAY_3x4);
                    defaultParams.Value.setNamedAutoConstant("cameraMatrix", AutoConstantType.ACT_VIEWPROJ_MATRIX);

                    if (description.NumHardwarePoses > 0)
                    {
                        defaultParams.Value.setNamedAutoConstant("poseAnimAmount", AutoConstantType.ACT_ANIMATION_PARAMETRIC);
                    }
                }
                else
                {
                    defaultParams.Value.setNamedAutoConstant("cameraMatrix", AutoConstantType.ACT_WORLDVIEWPROJ_MATRIX);
                    defaultParams.Value.setNamedAutoConstant("eyePosition", AutoConstantType.ACT_CAMERA_POSITION_OBJECT_SPACE);
                    defaultParams.Value.setNamedAutoConstant("lightAttenuation", AutoConstantType.ACT_LIGHT_ATTENUATION, 0);
                    defaultParams.Value.setNamedAutoConstant("lightPosition", AutoConstantType.ACT_LIGHT_POSITION_OBJECT_SPACE, 0);
                }
            }

            return(program);
        }
Beispiel #2
0
        protected override HighLevelGpuProgramSharedPtr setupUnifiedFrag(String name, MaterialDescription description, TextureMaps maps, bool alpha)
        {
            var program = HighLevelGpuProgramManager.Instance.createProgram(name, ResourceGroupName, "glsles", GpuProgramType.GPT_FRAGMENT_PROGRAM);

            program.Value.SourceFile = UnifiedShaderBase + "UnifiedFS.glsl";
            program.Value.setParam("preprocessor_defines", DetermineFragmentPreprocessorDefines(maps, alpha, description.HasGlossMap, description.IsHighlight, description.HasOpacityValue));
            program.Value.load();

            using (var defaultParams = program.Value.getDefaultParameters())
            {
                try
                {
                    int textureIndex = 0;
                    if ((maps & TextureMaps.Normal) == TextureMaps.Normal)
                    {
                        defaultParams.Value.setNamedConstant("normalTexture", textureIndex++);
                    }
                    if ((maps & TextureMaps.Diffuse) == TextureMaps.Diffuse)
                    {
                        defaultParams.Value.setNamedConstant("colorTexture", textureIndex++);
                    }
                    if ((maps & TextureMaps.Specular) == TextureMaps.Specular)
                    {
                        defaultParams.Value.setNamedConstant("specularTexture", textureIndex++);
                    }
                    if ((maps & TextureMaps.Opacity) == TextureMaps.Opacity && separateOpacityMap)
                    {
                        defaultParams.Value.setNamedConstant("opacityTexture", textureIndex++);
                    }
                    if (maps != TextureMaps.None)
                    {
                        defaultParams.Value.setNamedConstant("indirectionTex", textureIndex++);
                    }

                    defaultParams.Value.setNamedAutoConstant("lightDiffuseColor", AutoConstantType.ACT_LIGHT_DIFFUSE_COLOUR, 0);
                    defaultParams.Value.setNamedAutoConstant("emissiveColor", AutoConstantType.ACT_SURFACE_EMISSIVE_COLOUR);

                    if (description.HasGlossMap)
                    {
                        defaultParams.Value.setNamedConstant("glossyStart", 40.0f);
                        defaultParams.Value.setNamedConstant("glossyRange", 0.0f);
                    }
                    else
                    {
                        defaultParams.Value.setNamedAutoConstant("glossyness", AutoConstantType.ACT_SURFACE_SHININESS);
                    }

                    if ((maps & TextureMaps.Diffuse) == 0)
                    {
                        defaultParams.Value.setNamedAutoConstant("diffuseColor", AutoConstantType.ACT_SURFACE_DIFFUSE_COLOUR);
                    }

                    //Check for need to pass specular color
                    if ((maps & TextureMaps.Specular) == 0)
                    {
                        defaultParams.Value.setNamedAutoConstant("specularColor", AutoConstantType.ACT_SURFACE_SPECULAR_COLOUR);
                    }

                    if (description.IsHighlight)
                    {
                        defaultParams.Value.setNamedAutoConstant("highlightColor", AutoConstantType.ACT_CUSTOM, 1);
                    }

                    if (alpha)
                    {
                        defaultParams.Value.setNamedAutoConstant("alpha", AutoConstantType.ACT_CUSTOM, 0);
                    }
                }
                catch (Exception)
                {
                    Logging.Log.Warning($"Could not set params for frag program '{name}'");
                }
            }

            return(program);
        }