From 439ef40cff7514204c69cdca69f5fd84e30fe7f5 Mon Sep 17 00:00:00 2001 From: Josh Yelon Date: Sun, 16 Dec 2007 08:05:18 +0000 Subject: [PATCH] Just getting started with real shader generator --- panda/src/pgraph/shaderGenerator.cxx | 99 ++++++++++++++++++---------- 1 file changed, 63 insertions(+), 36 deletions(-) diff --git a/panda/src/pgraph/shaderGenerator.cxx b/panda/src/pgraph/shaderGenerator.cxx index 6593c8e144..19d57051b4 100644 --- a/panda/src/pgraph/shaderGenerator.cxx +++ b/panda/src/pgraph/shaderGenerator.cxx @@ -25,45 +25,72 @@ // Access: Public, Static // Description: This is the routine that implements the next-gen // fixed function pipeline by synthesizing a shader. +// +// Currently supports: +// - textures +// - materials +// - lights +// +// Not yet supported: +// - vertex colors +// - texgen +// - texmatrix +// - separate normal and gloss +// - lots of other things +// //////////////////////////////////////////////////////////////////// CPT(RenderAttrib) ShaderGenerator:: synthesize_shader(const RenderState *rs) { - - // Stub code: just return this shader. + AttribSlots attribs; + rs->store_into_slots(&attribs); - PT(Shader) shader = Shader::make( - "//Cg \n" - "// \n" - "//Cg profile arbvp1 arbfp1 \n" - " \n" - "void vshader(float4 vtx_position : POSITION, \n" - " float3 vtx_normal : NORMAL, \n" - " float4 vtx_color : COLOR, \n" - " out float4 l_position : POSITION, \n" - " out float4 l_brite : TEXCOORD0, \n" - " out float4 l_color : COLOR, \n" - " uniform float4 mspos_light, \n" - " uniform float4x4 mat_modelproj) \n" - "{ \n" - " l_position = mul(mat_modelproj, vtx_position); \n" - " float3 N = normalize(vtx_normal); \n" - " float3 lightVector = normalize(mspos_light - vtx_position); \n" - " l_brite = max(dot(N,lightVector), 0); \n" - " l_color = vtx_color; \n" - "} \n" - " \n" - " \n" - "void fshader(float4 l_brite : TEXCOORD0, \n" - " float4 l_color : COLOR, \n" - " out float4 o_color : COLOR) \n" - "{ \n" - " if (l_brite.x<0.5) l_brite=0.8; \n" - " else l_brite=1.2; \n" - " o_color=l_brite * l_color; \n" - "} \n" - ); - CPT(RenderAttrib) rattr = rs->get_shader(); - if (rattr == 0) rattr = ShaderAttrib::make(); - return DCAST(ShaderAttrib, rattr)->set_shader(shader); + int num_textures = 0; + if (attribs._texture) { + num_textures = attribs._texture->get_num_on_stages(); + } + + ostringstream text; + CPT(RenderAttrib) rattrib = ShaderAttrib::make(); + + text << "//Cg\n"; + + text << "void vshader(\n"; + for (int i=0; iset_shader(shader); + return rattrib; }