示例#1
0
bool C4LandscapeRenderGL::LoadShader(C4GroupSet *pGroups, C4Shader& shader, const char* name, int ssc)
{
	// Setup #defines
	shader.AddDefine("OPENCLONK");
	shader.AddDefine("OC_LANDSCAPE");
	if(ssc & C4SSC_LIGHT) shader.AddDefine("OC_DYNAMIC_LIGHT"); // sample light from light texture

	// Create vertex shader
	shader.LoadVertexSlices(pGroups, "LandscapeVertexShader.glsl");

	// Then load slices for fragment shader
	shader.LoadFragmentSlices(pGroups, "CommonShader.glsl");
	shader.LoadFragmentSlices(pGroups, "LandscapeShader.glsl");

	// Make attribute name map
	const char* AttributeNames[C4LRA_Count + 1];
	AttributeNames[C4LRA_Position] = "oc_Position";
	AttributeNames[C4LRA_LandscapeTexCoord] = "oc_LandscapeTexCoord";
	AttributeNames[C4LRA_LightTexCoord] = "oc_LightTexCoord"; // unused if no dynamic light
	AttributeNames[C4LRA_Count] = NULL;

	// Initialise!
	if (!shader.Init(name, UniformNames, AttributeNames)) {
		shader.ClearSlices();
		return false;
	}

	return true;
}
示例#2
0
	virtual void AddShaderSlices(C4Shader& shader, int ssc)
	{
#ifndef USE_CONSOLE
		// Add mesh-independent slices
		shader.AddDefine("OPENCLONK");
		shader.AddDefine("OC_MESH");

		if (ssc & C4SSC_MOD2) shader.AddDefine("OC_CLRMOD_MOD2");
		if (ssc & C4SSC_LIGHT) shader.AddDefine("OC_DYNAMIC_LIGHT");

		// Note these are never set for meshes at the moment:
		if (ssc & C4SSC_BASE) shader.AddDefine("OC_HAVE_BASE");
		if (ssc & C4SSC_OVERLAY) shader.AddDefine("OC_HAVE_OVERLAY");

		shader.LoadFragmentSlices(&::GraphicsResource.Files, "CommonShader.glsl");
		shader.LoadFragmentSlices(&::GraphicsResource.Files, "ObjectShader.glsl");
#endif
	}
示例#3
0
bool CStdGL::PrepareSpriteShader(C4Shader& shader, const char* name, int ssc, C4GroupSet* pGroups, const char* const* additionalDefines, const char* const* additionalSlices)
{
	const char* uniformNames[C4SSU_Count + 1];
	uniformNames[C4SSU_ProjectionMatrix] = "projectionMatrix";
	uniformNames[C4SSU_ModelViewMatrix] = "modelviewMatrix";
	uniformNames[C4SSU_NormalMatrix] = "normalMatrix";
	uniformNames[C4SSU_ClrMod] = "clrMod";
	uniformNames[C4SSU_Gamma] = "gamma";
	uniformNames[C4SSU_BaseTex] = "baseTex";
	uniformNames[C4SSU_OverlayTex] = "overlayTex";
	uniformNames[C4SSU_OverlayClr] = "overlayClr";
	uniformNames[C4SSU_LightTex] = "lightTex";
	uniformNames[C4SSU_LightTransform] = "lightTransform";
	uniformNames[C4SSU_NormalTex] = "normalTex";
	uniformNames[C4SSU_AmbientTex] = "ambientTex";
	uniformNames[C4SSU_AmbientTransform] = "ambientTransform";
	uniformNames[C4SSU_AmbientBrightness] = "ambientBrightness";
	uniformNames[C4SSU_MaterialAmbient] = "materialAmbient"; // unused
	uniformNames[C4SSU_MaterialDiffuse] = "materialDiffuse"; // unused
	uniformNames[C4SSU_MaterialSpecular] = "materialSpecular"; // unused
	uniformNames[C4SSU_MaterialEmission] = "materialEmission"; // unused
	uniformNames[C4SSU_MaterialShininess] = "materialShininess"; // unused
	uniformNames[C4SSU_Bones] = "bones"; // unused
	uniformNames[C4SSU_CullMode] = "cullMode"; // unused
	uniformNames[C4SSU_FrameCounter] = "frameCounter";
	uniformNames[C4SSU_Count] = NULL;

	const char* attributeNames[C4SSA_Count + 1];
	attributeNames[C4SSA_Position] = "oc_Position";
	attributeNames[C4SSA_Normal] = "oc_Normal"; // unused
	attributeNames[C4SSA_TexCoord] = "oc_TexCoord"; // only used if C4SSC_Base is set
	attributeNames[C4SSA_Color] = "oc_Color";
	attributeNames[C4SSA_BoneIndices0] = "oc_BoneIndices0"; // unused
	attributeNames[C4SSA_BoneIndices1] = "oc_BoneIndices1"; // unused
	attributeNames[C4SSA_BoneWeights0] = "oc_BoneWeights0"; // unused
	attributeNames[C4SSA_BoneWeights1] = "oc_BoneWeights1"; // unused
	attributeNames[C4SSA_Count] = NULL;

	// Clear previous content
	shader.Clear();
	shader.ClearSlices();

	// Start with #defines
	shader.AddDefine("OPENCLONK");
	shader.AddDefine("OC_SPRITE");
	if (ssc & C4SSC_MOD2) shader.AddDefine("OC_CLRMOD_MOD2");
	if (ssc & C4SSC_NORMAL) shader.AddDefine("OC_WITH_NORMALMAP");
	if (ssc & C4SSC_LIGHT) shader.AddDefine("OC_DYNAMIC_LIGHT");
	if (ssc & C4SSC_BASE) shader.AddDefine("OC_HAVE_BASE");
	if (ssc & C4SSC_OVERLAY) shader.AddDefine("OC_HAVE_OVERLAY");

	if (additionalDefines)
		for (const char* const* define = additionalDefines; *define != NULL; ++define)
			shader.AddDefine(*define);

	// Then load slices for fragment and vertex shader
	shader.LoadVertexSlices(pGroups, "SpriteVertexShader.glsl");
	shader.LoadFragmentSlices(pGroups, "CommonShader.glsl");
	shader.LoadFragmentSlices(pGroups, "ObjectShader.glsl");

	if (additionalSlices)
		for (const char* const* slice = additionalSlices; *slice != NULL; ++slice)
			shader.LoadFragmentSlices(pGroups, *slice);

	if (!shader.Init(name, uniformNames, attributeNames))
	{
		shader.ClearSlices();
		return false;
	}

	return true;
}