差分

ナビゲーションに移動 検索に移動

社畜PC

6,383 バイト除去, 2019年10月10日 (木) 11:57
編集の要約なし
1つの'''社畜PC'''(しゃちくぴーしー)とは、[[ポリゴンメッシュブラック企業]][[GPU社畜]]側で複製することでに配布することを想定して開発および販売されている[[DrawコールPC]]を減らして描画を高速化する「[[ハードウェアインスタンシング]]」という技術がある。のことである。
ただ== 概要 ==一般的には「これ[[MonoGameスマホ]]よりも性能悪いんじゃないのか」という限界まで「安さ」だけを追求した[[OpenGL社畜]]の組み合わせの環境では長らく「new NotImplementedException()」であった。を酷使するための[[PC]]である。
これがついにMonoGame 3.7で[[OpenGLCPU]]環境でもなどは数字を大きく見せる目的で結構マシなものが採用される傾向があるが、[[ハードウェアインスタンシングキーボード]]が使えるようになったそうだ。さっそく[[MacOSマウス]]上で試してみた。[[ハードウェアインスタンシング液晶]]が使えるとなると[[ボリュームレンダリング]]の実装が捗る可能性がある。などの数字で表現しにくいパーツは人体に悪影響のあるレベルで限界に挑戦したものが多い。
==HLSLを書く==一方で歴史ある[[HLSLソフトウェア]]はこんな感じ。今回は移動だけで回転はしていない。 の開発会社などの[[MacIT企業]]上ででは「[[HLSLiMac 5K]]よりも高価で低性能」な[[コンパイル富士通]]する方法は「 [[MonoGameでプログラマブルシェーダーを使うNEC]]」および「など[[InfinitespaceStudios.PipelinePC]]」の項目を参照。を採用し[[ITドカタ]]に配給していることが多い。いわゆる[[大人の事情]]である。あきらかに意味不明な価格であっても買わなければならないのである。それが大人である。
<syntaxhighlight lang="text">// file: effect4.fx=デスクトップ==
// ----------------------------------------------------------------*[[PCケース]]は[[スリムタワー]]// MonoGame PipelineでOpenGL環境の場合は「OPENGL」シンボルが立っている。*[[CPU]]は[[セレロン]](CPUは数字で表現できるので、ここだけCore i7というのも多い)// 以下は定型文だと思ってコピペしとけ。*[[HDD]]は500GB(最近は[[HDD]]並に遅い[[SSD]]も人気)#if OPENGL*[[メモリ]]は4GB #define SV_POSITION POSITION*[[液晶]]は目潰し #define VS_SHADERMODEL vs_3_0*[[MIMO]]非対応の[[WiFi]] #define PS_SHADERMODEL ps_3_0*腱鞘炎になる[[キーボード]]#else #define VS_SHADERMODEL vs_4_0_level_9_1 #define PS_SHADERMODEL ps_4_0_level_9_1#endif*保証期間が過ぎると爆発炎上する[[電解コンデンサー]]
// ----------------------------------------------------------------// 呼び出し側(C#)から設定されるグローバル変数(シェーダー内では実質定数)float4x4 myView : VIEW;float4x4 myProjection : PROJECTION;==ノートPC==
// ----------------------------------------------------------------// 入出力用の構造体struct VertexPositionColor{ float4 Position : POSITION0; float4 Color : COLOR;}; // ----------------------------------------------------------------// バーテックスシェーダーVertexPositionColor MyVertexShader( VertexPositionColor input, float3 position : POSITION1 ){ // inputの位置をpositionほど移動させる。 // 今回は移動だけ。 // 回転したい場合なども同じ要領でここで変形させる。 input.Position.xyz += position;  // 頂点をカメラから見た座標に変換する。 input.Position = mul( input.Position, mul(myView, myProjection)); return input;} // ----------------------------------------------------------------// ピクセルシェーダーfloat4 MyPixelShader(float4 color : COLOR) : COLOR0{ return color;} technique HardwareInstancing{ pass Pass1 { VertexShader = compile VS_SHADERMODEL MyVertexShader(); PixelShader = compile PS_SHADERMODEL MyPixelShader(); }}</syntaxhighlight>==C#で呼び出してみる==この*[[コードレッツノート]]は「を抱えて颯爽と新幹線に乗り込み、[[MonoGameのカメラを作るドヤ顔]]」で作ったカメラを使っている。Cameraクラスは[[MonoGameパワポ]]標準物ではないので注意。 <syntaxhighlight lang="csharp"> using System; using System.Collections.Generic; using System.Text; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Input;  public class Game1 : Game { GraphicsDeviceManager graphics;  Camera camera; Effect effect; VertexBuffer triangleVertexBuffer; IndexBuffer indexBuffer; DynamicVertexBuffer instanceVertexBuffer;  VertexPositionColorを編集する、そんな[] vertices = { new VertexPositionColor(new Vector3(-1, 1, 0), Color.Blue ), new VertexPositionColor(new Vector3( 1, 1, 0), Color.White), new VertexPositionColor(new Vector3( 1, -1, 0), Color.Red ) };  Vector3[社畜] instances = new Vector3[] { new Vector3(0f, 0f, 0f), new Vector3(1f, 1f, 0f), new Vector3(2f, 2f, 0f) };  public Game1() { graphics = new GraphicsDeviceManager(this);に、私はなりたい Content.RootDirectory = "Content"; }  protected override void Initialize() { IsMouseVisible = true; base.Initialize(); }  protected override void LoadContent() { // 即席カメラ camera = new Camera(this); camera.Position = new Vector3(0, 0, 10); camera.Target = new Vector3(0, 0, 0);  // エフェクト読み込み effect = Content.Load<Effect>("effect4");  // バーテックスバッファーを生成 triangleVertexBuffer = new VertexBuffer( GraphicsDevice, VertexPositionColor.VertexDeclaration, vertices.Length, BufferUsage.WriteOnly); triangleVertexBuffer.SetData<VertexPositionColor>(vertices);  // インデックスバッファーを生成 var index = new ushort*[] { 0, 1, 2 }; indexBuffer = new IndexBuffer( GraphicsDevice, IndexElementSize.SixteenBits, index.Length, BufferUsage.WriteOnly); indexBuffer.SetData<ushort>(index);  // インスタンスバッファーを生成 instanceVertexBuffer = new DynamicVertexBuffer( GraphicsDevice, new VertexDeclaration( new VertexElement( offset: 0, elementFormat: VertexElementFormat.Vector3, elementUsage: VertexElementUsage.Position, usageIndex: 1)), instances.Length, BufferUsage.WriteOnly); instanceVertexBuffer.SetData(instances);  }  protected override void Update(GameTime gameTime) { if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape)) Exit();  // TODO: Add your update logic here camera.Angle += 1f;  base.Update(gameTime); }  protected override void Draw(GameTime gameTime) { GraphicsDevice.Clear(Color.CornflowerBlue);  // シェーダーのグローバル変数に値をセットする effect.Parameters["myView"液晶].SetValue(camera.View); effect.Parameters["myProjection"].SetValue(camera.Projection);  // バーテックスバッファーを転送 GraphicsDevice.SetVertexBuffers( new VertexBufferBinding(triangleVertexBuffer, 0, 0), new VertexBufferBinding(instanceVertexBuffer, 0, 1));  // インデックスバッファーを転送 GraphicsDevice.Indices = indexBuffer;  // インスタンスバッファーを転送 instanceVertexBuffer.SetData(instances, 0, instances.Length, SetDataOptions.Discard);  // 描画 foreach (EffectPass pass in effect.CurrentTechnique.Passes) { pass.Apply();  graphics.GraphicsDevice.DrawInstancedPrimitives( primitiveType: PrimitiveType.TriangleList, baseVertex: 0, startIndex: 0, primitiveCount: vertices.Length / 3, instanceCount: instances.Length);  }  base.Draw(gameTime); } }</syntaxhighlight> ==Mac上で動かしてみる==こんな感じ。[[Mac]]でも[[HLSL]]で書いた[[シェーダー]]が使えてる。なお、[[OpenGL]]系の環境では[[シェーダーモデル解像度]]は3.0までだ。まあSM3.0もあれば元気があれば何でもできる。 <movie>https://youtu.be/qU-toUOhvRI</movie>は1366x768
==関連項目==
*[[MonoGameでプログラマブルシェーダーを使う]]*[[MonoGameでピクセルシェーダーを使ってテクスチャを貼る‎]]*[[ハードウェアインスタンシング]]*[[疑似インスタンシング]]*[[メッシュベイカー]]*[[ドローコール]] [[category: MonoGame]][[category: HLSLクオカードの歌]]
匿名利用者

案内メニュー