利用者:Yiming/GSoC 2018/Questions

提供: wiki
2018年6月9日 (土) 20:03時点におけるwiki>Yimingによる版
(差分) ← 古い版 | 最新版 (差分) | 新しい版 → (差分)
移動先: 案内検索

Quesions and answers

On GPU/DRW/GWN

1. What's the difference between ShaderGroup/Pass/Framebuffer?

  • ShaderGroup is used to warp a shader program (as in OpenGL).
  • Pass is used to group Shader and drawing calls. It does not hold actual buffer object.
  • Framebuffer is used to warp a FBO.

2. What's the difference between GPU/DRW/GWN APIs?

  • GPU is for warpping OpenGL objects and functions.
  • DRW is for excuting drawing-related command.
  • GWN is a batch tool to generate calls that can be passed to DRW.

3. Can we use customized batch to draw primitives onto framebuffers?

  • Yes, the DRW calls resets drawing states to its required state every time. So as long as your modification is covered by DRW, you are free to use your code.

4. When matrix is not set, what coordinate is used when doing vertex shading?

  • The default full screen rect shader doesn't have vertex transform in its vertex shader, and the coordinates is in the NDC coordinate.(X from -1 to 1, Y from -1 to 1)

5. Can I set my own matrix using my own drawing codes?

  • Yes, the matrix is reset when DRW needs it. So no worries for destroying drawing state.

6. Does GPU/DRW support multisample textures?
Also if it does support, can transform_to_screen() display it correctly?
If not, how do we achieve multisample? By rendering it multiple times or something?
Any APIs for doing it?

  • Yes, then in shader use your Sampler2DMS texture refernce. Haven't tested if it displays correctly when using transform to screen function.

8. How does blender's shader deal with object matrix?

  • When creating a draw call, the last argument of DRW_shgroup_call_add() is obmat. DRW will internally generate MVP and normal matrix and pass them to the shaders.

9. Uniform array assign.

  • Seems a little tricky. Float array doesn't seem to work on vec4, and you should take care when using vec4 functions, the array number should be 1 instead of 4, otherwise it will be treated like a mat4 (which is a 4*4 matrix). See DRW_shgroup_uniform_vec4();

ON Mesh Operations

1. How to access mesh's global-space vertex position and global-space normal (original data prefered)
.It seems that object drawing code is warpped by batch functions, then do we have functions for accesing these data directly?

  • By applying ob->obmat onto mesh vertex. The normal matrix is the inverse-transpose of ob->obmat (but the 3X3 part is enough). There're several places where this is implemented on software side in blender. ob->obmat is the final global matrix with everything(parents,constraints..) applied.

2. BMesh creation, access and delete.

   Object* ob = some_mesh_object;
   Mesh* me = ob->data;
   
   /* create bmesh holder */
   BMesh* bm = BM_mesh_create(&allocsize, &((struct BMeshCreateParams){.use_toolflags = true,}));
   
   /* fill bmesh data */
   BM_mesh_bm_from_me(bm, me, &((struct BMeshFromMeshParams){.calc_face_normal = true,}));
   
   /* this create the lookup table for bmesh. */
   /* if you want to access bmesh elements by index, then the table for correspoding type must be available */
   BM_mesh_elem_table_ensure(bm, BM_VERT|BM_EDGE|BM_FACE); /* creating one or two of them is also okay */
   
   /* access at index */
   BMEdge* e = BM_edge_at_index(bm,i/*uint32 index*/);
   
   /* destroy bmesh when you are done */
   BM_mesh_free(bm);


On BLI

1. Usage on BLI_mempool_xxx?

   /* Creation */
   pool = BLI_mempool_create(sizeof(SomeStructure), 0 /* max element limit, 0 for no limit */, 512 /* element per trunk */, BLI_MEMPOOL_NOP /* flags */);
   
   /* Allocate */
   /* when trunk run out, a new one will be automatically added so the allocation will always success */
   /* unless out of memory or limit is set in pool */
   element = BLI_mempool_alloc(pool);
   element = BLI_mempool_calloc(pool);

Other

1. RNA/data Out of sync?

  • New DepsGraph uses copy on write on many places. Some sync functions need to be manually added when modifying data. See T54810 for detail info.