def createNorShaders(self, textures, matTextures): """ handle normal mapping shader depending on tangent space calculations. """ data = [ShaderData(), ShaderData(), ShaderData()] norTexData = matTextures.get(Texture2D.MAP_TO_NOR, []) for (tex, texData) in norTexData: _, _, _, i = texData bumpFrag = BumpMapFrag(enabledLights=self.enabledLights) bumpFrag.setArgs(["texel%d" % i, "n"]) data[FRAG_SHADER].functions.append(bumpFrag) data[FRAG_SHADER].localVars["texel%d" % i] = \ ("vec4", "texture2D( Texture%d, gl_TexCoord[0].xy )" % i) # need uv coordinate data[VERT_SHADER].exports["gl_TexCoord[0].xy"] = "vertexUV" if tex.tangentSpace: # need to convert some vectors to tangent space bumpVert = BumpMapVert(enabledLights=self.enabledLights) bumpVert.setArgs(["n"]) data[VERT_SHADER].functions.append(bumpVert) data[VERT_SHADER].localVars["n"] = ("vec3", "normalize( gl_NormalMatrix * vertexNormal )") data[VERT_SHADER].exports[NORMAL_VARYING] = "n" return data
def createNorShaders(self, textures, matTextures): """ create normal mapping aka bump mapping shader. """ data = [ShaderData(), ShaderData(), ShaderData()] norTexData = matTextures.get(Texture2D.MAP_TO_NOR, []) for (tex, texData) in norTexData: tex, _, _, i = texData if tex.tangentSpace: continue # create eye space normal mapping shader, # tangent space cannot be calculated by all segments. bumpFrag = BumpMapFrag(enabledLights=self.enabledLights) bumpFrag.setArgs(["texel%d" % i, "uv", "n"]) data[FRAG_SHADER].functions.append(bumpFrag) return data