--Chapter 6: Geo Shaders—

NOTE: This goes with the PICA200’s Geometery Shader chapter. Please learn that before you learn this. Otherwise, you can skip to the next chapter

One thing about using Geometery shaders is that when you apply them in code, you only have to change 4 lines. We will take the code from Chapter 2 and modify it a bit.

Under the “shaderProgramSetVsh” function, create a new function named “shaderProgramSetGsh” with the arguments of “(&program, &program_dvlb->DVLE[1], 6)”. This will do the same thing as the above function except that after “DVLE”, the element number is changed to 1 and there’s a stride number set to 6 so that it processes a triangle at a time. You will need this function every time you use a Geo Shader.

Now, go to the “shaderInstanceGetUniformLocation” function, and change “program.vertexShader” to “program.geometeryShader”. Now, for the last 2 functions, go to the scene render function, and change the “GPU_VERTEX_SHADER” argument in the “C3D_FVUnifMtx4x4” function to “GPU_GEOMETERY_SHADER” and in the “C3D_DrawArrays” function, change the “GPU_TRIANGLES” argument to “GPU_GEOMETERY_PRIM”. The functions should look like this:

static void sceneInit(){

// Load the shaders and create a shader program

// The geoshader stride is set to 6 so that it processes a triangle at a time

program_dvlb = DVLB_ParseFile((u32*)program_shbin, program_shbin_size);

shaderProgramInit(&program);

shaderProgramSetVsh(&program, &program_dvlb->DVLE[0]);

shaderProgramSetGsh(&program, &program_dvlb->DVLE[1], 6);

C3D_BindProgram(&program);

// Get the location of the projection matrix uniform

uLoc_projection = shaderInstanceGetUniformLocation(program.geometryShader, "projection");

// rest of the function

}

static void sceneRender(){

// Update the uniforms

C3D_FVUnifMtx4x4(GPU_GEOMETRY_SHADER, uLoc_projection, &projection);

// Draw the VBO - GPU_GEOMETRY_PRIM allows the geoshader to control primitive emission

C3D_DrawArrays(GPU_GEOMETRY_PRIM, 0, vertex_list_count);

}

And that is it for editing the functions but for the vertices and colors, add these functions at the top of the file:

typedef struct { float position[3]; float color[4]; } vertex;

static const vertex vertex_list[] =

{

{ {200.0f, 200.0f, 0.5f}, {1.0f, 0.0f, 0.0f, 1.0f} },

{ {100.0f, 40.0f, 0.5f}, {0.0f, 1.0f, 0.0f, 1.0f} },

{ {300.0f, 40.0f, 0.5f}, {0.0f, 0.0f, 1.0f, 1.0f} },

};

This will complete out triforce effect triangle. Also, make sure you included the shaders right. If you have both a vertex shader and a geo shader named view.g.pica (or .v.pica) then just include them in one statement as:

include “view_shbin.h”

That’s it for this chapter. In the next chapter, we will learn about light.

results matching ""

    No results matching ""