本文整理汇总了C#中Device.SetSamplerState方法的典型用法代码示例。如果您正苦于以下问题:C# Device.SetSamplerState方法的具体用法?C# Device.SetSamplerState怎么用?C# Device.SetSamplerState使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Device
的用法示例。
在下文中一共展示了Device.SetSamplerState方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Render
private RenderInfo[] Render(Device dev, MatrixStack transform, EditorCamera cam)
{
List<RenderInfo> result = new List<RenderInfo>();
if (!enabled)
return result.ToArray();
float dist = cam.Position.Distance(affectedPoint.ToVector3()) * 0.0825f;
BoundingSphere gizmoSphere = new BoundingSphere() { Center = new Vertex(affectedPoint.X, affectedPoint.Y, affectedPoint.Z), Radius = (1.0f * Math.Abs(dist)) };
#region Setting Render States
dev.SetSamplerState(0, SamplerStageStates.MinFilter, (int)TextureFilter.Point); // no fancy filtering is required because no textures are even being used
dev.SetSamplerState(0, SamplerStageStates.MagFilter, (int)TextureFilter.Point);
dev.SetSamplerState(0, SamplerStageStates.MipFilter, (int)TextureFilter.Point);
dev.SetRenderState(RenderStates.Lighting, true);
dev.SetRenderState(RenderStates.SpecularEnable, false);
dev.SetRenderState(RenderStates.Ambient, Color.White.ToArgb());
dev.SetRenderState(RenderStates.AlphaBlendEnable, false);
dev.SetRenderState(RenderStates.ColorVertex, false);
dev.Clear(ClearFlags.ZBuffer, 0, 1, 0);
#endregion
transform.Push();
transform.TranslateLocal(affectedPoint.X, affectedPoint.Y, affectedPoint.Z);
if (scaleHandlesToCam) transform.ScaleLocal(Math.Abs(dist), Math.Abs(dist), Math.Abs(dist));
else transform.ScaleLocal(handleSize, handleSize, handleSize);
#region Creating Render Info
RenderInfo xRenderInfo = new RenderInfo(Gizmo.XMoveMesh, 0, transform.Top, (selectedAxes == GizmoSelectedAxes.X_AXIS) ? Gizmo.HighlightMaterial : Gizmo.XMaterial, null, FillMode.Solid, gizmoSphere);
result.Add(xRenderInfo);
RenderInfo yRenderInfo = new RenderInfo(Gizmo.YMoveMesh, 0, transform.Top, (selectedAxes == GizmoSelectedAxes.Y_AXIS) ? Gizmo.HighlightMaterial : Gizmo.YMaterial, null, FillMode.Solid, gizmoSphere);
result.Add(yRenderInfo);
RenderInfo zRenderInfo = new RenderInfo(Gizmo.ZMoveMesh, 0, transform.Top, (selectedAxes == GizmoSelectedAxes.Z_AXIS) ? Gizmo.HighlightMaterial : Gizmo.ZMaterial, null, FillMode.Solid, gizmoSphere);
result.Add(zRenderInfo);
RenderInfo xyRenderInfo = new RenderInfo(Gizmo.XYMoveMesh, 0, transform.Top, (selectedAxes == GizmoSelectedAxes.XY_AXIS) ? Gizmo.HighlightMaterial : Gizmo.DoubleAxisMaterial, null, FillMode.Solid, gizmoSphere);
result.Add(xyRenderInfo);
RenderInfo zxRenderInfo = new RenderInfo(Gizmo.ZXMoveMesh, 0, transform.Top, (selectedAxes == GizmoSelectedAxes.XZ_AXIS) ? Gizmo.HighlightMaterial : Gizmo.DoubleAxisMaterial, null, FillMode.Solid, gizmoSphere);
result.Add(zxRenderInfo);
RenderInfo zyRenderInfo = new RenderInfo(Gizmo.ZYMoveMesh, 0, transform.Top, (selectedAxes == GizmoSelectedAxes.ZY_AXIS) ? Gizmo.HighlightMaterial : Gizmo.DoubleAxisMaterial, null, FillMode.Solid, gizmoSphere);
result.Add(zyRenderInfo);
#endregion
transform.Pop();
return result.ToArray();
}
示例2: Render
// TODO: Consider returning IEnumerable<RenderInfo>
private RenderInfo[] Render(Device dev, MatrixStack transform, EditorCamera cam)
{
List<RenderInfo> result = new List<RenderInfo>();
if (!enabled)
return result.ToArray();
float dist = cam.Position.Distance(position) * 0.0825f;
BoundingSphere gizmoSphere = new BoundingSphere() { Center = new Vertex(position.X, position.Y, position.Z), Radius = (1.0f * Math.Abs(dist)) };
#region Setting Render States
dev.SetSamplerState(0, SamplerStageStates.MinFilter, (int)TextureFilter.Point); // no fancy filtering is required because no textures are even being used
dev.SetSamplerState(0, SamplerStageStates.MagFilter, (int)TextureFilter.Point);
dev.SetSamplerState(0, SamplerStageStates.MipFilter, (int)TextureFilter.Point);
dev.SetRenderState(RenderStates.Lighting, true);
dev.SetRenderState(RenderStates.SpecularEnable, false);
dev.SetRenderState(RenderStates.Ambient, Color.White.ToArgb());
dev.SetRenderState(RenderStates.AlphaBlendEnable, false);
dev.SetRenderState(RenderStates.ColorVertex, false);
dev.Clear(ClearFlags.ZBuffer, 0, 1, 0);
#endregion
transform.Push();
transform.TranslateLocal(position.X, position.Y, position.Z);
transform.RotateXYZLocal(rotation.X, rotation.Y, rotation.Z);
transform.ScaleLocal(Math.Abs(dist), Math.Abs(dist), Math.Abs(dist));
#region Handling Transform Modes
switch (mode)
{
case TransformMode.TRANFORM_MOVE:
{
RenderInfo xRenderInfo = new RenderInfo(Gizmo.XMoveMesh, 0, transform.Top, (selectedAxes == GizmoSelectedAxes.X_AXIS) ? Gizmo.HighlightMaterial : Gizmo.XMaterial, null, FillMode.Solid, gizmoSphere);
result.Add(xRenderInfo);
RenderInfo yRenderInfo = new RenderInfo(Gizmo.YMoveMesh, 0, transform.Top, (selectedAxes == GizmoSelectedAxes.Y_AXIS) ? Gizmo.HighlightMaterial : Gizmo.YMaterial, null, FillMode.Solid, gizmoSphere);
result.Add(yRenderInfo);
RenderInfo zRenderInfo = new RenderInfo(Gizmo.ZMoveMesh, 0, transform.Top, (selectedAxes == GizmoSelectedAxes.Z_AXIS) ? Gizmo.HighlightMaterial : Gizmo.ZMaterial, null, FillMode.Solid, gizmoSphere);
result.Add(zRenderInfo);
if (!isTransformLocal) // this is such a cop-out. I'll try to find a better solution.
{
RenderInfo xyRenderInfo = new RenderInfo(Gizmo.XYMoveMesh, 0, transform.Top, (selectedAxes == GizmoSelectedAxes.XY_AXIS) ? Gizmo.HighlightMaterial : Gizmo.DoubleAxisMaterial, null, FillMode.Solid, gizmoSphere);
result.Add(xyRenderInfo);
RenderInfo zxRenderInfo = new RenderInfo(Gizmo.ZXMoveMesh, 0, transform.Top, (selectedAxes == GizmoSelectedAxes.XZ_AXIS) ? Gizmo.HighlightMaterial : Gizmo.DoubleAxisMaterial, null, FillMode.Solid, gizmoSphere);
result.Add(zxRenderInfo);
RenderInfo zyRenderInfo = new RenderInfo(Gizmo.ZYMoveMesh, 0, transform.Top, (selectedAxes == GizmoSelectedAxes.ZY_AXIS) ? Gizmo.HighlightMaterial : Gizmo.DoubleAxisMaterial, null, FillMode.Solid, gizmoSphere);
result.Add(zyRenderInfo);
}
}
break;
case TransformMode.TRANSFORM_ROTATE:
{
RenderInfo xRenderInfo = new RenderInfo(Gizmo.XRotateMesh, 0, transform.Top, (selectedAxes == GizmoSelectedAxes.X_AXIS) ? Gizmo.HighlightMaterial : Gizmo.XMaterial, null, FillMode.Solid, gizmoSphere);
result.Add(xRenderInfo);
RenderInfo yRenderInfo = new RenderInfo(Gizmo.YRotateMesh, 0, transform.Top, (selectedAxes == GizmoSelectedAxes.Y_AXIS) ? Gizmo.HighlightMaterial : Gizmo.YMaterial, null, FillMode.Solid, gizmoSphere);
result.Add(yRenderInfo);
RenderInfo zRenderInfo = new RenderInfo(Gizmo.ZRotateMesh, 0, transform.Top, (selectedAxes == GizmoSelectedAxes.Z_AXIS) ? Gizmo.HighlightMaterial : Gizmo.ZMaterial, null, FillMode.Solid, gizmoSphere);
result.Add(zRenderInfo);
}
break;
case TransformMode.NONE:
{
RenderInfo xRenderInfo = new RenderInfo(Gizmo.XNullMesh, 0, transform.Top, Gizmo.XMaterial, null, FillMode.Solid, gizmoSphere);
result.Add(xRenderInfo);
RenderInfo yRenderInfo = new RenderInfo(Gizmo.YNullMesh, 0, transform.Top, Gizmo.YMaterial, null, FillMode.Solid, gizmoSphere);
result.Add(yRenderInfo);
RenderInfo zRenderInfo = new RenderInfo(Gizmo.ZNullMesh, 0, transform.Top, Gizmo.ZMaterial, null, FillMode.Solid, gizmoSphere);
result.Add(zRenderInfo);
}
break;
case TransformMode.TRANSFORM_SCALE:
{
RenderInfo xRenderInfo = new RenderInfo(Gizmo.XScaleMesh, 0, transform.Top, (selectedAxes == GizmoSelectedAxes.X_AXIS) ? Gizmo.HighlightMaterial : Gizmo.XMaterial, null, FillMode.Solid, gizmoSphere);
result.Add(xRenderInfo);
RenderInfo yRenderInfo = new RenderInfo(Gizmo.YScaleMesh, 0, transform.Top, (selectedAxes == GizmoSelectedAxes.Y_AXIS) ? Gizmo.HighlightMaterial : Gizmo.YMaterial, null, FillMode.Solid, gizmoSphere);
result.Add(yRenderInfo);
RenderInfo zRenderInfo = new RenderInfo(Gizmo.ZScaleMesh, 0, transform.Top, (selectedAxes == GizmoSelectedAxes.Z_AXIS) ? Gizmo.HighlightMaterial : Gizmo.ZMaterial, null, FillMode.Solid, gizmoSphere);
result.Add(zRenderInfo);
}
break;
}
#endregion
transform.Pop();
return result.ToArray();
}
示例3: RunLoop
public void RunLoop()
{
RunLoopCreated = true;
mRunThread = new System.Threading.Thread(() =>
{
ParentForm.Visible = true;
ParentForm.Visible = false;
var ctrl = mRenderWindow;
mDriver = new Direct3D();
mDevice = new Device(mDriver, 0, DeviceType.Hardware, ctrl.Handle, CreateFlags.HardwareVertexProcessing
| CreateFlags.Multithreaded,
new PresentParameters()
{
Windowed = true,
BackBufferFormat = Format.A8R8G8B8,
BackBufferHeight = ctrl.ClientSize.Height,
BackBufferWidth = ctrl.ClientSize.Width,
EnableAutoDepthStencil = true,
AutoDepthStencilFormat = Format.D24S8,
SwapEffect = SwapEffect.Discard,
DeviceWindowHandle = ctrl.Handle,
}
);
mDevice.SetTransform(TransformState.Projection, Matrix.PerspectiveFovLH((45.0f * (float)Math.PI) / 180.0f, ctrl.ClientSize.Width / (float)ctrl.ClientSize.Height, 0.1f, 100000.0f));
mDevice.SetRenderState(RenderState.Lighting, false);
mDevice.SetRenderState(RenderState.ZEnable, true);
mDevice.SetRenderState(RenderState.CullMode, Cull.None);
mDevice.SetSamplerState(0, SamplerState.MinFilter, TextureFilter.Linear);
mDevice.SetSamplerState(0, SamplerState.MagFilter, TextureFilter.Linear);
mDevice.SetSamplerState(0, SamplerState.MipFilter, TextureFilter.Linear);
InputManager = new Video.Input.InputManager();
InputManager.InputWindow = ctrl;
Camera = new ModelCamera(ctrl, this);
TextureManager = new Video.TextureManager(mDevice);
Application.Idle += (sender, args) =>
{
if (ParentForm.Visible == false)
return;
MSG msg = new MSG();
while (!PeekMessage(ref msg, IntPtr.Zero, 0, 0, 0))
RenderFrame();
};
if (LoadDone != null)
LoadDone();
LoadEvent.Set();
ParentForm.Visible = true;
Application.Run(ParentForm);
}
);
mRunThread.Start();
Game.GameManager.GameTerminated += () =>
{
if (ParentForm.IsDisposed == false)
ParentForm.Invoke(new Action(ParentForm.Dispose));
};
}
示例4: Reset
public void Reset()
{
try
{
pps.BackBufferWidth = renderTarget.Width;
pps.BackBufferHeight = renderTarget.Height;
if (device != null)
device.Dispose();
if (texture != null)
texture.Dispose();
if (vertexBuffer != null)
vertexBuffer.Dispose();
device = new SlimDX.Direct3D9.Device(d3d, 0, SlimDX.Direct3D9.DeviceType.Hardware, renderTarget.Handle, CreateFlags.HardwareVertexProcessing, pps);
texture = new Texture(device, imageScaler.ResizedX, imageScaler.ResizedY, 0, Usage.Dynamic, Format.X8R8G8B8, Pool.Default);
LoadCharSheet();
vertexBuffer = new VertexBuffer(device, 4 * Marshal.SizeOf(typeof(Vertex)), Usage.WriteOnly, VertexFormat.PositionRhw | VertexFormat.Texture1, Pool.Managed);
DataStream stream = vertexBuffer.Lock(0, 0, LockFlags.None);
Vertex[] vertexData = new Vertex[4];
vertexData[0].PositionRhw = new Vector4(renderTarget.Width, renderTarget.Height, 0f, 1f);
vertexData[0].Texture1 = new Vector2(1f, 1f);
vertexData[1].PositionRhw = new Vector4(0f, renderTarget.Height, 0f, 1f);
vertexData[1].Texture1 = new Vector2(0f, 1f);
vertexData[2].PositionRhw = new Vector4(renderTarget.Width, 0f, 0f, 1f);
vertexData[2].Texture1 = new Vector2(1f, 0f);
vertexData[3].PositionRhw = new Vector4(0f, 0f, 0f, 1f);
vertexData[3].Texture1 = new Vector2(0f, 0f);
stream.WriteRange(vertexData);
vertexBuffer.Unlock();
device.VertexFormat = VertexFormat.PositionRhw | VertexFormat.Texture1;
device.SetStreamSource(0, vertexBuffer, 0, Marshal.SizeOf(typeof(Vertex)));
if (smoothOutput)
device.SetSamplerState(0, SamplerState.MagFilter, TextureFilter.Linear);
else
device.SetSamplerState(0, SamplerState.MagFilter, TextureFilter.Point);
device.SetSamplerState(0, SamplerState.AddressU, TextureAddress.Clamp);
device.SetSamplerState(0, SamplerState.AddressV, TextureAddress.Clamp);
device.SetSamplerState(0, SamplerState.AddressW, TextureAddress.Clamp);
device.SetTexture(0, texture);
}
catch (Direct3D9Exception e)
{
device = null;
}
}
示例5: changeTextureFiltering
private void changeTextureFiltering(Device d3dDevice, string filtering)
{
if (filtering == "Nearest")
{
d3dDevice.SetSamplerState(0, SamplerStageStates.MinFilter, (int)TextureFilter.Point);
d3dDevice.SetSamplerState(0, SamplerStageStates.MagFilter, (int)TextureFilter.Point);
d3dDevice.SetSamplerState(0, SamplerStageStates.MipFilter, (int)TextureFilter.Point);
}
else if (filtering == "Linear")
{
d3dDevice.SetSamplerState(0, SamplerStageStates.MinFilter, (int)TextureFilter.Linear);
d3dDevice.SetSamplerState(0, SamplerStageStates.MagFilter, (int)TextureFilter.Linear);
d3dDevice.SetSamplerState(0, SamplerStageStates.MipFilter, (int)TextureFilter.Linear);
}
else if (filtering == "Bilinear")
{
d3dDevice.SetSamplerState(0, SamplerStageStates.MinFilter, (int)TextureFilter.GaussianQuad);
d3dDevice.SetSamplerState(0, SamplerStageStates.MagFilter, (int)TextureFilter.GaussianQuad);
d3dDevice.SetSamplerState(0, SamplerStageStates.MipFilter, (int)TextureFilter.GaussianQuad);
}
else if (filtering == "Anisotropic")
{
d3dDevice.SetSamplerState(0, SamplerStageStates.MinFilter, (int)TextureFilter.Anisotropic);
d3dDevice.SetSamplerState(0, SamplerStageStates.MagFilter, (int)TextureFilter.Anisotropic);
d3dDevice.SetSamplerState(0, SamplerStageStates.MipFilter, (int)TextureFilter.Anisotropic);
}
}
示例6: Renderer
public Renderer(Control control)
{
PresentParameters presentParams = new PresentParameters();
presentParams.Windowed = true;
presentParams.BackBufferCount = 0;
presentParams.BackBufferWidth = Screen.PrimaryScreen.WorkingArea.Width;
presentParams.BackBufferHeight = Screen.PrimaryScreen.WorkingArea.Height;
Device = new Device(new Direct3D(), 0, DeviceType.Hardware, control.Handle, CreateFlags.SoftwareVertexProcessing, presentParams);
if ((Device.Capabilities.VertexProcessingCaps & VertexProcessingCaps.Tweening) == 0)
{
Report.ReportLog("Vertex tweening is not supported!");
}
Device.SetRenderState(RenderState.Lighting, true);
Device.SetRenderState(RenderState.DiffuseMaterialSource, ColorSource.Material);
Device.SetRenderState(RenderState.EmissiveMaterialSource, ColorSource.Material);
Device.SetRenderState(RenderState.SpecularMaterialSource, ColorSource.Material);
Device.SetRenderState(RenderState.SpecularEnable, true);
Device.SetRenderState(RenderState.AlphaBlendEnable, true);
Device.SetRenderState(RenderState.BlendOperationAlpha, BlendOperation.Add);
Device.SetRenderState(RenderState.SourceBlend, Blend.SourceAlpha);
Device.SetRenderState(RenderState.DestinationBlend, Blend.InverseSourceAlpha);
Device.SetSamplerState(0, SamplerState.MaxAnisotropy, 4);
Device.SetSamplerState(0, SamplerState.MagFilter, TextureFilter.Anisotropic);
Device.SetSamplerState(0, SamplerState.MinFilter, TextureFilter.Anisotropic);
Device.SetSamplerState(0, SamplerState.MipFilter, TextureFilter.Linear);
Light light = new Light();
light.Type = LightType.Directional;
light.Ambient = new Color4(int.Parse((string)Gui.Config["LightAmbientARGB"], System.Globalization.NumberStyles.AllowHexSpecifier));
light.Diffuse = new Color4(int.Parse((string)Gui.Config["LightDiffuseARGB"], System.Globalization.NumberStyles.AllowHexSpecifier));
light.Specular = new Color4(int.Parse((string)Gui.Config["LightSpecularARGB"], System.Globalization.NumberStyles.AllowHexSpecifier));
Device.SetLight(0, light);
Device.EnableLight(0, true);
TextFont = new SlimDX.Direct3D9.Font(Device, new System.Drawing.Font("Arial", 8));
TextColor = new Color4(Color.White);
CursorMesh = Mesh.CreateSphere(Device, 1, 10, 10);
CursorMaterial = new Material();
CursorMaterial.Ambient = new Color4(1, 1f, 1f, 1f);
CursorMaterial.Diffuse = new Color4(1, 0.6f, 1, 0.3f);
showNormals = (bool)Gui.Config["ShowNormals"];
showBones = (bool)Gui.Config["ShowBones"];
string[] mode = Enum.GetNames(typeof(ShowBoneWeights));
for (int i = 0; i < mode.Length; i++)
{
if (mode[i] == (string)Gui.Config["ShowBoneWeights"])
{
showBoneWeights = (ShowBoneWeights)i;
break;
}
}
wireframe = (bool)Gui.Config["Wireframe"];
culling = (bool)Gui.Config["Culling"];
Background = Color.FromArgb(int.Parse((string)Gui.Config["RendererBackgroundARGB"], System.Globalization.NumberStyles.AllowHexSpecifier));
isInitialized = true;
camera = new Camera(control);
RenderControl = control;
}
示例7: Initialize
public static void Initialize(IntPtr windowHandle)
{
handle = windowHandle;
device = new Device(new Direct3D(), 0, DeviceType.Hardware, handle, CreateFlags.SoftwareVertexProcessing, new PresentParameters()
{
//PresentationInterval = PresentInterval.One,
BackBufferWidth = 512,
BackBufferHeight = 512
});
device.SetDialogBoxMode(false);
device.SetTextureStageState(0, TextureStage.ColorOperation, TextureOperation.SelectArg1);
device.SetTextureStageState(0, TextureStage.ColorArg1, TextureArgument.Texture);
device.SetTextureStageState(0, TextureStage.ColorArg2, TextureArgument.Diffuse);
device.SetTextureStageState(0, TextureStage.AlphaOperation, TextureOperation.SelectArg1);
device.SetTextureStageState(0, TextureStage.AlphaArg1, TextureArgument.Texture);
device.SetTextureStageState(0, TextureStage.AlphaArg2, TextureArgument.Diffuse);
device.SetRenderState(RenderState.Lighting, false);
device.SetRenderState(RenderState.ZEnable, false);
device.SetRenderState(RenderState.CullMode, Cull.None);
device.SetRenderState(RenderState.SourceBlend, Blend.SourceAlpha);
device.SetRenderState(RenderState.DestinationBlend, Blend.InverseSourceAlpha);
device.SetRenderState(RenderState.AlphaBlendEnable, false);
device.SetSamplerState(0, SamplerState.MinFilter, TextureFilter.Linear);
device.SetSamplerState(0, SamplerState.MagFilter, TextureFilter.Linear);
device.VertexFormat = VertexFormat.PositionRhw | VertexFormat.Texture1;
vertex = new VertexBuffer(device, 4 * 24, Usage.WriteOnly | Usage.Dynamic, VertexFormat.None, Pool.Default);
texture = new Texture(device, 512, 512, 1, Usage.Dynamic, Format.X8R8G8B8, Pool.Default);
device.Clear(ClearFlags.Target | ClearFlags.ZBuffer, Color.Black, 1.0f, 0);
device.Present();
}
示例8: RenderBloom
public void RenderBloom(Device device, Effect effect)
{
BrightPassFilter(device, effect);
Surface orgTarget = device.GetRenderTarget(0);
Vector2[] sampleOffsets = new Vector2[16];
Vector4[] sampleWeights = new Vector4[16];
float[] afSampleOffsets = new float[16];
Surface surfDest = BloomTex[1].GetSurfaceLevel(0);
SurfaceDescription desc = BrightPassTex.GetSurfaceLevel(0).Description;
Surface OriginalDS = device.DepthStencilSurface;
device.DepthStencilSurface = Renderer.Instance.RenderDepthSurface;
GetSampleOffsets_Bloom(desc.Width, afSampleOffsets, ref sampleWeights, 3.0f, 1.25f);
for (int i = 0; i < 16; i++)
{
sampleOffsets[i] = new Vector2(afSampleOffsets[i], 0f);
}
effect.Technique = "Bloom";
effect.SetValue("g_avSampleWeights", sampleWeights);
effect.SetValue<Vector2>(new EffectHandle("g_avSampleOffsets"), sampleOffsets);
device.SetRenderTarget(0, surfDest);
device.SetTexture(0, BrightPassTex);
device.SetSamplerState(0, SamplerState.MinFilter, (int)TextureFilter.Point);
device.SetSamplerState(0, SamplerState.MagFilter, (int)TextureFilter.Point);
Renderer.Instance.DrawFullScreenQuad();
device.SetTexture(0, null);
surfDest.Dispose();
surfDest = BloomTex[0].GetSurfaceLevel(0);
GetSampleOffsets_Bloom(desc.Height, afSampleOffsets, ref sampleWeights, 3.0f, 1.25f);
for (int i = 0; i < 16; i++)
{
sampleOffsets[i] = new Vector2(0f, afSampleOffsets[i]);
}
effect.Technique = "Bloom";
effect.SetValue("g_avSampleWeights", sampleWeights);
effect.SetValue<Vector2>(new EffectHandle("g_avSampleOffsets"), sampleOffsets);
device.SetRenderTarget(0, surfDest);
device.SetTexture(0, BloomTex[1]);
Renderer.Instance.DrawFullScreenQuad();
device.SetTexture(0, null);
device.SetRenderTarget(0, orgTarget);
device.DepthStencilSurface = OriginalDS;
}
示例9: BrightPassFilter
private void BrightPassFilter(Device device, Effect effect)
{
Surface OriginalDS = device.DepthStencilSurface;
device.DepthStencilSurface = Renderer.Instance.RenderDepthSurface;
Vector2[] sampleOffsets = new Vector2[16];
Surface brightPassSurface = BrightPassTex.GetSurfaceLevel(0);
SurfaceDescription backbufDescr = Renderer.Instance.RenderSurface.Description;
GetSampleOffsetsets_DownScale3x3(backbufDescr.Width / 2, backbufDescr.Height / 2, ref sampleOffsets);
effect.SetValue<Vector2>(new EffectHandle("g_avSampleOffsets"), sampleOffsets);
effect.Technique = "DownScale3x3_BrightPass_RGBE8";
Surface orgTarget = device.GetRenderTarget(0);
device.SetRenderTarget(0, brightPassSurface);
device.SetTexture(0, Renderer.Instance.RenderTexture);
device.SetTexture(1, Renderer.Instance.AvgLum);
device.SetSamplerState(0, SamplerState.MagFilter, (int)TextureFilter.Linear);
device.SetSamplerState(0, SamplerState.MinFilter, (int)TextureFilter.Linear);
Renderer.Instance.DrawFullScreenQuad();
device.SetTexture(0, null);
device.SetTexture(1, null);
device.SetRenderTarget(0, orgTarget);
device.DepthStencilSurface = OriginalDS;
}
示例10: MeasureLuminance
public void MeasureLuminance(Effect effect, Device device)
{
Surface OriginalRenderTarget = device.GetRenderTarget(0);
Vector2[] sampleOffsets = new Vector2[16];
Texture dest = ToneMapTex[nToneMapTex - 1];
SurfaceDescription destDescr = dest.GetLevelDescription(0);
SurfaceDescription sourceDescr = Renderer.Instance.RenderSurface.Description;
GetSampleOffsets_DownScale2x2_Lum(sourceDescr.Width, sourceDescr.Height, destDescr.Width, destDescr.Height, ref sampleOffsets);
effect.SetValue<Vector2>(new EffectHandle("g_avSampleOffsets"), sampleOffsets);
effect.Technique = "DownScale2x2_Lum_RGBE8";
Surface destSurface = dest.GetSurfaceLevel(0);
device.SetRenderTarget(0, destSurface);
Surface OriginalDS = device.DepthStencilSurface;
device.DepthStencilSurface = Renderer.Instance.RenderDepthSurface;
device.SetSamplerState(0, SamplerState.MagFilter, (int)TextureFilter.Linear);
device.SetSamplerState(0, SamplerState.MinFilter, (int)TextureFilter.Linear);
device.SetTexture(0, Renderer.Instance.RenderTexture);
Renderer.Instance.DrawFullScreenQuad();
device.SetTexture(0, null);
effect.Technique = "DownScale3x3_RGBE8";
for (int i = nToneMapTex - 1; i > 0; i--)
{
Surface source = ToneMapTex[i].GetSurfaceLevel(0);
dest = ToneMapTex[i - 1];
destSurface = dest.GetSurfaceLevel(0);
GetSampleOffsetsets_DownScale3x3(destSurface.Description.Width, destSurface.Description.Height, ref sampleOffsets);
effect.SetValue<Vector2>(new EffectHandle("g_avSampleOffsets"), sampleOffsets);
device.SetRenderTarget(0, destSurface);
device.SetTexture(0, ToneMapTex[i]);
//device.SetSamplerState(0, SamplerStageStates.MagFilter, (int)TextureFilter.Point);
//device.SetSamplerState(0, SamplerStageStates.MinFilter, (int)TextureFilter.Point);
Renderer.Instance.DrawFullScreenQuad();
device.SetTexture(0, null);
}
// Add calculated luminance to average
if (CurrentAvgToneMap == -1)
{
Rectangle avgrect = new Rectangle(new Point(), new Size(1, 1));
device.StretchRectangle(ToneMapTex[0].GetSurfaceLevel(0), avgrect, avgToneMap[0].GetSurfaceLevel(0), avgrect, TextureFilter.Point);
CurrentAvgToneMap = 0;
}
else
{
effect.Technique = "CalcAvgLum_RGBE8";
device.SetTexture(0, avgToneMap[CurrentAvgToneMap]); // "main" average
int other = (CurrentAvgToneMap == 0 ? 1 : 0);
device.SetTexture(1, ToneMapTex[0]); // new average to be added
Surface surf = avgToneMap[other].GetSurfaceLevel(0);
device.SetRenderTarget(0, surf); // unused "main" average texture used as rendertarget
Renderer.Instance.DrawFullScreenQuad();
device.SetTexture(0, null);
device.SetTexture(1, null);
CurrentAvgToneMap = other; // swap avgTonemap usage next frame
}
device.SetRenderTarget(0, OriginalRenderTarget);
device.DepthStencilSurface = OriginalDS;
// Read result
device.GetRenderTargetData(AverageLum.GetSurfaceLevel(0), LockableAverage.GetSurfaceLevel(0));
DataRectangle rect = LockableAverage.LockRectangle(0, LockFlags.ReadOnly);
Color4 color = new Color4(rect.Data.Read<int>());
LockableAverage.UnlockRectangle(0);
// Revert LogLum encoding
float invLogLumRange = 1.0f / (MaxLogLum + MinLogLum);
float logLumOffset = MinLogLum * invLogLumRange;
double avgLum = Math.Exp((color.Alpha) / (invLogLumRange + logLumOffset));
effect.SetValue("avgLogLum", avgLum);
//System.Console.WriteLine(avgLum);
}
示例11: Render
/// <summary>Renders the view.</summary>
public void Render(Device device)
{
device.SetRenderState(RenderState.CullMode, Cull.None);
device.SetRenderState(RenderState.ZEnable, ZBufferType.DontUseZBuffer);
device.SetRenderState(RenderState.ZWriteEnable, false);
device.SetSamplerState(0, SamplerState.MinFilter, TextureFilter.Point);
device.SetSamplerState(0, SamplerState.MagFilter, _useLinearFiltering ? TextureFilter.Linear : TextureFilter.Point);
device.SetSamplerState(0, SamplerState.MipFilter, TextureFilter.Point);
device.SetRenderState(RenderState.ShadeMode, ShadeMode.Flat);
device.SetRenderState(RenderState.FillMode, FillMode.Solid);
device.SetRenderState(RenderState.Lighting, false);
device.SetTexture(0, _viewTexture);
device.SetStreamSource(0, _vertexBuffer, 0, Marshal.SizeOf(typeof(DX9TransformedColorTexture)));
device.VertexDeclaration = _vertexDeclaration;
device.DrawPrimitives(PrimitiveType.TriangleStrip, 0, 2);
}