public void ReloadHairAsset() { HairWorksIntegration.hwAssetReload(m_hasset); HairWorksIntegration.hwAssetGetDefaultDescriptor(m_hasset, ref m_params); HairWorksIntegration.hwInstanceSetDescriptor(m_hinstance, ref m_params); RepaintWindow(); }
static void BeginRender() { if (s_command_buffer == null) { s_command_buffer = new CommandBuffer(); s_command_buffer.name = "Hair"; s_command_buffer.IssuePluginEvent(HairWorksIntegration.hwGetRenderEventFunc(), 0); } var cam = Camera.current; if (cam != null) { Matrix4x4 V = cam.worldToCameraMatrix; Matrix4x4 P = GL.GetGPUProjectionMatrix(cam.projectionMatrix, DoesRenderToTexture(cam)); float fov = cam.fieldOfView; HairWorksIntegration.hwSetViewProjection(ref V, ref P, fov); HairLight.AssignLightData(); if (!s_cameras.Contains(cam)) { cam.AddCommandBuffer(s_timing, s_command_buffer); s_cameras.Add(cam); } } HairWorksIntegration.hwBeginScene(); }
void LateUpdate() { if (s_nth_LateUpdate++ == 0) { HairWorksIntegration.hwStepSimulation(Time.deltaTime); } }
void Update() { if (!m_hasset) { return; } UpdateBones(); HairWorksIntegration.hwInstanceSetDescriptor(m_hinstance, ref m_params); HairWorksIntegration.hwInstanceUpdateSkinningMatrices(m_hinstance, m_skinning_matrices.Length, m_skinning_matrices_ptr); if (m_probe_mesh != null) { var bmin = Vector3.zero; var bmax = Vector3.zero; HairWorksIntegration.hwInstanceGetBounds(m_hinstance, ref bmin, ref bmax); var center = (bmin + bmax) * 0.5f; var size = bmax - center; m_probe_mesh.bounds = new Bounds(center, size); } s_nth_LateUpdate = 0; }
void LateUpdate() { HairWorksIntegration.hwStepSimulation(Time.deltaTime); SphericalHarmonicsL2 aSample; // SH sample consists of 27 floats LightProbes.GetInterpolatedProbe(this.transform.position, this.GetComponent <MeshRenderer>(), out aSample); for (int iC = 0; iC < 3; iC++) { avCoeff[iC] = new Vector4((float)aSample [iC, 3], aSample [iC, 1], aSample [iC, 2], aSample [iC, 0] - aSample [iC, 6]); } for (int iC = 0; iC < 3; iC++) { avCoeff [iC + 3].x = aSample [iC, 4]; avCoeff [iC + 3].y = aSample [iC, 5]; avCoeff [iC + 3].z = 3.0f * aSample [iC, 6]; avCoeff [iC + 3].w = aSample [iC, 7]; } avCoeff [6].x = aSample [0, 8]; avCoeff [6].y = aSample [1, 8]; avCoeff [6].y = aSample [2, 8]; avCoeff [6].w = 1.0f; if (oldColor != ambientLight) { aSample.AddAmbientLight(ambientLight); oldColor = ambientLight; } }
public void UpdateBones() { int num_bones = HairWorksIntegration.hwAssetGetNumBones(m_hasset); if (m_bones == null || m_bones.Length != num_bones) { m_bones = new Transform[num_bones]; if (m_root_bone == null) { m_root_bone = GetComponent <Transform>(); } var children = m_root_bone.GetComponentsInChildren <Transform>(); for (int i = 0; i < num_bones; ++i) { string name = HairWorksIntegration.hwAssetGetBoneNameString(m_hasset, i); m_bones[i] = Array.Find(children, (a) => { return(a.name == name); }); if (m_bones[i] == null) { m_bones[i] = m_root_bone; } } } if (m_skinning_matrices == null) { m_inv_bindpose = new Matrix4x4[num_bones]; m_skinning_matrices = new Matrix4x4[num_bones]; m_skinning_matrices_ptr = Marshal.UnsafeAddrOfPinnedArrayElement(m_skinning_matrices, 0); for (int i = 0; i < num_bones; ++i) { m_inv_bindpose[i] = Matrix4x4.identity; m_skinning_matrices[i] = Matrix4x4.identity; } for (int i = 0; i < num_bones; ++i) { HairWorksIntegration.hwAssetGetBindPose(m_hasset, i, ref m_inv_bindpose[i]); m_inv_bindpose[i] = m_inv_bindpose[i].inverse; } m_conversion_matrix = Matrix4x4.identity; if (m_invert_bone_x) { m_conversion_matrix *= Matrix4x4.Scale(new Vector3(-1.0f, 1.0f, 1.0f)); } } for (int i = 0; i < m_bones.Length; ++i) { var t = m_bones[i]; if (t != null) { m_skinning_matrices[i] = t.localToWorldMatrix * m_conversion_matrix * m_inv_bindpose[i]; } } }
public void Render() { if (!m_hasset) { return; } HairWorksIntegration.hwSetShader(m_hshader); HairWorksIntegration.hwSetSphericalHarmonics(ref avCoeff [0], ref avCoeff [1], ref avCoeff [2], ref avCoeff [3], ref avCoeff [4], ref avCoeff [5], ref avCoeff [6]); HairWorksIntegration.hwRender(m_hinstance); }
void Render() { if (!m_hasset) { return; } HairWorksIntegration.hwSetShader(m_hshader); HairWorksIntegration.hwRender(m_hinstance); }
public void LoadHairShader(string path_to_cso) { // release existing shader if (m_hshader) { HairWorksIntegration.hwShaderRelease(m_hshader); m_hshader = hwHShader.NullHandle; } // load shader if (m_hshader = HairWorksIntegration.hwShaderLoadFromFile(Application.streamingAssetsPath + "/" + path_to_cso)) { m_hair_shader = path_to_cso; } #if UNITY_EDITOR RepaintWindow(); #endif }
static void BeginRender() { if (s_command_buffer == null) { s_command_buffer = new CommandBuffer(); s_command_buffer.name = "Hair"; s_command_buffer.IssuePluginEvent(HairWorksIntegration.hwGetRenderEventFunc(), 0); } var cam = Camera.current; bool goodToGo = false; #if UNITY_EDITOR if (UnityEditor.EditorApplication.isPlaying) { goodToGo = cam.CompareTag("MainCamera"); } else { goodToGo = cam.CompareTag("Untagged"); } #else goodToGo = cam.CompareTag("MainCamera"); #endif if (cam != null && goodToGo) { Matrix4x4 V = cam.worldToCameraMatrix; Matrix4x4 P = GL.GetGPUProjectionMatrix(cam.projectionMatrix, DoesRenderToTexture(cam)); float fov = cam.fieldOfView; HairWorksIntegration.hwSetViewProjection(ref V, ref P, fov); HairLight.AssignLightData(); if (!s_cameras.Contains(cam)) { cam.AddCommandBuffer(s_timing, s_command_buffer); s_cameras.Add(cam); } } //foreach (HairLight hLight in HairLight.GetInstances()) { //if (Camera.current == Camera.main) //hLight.RenderShadowDepth (Camera.main); //} HairWorksIntegration.hwBeginScene(); }
public void LoadHairAsset(string path_to_apx, bool reset_params = true) { // release existing instance & asset if (m_hinstance) { HairWorksIntegration.hwInstanceRelease(m_hinstance); m_hinstance = hwHInstance.NullHandle; } if (m_hasset) { HairWorksIntegration.hwAssetRelease(m_hasset); m_hasset = hwHAsset.NullHandle; } // load & create instance if (m_hasset = HairWorksIntegration.hwAssetLoadFromFile(Application.streamingAssetsPath + "/" + path_to_apx)) { m_hair_asset = path_to_apx; m_hinstance = HairWorksIntegration.hwInstanceCreate(m_hasset); if (reset_params) { HairWorksIntegration.hwAssetGetDefaultDescriptor(m_hasset, ref m_params); } } // update bone structure if (reset_params) { m_bones = null; m_skinning_matrices = null; m_skinning_matrices_ptr = IntPtr.Zero; } UpdateBones(); #if UNITY_EDITOR Update(); RepaintWindow(); #endif }
static public void AssignLightData() { if (s_light_data == null) { s_light_data = new hwLightData[hwLightData.MaxLights]; s_light_data_ptr = Marshal.UnsafeAddrOfPinnedArrayElement(s_light_data, 0); } var instances = GetInstances(); int n = Mathf.Min(instances.Count, hwLightData.MaxLights); int i = 0; foreach (var l in instances) { s_light_data[i] = l.GetLightData(); if (++i == n) { break; } } HairWorksIntegration.hwSetLights(n, s_light_data_ptr); }
void LateUpdate() { HairWorksIntegration.hwStepSimulation(Time.deltaTime); if (LightmapSettings.lightProbes.count > 0) { SphericalHarmonicsL2 aSample; // SH sample consists of 27 floats LightProbes.GetInterpolatedProbe(this.transform.position, this.GetComponent <MeshRenderer> (), out aSample); aSample.AddAmbientLight(ambientLight); for (int iC = 0; iC < 3; iC++) { avCoeff [iC] = new Vector4((float)aSample [iC, 3], aSample [iC, 1], aSample [iC, 2], aSample [iC, 0] - aSample [iC, 6]); } for (int iC = 0; iC < 3; iC++) { avCoeff [iC + 3].x = aSample [iC, 4]; avCoeff [iC + 3].y = aSample [iC, 5]; avCoeff [iC + 3].z = 3.0f * aSample [iC, 6]; avCoeff [iC + 3].w = aSample [iC, 7]; } avCoeff [6].x = aSample [0, 8]; avCoeff [6].y = aSample [1, 8]; avCoeff [6].y = aSample [2, 8]; avCoeff [6].w = 1.0f; } else { avCoeff [0] = Vector4.zero; avCoeff [1] = Vector4.zero; avCoeff [2] = Vector4.zero; avCoeff [3] = Vector4.zero; avCoeff [4] = Vector4.zero; avCoeff [5] = Vector4.zero; avCoeff [6] = Vector4.zero; } }
void Awake() { HairWorksIntegration.hwSetLogCallback(); }
public void AssignTexture(hwTextureType type, Texture2D tex) { HairWorksIntegration.hwInstanceSetTexture(m_hinstance, type, tex.GetNativeTexturePtr()); }
public static void EndRender() { HairWorksIntegration.hwEndScene(); }
public void ReloadHairShader() { HairWorksIntegration.hwShaderReload(m_hshader); RepaintWindow(); }
void Awake() { HairWorksIntegration.hwSetLogCallback(); oldColor = ambientLight; }
void Update() { UpdateBones(); HairWorksIntegration.hwInstanceSetDescriptor(m_hinstance, ref m_params); HairWorksIntegration.hwInstanceUpdateSkinningMatrices(m_hinstance, m_skinning_matrices.Length, m_skinning_matrices_ptr); if (m_probe_mesh != null) { var bmin = Vector3.zero; var bmax = Vector3.zero; HairWorksIntegration.hwInstanceGetBounds(m_hinstance, ref bmin, ref bmax); var center = (bmin + bmax) * 0.5f; var size = bmax - center; m_probe_mesh.bounds = new Bounds(center, size); } if (updateTextures) { if (root != null) { AssignTexture(hwTextureType.ROOT_COLOR, root); } if (tip != null) { AssignTexture(hwTextureType.TIP_COLOR, tip); } if (specular != null) { AssignTexture(hwTextureType.SPECULAR, specular); } if (clump != null) { AssignTexture(hwTextureType.CLUMP_SCALE, clump); } if (density != null) { AssignTexture(hwTextureType.DENSITY, density); } if (stiffness != null) { AssignTexture(hwTextureType.STIFFNESS, stiffness); } if (waviness != null) { AssignTexture(hwTextureType.WAVE_SCALE, waviness); } if (width != null) { AssignTexture(hwTextureType.WIDTH, width); } if (rootStiffness != null) { AssignTexture(hwTextureType.ROOT_STIFFNESS, rootStiffness); } if (clumpRoundness != null) { AssignTexture(hwTextureType.CLUMP_ROUNDNESS, clumpRoundness); } if (waveFrequency != null) { AssignTexture(hwTextureType.WAVE_FREQ, waveFrequency); } if (strand != null) { AssignTexture(hwTextureType.STRAND, strand); } if (length != null) { AssignTexture(hwTextureType.LENGTH, length); } if (weights != null) { AssignTexture(hwTextureType.WEIGHTS, weights); } updateTextures = false; } }
void OnDestroy() { HairWorksIntegration.hwInstanceRelease(m_hinstance); HairWorksIntegration.hwAssetRelease(m_hasset); }