示例#1
0
            public void SetSamplers(VertexShaderType shaderType, int slot, SamplerState[] samplers)
            {
                if (slot < 0)
                {
                    return;
                }
                int  idx        = SamplerCheckVertexShaderStartIdx + slot;
                bool needUpdate = false;

                for (int i = 0; i < samplers.Length; ++i)
                {
                    if (SamplerStateCheck[idx + i] != samplers[i])
                    {
                        needUpdate = true;
                        break;
                    }
                }
                if (needUpdate)
                {
                    for (int i = 0; i < samplers.Length; ++i)
                    {
                        SamplerStateCheck[idx + i] = samplers[i];
                    }
                    deviceContext.VertexShader.SetSamplers(slot, samplers);
                }
            }
示例#2
0
 public void SetShaderResources(VertexShaderType shaderType, int slot, ShaderResourceView[] texture)
 {
     if (slot < 0)
     {
         return;
     }
     deviceContext.VertexShader.SetShaderResources(slot, texture);
 }
示例#3
0
 public void SetSamplers(VertexShaderType shaderType, int slot, SamplerState[] samplers)
 {
     if (slot < 0)
     {
         return;
     }
     deviceContext.VertexShader.SetSamplers(slot, samplers);
 }
示例#4
0
            public void SetSampler(VertexShaderType shaderType, int slot, SamplerState sampler)
            {
                if (slot < 0)
                {
                    return;
                }
                int idx = SamplerCheckVertexShaderStartIdx + slot;

                if (SamplerStateCheck[idx] != sampler)
                {
                    SamplerStateCheck[idx] = sampler;
                    deviceContext.VertexShader.SetSampler(slot, sampler);
                }
            }
 /// <summary>
 /// Adds a new material renderer to the VideoDriver, based on a high level shading language. Currently only HLSL/D3D9 and GLSL/OpenGL is supported. 
 /// </summary>
 /// <param name="vsprogram">String containing the source of the vertex shader program. This can be "" if no vertex program should be used. </param>
 /// <param name="ventrypoint">Name of the function of the vertexShaderProgram </param>
 /// <param name="vsCompileTarget">Vertex shader version where the high level shader should be compiled to. </param>
 /// <param name="psprogram">String containing the source of the pixel shader program. This can be "" if no pixel shader should be used.</param>
 /// <param name="psEntryPoint">Entry name of the function of the pixelShaderEntryPointName </param>
 /// <param name="psCompileTarget">Pixel shader version where the high level shader should be compiled to. </param>
 /// <param name="callback">Delegate in which you can set the needed vertex and pixel shader program constants.</param>
 /// <param name="baseMat">Base material which renderstates will be used to shade the material. </param>
 /// <param name="userData">An user data int. This int can be set to any value and will be set as parameter in the callback method when calling OnSetConstants(). In this way it is easily possible to use the same delegate method for multiple materials and distinguish between them during the call.</param>
 /// <returns>The Material to use with SetMaterial (with a C-style explicit cast). -1 if failed</returns>
 public int AddHighLevelShaderMaterial(string vsprogram, string ventrypoint, VertexShaderType vsCompileTarget, string psprogram, string psEntryPoint, PixelShaderType psCompileTarget, OnShaderConstantSetDelegate callback, MaterialType baseMat, int userData)
 {
     //WORKAROUND : Bug found by DeusXL, little workaround I don't like at all but needed !
     string vsfilename = System.IO.Path.GetTempFileName();
     StreamWriter vssw = new StreamWriter(vsfilename, false);
     string psfilename = System.IO.Path.GetTempFileName();
     StreamWriter pssw = new StreamWriter(psfilename, false);
     vssw.WriteLine(vsprogram);
     pssw.WriteLine(psprogram);
     vssw.Close();
     pssw.Close();
     int ret = AddHighLevelShaderMaterialFromFiles(vsfilename, ventrypoint, vsCompileTarget, psfilename, psEntryPoint, psCompileTarget, callback, baseMat, userData);
     try { File.Delete(vsfilename); File.Delete(psfilename); }
     catch (Exception) { }
     return ret;
 }
示例#6
0
 public VertexShader GetShader(VertexShaderType type)
 {
     return(VertexShader);
 }
 /// <summary>
 /// Adds a new material renderer to the VideoDriver, based on a high level shading language. Currently only HLSL/D3D9 and GLSL/OpenGL is supported. 
 /// </summary>
 /// <param name="program">String containing the path to the vertex shader program. This can be "" (empty string) if no vertex program should be used. </param>
 /// <param name="ventrypoint">Name of the function of the vertexShaderProgram </param>
 /// <param name="vsCompileTarget">Vertex shader version where the high level shader should be compiled to. </param>
 /// <param name="pixelShaderProgram">String containing the path to the pixel shader program. This can be "" (empty string) if no pixel shader should be used.</param>
 /// <param name="psEntryPoint">Entry name of the function of the pixelShaderEntryPointName </param>
 /// <param name="psCompileTarget">Pixel shader version where the high level shader should be compiled to. </param>
 /// <param name="callback">Delegate in which you can set the needed vertex and pixel shader program constants.</param>
 /// <param name="baseMat">Base material which renderstates will be used to shade the material. </param>
 /// <param name="userData">An user data int. This int can be set to any value and will be set as parameter in the callback method when calling OnSetConstants(). In this way it is easily possible to use the same delegate method for multiple materials and distinguish between them during the call.</param>
 /// <returns>The Material to use with SetMaterial (with a C-style explicit cast). -1 if failed</returns>
 public int AddHighLevelShaderMaterialFromFiles(string program, string ventrypoint, VertexShaderType vsCompileTarget, string pixelShaderProgram, string psEntryPoint, PixelShaderType psCompileTarget, OnShaderConstantSetDelegate callback, MaterialType baseMat, int userData)
 {
     return GPU_AddHighLevelShaderMaterialFromFiles(_raw, program, ventrypoint, vsCompileTarget, pixelShaderProgram, psEntryPoint, psCompileTarget, new ShaderConstantCallback(callback).OnNativeShaderConstant, baseMat, userData);
 }
 static extern int GPU_AddHighLevelShaderMaterialFromFiles(IntPtr gpu, string file, string ventrypoint, VertexShaderType vsCompileTarget, string psfile, string psEntryPoint, PixelShaderType psCompileTarget, OnNativeSCSD callback, MaterialType baseMat, int userData);
示例#9
0
 public SamplerState[] GetSampler(VertexShaderType shaderType, int startSlot, int num)
 {
     return(deviceContext.VertexShader.GetSamplers(startSlot, num));
 }
示例#10
0
 public ShaderResourceView[] GetShaderResources(VertexShaderType shaderType, int startSlot, int num)
 {
     return(deviceContext.VertexShader.GetShaderResources(startSlot, num));
 }
		public static ParticleSystemCompiledShaderData BuildGpuLogicPixelShader(IEnumerable<ParticleSystemLogicStep> steps, LogicType logicType, VertexShaderType vsType, bool useUserValues, bool useColours, bool storeLifeData, ContentTargetPlatform targetPlatform, bool useUserDataPositionBuffer, string pathToShaderSystem)
		{
			if (steps == null)
				throw new ArgumentNullException();

			StringBuilder output = new StringBuilder();
			Random random = new Random();

			foreach (ParticleSystemLogicStep step in steps)
				BuildStep(step, output, 1, random);

			//fixup the preprocssor defines
			string shaderCodeFixup = GpuParticleShaderBuilder.BaseShader.Replace("_#", "#");

			//insert the custom code
			string shaderCode = shaderCodeFixup.Replace(GpuParticleShaderBuilder.replaceMarker, output.ToString());

			//build the shader header and main method.

			StringBuilder header = new StringBuilder();
			StringBuilder methodHeader = new StringBuilder();
			StringBuilder methodPS = new StringBuilder();

			methodPS.Append("void PS(float4 texRandIndex : TEXCOORD0");

			if (logicType != LogicType.Frame)
				methodPS.Append(", float4 lifeIndex : TEXCOORD1");
			else
				methodHeader.Append("float4 lifeIndex = 0;");

			if (logicType == LogicType.Once)
			{
				methodPS.Append(", float4 defaultPosition : TEXCOORD2");
				methodPS.Append(", float4 defaultVelocity : TEXCOORD3");
				methodPS.Append(", float4 defaultColour   : TEXCOORD4");
				methodPS.Append(", float4 defaultUserData : TEXCOORD5");
			}
			else
			{
				methodHeader.Append("float4 defaultPosition = 0, defaultVelocity = 0;");
				methodHeader.Append("float4 defaultColour = 1, defaultUserData = 0;");
			}

			int colIndex = 2;

			methodPS.Append(", out float4 posOut : COLOR0, out float4 velOut : COLOR1");


			if (useColours)
				methodPS.AppendFormat(", out float4 colOut : COLOR{0}", colIndex++);
			else
				methodHeader.Append("float4 colOut = 1;");

			if (useUserValues)
				methodPS.AppendFormat(", out float4 userOut : COLOR{0}", colIndex++);
			else
				methodHeader.Append("float4 userOut = 0;");

			methodPS.AppendLine(")");
			methodPS.AppendLine("{");
			methodPS.Append("\t");
			methodPS.Append(methodHeader);
			methodPS.AppendLine();

			methodPS.Append("\t");
			methodPS.AppendLine(@"PS_Method(texRandIndex,lifeIndex, defaultPosition, defaultVelocity, defaultColour, defaultUserData,posOut, velOut, colOut, userOut);");
			methodPS.AppendLine("}");

			int colourIndex = -1, userIndex = -1, lifeIndex = -1;

			if (logicType != LogicType.Once)
			{
				int samplerIndex = 3;
				header.AppendLine();
				header.AppendLine("#define TEXTURE_PARTICLE_METHOD");
				if (useColours)
				{
					colourIndex = samplerIndex;
					header.AppendLine("#define USER_COLOUR_TEX");
					header.AppendLine(string.Format(@"sampler2D ColourSampler : register(ps,s{0});", samplerIndex++));
				}
				if (useUserValues)
				{
					userIndex = samplerIndex;
					header.AppendLine("#define USER_USER_TEX");
					header.AppendLine(string.Format(@"sampler2D UserSampler : register(ps,s{0});", samplerIndex++));
				}
				if (storeLifeData && logicType == LogicType.Frame)
				{
					lifeIndex = samplerIndex;
					header.AppendLine("#define USER_LIFE_TEX");
					header.AppendLine(string.Format(@"sampler2D LifeSampler : register(ps,s{0});", samplerIndex++));
				}

				if (logicType == LogicType.Frame || logicType == LogicType.FrameMove)
					header.AppendLine("#define ADD_VELOCITY");
			}

			switch (vsType)
			{
				case VertexShaderType.Clone:
					header.AppendLine("#define VS_CLONE");
					break;
				case VertexShaderType.Frame:
					header.AppendLine("#define VS_FRAME");
					break;
				case VertexShaderType.Once:
					header.AppendLine("#define VS_ONCE");
					break;
			}

			if (useUserDataPositionBuffer)
			{
				header.AppendLine("#define POS_WRITTEN_TO_USER");
			}


			StringBuilder completeShader = new StringBuilder();

			completeShader.Append(header);
			completeShader.AppendLine();
			completeShader.Append(shaderCode);
			completeShader.AppendLine();
			completeShader.Append(methodPS);
			completeShader.AppendLine();
			completeShader.Append(techniqueCode);
			completeShader.AppendLine();


			if (ShaderCompileDelegate == null)
				LinkToShaderCompiler(pathToShaderSystem);

			string errors;
			byte[] shaderBytes = ShaderCompileDelegate(completeShader.ToString(), "", targetPlatform == ContentTargetPlatform.Xbox360, out errors);

			if (errors != null)
				throw new InvalidOperationException("GPU Particle System Pixel Shader failed to compile:" + Environment.NewLine + errors);

			return new ParticleSystemCompiledShaderData(shaderBytes, targetPlatform == ContentTargetPlatform.Xbox360, colourIndex, userIndex, lifeIndex);
		}