-
Notifications
You must be signed in to change notification settings - Fork 242
Commit
release-izar
- Loading branch information
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
// Copyright 2015 Google Inc. All rights reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
|
||
// To use in a surface shader, add the following text to the code: | ||
// | ||
// #pragma surface ... vertex:vert <-- add "vertex:vert" to this line | ||
// #include "CardboardDistortion.cginc" <-- copy the next 4 lines | ||
// void vert (inout appdata_base v) { | ||
// v.vertex = undistortSurface(v.vertex); | ||
// } | ||
|
||
// To use in a vertex shader, modify it as follows: | ||
// | ||
// #include "CardboardDistortion.cginc" <-- add this | ||
// | ||
// v2f vert (appdata_blah v) { | ||
// v2f o; | ||
// o.vertex = undistortVertex(v.vertex); <-- replace "mul(UNITY_MATRIX_MVP, v.vertex)" | ||
// ... | ||
// return o; | ||
// } | ||
|
||
float4 _Undistortion; | ||
float _MaxRadSq; | ||
float _NearClip; | ||
float4x4 _RealProjection; | ||
float4x4 _FixProjection; | ||
|
||
// Convert point from world space to undistorted camera space. | ||
float4 undistort(float4 pos) { | ||
// Go to camera space. | ||
pos = mul(UNITY_MATRIX_MV, pos); | ||
if (pos.z <= -_NearClip) { // Reminder: Forward is -Z. | ||
// Undistort the point's coordinates in XY. | ||
float r2 = clamp(dot(pos.xy, pos.xy) / (pos.z*pos.z), 0, _MaxRadSq); | ||
pos.xy *= 1 + (_Undistortion.x + _Undistortion.y*r2)*r2; | ||
} | ||
return pos; | ||
} | ||
|
||
// Multiply by no-lens projection matrix after undistortion. | ||
float4 undistortVertex(float4 pos) { | ||
return mul(_RealProjection, undistort(pos)); | ||
} | ||
|
||
// Surface shader hides away the MVP multiplication, so we have | ||
// to multiply by _FixProjection = inverse(MVP)*_RealProjection. | ||
float4 undistortSurface(float4 pos) { | ||
return mul(_FixProjection, undistort(pos)); | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
// Copyright 2015 Google Inc. All rights reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
using UnityEngine; | ||
using UnityEditor; | ||
using System.Collections; | ||
|
||
/// A custom editor for properties on the CardboardAudioListener script. This appears in the | ||
/// Inspector window of a CardboardAudioListener object. | ||
[CustomEditor(typeof(CardboardAudioListener))] | ||
public class CardboardAudioListenerEditor : Editor { | ||
private SerializedProperty globalGainDb = null; | ||
private SerializedProperty quality = null; | ||
private SerializedProperty worldScale = null; | ||
|
||
private GUIContent globalGainLabel = new GUIContent("Global Gain (dB)", | ||
"Sets the global gain of the system. Can be used to adjust the overall output volume."); | ||
private GUIContent qualityLabel = new GUIContent("Quality", | ||
"Sets the quality mode in which the spatial audio will be rendered. " + | ||
"Higher quality modes allow for increased fidelity at the cost of greater CPU usage."); | ||
private GUIContent worldScaleLabel = new GUIContent("World Scale", | ||
"Sets the ratio between game units and real world units (meters)."); | ||
|
||
void OnEnable () { | ||
globalGainDb = serializedObject.FindProperty("globalGainDb"); | ||
quality = serializedObject.FindProperty("quality"); | ||
worldScale = serializedObject.FindProperty("worldScale"); | ||
} | ||
|
||
/// @cond | ||
public override void OnInspectorGUI () { | ||
serializedObject.Update(); | ||
|
||
// Rendering quality can only be modified through the Inspector in Edit mode. | ||
GUI.enabled = !EditorApplication.isPlaying; | ||
EditorGUILayout.PropertyField(quality, qualityLabel); | ||
GUI.enabled = true; | ||
|
||
EditorGUILayout.Separator(); | ||
|
||
EditorGUILayout.Slider(globalGainDb, CardboardAudio.minGainDb, CardboardAudio.maxGainDb, | ||
globalGainLabel); | ||
EditorGUILayout.Slider(worldScale, CardboardAudio.minWorldScale, CardboardAudio.maxWorldScale, | ||
worldScaleLabel); | ||
|
||
serializedObject.ApplyModifiedProperties(); | ||
} | ||
/// @endcond | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
// Copyright 2015 Google Inc. All rights reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
using UnityEngine; | ||
using UnityEditor; | ||
using System.Collections; | ||
|
||
/// A custom editor for properties on the CardboardAudioRoom script. This appears in the Inspector | ||
/// window of a CardboardAudioRoom object. | ||
[CustomEditor(typeof(CardboardAudioRoom))] | ||
[CanEditMultipleObjects] | ||
public class CardboardAudioRoomEditor : Editor { | ||
private SerializedProperty leftWall = null; | ||
private SerializedProperty rightWall = null; | ||
private SerializedProperty floor = null; | ||
private SerializedProperty ceiling = null; | ||
private SerializedProperty backWall = null; | ||
private SerializedProperty frontWall = null; | ||
private SerializedProperty reflectivity = null; | ||
private SerializedProperty reverbGainDb = null; | ||
private SerializedProperty reverbBrightness = null; | ||
private SerializedProperty reverbTime = null; | ||
private SerializedProperty size = null; | ||
|
||
private GUIContent surfaceMaterialsLabel = new GUIContent("Surface Materials", | ||
"Room surface materials to calculate the acoustic properties of the room."); | ||
private GUIContent surfaceMaterialLabel = new GUIContent("Surface Material", | ||
"Surface material used to calculate the acoustic properties of the room."); | ||
private GUIContent reflectivityLabel = new GUIContent("Reflectivity", | ||
"Adjusts what proportion of the direct sound is reflected back by each surface, after an " + | ||
"appropriate delay. Reverberation is unaffected by this setting."); | ||
private GUIContent reverbGainLabel = new GUIContent("Gain (dB)", | ||
"Applies a gain adjustment to the reverberation in the room. The default value will leave " + | ||
"reverb unaffected."); | ||
private GUIContent reverbPropertiesLabel = new GUIContent("Reverb Properties", | ||
"Parameters to adjust the reverb properties of the room."); | ||
private GUIContent reverbBrightnessLabel = new GUIContent("Brightness", | ||
"Adjusts the balance between high and low frequencies in the reverb."); | ||
private GUIContent reverbTimeLabel = new GUIContent("Time", | ||
"Adjusts the overall duration of the reverb by a positive scaling factor."); | ||
private GUIContent sizeLabel = new GUIContent("Size", "Sets the room dimensions."); | ||
|
||
void OnEnable () { | ||
leftWall = serializedObject.FindProperty("leftWall"); | ||
rightWall = serializedObject.FindProperty("rightWall"); | ||
floor = serializedObject.FindProperty("floor"); | ||
ceiling = serializedObject.FindProperty("ceiling"); | ||
backWall = serializedObject.FindProperty("backWall"); | ||
frontWall = serializedObject.FindProperty("frontWall"); | ||
reflectivity = serializedObject.FindProperty("reflectivity"); | ||
reverbGainDb = serializedObject.FindProperty("reverbGainDb"); | ||
reverbBrightness = serializedObject.FindProperty("reverbBrightness"); | ||
reverbTime = serializedObject.FindProperty("reverbTime"); | ||
size = serializedObject.FindProperty("size"); | ||
} | ||
|
||
/// @cond | ||
public override void OnInspectorGUI () { | ||
serializedObject.Update(); | ||
|
||
EditorGUILayout.LabelField(surfaceMaterialsLabel); | ||
++EditorGUI.indentLevel; | ||
DrawSurfaceMaterial(leftWall); | ||
DrawSurfaceMaterial(rightWall); | ||
DrawSurfaceMaterial(floor); | ||
DrawSurfaceMaterial(ceiling); | ||
DrawSurfaceMaterial(backWall); | ||
DrawSurfaceMaterial(frontWall); | ||
--EditorGUI.indentLevel; | ||
|
||
EditorGUILayout.Separator(); | ||
|
||
EditorGUILayout.Slider(reflectivity, 0.0f, CardboardAudio.maxReflectivity, reflectivityLabel); | ||
|
||
EditorGUILayout.Separator(); | ||
|
||
EditorGUILayout.LabelField(reverbPropertiesLabel); | ||
++EditorGUI.indentLevel; | ||
EditorGUILayout.Slider(reverbGainDb, CardboardAudio.minGainDb, CardboardAudio.maxGainDb, | ||
reverbGainLabel); | ||
EditorGUILayout.Slider(reverbBrightness, CardboardAudio.minReverbBrightness, | ||
CardboardAudio.maxReverbBrightness, reverbBrightnessLabel); | ||
EditorGUILayout.Slider(reverbTime, 0.0f, CardboardAudio.maxReverbTime, reverbTimeLabel); | ||
--EditorGUI.indentLevel; | ||
|
||
EditorGUILayout.Separator(); | ||
|
||
EditorGUILayout.PropertyField(size, sizeLabel); | ||
|
||
serializedObject.ApplyModifiedProperties(); | ||
} | ||
/// @endcond | ||
|
||
private void DrawSurfaceMaterial (SerializedProperty surfaceMaterial) { | ||
#if UNITY_4_5 | ||
surfaceMaterialLabel.text = ObjectNames.NicifyVariableName(surfaceMaterial.name); | ||
#else | ||
surfaceMaterialLabel.text = surfaceMaterial.displayName; | ||
#endif | ||
EditorGUILayout.PropertyField(surfaceMaterial, surfaceMaterialLabel); | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.