public override void OnPreviewGUI(Rect r, GUIStyle background) { GradientTexture gradientTexture = target as GradientTexture; Texture2D texture = gradientTexture.GetTexture(); if (texture != null) { Rect previewRect = new Rect(r); float textureAspectRatio = gradientTexture.resolution.x / gradientTexture.resolution.y; float previewAspectRatio = r.width / r.height; if (textureAspectRatio >= previewAspectRatio) { float scale = gradientTexture.resolution.x / r.width; float newHeight = gradientTexture.resolution.y / scale; previewRect.width = r.width; previewRect.height = newHeight; previewRect.y = (r.height / 2.0f) - (newHeight / 2.0f); } else { float scale = gradientTexture.resolution.y / r.height; float newWidth = gradientTexture.resolution.x / scale; previewRect.width = newWidth; previewRect.height = r.height; previewRect.x = (r.width / 2.0f) - (newWidth / 2.0f); } EditorGUI.DrawPreviewTexture(previewRect, texture); } }
void Update() { var material = m_Raymarcher.GetRaymarchMaterial(); bool useReflections = m_Reflections > 0; bool kw = material.IsKeywordEnabled(REFLECTIONS_KEYWORD); if (kw && !useReflections) { material.DisableKeyword(REFLECTIONS_KEYWORD); } else if (!kw && useReflections) { material.EnableKeyword(REFLECTIONS_KEYWORD); } material.SetInt("_Reflections", m_Reflections); material.SetInt("_ReflectionSteps", m_ReflectionSteps); material.SetColor("_ReflectionColor", m_ReflectionColor); material.SetFloat("_Glow", m_Glow); material.SetColor("_GlowColor", m_ColorizedGlow); material.SetTexture("_SkyGradient", m_SkyGradient.GetTexture()); material.SetFloat("_SkyGradientNoise", m_SkyGradientNoise); }