Пример #1
0
void phongShaderOverride::getCustomMappings(
	MHWRender::MAttributeParameterMappingList& mappings)
{
	// The "color" and "incandescence" attributes are all named the same as
	// the corresponding parameters on the fragment so they will map
	// automatically. Need to remap "diffuseReflectivity", "translucenceCoeff",
	// "reflectionGain" and "power" though.
	MHWRender::MAttributeParameterMapping diffuseMapping(
		"diffuse", "diffuseReflectivity", true, true);
	mappings.append(diffuseMapping);

	MHWRender::MAttributeParameterMapping translucenceMapping(
		"translucence", "translucenceCoeff", true, true);
	mappings.append(translucenceMapping);

	MHWRender::MAttributeParameterMapping reflectivityMapping(
		"reflectivity", "reflectionGain", true, true);
	mappings.append(reflectivityMapping);

	MHWRender::MAttributeParameterMapping powerMapping(
		"cosinePower", "power", true, true);
	mappings.append(powerMapping);

	// Our phong only uses a single float for specularity, while the Maya
	// phong fragment uses a full 3-float color. We could add a remap fragment
	// in front to expand the float to a 3-float, but it is simpler here to
	// just set the parameter manually in updateShader(). So add an empty
	// mapping to ensure the parameter gets renamed.
	MHWRender::MAttributeParameterMapping specColMapping(
		"specularColor", "", true, true);
	mappings.append(specColMapping);

}
void simpleNoiseShaderOverride::getCustomMappings(
	MHWRender::MAttributeParameterMappingList& mappings)
{
	// Set up some mappings for the noise map parameters on fragment, as there
	// is no correspondence to attributes on the node for them.
	MHWRender::MAttributeParameterMapping mapMapping(
		"noiseLookupMap", "", false, true);
	mappings.append(mapMapping);

	MHWRender::MAttributeParameterMapping textureSamplerMapping(
		"noiseLookupMapSampler", "", false, true);
	mappings.append(textureSamplerMapping);
}
Пример #3
0
void inNullOverride::getCustomMappings(
	MHWRender::MAttributeParameterMappingList& mappings)
{
	// The "color", "transparency" and "incandescence" attributes are all
	// named the same as the corresponding parameters on the fragment so they
	// will map automatically. Need to remap diffuseReflectivity and
	// translucence though
	MHWRender::MAttributeParameterMapping diffuseMapping(
		"diffuse", "diffuseReflectivity", true, true);
	mappings.append(diffuseMapping);

	MHWRender::MAttributeParameterMapping translucenceMapping(
		"translucence", "translucenceCoeff", true, true);
	mappings.append(translucenceMapping);
}
Пример #4
0
void phongShaderOverride::updateShader(
	MHWRender::MShaderInstance& shader,
	const MHWRender::MAttributeParameterMappingList& mappings)
{
	// Cache resolved name if found to avoid lookup on every update
	if (fResolvedSpecularColorName.length() == 0)
	{
		const MHWRender::MAttributeParameterMapping* mapping =
			mappings.findByParameterName("specularColor");
		if (mapping)
		{
			fResolvedSpecularColorName = mapping->resolvedParameterName();
		}
	}

	// Set parameter
	if (fResolvedSpecularColorName.length() > 0)
	{
		shader.setParameter(fResolvedSpecularColorName, fSpecularColor);
	}
}
void simpleNoiseShaderOverride::updateShader(
	MHWRender::MShaderInstance& shader,
	const MHWRender::MAttributeParameterMappingList& mappings)
{
	// Handle resolved name caching
	if (fResolvedNoiseMapName.length() == 0)
	{
		const MHWRender::MAttributeParameterMapping* mapping =
			mappings.findByParameterName("noiseLookupMap");
		if (mapping)
		{
			fResolvedNoiseMapName = mapping->resolvedParameterName();
		}
	}
	if (fResolvedNoiseSamplerName.length() == 0)
	{
		const MHWRender::MAttributeParameterMapping* mapping =
			mappings.findByParameterName("noiseLookupMapSampler");
		if (mapping)
		{
			fResolvedNoiseSamplerName = mapping->resolvedParameterName();
		}
	}

	// Set the parameters on the shader
	if (fResolvedNoiseMapName.length() > 0 &&
		fResolvedNoiseSamplerName.length() > 0)
	{
		// Set a point-clamp sampler to the shader
		if (!fNoiseSamplerState)
		{
			MHWRender::MSamplerStateDesc desc;
			desc.filter = MHWRender::MSamplerState::kMinMagMipPoint;
			desc.addressU = desc.addressV = desc.addressW =
				MHWRender::MSamplerState::kTexClamp;
			desc.minLOD = 0;
			desc.maxLOD = 0;
			fNoiseSamplerState =
				MHWRender::MStateManager::acquireSamplerState(desc);
		}
		if (fNoiseSamplerState)
		{
			shader.setParameter(fResolvedNoiseSamplerName, *fNoiseSamplerState);
		}

		// Generate the noise lookup table texture if necessary
		if (!fNoiseTexture)
		{
			MHWRender::MRenderer* renderer =
				MHWRender::MRenderer::theRenderer();
			MHWRender::MTextureManager* textureMgr =
				renderer ? renderer->getTextureManager() : NULL;
			if (textureMgr)
			{
				// First, search the texture cache to see if another instance of
				// this override has already generated the texture. We can reuse
				// it to save GPU memory since the noise data is constant.
				fNoiseTexture =
					textureMgr->findTexture(sNoiseLookupTextureName);

				// Not in cache, so we need to actually build the texture
				if (!fNoiseTexture)
				{
					// Get Maya's noise table
					const std::vector<float>& noiseData = GetMayaNoiseTable();

					// Create a 3D texture containing the data
					MHWRender::MTextureDescription desc;
					desc.setToDefault2DTexture();
					desc.fWidth = desc.fHeight = desc.fDepth =
						MRenderUtil::noiseTableCubeSide();
					desc.fFormat = MHWRender::kR32_FLOAT;
					desc.fTextureType = MHWRender::kVolumeTexture;
					desc.fMipmaps = 1;
					fNoiseTexture = textureMgr->acquireTexture(
						sNoiseLookupTextureName,
						desc,
						(const void*)&(noiseData[0]),
						false);
				}
			}
		}

		// Set the texture to the shader instance
		if (fNoiseTexture)
		{
			MHWRender::MTextureAssignment textureAssignment;
			textureAssignment.texture = fNoiseTexture;
			shader.setParameter(fResolvedNoiseMapName, textureAssignment);
		}
	}
}