예제 #1
0
 public FrameBufferObject(int width, int height)
 {
     FrameBufferTexture = TextureFactory.Create(TextureWrapMode.ClampToEdge, width, height);
     FrameBufferTexture.LoadEmptyTexture(PixelInternalFormat.Rgba, PixelFormat.Bgra, true);
     TextureHandle = FrameBufferTexture.MyTextureHandle;
     Width         = width;
     Height        = height;
 }
예제 #2
0
        public void Texture_OK()
        {
            //Act
            ITexture texture = TextureFactory.Create(Utils.Utils.GetImageResource <ITerrain>("Landscape.Terrains.Dirt.jpg"), TextureWrapMode.ClampToEdge);

            //Assert
            Bitmap bitmap = new Bitmap(Utils.Utils.GetImageResource <ITerrain>("Landscape.Terrains.Dirt.jpg"));

            VerifyImage(bitmap, texture.TextureImage);
        }
예제 #3
0
파일: Plane.cs 프로젝트: mainblade/OpentK3D
 public Plane(bool invertAllFaces, Vbo p1, Vbo p2, Vbo p3, Vbo p4, Image textureImage, TextureWrapMode textureWrapMode = TextureWrapMode.ClampToEdge) : this(invertAllFaces, p1, p2, p3, p4)
 {
     if (textureImage != null)
     {
         Texture1 = TextureFactory.Create(textureImage, textureWrapMode);
     }
     else
     {
         Texture1 = TextureFactory.Create(TextureWrapMode.ClampToEdge, 50, 50);
     }
 }
예제 #4
0
 public IEnumerable <TextureImportParam> Enumerate(GltfParser parser)
 {
     for (int i = 0; i < parser.GLTF.materials.Count; ++i)
     {
         var vrmMaterial = m_vrm.materialProperties[i];
         if (vrmMaterial.shader == MToon.Utils.ShaderName)
         {
             // MToon
             foreach (var kv in vrmMaterial.textureProperties)
             {
                 // SRGB color or normalmap
                 yield return(TextureFactory.Create(parser, kv.Value, kv.Key, default, default));
예제 #5
0
        public Terrain(Image heightmapImage, Image blendMap, params Image[] image)
        {
            Center = new Vector3(Width / 2, 0, Height / 2);

            Texture1 = TextureFactory.Create(image[0], TextureWrapMode.Repeat);
            Texture2 = TextureFactory.Create(image[1], TextureWrapMode.Repeat);
            Texture3 = TextureFactory.Create(image[2], TextureWrapMode.Repeat);
            Texture4 = TextureFactory.Create(blendMap, TextureWrapMode.Repeat);

            heightMap = new Bitmap(heightmapImage);
            Width     = heightMap.Width;
            Height    = heightMap.Height;
            heights   = new float[Width, Height];
            Vertices  = new Vbo[Width * Height];
            Indices   = new List <int>();
        }
예제 #6
0
파일: Water.cs 프로젝트: mainblade/OpentK3D
        public void Load()
        {
            Foam = TextureFactory.Create(Utils.Utils.GetImageResource <ITerrain>("Landscape.Terrains.foam.jpg"), TextureWrapMode.Repeat);

            LoadWaveNumbersModerate();
            DataTexture.LoadData(SizedInternalFormat.Rgba16f, WaveNumbers);

            Texture3 = Foam;
            Texture4 = DataTexture;
            Texture5 = TextureFactory.Create(Utils.Utils.GetImageResource <ITerrain>("Landscape.Terrains.IKT4l.jpg"), TextureWrapMode.Repeat);


            for (int i = 0; i < Width; i += 1)
            {
                for (int j = 0; j < Height; j += 1)
                {
                    Vertices[i + j * Width] = new Vbo
                    {
                        Position = new Vector3((float)i, (float)1, (float)j),
                        TexCoord = new Vector2((float)i / Width, (float)j / Height),
                        Normal   = new Vector3(0, 1, 0),
                    };
                }
            }

            for (int i = 0; i < Width - 1; i++)
            {
                for (int j = 0; j < Height - 1; j++)
                {
                    Indices.Add(j * Width + i);
                    Indices.Add(j * Width + i + 1);
                    Indices.Add((j + 1) * Width + i);
                    Indices.Add((j + 1) * Width + i + 1);
                    Indices.Add((j + 1) * Width + i);
                    Indices.Add(j * Width + i + 1);
                }
            }
            indice = Indices.ToArray();

            Refraction = FramBufferOBjectFactory.Create(Width, Height);
            Refraction.Load();

            Reflection = FramBufferOBjectFactory.Create(Width, Height);
            Reflection.Load();

            InitWaterShader();
        }
예제 #7
0
파일: Water.cs 프로젝트: mainblade/OpentK3D
        public Water(int width, int height)
        {
            Width       = width;
            Height      = height;
            Center      = new Vector3(Width / 2, Height / 2, 0);
            Vertices    = new Vbo[Width * Height];
            Indices     = new List <int>();
            DataTexture = TextureFactory.Create();
            WaveNumbers = new float[24, 4];

            stopwatch = new Stopwatch();
            stopwatch.Start();

            _randomAngle      = new Random();
            _randomWaveNumber = new Random();

            ReflectionClipPlane = new float[] { 0, -1, 0, 0 };
            RefractionClipPlane = new float[] { 0, 1, 0, 0 };
        }
예제 #8
0
        public static async Task <Material> CreateAsync(IAwaitCaller awaitCaller, GltfParser parser, int m_index, glTF_VRM_Material vrmMaterial, GetTextureAsyncFunc getTexture)
        {
            var item       = vrmMaterial;
            var shaderName = item.shader;
            var shader     = Shader.Find(shaderName);

            if (shader == null)
            {
                //
                // no shader
                //
                if (VRM_SHADER_NAMES.Contains(shaderName))
                {
                    Debug.LogErrorFormat("shader {0} not found. set Assets/VRM/Shaders/VRMShaders to Edit - project setting - Graphics - preloaded shaders", shaderName);
                }
                else
                {
                    // #if VRM_DEVELOP
                    //                     Debug.LogWarningFormat("unknown shader {0}.", shaderName);
                    // #endif
                }
                return(await MaterialFactory.DefaultCreateMaterialAsync(awaitCaller, parser, m_index, getTexture));
            }

            //
            // restore VRM material
            //
            var material = new Material(shader);

            // use material.name, because material name may renamed in GltfParser.
            material.name        = parser.GLTF.materials[m_index].name;
            material.renderQueue = item.renderQueue;

            foreach (var kv in item.floatProperties)
            {
                material.SetFloat(kv.Key, kv.Value);
            }
            foreach (var kv in item.vectorProperties)
            {
                if (item.textureProperties.ContainsKey(kv.Key))
                {
                    // texture offset & scale
                    material.SetTextureOffset(kv.Key, new Vector2(kv.Value[0], kv.Value[1]));
                    material.SetTextureScale(kv.Key, new Vector2(kv.Value[2], kv.Value[3]));
                }
                else
                {
                    // vector4
                    var v = new Vector4(kv.Value[0], kv.Value[1], kv.Value[2], kv.Value[3]);
                    material.SetVector(kv.Key, v);
                }
            }
            foreach (var kv in item.textureProperties)
            {
                var param   = TextureFactory.Create(parser, kv.Value, kv.Key, 1, 1);
                var texture = await getTexture(awaitCaller, parser.GLTF, param);

                if (texture != null)
                {
                    material.SetTexture(kv.Key, texture);
                }
            }
            foreach (var kv in item.keywordMap)
            {
                if (kv.Value)
                {
                    material.EnableKeyword(kv.Key);
                }
                else
                {
                    material.DisableKeyword(kv.Key);
                }
            }
            foreach (var kv in item.tagMap)
            {
                material.SetOverrideTag(kv.Key, kv.Value);
            }

            if (shaderName == MToon.Utils.ShaderName)
            {
                // TODO: Material拡張にMToonの項目が追加されたら旧バージョンのshaderPropから変換をかける
                // インポート時にUniVRMに含まれるMToonのバージョンに上書きする
                material.SetFloat(MToon.Utils.PropVersion, MToon.Utils.VersionNumber);
            }

            return(material);
        }