opengl - Shader program to Vertex + Fragment shader -
i studying a tutorial uses shader:
struct vsinput { vec3 position; vec2 texcoord; vec3 normal; }; interface vsoutput { vec3 worldpos; vec2 texcoord; vec3 normal; }; uniform mat4 gwvp; uniform mat4 gworld; shader vsmain(in vsinput vsin:0, out vsoutput vsout) { gl_position = gwvp * vec4(vsin.position, 1.0); vsout.texcoord = vsin.texcoord; vsout.normal = (gworld * vec4(vsin.normal, 0.0)).xyz; vsout.worldpos = (gworld * vec4(vsin.position, 1.0)).xyz; }; struct fsoutput { vec3 worldpos; vec3 diffuse; vec3 normal; vec3 texcoord; }; uniform sampler2d gcolormap; shader fsmain(in vsoutput fsin, out fsoutput fsout) { fsout.worldpos = fsin.worldpos; fsout.diffuse = texture(gcolormap, fsin.texcoord).xyz; fsout.normal = normalize(fsin.normal); fsout.texcoord = vec3(fsin.texcoord, 0.0); }; program geometrypass { vs(410)=vsmain(); fs(410)=fsmain(); };
it's geometry pass shader deferred rendering. trying port qt based program code can load vertex , fragment shaders separately.
can give suggestion of how can split above 2 loadable shaders ?
also, far understand, shader needs opengl core 4.1.0. necessary or there other way achieve same result using lower level (let's 3.3) ?
this looks cgfx variant using glsl code bunch of cg syntax added. convert valid glsl, need split separate vertex , fragment shaders, rename entry points each main
, move arguments entry point out multiple global variables rather structs (renaming things avoid collisions.) subtle detail :0
semantic on vsmain input argument, becomes layout
qualifiers on corresponding in
globals.
so vertex shader becomes:
#version 410 compatibility //struct vsinput //{ in layout(location = 0) vec3 position; in layout(location = 1) vec2 in_texcoord; in layout(location = 2) vec3 in_normal; //}; //interface vsoutput //{ out vec3 worldpos; out vec2 texcoord; out vec3 normal; //}; uniform mat4 gwvp; uniform mat4 gworld; //shader vsmain(in vsinput vsin:0, out vsoutput vsout) main() { gl_position = gwvp * vec4(position, 1.0); texcoord = in_texcoord; normal = (gworld * vec4(in_normal, 0.0)).xyz; worldpos = (gworld * vec4(position, 1.0)).xyz; }
the fragment shader transformed
Comments
Post a Comment