Пример #1
0
		static void gpu_OnSetConstants(MaterialRendererServices services, int userData)
		{
			VideoDriver driver = services.VideoDriver;

			if (useHighLevelShaders && shaderFirstUpdate)
			{
				shaderWorldViewProjId = services.GetVertexShaderConstantID("mWorldViewProj");
				shaderTransWorldId = services.GetVertexShaderConstantID("mTransWorld");
				shaderInvWorldId = services.GetVertexShaderConstantID("mInvWorld");
				shaderLightPosId = services.GetVertexShaderConstantID("mLightPos");
				shaderLightColorId = services.GetVertexShaderConstantID("mLightColor");

				// textures id are important only for OpenGL interface
				if (driver.DriverType == DriverType.OpenGL)
					shaderTextureId = services.GetVertexShaderConstantID("myTexture");

				shaderFirstUpdate = false;
			}

			// set inverted world matrix
			// if we are using highlevel shaders (the user can select this when
			// starting the program), we must set the constants by name

			Matrix invWorld = driver.GetTransform(TransformationState.World);
			invWorld.MakeInverse();

			if (useHighLevelShaders)
				services.SetVertexShaderConstant(shaderInvWorldId, invWorld.ToArray());
			else
				services.SetVertexShaderConstant(0, invWorld.ToArray());

			// set clip matrix

			Matrix worldViewProj = driver.GetTransform(TransformationState.Projection);
			worldViewProj *= driver.GetTransform(TransformationState.View);
			worldViewProj *= driver.GetTransform(TransformationState.World);

			if (useHighLevelShaders)
				services.SetVertexShaderConstant(shaderWorldViewProjId, worldViewProj.ToArray());
			else
				services.SetVertexShaderConstant(4, worldViewProj.ToArray());

			// set camera position

			Vector3Df pos = device.SceneManager.ActiveCamera.AbsolutePosition;

			if (useHighLevelShaders)
				services.SetVertexShaderConstant(shaderLightPosId, pos.ToArray());
			else
				services.SetVertexShaderConstant(8, pos.ToArray());

			// set light color

			Colorf col = new Colorf(0, 1, 1, 0);

			if (useHighLevelShaders)
				services.SetVertexShaderConstant(shaderLightColorId, col.ToArray());
			else
				services.SetVertexShaderConstant(9, col.ToArray());

			// set transposed world matrix

			Matrix transpWorld = driver.GetTransform(TransformationState.World).Transposed;

			if (useHighLevelShaders)
			{
				services.SetVertexShaderConstant(shaderTransWorldId, transpWorld.ToArray());
				services.SetPixelShaderConstant(shaderTextureId, new int[] { 0 });
			}
			else
			{
				services.SetVertexShaderConstant(10, transpWorld.ToArray());
			}
		}
Пример #2
0
        static void gpu_OnSetConstants(MaterialRendererServices services, int userData)
        {
            VideoDriver driver = services.VideoDriver;

            if (useHighLevelShaders && shaderFirstUpdate)
            {
                shaderWorldViewProjId = services.GetVertexShaderConstantID("mWorldViewProj");
                shaderTransWorldId    = services.GetVertexShaderConstantID("mTransWorld");
                shaderInvWorldId      = services.GetVertexShaderConstantID("mInvWorld");
                shaderLightPosId      = services.GetVertexShaderConstantID("mLightPos");
                shaderLightColorId    = services.GetVertexShaderConstantID("mLightColor");

                // textures id are important only for OpenGL interface
                if (driver.DriverType == DriverType.OpenGL)
                {
                    shaderTextureId = services.GetVertexShaderConstantID("myTexture");
                }

                shaderFirstUpdate = false;
            }

            // set inverted world matrix
            // if we are using highlevel shaders (the user can select this when
            // starting the program), we must set the constants by name

            Matrix invWorld = driver.GetTransform(TransformationState.World);

            invWorld.MakeInverse();

            if (useHighLevelShaders)
            {
                services.SetVertexShaderConstant(shaderInvWorldId, invWorld.ToArray());
            }
            else
            {
                services.SetVertexShaderConstant(0, invWorld.ToArray());
            }

            // set clip matrix

            Matrix worldViewProj = driver.GetTransform(TransformationState.Projection);

            worldViewProj *= driver.GetTransform(TransformationState.View);
            worldViewProj *= driver.GetTransform(TransformationState.World);

            if (useHighLevelShaders)
            {
                services.SetVertexShaderConstant(shaderWorldViewProjId, worldViewProj.ToArray());
            }
            else
            {
                services.SetVertexShaderConstant(4, worldViewProj.ToArray());
            }

            // set camera position

            Vector3Df pos = device.SceneManager.ActiveCamera.AbsolutePosition;

            if (useHighLevelShaders)
            {
                services.SetVertexShaderConstant(shaderLightPosId, pos.ToArray());
            }
            else
            {
                services.SetVertexShaderConstant(8, pos.ToArray());
            }

            // set light color

            Colorf col = new Colorf(0, 1, 1, 0);

            if (useHighLevelShaders)
            {
                services.SetVertexShaderConstant(shaderLightColorId, col.ToArray());
            }
            else
            {
                services.SetVertexShaderConstant(9, col.ToArray());
            }

            // set transposed world matrix

            Matrix transpWorld = driver.GetTransform(TransformationState.World).Transposed;

            if (useHighLevelShaders)
            {
                services.SetVertexShaderConstant(shaderTransWorldId, transpWorld.ToArray());
                services.SetPixelShaderConstant(shaderTextureId, new int[] { 0 });
            }
            else
            {
                services.SetVertexShaderConstant(10, transpWorld.ToArray());
            }
        }
Пример #3
0
        void OnShaderSet(MaterialRendererServices services, int userData)
        {
            if (userData == 2 || userData == 3) //All DirectX Shaders
            {
                Matrix4 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);
        }