示例#1
0
    ///////////////////////////////////////////

    static void Initialize()
    {
        // Art resources for the terrain widget
        pedestalModel = Model.FromFile("Pedestal.glb", Default.ShaderUI);
        compassModel  = Model.FromFile("Compass.glb");
        widgetModel   = Model.FromFile("MoveWidget.glb");

        terrain = new Terrain(
            chunkDetail: 64,
            chunkSize:   0.6f,
            chunkGrid:   2);
        terrain.clipRadius = 0.3f;

        // Add a floor if we're in VR, and hide the hands if we're in AR!
        if (SK.System.displayType == Display.Opaque)
        {
            floorMesh = Mesh.GeneratePlane(new Vec2(10, 10));
            floorMat  = Default.Material.Copy();
            floorMat[MatParamName.DiffuseTex] = Tex.FromFile("floor.png");
            floorMat[MatParamName.TexScale]   = 8;
        }
        else
        {
            Default.MaterialHand[MatParamName.ColorTint] = Color.Black;
            //Input.HandVisible(Handed.Max, false);
        }

        // Load up an initial, default location
        LoadLocation(0);
    }
示例#2
0
        public void Update()
        {
            if (!_doOnce)
            {
                Material mat = _model.GetMaterial(0);
                mat.SetTexture("diffuse", Tex.FromFile("Floor.png"));

                _doOnce = true;
            }
            _model.Draw(Matrix.T(Vec3.Zero));
        }
示例#3
0
    void InitNewMaterial()
    {
        // Start by just making a duplicate of the default! This creates a new
        // Material that we're free to change as much as we like.
        newMaterial = Material.Default.Copy();

        // Assign an image file as the primary color of the surface.
        newMaterial[MatParamName.DiffuseTex] = Tex.FromFile("floor.png");

        // Tint the whole thing greenish.
        newMaterial[MatParamName.ColorTint] = Color.HSV(0.3f, 0.4f, 1.0f);
    }
示例#4
0
    public Block(string texturePath)
    {
        texture             = Tex.FromFile(texturePath, false);
        texture.SampleMode  = TexSample.Point;
        material["diffuse"] = texture;

        cursorMaterial = material.Copy();
        cursorMaterial.Transparency = Transparency.Blend;
        cursorMaterial["color"]     = new Color(1, 1, 1, cursorOpacity);
        cursorMaterial.DepthTest    = DepthTest.Always;
        cursorMaterial.DepthWrite   = false;
    }
示例#5
0
    static void CommonInit()
    {
        Material floorMat = Default.Material.Copy();

        floorMat[MatParamName.DiffuseTex] = Tex.FromFile("Floor.png");
        floorMat[MatParamName.TexScale]   = 16;

        floorMesh = Model.FromMesh(Mesh.GenerateCube(Vec3.One), floorMat);
        floorTr   = Matrix.TRS(new Vec3(0, -1.5f, 0), Quat.Identity, new Vec3(20, 1, 20));

        demoSelectPose.position    = new Vec3(0, 0, -0.25f);
        demoSelectPose.orientation = Quat.LookDir(-Vec3.Forward);
    }
示例#6
0
    public void Initialize()
    {
        Tex uvTex = Tex.FromFile("UVTex.png");

        uvTex.SampleMode = TexSample.Point;

        material = Default.Material.Copy();
        material[MatParamName.DiffuseTex] = uvTex;

        materialWire           = Default.MaterialUnlit.Copy();
        materialWire.Wireframe = true;
        materialWire.DepthTest = DepthTest.Always;

        /// :CodeSample: Mesh.GenerateCube
        /// ### UV and Face layout
        /// Here's a test image that illustrates how this mesh's geometry is
        /// laid out.
        /// ![Procedural Cube Mesh]({{site.screen_url}}/ProcGeoCube.jpg)
        meshCube = Mesh.GenerateCube(Vec3.One);
        /// :End:
        /// :CodeSample: Mesh.GenerateRoundedCube
        /// ### UV and Face layout
        /// Here's a test image that illustrates how this mesh's geometry is
        /// laid out.
        /// ![Procedural Cube Mesh]({{site.screen_url}}/ProcGeoRoundedCube.jpg)
        meshRoundedCube = Mesh.GenerateRoundedCube(Vec3.One, 0.05f);
        /// :End:
        /// :CodeSample: Mesh.GenerateSphere
        /// ### UV and Face layout
        /// Here's a test image that illustrates how this mesh's geometry is
        /// laid out.
        /// ![Procedural Cube Mesh]({{site.screen_url}}/ProcGeoSphere.jpg)
        meshSphere = Mesh.GenerateSphere(1);
        /// :End:
        /// :CodeSample: Mesh.GenerateCylinder
        /// ### UV and Face layout
        /// Here's a test image that illustrates how this mesh's geometry is
        /// laid out.
        /// ![Procedural Cube Mesh]({{site.screen_url}}/ProcGeoCylinder.jpg)
        meshCylinder = Mesh.GenerateCylinder(1, 1, Vec3.Up);
        /// :End:
        /// :CodeSample: Mesh.GeneratePlane
        /// ### UV and Face layout
        /// Here's a test image that illustrates how this mesh's geometry is
        /// laid out.
        /// ![Procedural Cube Mesh]({{site.screen_url}}/ProcGeoPlane.jpg)
        meshPlane = Mesh.GeneratePlane(Vec2.One);
        /// :End:
    }
示例#7
0
    public void Initialize()
    {
        _material = new Material(Shader.FromFile("shader_param_types.hlsl"));
        _material[MatParamName.DiffuseTex] = Tex.FromFile("test.png");
        _material["on_off"] = true;
        _material["color"]  = Color.White * 0.5f;

        ShaderParamsData data = new ShaderParamsData {
            a_x = 1, a_y = 2, b_x = 3, b_y = 4
        };

        _material.SetData("data", data);

        _material.SetInt("id_set", 1, 2, 3, 4);
        _material.SetUInt("id_set2", 1, 2, 3, 4);
    }
示例#8
0
    static void CommonInit()
    {
        Log.Subscribe(OnLog);

        Material floorMat = Material.Copy(DefaultIds.material);

        floorMat["diffuse"]   = Tex.FromFile("Floor.png");
        floorMat["tex_scale"] = 16;

        floorMesh = Model.FromMesh(Mesh.GenerateCube(Vec3.One), floorMat);
        floorTr   = Matrix.TRS(new Vec3(0, -1.5f, 0), Quat.Identity, new Vec3(20, 1, 20));

        floorSolid = new Solid(new Vec3(0, -1.5f, 0), Quat.Identity, SolidType.Immovable);
        floorSolid.AddBox(new Vec3(20, 1, 20));

        demoSelectPose.position    = new Vec3(0, 0, -0.25f);
        demoSelectPose.orientation = Quat.LookDir(-Vec3.Forward);
    }
示例#9
0
    static void CommonInit()
    {
        /// :CodeSample: Log.Subscribe Log
        /// Then you add the OnLog method into the log events like this in your initialization
        /// code!
        Log.Subscribe(OnLog);
        /// :End:

        Material floorMat = Default.Material.Copy();

        floorMat["diffuse"]   = Tex.FromFile("Floor.png");
        floorMat["tex_scale"] = 16;

        floorMesh = Model.FromMesh(Mesh.GenerateCube(Vec3.One), floorMat);
        floorTr   = Matrix.TRS(new Vec3(0, -1.5f, 0), Quat.Identity, new Vec3(20, 1, 20));

        demoSelectPose.position    = new Vec3(0, 0, -0.25f);
        demoSelectPose.orientation = Quat.LookDir(-Vec3.Forward);
    }
示例#10
0
        public static void LoadMaterials(this IMaterialHostElement materialHostElement, SK.Model model, ICacheService cacheService)
        {
            var materialGroups = materialHostElement.GetMaterialGroups();

            foreach (var materialGroup in materialGroups)
            {
                var material     = materialGroup.GetMaterial();
                var texture      = materialGroup.GetTexture();
                var videoTexture = materialGroup.GetVideo();
                var webTexture   = materialGroup.GetWeb();

                if (material != null)
                {
                    //assign materials during draw instead of here
                    //var skMaterial = model.GetMaterial(0);
                    //if (materialGroup.Id == -1)
                    //{
                    //    model.SetMaterial(Material.FromColor(material.Diffuse.ToColor()));
                    //}
                    //else
                    //{
                    //    model.SetMaterial((uint)materialGroup.Id, Material.FromColor(material.Diffuse.ToColor()));
                    //}
                }

                if (texture != null)
                {
                    var fileExtension = texture.Source.FileExtension();
                    var hash          = texture.Source.ToMD5() + fileExtension;
                    var path          = System.IO.Path.Combine((cacheService as CacheService).CacheDir.Path, hash);

                    var mat = model.GetMaterial(0);
                    mat.SetTexture("diffuse", Tex.FromFile(path));
                }
            }
        }
示例#11
0
 public void Initialize()
 {
     _material = new Material(Shader.FromFile("matrix_param.hlsl"));
     _material[MatParamName.DiffuseTex] = Tex.FromFile("test.png");
     _material["custom_transform"]      = (Matrix)System.Numerics.Matrix4x4.Transpose(Matrix.TS(-0.25f, 0, 0, 0.25f));
 }
示例#12
0
    public void Initialize()
    {
        oldSkyTex   = Renderer.SkyTex;
        oldSkyLight = Renderer.SkyLight;

        /// :CodeSample: Renderer.SkyTex Renderer.SkyLight Tex.FromCubemapEquirectangular
        /// ## Setting lighting to an equirect cubemap
        /// Changing the environment's lighting based on an image is a really
        /// great way to instantly get a particular feel to your scene! A neat
        /// place to find compatible equirectangular images for this is
        /// [Poly Haven](https://polyhaven.com/hdris)
        Renderer.SkyTex   = Tex.FromCubemapEquirectangular("old_depot.hdr", out SphericalHarmonics lighting);
        Renderer.SkyLight = lighting;
        /// And here's what it looks like applied to the default Material!
        /// ![Default Material example]({{site.screen_url}}/MaterialDefault.jpg)
        /// :End:

        meshSphere = Mesh.GenerateSphere(1, 8);

        /// :CodeSample: Default.Material
        /// If you want to modify the default material, it's recommended to
        /// copy it first!
        matDefault = Default.Material.Copy();
        /// And here's what it looks like:
        /// ![Default Material example]({{site.screen_url}}/MaterialDefault.jpg)
        /// :End:

        /// :CodeSample: Default.MaterialUI
        /// This Material is basically the same as Default.Material, except it
        /// also adds some glow to the surface near the user's fingers. It
        /// works best on flat surfaces, and in StereoKit's design language,
        /// can be used to indicate that something is interactive.
        matUI = Default.MaterialUI.Copy();
        /// And here's what it looks like:
        /// ![UI Material example]({{site.screen_url}}/MaterialUI.jpg)
        /// :End:

        /// :CodeSample: Material.Wireframe
        /// Here's creating a simple wireframe material!
        matWireframe           = Default.Material.Copy();
        matWireframe.Wireframe = true;
        /// Which looks like this:
        /// ![Wireframe material example]({{site.screen_url}}/MaterialWireframe.jpg)
        /// :End:

        /// :CodeSample: Material.FaceCull Cull.Front
        /// Here's setting FaceCull to Front, which is the opposite of the
        /// default behavior. On a sphere, this is a little hard to see, but
        /// you might notice here that the lighting is for the back side of
        /// the sphere!
        matCull          = Default.Material.Copy();
        matCull.FaceCull = Cull.Front;
        /// ![FaceCull material example]({{site.screen_url}}/MaterialCull.jpg)
        /// :End:

        /// :CodeSample: Material.Transparency Transparency.Add
        /// ## Additive Transparency
        /// Here's an example material with additive transparency.
        /// Transparent materials typically don't write to the depth buffer,
        /// but this may vary from case to case. Note that the material's
        /// alpha does not play any role in additive transparency! Instead,
        /// you could make the material's tint darker.
        matAlphaAdd = Default.Material.Copy();
        matAlphaAdd.Transparency = Transparency.Add;
        matAlphaAdd.DepthWrite   = false;
        /// ![Additive transparency example]({{site.screen_url}}/MaterialAlphaAdd.jpg)
        /// :End:

        /// :CodeSample: Material.Transparency Transparency.Blend
        /// ## Alpha Blending
        /// Here's an example material with an alpha blend transparency.
        /// Transparent materials typically don't write to the depth buffer,
        /// but this may vary from case to case. Here we're setting the alpha
        /// through the material's Tint value, but the diffuse texture's
        /// alpha and the instance render color's alpha may also play a part
        /// in the final alpha value.
        matAlphaBlend = Default.Material.Copy();
        matAlphaBlend.Transparency            = Transparency.Blend;
        matAlphaBlend.DepthWrite              = false;
        matAlphaBlend[MatParamName.ColorTint] = new Color(1, 1, 1, 0.75f);
        /// ![Alpha blend example]({{site.screen_url}}/MaterialAlphaBlend.jpg)
        /// :End:

        matTextured = Default.Material.Copy();
        matTextured[MatParamName.DiffuseTex] = Tex.FromFile("floor.png");

        /// :CodeSample: Default.MaterialUnlit
        matUnlit = Default.MaterialUnlit.Copy();
        matUnlit[MatParamName.DiffuseTex] = Tex.FromFile("floor.png");
        /// ![Unlit material example]({{site.screen_url}}/MaterialUnlit.jpg)
        /// :End:

        /// :CodeSample: Default.MaterialPBR
        /// Occlusion (R), Roughness (G), and Metal (B) are stored
        /// respectively in the R, G and B channels of their texture.
        /// Occlusion can be separated out into a different texture as per
        /// the GLTF spec, so you do need to assign it separately from the
        /// Metal texture.
        matPBR = Default.MaterialPBR.Copy();
        matPBR[MatParamName.DiffuseTex]   = Tex.FromFile("metal_plate_diff.jpg");
        matPBR[MatParamName.MetalTex]     = Tex.FromFile("metal_plate_metal.jpg", false);
        matPBR[MatParamName.OcclusionTex] = Tex.FromFile("metal_plate_metal.jpg", false);
        /// ![PBR material example]({{site.screen_url}}/MaterialPBR.jpg)
        /// :End:

        /// :CodeSample: Default.MaterialUIBox
        /// The UI Box material has 3 parameters to control how the box wires
        /// are rendered. The initial size in meters is 'border_size', and
        /// can grow by 'border_size_grow' meters based on distance to the
        /// user's hand. That distance can be configured via the
        /// 'border_affect_radius' property of the shader, which is also in
        /// meters.
        matUIBox = Default.MaterialUIBox.Copy();
        matUIBox["border_size"]          = 0.005f;
        matUIBox["border_size_grow"]     = 0.01f;
        matUIBox["border_affect_radius"] = 0.2f;
        /// ![UI box material example]({{site.screen_url}}/MaterialUIBox.jpg)
        /// :End:

        matParameters = Default.Material.Copy();
        matParameters[MatParamName.DiffuseTex] = Tex.FromFile("floor.png");
        matParameters[MatParamName.ColorTint]  = Color.HSV(0.6f, 0.7f, 1f);
        matParameters[MatParamName.TexScale]   = 2;
    }