本文整理汇总了C#中Camera.GetProjectionMatrix方法的典型用法代码示例。如果您正苦于以下问题:C# Camera.GetProjectionMatrix方法的具体用法?C# Camera.GetProjectionMatrix怎么用?C# Camera.GetProjectionMatrix使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Camera
的用法示例。
在下文中一共展示了Camera.GetProjectionMatrix方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Draw
public void Draw(Camera camera, GameTime gameTime)
{
_device.BlendState = BlendState.Opaque;
_device.DepthStencilState = DepthStencilState.Default;
_effect.CurrentTechnique = _effect.Techniques["Colored"];
_effect.Parameters["xView"].SetValue(camera.GetViewMatrix());
_effect.Parameters["xProjection"].SetValue(camera.GetProjectionMatrix());
_effect.Parameters["xWorld"].SetValue(Matrix.Identity);
Vector3 lightDirection = new Vector3(-1.0f, -2.0f, 4.0f);
lightDirection.Normalize();
_effect.Parameters["xLightDirection"].SetValue(lightDirection);
_effect.Parameters["xAmbient"].SetValue(0.3f);
_effect.Parameters["xEnableLighting"].SetValue(true);
_device.SetVertexBuffer(buffer);
foreach (EffectPass pass in _effect.CurrentTechnique.Passes)
{
pass.Apply();
foreach (var leafNode in _nodes)
{
leafNode.Draw(gameTime);
}
}
}
示例2: Render
public void Render(Camera camera, RenderTarget gbuffer, RenderTarget input, RenderTarget output)
{
if (ShaderParams == null)
{
ShaderParams = new ScreenSpaceReflectionsShaderParams();
Shader.GetUniformLocations(ShaderParams);
}
Matrix4 viewMatrix;
camera.GetViewMatrix(out viewMatrix);
Matrix4 projectionMatrix;
camera.GetProjectionMatrix(out projectionMatrix);
var viewProjectionMatrix = viewMatrix * projectionMatrix;
var cameraClipPlane = new Vector2(camera.NearClipDistance, camera.FarClipDistance);
var itView = Matrix4.Transpose(Matrix4.Invert(viewMatrix));
Backend.BeginPass(output, new Vector4(0.0f, 0.0f, 0.0f, 1.0f));
Backend.BeginInstance(Shader.Handle, new int[] { input.Textures[0].Handle, gbuffer.Textures[1].Handle, gbuffer.Textures[3].Handle },
samplers: new int[] { Backend.DefaultSamplerNoFiltering, Backend.DefaultSamplerNoFiltering, Backend.DefaultSamplerNoFiltering });
Backend.BindShaderVariable(ShaderParams.SamplerScene, 0);
Backend.BindShaderVariable(ShaderParams.SamplerNormal, 1);
Backend.BindShaderVariable(ShaderParams.SamplerDepth, 2);
Backend.BindShaderVariable(ShaderParams.CameraPosition, ref camera.Position);
Backend.BindShaderVariable(ShaderParams.ViewProjectionMatrix, ref projectionMatrix);
Backend.BindShaderVariable(ShaderParams.CameraClipPlane, ref cameraClipPlane);
Backend.BindShaderVariable(ShaderParams.ItView, ref itView);
Backend.DrawMesh(QuadMesh.MeshHandle);
Backend.EndPass();
}
示例3: RenderThread
static unsafe void RenderThread(Sample sample)
{
// initialize the renderer
Bgfx.Init(RendererBackend.Direct3D11);
Bgfx.Reset(sample.WindowWidth, sample.WindowHeight, ResetFlags.Vsync);
// enable debug text
Bgfx.SetDebugFeatures(DebugFeatures.DisplayText);
// load shaders
var programTextureLighting = ResourceLoader.LoadProgram("vs_stencil_texture_lighting", "fs_stencil_texture_lighting");
var programColorLighting = ResourceLoader.LoadProgram("vs_stencil_color_lighting", "fs_stencil_color_lighting");
var programColorTexture = ResourceLoader.LoadProgram("vs_stencil_color_texture", "fs_stencil_color_texture");
var programColorBlack = ResourceLoader.LoadProgram("vs_stencil_color", "fs_stencil_color_black");
var programTexture = ResourceLoader.LoadProgram("vs_stencil_texture", "fs_stencil_texture");
// load meshes
var bunnyMesh = ResourceLoader.LoadMesh("bunny.bin");
var columnMesh = ResourceLoader.LoadMesh("column.bin");
var hplaneMesh = new Mesh(MemoryBlock.FromArray(StaticMeshes.HorizontalPlane), PosNormalTexcoordVertex.Layout, StaticMeshes.PlaneIndices);
var vplaneMesh = new Mesh(MemoryBlock.FromArray(StaticMeshes.VerticalPlane), PosNormalTexcoordVertex.Layout, StaticMeshes.PlaneIndices);
// load textures
var figureTex = ResourceLoader.LoadTexture("figure-rgba.dds");
var flareTex = ResourceLoader.LoadTexture("flare.dds");
var fieldstoneTex = ResourceLoader.LoadTexture("fieldstone-rgba.dds");
// create uniforms
var colorTextureHandle = new Uniform("u_texColor", UniformType.Int1);
var uniforms = new Uniforms();
uniforms.SubmitConstUniforms();
// light colors
uniforms.LightColor = new[] {
new Vector4(1.0f, 0.7f, 0.2f, 0.0f), // yellow
new Vector4(0.7f, 0.2f, 1.0f, 0.0f), // purple
new Vector4(0.2f, 1.0f, 0.7f, 0.0f), // cyan
new Vector4(1.0f, 0.4f, 0.2f, 0.0f) // orange
};
// camera
var camera = new Camera(60.0f, sample.WindowWidth, sample.WindowHeight, 0.1f, 100.0f);
camera.Position = new Vector3(0.0f, 18.0f, -40.0f);
// start the frame clock
var clock = new Clock();
clock.Start();
// main loop
while (sample.ProcessEvents(ResetFlags.Vsync)) {
// tick the clock
var elapsed = clock.Frame();
var time = clock.TotalTime();
// write some debug text
Bgfx.DebugTextClear();
Bgfx.DebugTextWrite(0, 1, DebugColor.White, DebugColor.Blue, "SharpBgfx/Samples/13-Stencil");
Bgfx.DebugTextWrite(0, 2, DebugColor.White, DebugColor.Cyan, "Description: Stencil reflections.");
Bgfx.DebugTextWrite(0, 3, DebugColor.White, DebugColor.Cyan, "Frame: {0:F3} ms", elapsed * 1000);
// clear the background
Bgfx.SetViewClear(BaseId, ClearTargets.Color | ClearTargets.Depth | ClearTargets.Stencil, 0x30303000);
Bgfx.SetViewRect(BaseId, 0, 0, sample.WindowWidth, sample.WindowHeight);
Bgfx.Touch(BaseId);
// set view params for each pass
var viewMtx = camera.GetViewMatrix();
var projMtx = camera.GetProjectionMatrix();
for (byte i = PassId0; i <= PassId4; i++) {
Bgfx.SetViewRect(i, 0, 0, sample.WindowWidth, sample.WindowHeight);
Bgfx.SetViewTransform(i, (float*)&viewMtx, (float*)&projMtx);
}
// first pass - draw ground plane
var floorMtx = FloorTransform;
hplaneMesh.Submit(PassId0, programColorBlack, &floorMtx, StateGroups[PrebuiltRenderState.StencilReflectionCraftStencil], uniforms);
// second pass - reflected objects
Bgfx.SetViewClear(PassId1, ClearTargets.Depth, 0);
uniforms.AmbientPass = true;
uniforms.LightingPass = true;
uniforms.Color = new Vector4(0.70f, 0.65f, 0.60f, 0.8f);
uniforms.LightCount = LightCount;
// light positions
var lightPositions = new Vector4[LightCount];
var reflectedLights = new Vector4[LightCount];
for (int i = 0; i < lightPositions.Length; i++) {
var v3 = new Vector3(
(float)Math.Sin(time * 1.1 + i * 0.03 + i * 1.07 * Math.PI / 2) * 20.0f,
8.0f + (1.0f - (float)Math.Cos(time * 1.5 + i * 0.29 + 1.49f * Math.PI / 2)) * 4.0f,
(float)Math.Cos(time * 1.3 + i * 0.13 + i * 1.79 * Math.PI / 2) * 20.0f
);
lightPositions[i] = new Vector4(v3, 15.0f);
reflectedLights[i] = new Vector4(Vector3.Transform(v3, ReflectionTransform), 15.0f);
}
uniforms.LightPosRadius = reflectedLights;
var bunnyMtx =
//.........这里部分代码省略.........
示例4: SetCamera
public void SetCamera(Camera c)
{
cam = c;
if (c == null)
return;
CheckError();
GL.MatrixMode(MatrixMode.Projection);
Matrix4 m3 = c.GetProjectionMatrix();
GL.LoadMatrix(ref m3);
GL.MatrixMode(MatrixMode.Modelview);
Matrix4 m = c.Matrix;//Matrix4Extensions.FromQuaternion(c.Orientation);
Vector3 t = new Vector3();
Vector3 x, y;
Vector3 pos = Matrix4Extensions.ExtractTranslation(m);
Matrix4Extensions.ExtractBasis(m, out x, out y, out t);
t += pos;
if (c.Shake > 0)
{
t += c.Shake * VecRandom.Instance.NextUnitVector3();
pos += c.Shake * VecRandom.Instance.NextUnitVector3();
}
global::OpenTK.Matrix4 m2=global::OpenTK.Matrix4.LookAt(pos.X, pos.Y, pos.Z, t.X, t.Y, t.Z, y.X, y.Y, y.Z);
GL.LoadMatrix(ref m2);
Viewport vp;
if(c.View!=null)
{
vp = c.View;
}
else
{
//vp = new Viewport(0,0,Size.X,Size.Y);
vp = new Viewport(0, 0, currentwidth, currentheight);
}
States.Enable((int)GetPName.ScissorTest);
GL.Scissor(vp.X, vp.Y, vp.W, vp.H);
GL.Viewport(vp.X, vp.Y, vp.W, vp.H);
CheckError();
}
示例5: Render
public RenderTarget Render(Stage stage, Camera camera)
{
if (!HandlesInitialized)
{
InitializeHandles();
HandlesInitialized = true;
}
RenderedLights = 0;
// Init common matrices
Matrix4 view, projection;
camera.GetViewMatrix(out view);
camera.GetProjectionMatrix(out projection);
// Render scene to GBuffer
var clearColor = stage.ClearColor;
clearColor.W = 0;
Backend.ProfileBeginSection(Profiler.GBuffer);
Backend.BeginPass(GBuffer, clearColor, true);
RenderScene(stage, camera, ref view, ref projection);
Backend.EndPass();
Backend.ProfileEndSection(Profiler.GBuffer);
// Render light accumulation
Backend.ProfileBeginSection(Profiler.Lighting);
Backend.BeginPass(LightAccumulation, new Vector4(0.0f, 0.0f, 0.0f, 1.0f), true);
RenderAmbientLight(stage);
RenderLights(camera, ref view, ref projection, stage.GetLights(), stage);
Backend.EndPass();
Backend.ProfileEndSection(Profiler.Lighting);
var currentRenderTarget = Temporary;
var currentSource = LightAccumulation;
if (FogSettings.Enable)
{
Backend.BeginPass(currentRenderTarget, new Vector4(0.0f, 0.0f, 0.0f, 1.0f), false);
Backend.BeginInstance(FogShader.Handle, new int[] { currentSource.Textures[0].Handle, GBuffer.Textures[2].Handle }, new int[] { Backend.DefaultSamplerNoFiltering, Backend.DefaultSamplerNoFiltering }, LightAccumulatinRenderState);
Backend.BindShaderVariable(FogParams.SamplerScene, 0);
Backend.BindShaderVariable(FogParams.SamplerGBuffer2, 1);
Backend.BindShaderVariable(FogParams.FogStart, FogSettings.Start);
Backend.BindShaderVariable(FogParams.FogEnd, FogSettings.End);
Backend.BindShaderVariable(FogParams.FogColor, ref FogSettings.Color);
Vector2 screenSize = new Vector2(LightAccumulation.Width, LightAccumulation.Height);
Backend.BindShaderVariable(FogParams.ScreenSize, ref screenSize);
Backend.DrawMesh(QuadMesh.MeshHandle);
Backend.EndPass();
var tmp = currentRenderTarget;
currentRenderTarget = currentSource;
currentSource = tmp;
}
Backend.BeginPass(Output, new Vector4(0.0f, 0.0f, 0.0f, 1.0f), false);
Backend.BeginInstance(CombineShader.Handle, new int[] { currentSource.Textures[0].Handle }, new int[] { Backend.DefaultSamplerNoFiltering }, LightAccumulatinRenderState);
Backend.BindShaderVariable(CombineParams.SamplerLight, 0);
Backend.DrawMesh(QuadMesh.MeshHandle);
Backend.EndPass();
return Output;
}