public void UpdateSkinnedMeshRender(OvrAvatarComponent component, OvrAvatar avatar, IntPtr renderPart) { ovrAvatarVisibilityFlags visibilityMask = CAPI.ovrAvatarSkinnedMeshRenderPBSV2_GetVisibilityMask(renderPart): ovrAvatarTransform localTransform = CAPI.ovrAvatarSkinnedMeshRenderPBSV2_GetTransform(renderPart): UpdateSkinnedMesh(avatar, bones, localTransform, visibilityMask, renderPart): UpdateMeshMaterial(visibilityMask, mesh == null ? component.RootMeshComponent : mesh): bool isActive = this.gameObject.activeSelf: if( mesh != null ) { bool changedMaterial = CAPI.ovrAvatarSkinnedMeshRenderPBSV2_MaterialStateChanged(renderPart): if (changedMaterial || (!previouslyActive && isActive)) { ovrAvatarPBSMaterialState materialState = CAPI.ovrAvatarSkinnedMeshRenderPBSV2_GetPBSMaterialState(renderPart): Material mat = mesh.sharedMaterial: mat.SetVector("_AlbedoMultiplier", materialState.albedoMultiplier): mat.SetTexture("_Albedo", OvrAvatarComponent.GetLoadedTexture(materialState.albedoTextureID)): mat.SetTexture("_Metallicness", OvrAvatarComponent.GetLoadedTexture(materialState.metallicnessTextureID)): mat.SetFloat("_GlossinessScale", materialState.glossinessScale): } } previouslyActive = isActive: }
private void InitializeSingleComponentMaterial(IntPtr renderPart, int lodIndex) { ovrAvatarPBSMaterialState materialState = CAPI.ovrAvatarSkinnedMeshRenderPBSV2_GetPBSMaterialState(renderPart); int componentType = (int)OvrAvatarMaterialManager.GetComponentType(gameObject.name); var defaultProperties = AvatarMaterialManager.DefaultAvatarConfig.ComponentMaterialProperties; var diffuseTexture = OvrAvatarComponent.GetLoadedTexture(materialState.albedoTextureID); var normalTexture = OvrAvatarComponent.GetLoadedTexture(materialState.normalTextureID); var metallicTexture = OvrAvatarComponent.GetLoadedTexture(materialState.metallicnessTextureID); if (diffuseTexture == null) { diffuseTexture = AvatarMaterialManager.DiffuseFallbacks[lodIndex]; } if (normalTexture == null) { normalTexture = AvatarMaterialManager.NormalFallbacks[lodIndex]; } if (metallicTexture == null) { metallicTexture = AvatarMaterialManager.DiffuseFallbacks[lodIndex]; } mesh.sharedMaterial.SetTexture(OvrAvatarMaterialManager.AVATAR_SHADER_MAINTEX, diffuseTexture); mesh.sharedMaterial.SetTexture(OvrAvatarMaterialManager.AVATAR_SHADER_NORMALMAP, normalTexture); mesh.sharedMaterial.SetTexture(OvrAvatarMaterialManager.AVATAR_SHADER_ROUGHNESSMAP, metallicTexture); mesh.sharedMaterial.SetVector(OvrAvatarMaterialManager.AVATAR_SHADER_COLOR, materialState.albedoMultiplier); mesh.sharedMaterial.SetFloat(OvrAvatarMaterialManager.AVATAR_SHADER_DIFFUSEINTENSITY, defaultProperties[componentType].DiffuseIntensity); mesh.sharedMaterial.SetFloat(OvrAvatarMaterialManager.AVATAR_SHADER_RIMINTENSITY, defaultProperties[componentType].RimIntensity); mesh.sharedMaterial.SetFloat(OvrAvatarMaterialManager.AVATAR_SHADER_BACKLIGHTINTENSITY, defaultProperties[componentType].BacklightIntensity); mesh.sharedMaterial.SetFloat(OvrAvatarMaterialManager.AVATAR_SHADER_REFLECTIONINTENSITY, defaultProperties[componentType].ReflectionIntensity); mesh.GetClosestReflectionProbes(AvatarMaterialManager.ReflectionProbes); if (AvatarMaterialManager.ReflectionProbes != null && AvatarMaterialManager.ReflectionProbes.Count > 0) { mesh.sharedMaterial.SetTexture(OvrAvatarMaterialManager.AVATAR_SHADER_CUBEMAP, AvatarMaterialManager.ReflectionProbes[0].probe.texture); } #if UNITY_EDITOR mesh.sharedMaterial.EnableKeyword("FIX_NORMAL_ON"); #endif mesh.sharedMaterial.EnableKeyword("PBR_LIGHTING_ON"); }
private void InitializeCombinedMaterial(IntPtr renderPart, int lodIndex) { ovrAvatarPBSMaterialState[] materialStates = CAPI.ovrAvatar_GetBodyPBSMaterialStates(renderPart); if (materialStates.Length == (int)ovrAvatarBodyPartType.Count) { AvatarMaterialManager.CreateTextureArrays(); AvatarMaterialManager.LocalAvatarConfig = AvatarMaterialManager.DefaultAvatarConfig; var localProperties = AvatarMaterialManager.LocalAvatarConfig.ComponentMaterialProperties; AvatarLogger.Log("InitializeCombinedMaterial - Loading Material States"); for (int i = 0; i < materialStates.Length; i++) { localProperties[i].TypeIndex = (ovrAvatarBodyPartType)i; localProperties[i].Color = materialStates[i].albedoMultiplier; var diffuse = OvrAvatarComponent.GetLoadedTexture(materialStates[i].albedoTextureID); var normal = OvrAvatarComponent.GetLoadedTexture(materialStates[i].normalTextureID); var roughness = OvrAvatarComponent.GetLoadedTexture(materialStates[i].metallicnessTextureID); localProperties[i].Textures[(int)OvrAvatarMaterialManager.TextureType.DiffuseTextures] = diffuse == null ? AvatarMaterialManager.DiffuseFallbacks[lodIndex] : diffuse; localProperties[i].Textures[(int)OvrAvatarMaterialManager.TextureType.NormalMaps] = normal == null ? AvatarMaterialManager.NormalFallbacks[lodIndex] : normal; localProperties[i].Textures[(int)OvrAvatarMaterialManager.TextureType.RoughnessMaps] = roughness == null ? AvatarMaterialManager.DiffuseFallbacks[lodIndex] : roughness; AvatarLogger.Log(localProperties[i].TypeIndex.ToString()); AvatarLogger.Log(AvatarLogger.Tab + "Diffuse: " + materialStates[i].albedoTextureID); AvatarLogger.Log(AvatarLogger.Tab + "Normal: " + materialStates[i].normalTextureID); AvatarLogger.Log(AvatarLogger.Tab + "Metallic: " + materialStates[i].metallicnessTextureID); } if (EnableExpressive) { mesh.materials[0].SetVector(OvrAvatarMaterialManager.AVATAR_SHADER_IRIS_COLOR, ExpressiveParameters.irisColor); mesh.materials[0].SetVector(OvrAvatarMaterialManager.AVATAR_SHADER_LIP_COLOR, ExpressiveParameters.lipColor); mesh.materials[0].SetVector(OvrAvatarMaterialManager.AVATAR_SHADER_BROW_COLOR, ExpressiveParameters.browColor); mesh.materials[0].SetVector(OvrAvatarMaterialManager.AVATAR_SHADER_LASH_COLOR, ExpressiveParameters.lashColor); mesh.materials[0].SetVector(OvrAvatarMaterialManager.AVATAR_SHADER_SCLERA_COLOR, ExpressiveParameters.scleraColor); mesh.materials[0].SetVector(OvrAvatarMaterialManager.AVATAR_SHADER_GUM_COLOR, ExpressiveParameters.gumColor); mesh.materials[0].SetVector(OvrAvatarMaterialManager.AVATAR_SHADER_TEETH_COLOR, ExpressiveParameters.teethColor); mesh.materials[0].SetFloat(OvrAvatarMaterialManager.AVATAR_SHADER_LIP_SMOOTHNESS, ExpressiveParameters.lipSmoothness); } AvatarMaterialManager.ValidateTextures(); } }
private void UpdateAvatarComponent(ovrAvatarComponent component) { for (UInt32 renderPartIndex = 0; renderPartIndex < component.renderPartCount; renderPartIndex++) { if (RenderParts.Count <= renderPartIndex) { break; } OvrAvatarRenderComponent renderComponent = RenderParts[(int)renderPartIndex]; IntPtr renderPart = OvrAvatar.GetRenderPart(component, renderPartIndex); ovrAvatarRenderPartType type = CAPI.ovrAvatarRenderPart_GetType(renderPart); switch (type) { case ovrAvatarRenderPartType.SkinnedMeshRenderPBS: var mat = renderComponent.mesh.sharedMaterial; var bones = renderComponent.bones; ovrAvatarVisibilityFlags visibilityMask = CAPI.ovrAvatarSkinnedMeshRenderPBS_GetVisibilityMask(renderPart); ovrAvatarTransform localTransform = CAPI.ovrAvatarSkinnedMeshRenderPBS_GetTransform(renderPart); UpdateSkinnedMesh(localTransform, renderPart, bones); UInt64 albedoTextureID = CAPI.ovrAvatarSkinnedMeshRenderPBS_GetAlbedoTextureAssetID(renderPart); UInt64 surfaceTextureID = CAPI.ovrAvatarSkinnedMeshRenderPBS_GetSurfaceTextureAssetID(renderPart); mat.SetTexture("_Albedo", OvrAvatarComponent.GetLoadedTexture(albedoTextureID)); mat.SetTexture("_Surface", OvrAvatarComponent.GetLoadedTexture(surfaceTextureID)); break; default: break; } } }
private IEnumerator DeleteTextureSetCoroutine(TextureSet textureSetToDelete, int gameobjectID) { // Wait a conservative amount of time for gpu upload to finish. Unity 2017 doesn't support async GPU calls, // so this 10 second time is a very conservative delay for this process to occur, which should be <1 sec. yield return(new WaitForSeconds(GPU_TEXTURE_COPY_WAIT_TIME)); // Spin if an avatar is loading while (OvrAvatarSDKManager.Instance.IsAvatarLoading()) { yield return(null); } // The avatar's texture set is compared against all other loaded or loading avatar texture sets. foreach (var textureIdAndSingleMeshFlag in textureSetToDelete.TextureIDSingleMeshPair) { bool triggerDelete = !textureIdAndSingleMeshFlag.Value; if (triggerDelete) { foreach (KeyValuePair <int, TextureSet> textureSet in textureSets) { if (textureSet.Key == gameobjectID) { continue; } foreach (var comparisonTextureIDSingleMeshPair in textureSet.Value.TextureIDSingleMeshPair) { // Mark the texture as not deletable if it's present in another set and that set hasn't been processed // or that texture ID is marked as part of a single mesh component. if (comparisonTextureIDSingleMeshPair.Key == textureIdAndSingleMeshFlag.Key && (!textureSet.Value.IsProcessed || comparisonTextureIDSingleMeshPair.Value)) { triggerDelete = false; break; } } if (!triggerDelete) { break; } } } if (triggerDelete) { Texture2D textureToDelete = OvrAvatarComponent.GetLoadedTexture(textureIdAndSingleMeshFlag.Key); if (textureToDelete != null) { AvatarLogger.Log("Deleting texture " + textureIdAndSingleMeshFlag.Key); OvrAvatarSDKManager.Instance.DeleteAssetFromCache(textureIdAndSingleMeshFlag.Key); Destroy(textureToDelete); } } } textureSetToDelete.IsProcessed = true; textureSets.Remove(gameobjectID); }
internal void UpdateSkinnedMeshRenderPBS(OvrAvatar avatar, IntPtr renderPart, Material mat) { ovrAvatarVisibilityFlags visibilityMask = CAPI.ovrAvatarSkinnedMeshRenderPBS_GetVisibilityMask(renderPart): ovrAvatarTransform localTransform = CAPI.ovrAvatarSkinnedMeshRenderPBS_GetTransform(renderPart): UpdateSkinnedMesh(avatar, bones, localTransform, visibilityMask, renderPart): UInt64 albedoTextureID = CAPI.ovrAvatarSkinnedMeshRenderPBS_GetAlbedoTextureAssetID(renderPart): UInt64 surfaceTextureID = CAPI.ovrAvatarSkinnedMeshRenderPBS_GetSurfaceTextureAssetID(renderPart): mat.SetTexture("_Albedo", OvrAvatarComponent.GetLoadedTexture(albedoTextureID)): mat.SetTexture("_Surface", OvrAvatarComponent.GetLoadedTexture(surfaceTextureID)): }
internal void UpdateSkinnedMeshRenderPBS(OvrAvatar avatar, IntPtr renderPart, Material mat) { if (!isMaterialInitilized) { isMaterialInitilized = true; UInt64 albedoTextureID = CAPI.ovrAvatarSkinnedMeshRenderPBS_GetAlbedoTextureAssetID(renderPart); UInt64 surfaceTextureID = CAPI.ovrAvatarSkinnedMeshRenderPBS_GetSurfaceTextureAssetID(renderPart); mat.SetTexture("_Albedo", OvrAvatarComponent.GetLoadedTexture(albedoTextureID)); mat.SetTexture("_Surface", OvrAvatarComponent.GetLoadedTexture(surfaceTextureID)); } // Debug.Log("UpdateSkinnedMeshRenderPBS"); ovrAvatarVisibilityFlags visibilityMask = CAPI.ovrAvatarSkinnedMeshRenderPBS_GetVisibilityMask(renderPart); ovrAvatarTransform localTransform = CAPI.ovrAvatarSkinnedMeshRenderPBS_GetTransform(renderPart); UpdateSkinnedMesh(avatar, bones, localTransform, visibilityMask, renderPart); }
private void InitializeCombinedMaterial(IntPtr renderPart, int lodIndex) { ovrAvatarPBSMaterialState[] materialStates = CAPI.ovrAvatar_GetBodyPBSMaterialStates(renderPart); if (materialStates.Length == (int)ovrAvatarBodyPartType.Count) { AvatarMaterialManager.CreateTextureArrays(); AvatarMaterialManager.LocalAvatarConfig = AvatarMaterialManager.DefaultAvatarConfig; var localProperties = AvatarMaterialManager.LocalAvatarConfig.ComponentMaterialProperties; AvatarLogger.Log("InitializeCombinedMaterial - Loading Material States"); for (int i = 0; i < materialStates.Length; i++) { localProperties[i].TypeIndex = (ovrAvatarBodyPartType)i; localProperties[i].Color = materialStates[i].albedoMultiplier; var diffuse = OvrAvatarComponent.GetLoadedTexture(materialStates[i].albedoTextureID); var normal = OvrAvatarComponent.GetLoadedTexture(materialStates[i].normalTextureID); var roughness = OvrAvatarComponent.GetLoadedTexture(materialStates[i].metallicnessTextureID); localProperties[i].Textures[(int)OvrAvatarMaterialManager.TextureType.DiffuseTextures] = diffuse == null ? AvatarMaterialManager.DiffuseFallbacks[lodIndex] : diffuse; localProperties[i].Textures[(int)OvrAvatarMaterialManager.TextureType.NormalMaps] = normal == null ? AvatarMaterialManager.NormalFallbacks[lodIndex] : normal; localProperties[i].Textures[(int)OvrAvatarMaterialManager.TextureType.RoughnessMaps] = roughness == null ? AvatarMaterialManager.DiffuseFallbacks[lodIndex] : roughness; AvatarLogger.Log(localProperties[i].TypeIndex.ToString()); AvatarLogger.Log(AvatarLogger.Tab + "Diffuse: " + materialStates[i].albedoTextureID); AvatarLogger.Log(AvatarLogger.Tab + "Normal: " + materialStates[i].normalTextureID); AvatarLogger.Log(AvatarLogger.Tab + "Metallic: " + materialStates[i].metallicnessTextureID); } AvatarMaterialManager.ValidateTextures(); } #if UNITY_EDITOR mesh.sharedMaterial.EnableKeyword("FIX_NORMAL_ON"); #endif }
private void InitializeCombinedMaterial(IntPtr renderPart, int lodIndex) { ovrAvatarPBSMaterialState[] materialStates = CAPI.ovrAvatar_GetBodyPBSMaterialStates(renderPart); if (materialStates.Length == (int)ovrAvatarBodyPartType.Count) { avatarMaterialManager.CreateTextureArrays(); var localProperties = avatarMaterialManager.LocalAvatarConfig.ComponentMaterialProperties; AvatarLogger.Log("InitializeCombinedMaterial - Loading Material States"); for (int i = 0; i < materialStates.Length; i++) { localProperties[i].TypeIndex = (ovrAvatarBodyPartType)i; localProperties[i].Color = materialStates[i].albedoMultiplier; localProperties[i].DiffuseIntensity = OvrAvatarMaterialManager.DiffuseIntensities[i]; localProperties[i].RimIntensity = OvrAvatarMaterialManager.RimIntensities[i]; localProperties[i].ReflectionIntensity = OvrAvatarMaterialManager.ReflectionIntensities[i]; var diffuse = OvrAvatarComponent.GetLoadedTexture(materialStates[i].albedoTextureID); var normal = OvrAvatarComponent.GetLoadedTexture(materialStates[i].normalTextureID); var roughness = OvrAvatarComponent.GetLoadedTexture(materialStates[i].metallicnessTextureID); if (diffuse != null) { localProperties[i].Textures[(int)OvrAvatarMaterialManager.TextureType.DiffuseTextures] = diffuse; avatarMaterialManager.AddTextureIDToTextureManager(materialStates[i].albedoTextureID, false); } else { localProperties[i].Textures[(int)OvrAvatarMaterialManager.TextureType.DiffuseTextures] = OvrAvatarSDKManager.Instance.GetTextureCopyManager().FallbackTextureSets[lodIndex].DiffuseRoughness; } localProperties[i].Textures[(int)OvrAvatarMaterialManager.TextureType.DiffuseTextures].anisoLevel = 4; if (normal != null) { localProperties[i].Textures[(int)OvrAvatarMaterialManager.TextureType.NormalMaps] = normal; avatarMaterialManager.AddTextureIDToTextureManager(materialStates[i].normalTextureID, false); } else { localProperties[i].Textures[(int)OvrAvatarMaterialManager.TextureType.NormalMaps] = OvrAvatarSDKManager.Instance.GetTextureCopyManager().FallbackTextureSets[lodIndex].Normal; } localProperties[i].Textures[(int)OvrAvatarMaterialManager.TextureType.NormalMaps].anisoLevel = 4; if (roughness != null) { localProperties[i].Textures[(int)OvrAvatarMaterialManager.TextureType.RoughnessMaps] = roughness; avatarMaterialManager.AddTextureIDToTextureManager(materialStates[i].metallicnessTextureID, false); } else { localProperties[i].Textures[(int)OvrAvatarMaterialManager.TextureType.RoughnessMaps] = OvrAvatarSDKManager.Instance.GetTextureCopyManager().FallbackTextureSets[lodIndex].DiffuseRoughness; } localProperties[i].Textures[(int)OvrAvatarMaterialManager.TextureType.RoughnessMaps].anisoLevel = 16; AvatarLogger.Log(localProperties[i].TypeIndex.ToString()); AvatarLogger.Log(AvatarLogger.Tab + "Diffuse: " + materialStates[i].albedoTextureID); AvatarLogger.Log(AvatarLogger.Tab + "Normal: " + materialStates[i].normalTextureID); AvatarLogger.Log(AvatarLogger.Tab + "Metallic: " + materialStates[i].metallicnessTextureID); } if (EnableExpressive) { mesh.materials[0].SetVector(OvrAvatarMaterialManager.AVATAR_SHADER_IRIS_COLOR, ExpressiveParameters.irisColor); mesh.materials[0].SetVector(OvrAvatarMaterialManager.AVATAR_SHADER_LIP_COLOR, ExpressiveParameters.lipColor); mesh.materials[0].SetVector(OvrAvatarMaterialManager.AVATAR_SHADER_BROW_COLOR, ExpressiveParameters.browColor); mesh.materials[0].SetVector(OvrAvatarMaterialManager.AVATAR_SHADER_LASH_COLOR, ExpressiveParameters.lashColor); mesh.materials[0].SetVector(OvrAvatarMaterialManager.AVATAR_SHADER_SCLERA_COLOR, ExpressiveParameters.scleraColor); mesh.materials[0].SetVector(OvrAvatarMaterialManager.AVATAR_SHADER_GUM_COLOR, ExpressiveParameters.gumColor); mesh.materials[0].SetVector(OvrAvatarMaterialManager.AVATAR_SHADER_TEETH_COLOR, ExpressiveParameters.teethColor); mesh.materials[0].SetFloat(OvrAvatarMaterialManager.AVATAR_SHADER_LIP_SMOOTHNESS, ExpressiveParameters.lipSmoothness); } avatarMaterialManager.ValidateTextures(); } }
private void InitializeSingleComponentMaterial(IntPtr renderPart, int lodIndex) { ovrAvatarPBSMaterialState materialState = CAPI.ovrAvatarSkinnedMeshRenderPBSV2_GetPBSMaterialState(renderPart); int componentType = (int)OvrAvatarMaterialManager.GetComponentType(gameObject.name); Texture2D diffuseTexture = OvrAvatarComponent.GetLoadedTexture(materialState.albedoTextureID); Texture2D normalTexture = OvrAvatarComponent.GetLoadedTexture(materialState.normalTextureID); Texture2D metallicTexture = OvrAvatarComponent.GetLoadedTexture(materialState.metallicnessTextureID); if (diffuseTexture != null) { avatarMaterialManager.AddTextureIDToTextureManager(materialState.albedoTextureID, true); } else { diffuseTexture = OvrAvatarSDKManager.Instance.GetTextureCopyManager().FallbackTextureSets[lodIndex].DiffuseRoughness; } diffuseTexture.anisoLevel = 4; if (normalTexture != null) { avatarMaterialManager.AddTextureIDToTextureManager(materialState.normalTextureID, true); } else { normalTexture = OvrAvatarSDKManager.Instance.GetTextureCopyManager().FallbackTextureSets[lodIndex].Normal; } normalTexture.anisoLevel = 4; if (metallicTexture != null) { avatarMaterialManager.AddTextureIDToTextureManager(materialState.metallicnessTextureID, true); } else { metallicTexture = OvrAvatarSDKManager.Instance.GetTextureCopyManager().FallbackTextureSets[lodIndex].DiffuseRoughness; } metallicTexture.anisoLevel = 16; mesh.materials[0].SetTexture(OvrAvatarMaterialManager.AVATAR_SHADER_MAINTEX, diffuseTexture); mesh.materials[0].SetTexture(OvrAvatarMaterialManager.AVATAR_SHADER_NORMALMAP, normalTexture); mesh.materials[0].SetTexture(OvrAvatarMaterialManager.AVATAR_SHADER_ROUGHNESSMAP, metallicTexture); mesh.materials[0].SetVector(OvrAvatarMaterialManager.AVATAR_SHADER_COLOR, materialState.albedoMultiplier); mesh.materials[0].SetFloat(OvrAvatarMaterialManager.AVATAR_SHADER_DIFFUSEINTENSITY, OvrAvatarMaterialManager.DiffuseIntensities[componentType]); mesh.materials[0].SetFloat(OvrAvatarMaterialManager.AVATAR_SHADER_RIMINTENSITY, OvrAvatarMaterialManager.RimIntensities[componentType]); mesh.materials[0].SetFloat(OvrAvatarMaterialManager.AVATAR_SHADER_REFLECTIONINTENSITY, OvrAvatarMaterialManager.ReflectionIntensities[componentType]); mesh.GetClosestReflectionProbes(avatarMaterialManager.ReflectionProbes); if (avatarMaterialManager.ReflectionProbes != null && avatarMaterialManager.ReflectionProbes.Count > 0) { mesh.materials[0].SetTexture(OvrAvatarMaterialManager.AVATAR_SHADER_CUBEMAP, avatarMaterialManager.ReflectionProbes[0].probe.texture); } if (EnableExpressive) { mesh.materials[0].SetVector(OvrAvatarMaterialManager.AVATAR_SHADER_IRIS_COLOR, ExpressiveParameters.irisColor); mesh.materials[0].SetVector(OvrAvatarMaterialManager.AVATAR_SHADER_LIP_COLOR, ExpressiveParameters.lipColor); mesh.materials[0].SetVector(OvrAvatarMaterialManager.AVATAR_SHADER_BROW_COLOR, ExpressiveParameters.browColor); mesh.materials[0].SetVector(OvrAvatarMaterialManager.AVATAR_SHADER_LASH_COLOR, ExpressiveParameters.lashColor); mesh.materials[0].SetVector(OvrAvatarMaterialManager.AVATAR_SHADER_SCLERA_COLOR, ExpressiveParameters.scleraColor); mesh.materials[0].SetVector(OvrAvatarMaterialManager.AVATAR_SHADER_GUM_COLOR, ExpressiveParameters.gumColor); mesh.materials[0].SetVector(OvrAvatarMaterialManager.AVATAR_SHADER_TEETH_COLOR, ExpressiveParameters.teethColor); mesh.materials[0].SetFloat(OvrAvatarMaterialManager.AVATAR_SHADER_LIP_SMOOTHNESS, ExpressiveParameters.lipSmoothness); } }
private void InitializeSingleComponentMaterial(IntPtr renderPart, int lodIndex) { ovrAvatarPBSMaterialState materialState = CAPI.ovrAvatarSkinnedMeshRenderPBSV2_GetPBSMaterialState(renderPart); int componentType = (int)OvrAvatarMaterialManager.GetComponentType(gameObject.name); var defaultProperties = AvatarMaterialManager.DefaultAvatarConfig.ComponentMaterialProperties; var diffuseTexture = OvrAvatarComponent.GetLoadedTexture(materialState.albedoTextureID); var normalTexture = OvrAvatarComponent.GetLoadedTexture(materialState.normalTextureID); var metallicTexture = OvrAvatarComponent.GetLoadedTexture(materialState.metallicnessTextureID); if (diffuseTexture == null) { diffuseTexture = AvatarMaterialManager.DiffuseFallbacks[lodIndex]; } if (normalTexture == null) { normalTexture = AvatarMaterialManager.NormalFallbacks[lodIndex]; } if (metallicTexture == null) { metallicTexture = AvatarMaterialManager.DiffuseFallbacks[lodIndex]; } mesh.materials[0].SetTexture(OvrAvatarMaterialManager.AVATAR_SHADER_MAINTEX, diffuseTexture); mesh.materials[0].SetTexture(OvrAvatarMaterialManager.AVATAR_SHADER_NORMALMAP, normalTexture); mesh.materials[0].SetTexture(OvrAvatarMaterialManager.AVATAR_SHADER_ROUGHNESSMAP, metallicTexture); mesh.materials[0].SetVector(OvrAvatarMaterialManager.AVATAR_SHADER_COLOR, materialState.albedoMultiplier); mesh.materials[0].SetFloat(OvrAvatarMaterialManager.AVATAR_SHADER_DIFFUSEINTENSITY, defaultProperties[componentType].DiffuseIntensity); mesh.materials[0].SetFloat(OvrAvatarMaterialManager.AVATAR_SHADER_RIMINTENSITY, defaultProperties[componentType].RimIntensity); mesh.materials[0].SetFloat(OvrAvatarMaterialManager.AVATAR_SHADER_REFLECTIONINTENSITY, defaultProperties[componentType].ReflectionIntensity); mesh.GetClosestReflectionProbes(AvatarMaterialManager.ReflectionProbes); if (AvatarMaterialManager.ReflectionProbes != null && AvatarMaterialManager.ReflectionProbes.Count > 0) { mesh.materials[0].SetTexture(OvrAvatarMaterialManager.AVATAR_SHADER_CUBEMAP, AvatarMaterialManager.ReflectionProbes[0].probe.texture); } if (EnableExpressive) { mesh.materials[0].SetVector(OvrAvatarMaterialManager.AVATAR_SHADER_IRIS_COLOR, ExpressiveParameters.irisColor); mesh.materials[0].SetVector(OvrAvatarMaterialManager.AVATAR_SHADER_LIP_COLOR, ExpressiveParameters.lipColor); mesh.materials[0].SetVector(OvrAvatarMaterialManager.AVATAR_SHADER_BROW_COLOR, ExpressiveParameters.browColor); mesh.materials[0].SetVector(OvrAvatarMaterialManager.AVATAR_SHADER_LASH_COLOR, ExpressiveParameters.lashColor); mesh.materials[0].SetVector(OvrAvatarMaterialManager.AVATAR_SHADER_SCLERA_COLOR, ExpressiveParameters.scleraColor); mesh.materials[0].SetVector(OvrAvatarMaterialManager.AVATAR_SHADER_GUM_COLOR, ExpressiveParameters.gumColor); mesh.materials[0].SetVector(OvrAvatarMaterialManager.AVATAR_SHADER_TEETH_COLOR, ExpressiveParameters.teethColor); mesh.materials[0].SetFloat(OvrAvatarMaterialManager.AVATAR_SHADER_LIP_SMOOTHNESS, ExpressiveParameters.lipSmoothness); } }
private void UpdateAvatarComponent(IntPtr nativeComponent) { ovrAvatarComponent nativeAvatarComponent = new ovrAvatarComponent(); CAPI.ovrAvatarComponent_Get(nativeComponent, false, ref nativeAvatarComponent); ConvertTransform(nativeAvatarComponent.transform, transform); for (UInt32 renderPartIndex = 0; renderPartIndex < nativeAvatarComponent.renderPartCount; renderPartIndex++) { if (RenderParts.Count <= renderPartIndex) { break; } OvrAvatarRenderComponent renderComponent = RenderParts[(int)renderPartIndex]; IntPtr renderPart = OvrAvatar.GetRenderPart(nativeAvatarComponent, renderPartIndex); ovrAvatarRenderPartType type = CAPI.ovrAvatarRenderPart_GetType(renderPart); ovrAvatarTransform localTransform; ovrAvatarVisibilityFlags visibilityMask; var mesh = renderComponent.mesh; var bones = renderComponent.bones; switch (type) { case ovrAvatarRenderPartType.SkinnedMeshRenderPBS: visibilityMask = CAPI.ovrAvatarSkinnedMeshRenderPBS_GetVisibilityMask(renderPart); localTransform = CAPI.ovrAvatarSkinnedMeshRenderPBS_GetTransform(renderPart); if ((visibilityMask & ovrAvatarVisibilityFlags.FirstPerson) != 0) { renderComponent.gameObject.SetActive(true); mesh.enabled = true; } UpdateSkinnedMesh(localTransform, renderPart, bones); UInt64 albedoTextureID = CAPI.ovrAvatarSkinnedMeshRenderPBS_GetAlbedoTextureAssetID(renderPart); UInt64 surfaceTextureID = CAPI.ovrAvatarSkinnedMeshRenderPBS_GetSurfaceTextureAssetID(renderPart); mesh.sharedMaterial.SetTexture("_Albedo", OvrAvatarComponent.GetLoadedTexture(albedoTextureID)); mesh.sharedMaterial.SetTexture("_Surface", OvrAvatarComponent.GetLoadedTexture(surfaceTextureID)); break; case ovrAvatarRenderPartType.SkinnedMeshRenderPBS_V2: visibilityMask = CAPI.ovrAvatarSkinnedMeshRenderPBSV2_GetVisibilityMask(renderPart); localTransform = CAPI.ovrAvatarSkinnedMeshRenderPBSV2_GetTransform(renderPart); if ((visibilityMask & ovrAvatarVisibilityFlags.FirstPerson) != 0) { renderComponent.gameObject.SetActive(true); mesh.enabled = true; } UpdateSkinnedMesh(localTransform, renderPart, bones); ovrAvatarPBSMaterialState materialState = CAPI.ovrAvatarSkinnedMeshRenderPBSV2_GetPBSMaterialState(renderPart); Texture2D diffuseTexture = OvrAvatarComponent.GetLoadedTexture(materialState.albedoTextureID); Texture2D normalTexture = OvrAvatarComponent.GetLoadedTexture(materialState.normalTextureID); Texture2D metallicTexture = OvrAvatarComponent.GetLoadedTexture(materialState.metallicnessTextureID); mesh.materials[0].SetTexture("_MainTex", diffuseTexture); mesh.materials[0].SetTexture("_NormalMap", normalTexture); mesh.materials[0].SetTexture("_RoughnessMap", metallicTexture); break; default: break; } } }
private void UpdateMaterial() { if (MeshInstance == null || MaterialID == 0) { return; } var mat = MeshInstance.material; var matState = MaterialState; mat.SetColor("_BaseColor", matState.baseColor); mat.SetInt("_BaseMaskType", (int)matState.baseMaskType); mat.SetVector("_BaseMaskParameters", matState.baseMaskParameters); mat.SetVector("_BaseMaskAxis", matState.baseMaskAxis); if (matState.alphaMaskTextureID != 0) { mat.SetTexture("_AlphaMask", OvrAvatarComponent.GetLoadedTexture(matState.alphaMaskTextureID)); mat.SetTextureScale("_AlphaMask", new Vector2(matState.alphaMaskScaleOffset.x, matState.alphaMaskScaleOffset.y)); mat.SetTextureOffset("_AlphaMask", new Vector2(matState.alphaMaskScaleOffset.z, matState.alphaMaskScaleOffset.w)); } if (matState.normalMapTextureID != 0) { mat.EnableKeyword("NORMAL_MAP_ON"); mat.SetTexture("_NormalMap", OvrAvatarComponent.GetLoadedTexture(matState.normalMapTextureID)); mat.SetTextureScale("_NormalMap", new Vector2(matState.normalMapScaleOffset.x, matState.normalMapScaleOffset.y)); mat.SetTextureOffset("_NormalMap", new Vector2(matState.normalMapScaleOffset.z, matState.normalMapScaleOffset.w)); } if (matState.parallaxMapTextureID != 0) { mat.SetTexture("_ParallaxMap", OvrAvatarComponent.GetLoadedTexture(matState.parallaxMapTextureID)); mat.SetTextureScale("_ParallaxMap", new Vector2(matState.parallaxMapScaleOffset.x, matState.parallaxMapScaleOffset.y)); mat.SetTextureOffset("_ParallaxMap", new Vector2(matState.parallaxMapScaleOffset.z, matState.parallaxMapScaleOffset.w)); } if (matState.roughnessMapTextureID != 0) { mat.EnableKeyword("ROUGHNESS_ON"); mat.SetTexture("_RoughnessMap", OvrAvatarComponent.GetLoadedTexture(matState.roughnessMapTextureID)); mat.SetTextureScale("_RoughnessMap", new Vector2(matState.roughnessMapScaleOffset.x, matState.roughnessMapScaleOffset.y)); mat.SetTextureOffset("_RoughnessMap", new Vector2(matState.roughnessMapScaleOffset.z, matState.roughnessMapScaleOffset.w)); } mat.EnableKeyword(OvrAvatarComponent.LayerKeywords[matState.layerCount]); for (ulong layerIndex = 0; layerIndex < matState.layerCount; layerIndex++) { ovrAvatarMaterialLayerState layer = matState.layers[layerIndex]; mat.SetInt(OvrAvatarComponent.LayerSampleModeParameters[layerIndex], (int)layer.sampleMode); mat.SetInt(OvrAvatarComponent.LayerBlendModeParameters[layerIndex], (int)layer.blendMode); mat.SetInt(OvrAvatarComponent.LayerMaskTypeParameters[layerIndex], (int)layer.maskType); mat.SetColor(OvrAvatarComponent.LayerColorParameters[layerIndex], layer.layerColor); if (layer.sampleMode != ovrAvatarMaterialLayerSampleMode.Color) { string surfaceProperty = OvrAvatarComponent.LayerSurfaceParameters[layerIndex]; mat.SetTexture(surfaceProperty, OvrAvatarComponent.GetLoadedTexture(layer.sampleTexture)); mat.SetTextureScale(surfaceProperty, new Vector2(layer.sampleScaleOffset.x, layer.sampleScaleOffset.y)); mat.SetTextureOffset(surfaceProperty, new Vector2(layer.sampleScaleOffset.z, layer.sampleScaleOffset.w)); } if (layer.sampleMode == ovrAvatarMaterialLayerSampleMode.Parallax) { mat.EnableKeyword("PARALLAX_ON"); } mat.SetColor(OvrAvatarComponent.LayerSampleParametersParameters[layerIndex], layer.sampleParameters); mat.SetColor(OvrAvatarComponent.LayerMaskParametersParameters[layerIndex], layer.maskParameters); mat.SetColor(OvrAvatarComponent.LayerMaskAxisParameters[layerIndex], layer.maskAxis); } }