示例#1
0
        void OnShaderSet(MaterialRendererServices services, int userData)
        {
            if (userData == 2 || userData == 3) //All DirectX Shaders
            {
                Matrix4 worldViewProj;
                worldViewProj = _driver.GetTransform(TransformationState.Projection);
                worldViewProj *= _driver.GetTransform(TransformationState.View);
                worldViewProj *= _driver.GetTransform(TransformationState.World);
                services.SetVertexShaderConstant("mWorldViewProj", worldViewProj.ToShader());
            }
            if (userData == 1 || userData == 3) //Clamp Shaders
            {
                if (userData == 1) //OpenGL Clamp Shader
                {
                    services.SetPixelShaderConstant("DiffuseMap", 0f);
                    services.SetPixelShaderConstant("DetailMap", 1f);
                }
                services.SetPixelShaderConstant("WaterPositionY", WaterNode.Position.Y);
                return;
            }
            //Water Shaders
            float time = (float)((DateTime.Now.TimeOfDay.TotalMilliseconds));
            services.SetVertexShaderConstant("Time", time);
            services.SetVertexShaderConstant("WaveHeight", WaveHeight);
            services.SetVertexShaderConstant("WaveLength", WaveLength);
            services.SetVertexShaderConstant("WaveSpeed", WaveSpeed);

            services.SetPixelShaderConstant("AddedColor", AddedColor.ToShader());
            services.SetPixelShaderConstant("MultiColor", MultiColor.ToShader());
            services.SetPixelShaderConstant("WaveDisplacement", WaveDisplacement);
            services.SetPixelShaderConstant("WaveRepetition", WaveRepetition);
            services.SetPixelShaderConstant("RefractionFactor", RefractionFactor);
            services.SetPixelShaderConstant("UnderWater", IsUnderwater(_scene.ActiveCamera) ? 1.0f : 0.0f);
        }
示例#2
0
 public virtual void ShaderEvent(MaterialRendererServices services, int userData)
 {
 }
示例#3
0
        public void OnSetConstants(MaterialRendererServices services, int userData)
        {
            //This is called when we need to set shader's constants
            //It is very simple and taken from Irrlicht's original shader example.
            //Please notice that many types already has a "ToShader" func made especially
            //For exporting to shader floats !
            //If the structure you want has no such function, then simply use "ToUnmanaged" instead
            //IrrlichtNETCP.Matrix4 world = driver.GetTransform(TransformationState.World);
            //IrrlichtNETCP.Matrix4 invWorld = world;
            //invWorld.MakeInverse();
            //services.VideoDriver.GPUProgrammingServices.
            //services.SetVertexShaderConstant(invWorld.ToShader(), 0, 4);
            //services.SetVertexShaderConstant("LightPosition", (new Vector3D(128,128,128).ToShader()));

            //IrrlichtNETCP.Matrix4 worldviewproj;
            //worldviewproj = driver.GetTransform(TransformationState.Projection);
            ///worldviewproj *= driver.GetTransform(TransformationState.View);
            //worldviewproj *= world;

            //services.SetVertexShaderConstant(worldviewproj.ToShader(), 4, 4);

            //services.SetVertexShaderConstant(device.SceneManager.ActiveCamera.Position.ToShader(), 8, 1);

            //services.SetVertexShaderConstant(Colorf.Blue.ToShader(), 9, 1);
            //services.SetVertexShaderConstant(Colorf.Blue.ToShader(),9,1);//SurfaceColor; // (0.75, 0.75, 0.75)

            //world = world.GetTransposed();
            //services.SetVertexShaderConstant(world.ToShader(), 10, 4);
        }
示例#4
0
        static void OnShaderSet(MaterialRendererServices services, int userData)
        {
            //This is called when we need to set shader's constants
            //It is very simple and taken from Irrlicht's original shader example.
            //Please notice that many types already has a "ToShader" func made especially
            //For exporting to shader floats !
            //If the structure you want has no such function, then simply use "ToUnmanaged" instead
            Matrix4 world = Driver.GetTransform(TransformationState.World);
            Matrix4 invWorld = world;
            invWorld.MakeInverse();

            services.SetVertexShaderConstant(invWorld.ToShader(), 0, 4);

            Matrix4 worldviewproj;
            worldviewproj = Driver.GetTransform(TransformationState.Projection);
            worldviewproj *= Driver.GetTransform(TransformationState.View);
            worldviewproj *= world;

            services.SetVertexShaderConstant(worldviewproj.ToShader(), 4, 4);

            services.SetVertexShaderConstant(Scene.ActiveCamera.Position.ToShader(), 8, 1);

            services.SetVertexShaderConstant(Colorf.Blue.ToShader(), 9, 1);

            world = world.GetTransposed();
            services.SetVertexShaderConstant(world.ToShader(), 10, 4);
        }
示例#5
0
        public override void ShaderEvent(MaterialRendererServices services, int userData)
        {
            IrrlichtNETCP.VideoDriver driver = services.VideoDriver;

            // *****************************************
            // VERTEX SHADER CONSTANTS
            // *****************************************
            Matrix4 worldViewProj = driver.GetTransform(TransformationState.Projection);
            worldViewProj *= driver.GetTransform(TransformationState.View);
            worldViewProj *= driver.GetTransform(TransformationState.World);
            services.SetVertexShaderConstant("WorldViewProj", worldViewProj.ToShader(), 16);

            Matrix4 worldReflectionViewProj = driver.GetTransform(TransformationState.Projection);
            worldReflectionViewProj *= Camera.ViewMatrix;
            worldReflectionViewProj *= driver.GetTransform(TransformationState.World);
            services.SetVertexShaderConstant("WorldReflectionViewProj", worldReflectionViewProj.ToShader(), 16);

            services.SetVertexShaderConstant("WaveLength", 0.01f);   // 0.1

            float time = Reference.Device.Timer.Time / 1000000.0f;
            services.SetVertexShaderConstant("Time", time);

            services.SetVertexShaderConstant("WindForce", WindForce);
            services.SetVertexShaderConstant("WindDirection", WindDirection.ToShader(), 2);

            // *****************************************
            // PIXEL SHADER CONSTANTS
            // *****************************************
            Vector3D cameraPos = Reference.SceneManager.ActiveCamera.Position;
            services.SetPixelShaderConstant("CameraPosition", cameraPos.ToShader());
            services.SetPixelShaderConstant("WaveHeight", WaveHeight);
            services.SetPixelShaderConstant("WaterColor", WaterColor.ToShader());
            services.SetPixelShaderConstant("SpecularColor", SpecularColor.ToShader());
            services.SetPixelShaderConstant("Specular", Specular);
            services.SetPixelShaderConstant("ColorBlendFactor", ColorBlendFactor);

            base.ShaderEvent(services, userData);
        }