public void RemoveReceiver(ShadowReceiver receiver) { if (_ShadowReceivers.Contains(receiver)) { _ShadowReceivers.Remove(receiver); } }
// Token: 0x060001B5 RID: 437 RVA: 0x0001A3A0 File Offset: 0x000185A0 public void AddReceiver(ShadowReceiver receiver) { if (!this._ShadowReceivers.Contains(receiver)) { this._ShadowReceivers.Add(receiver); } }
void SetTerrainProperties() { ShadowReceiver shadowReceiver = (ShadowReceiver)target; if (shadowReceiver != null && shadowReceiver.IsTerrain()) { serializedObject.Update(); Terrain terrain = shadowReceiver.GetComponent <Terrain>(); if (terrain != null) { shadowReceiver = (ShadowReceiver)target; TerrainCollider terrainCollider = terrain.GetComponent <TerrainCollider>(); terrainCollider.enabled = false; terrain.castShadows = false; terrain.enabled = false; } serializedObject.ApplyModifiedProperties(); if (GUI.changed) { EditorUtility.SetDirty(terrain); } } }
public void AddReceiver(ShadowReceiver receiver) { if (!_ShadowReceivers.Contains(receiver)) { CheckForTerrain(receiver); _ShadowReceivers.Add(receiver); } }
/// <summary>Deserialize into new object instance</summary> public Cel(AnimationDeserializeContext context) { friendlyName = context.br.ReadNullableString(); spriteRef = new SpriteRef(context); if (context.br.ReadBoolean()) { shadowReceiver = new ShadowReceiver(context); } }
void CheckForTerrain(ShadowReceiver receiver) { #if !UNITY_3_5 && !UNITY_3_4 && !UNITY_3_3 && !UNITY_3_2 && !UNITY_3_1 && !UNITY_3_0 && !UNITY_3_0_0 if (receiver.IsTerrain()) { if (receiver.GetTerrain().materialTemplate != null) { receiver.GetTerrain().materialTemplate.SetTexture("_ShadowTex", _Tex.GetTexture()); } } #endif }
public void DrawShadowReceiver(Sprite whitemask, ShadowReceiver shadowReceiver, Position position, bool flipX, float debugOpacity = 0.7f) { if (Camera == null) { throw new InvalidOperationException("Cannot draw shadows outside of batch"); } if (debugDrawShadowReceivers) { sb.DrawWorld(whitemask, position, Color.White * debugOpacity, flipX); } if (shadowCasterList == null) { return; // Nothing to do } shadowCasterList.DrawShadowReceiver(this, whitemask, shadowReceiver, position, flipX); }
public void SetupShadowReceiver(Sprite whitemask, ShadowReceiver shadowReceiver, Position position, bool flipX) { if (debugDrawShadowReceiverCulling) { sb.DrawWorld(whitemask, position, Color.White, flipX); } // Setup matrix for drawing shadow sprites (matches SpriteBatch) shadowMaskEffect.Parameters["ViewProjectMatrix"].SetValue(Camera.ViewProjectMatrix); // Setup shadow mask: sb.GraphicsDevice.Textures[1] = whitemask.texture; sb.GraphicsDevice.SamplerStates[1] = SamplerState.PointClamp; // Setup matrix for calculating texture coordinates within the shadow mask (converts spritesheet corner positions in Display space to UVs) Matrix maskTextureMatrix; if (!flipX) { Vector2 drawOriginInSheet = new Vector2(whitemask.sourceRectangle.X + whitemask.origin.X, whitemask.sourceRectangle.Y + whitemask.origin.Y + 1); // <- equivelent to Sprite.DrawOrigin Vector2 maskTopLeftDisplay = position.ToDisplay() - drawOriginInSheet; maskTextureMatrix = Matrix.CreateTranslation(new Vector3(-maskTopLeftDisplay, 0)) * Matrix.CreateScale(1f / whitemask.texture.Width, 1f / whitemask.texture.Height, 1f); } else { Vector2 drawOriginInSheetFlipX = new Vector2(whitemask.texture.Width - (whitemask.sourceRectangle.X + whitemask.origin.X) - 1, whitemask.sourceRectangle.Y + whitemask.origin.Y + 1); // <- equivelent to Sprite.DrawOriginFlipX Vector2 maskTopLeftDisplay = position.ToDisplay() - drawOriginInSheetFlipX; maskTextureMatrix = Matrix.CreateTranslation(new Vector3(-maskTopLeftDisplay, 0)) * Matrix.CreateScale(1f / whitemask.texture.Width, 1f / whitemask.texture.Height, 1f) * Matrix.CreateScale(-1f, 1f, 1f) * Matrix.CreateTranslation(1, 0, 0); // <- equivalent to SpriteEffects.FlipHorizontally } shadowMaskEffect.Parameters["MaskTextureMatrix"].SetValue(maskTextureMatrix); if (!debugDrawShadowReceiverCulling) { // Break out of the active sprite batch to draw shadows using the mask effect: sb.End(); sb.Begin(0, null, SamplerState.PointClamp, null, rasterizerState, shadowMaskEffect, Camera.ViewMatrix); } }
void ApplyTerrainTextureMatrix(ShadowReceiver receiver) { bool standardTerrain = receiver.IsStandardTerrain(); if (standardTerrain) { if (receiver._terrainMaterial != null) { receiver.GetTerrain().materialTemplate.SetFloat("_UnityBugHack", Random.Range(0.0f, 1.0f)); receiver._terrainMaterial.SetMatrix("_GlobalProjector", _FinalMatrix); receiver._terrainMaterial.SetMatrix("_GlobalProjectorClip", _FinalClipMatrix); } } else { if (receiver._terrainMaterial != null) { receiver._terrainMaterial.SetMatrix("_GlobalProjector", _FinalMatrix); receiver._terrainMaterial.SetMatrix("_GlobalProjectorClip", _FinalClipMatrix); } receiver.GetTerrain().materialTemplate = receiver._terrainMaterial; } }
public void DrawShadowReceiver(DrawContext context, Sprite whitemask, ShadowReceiver shadowReceiver, Position shadowReceiverPosition, bool shadowReceiverFlipX) { Bounds receiverBounds = new Bounds(whitemask.WorldSpaceBounds).MaybeFlipX(shadowReceiverFlipX) + shadowReceiverPosition.ToWorldZero; bool startedReceivingShadows = false; // For each shadow caster: Debug.Assert(shadowCasterXBounds.Count == shadowCasters.Count); for (int i = 0; i < shadowCasterXBounds.Count; i++) { StartEnd casterWorldXBounds = shadowCasterXBounds[i]; if (casterWorldXBounds.start >= receiverBounds.endX || receiverBounds.startX >= casterWorldXBounds.end) { continue; // Horizontally out of range } var shadowCaster = shadowCasters[i]; // Determine the ground height of the shadow: int groundHeight; if (shadowReceiver.heightmap.HasData) { var heightmapView = new HeightmapView(shadowReceiver.heightmap, shadowReceiverPosition, shadowReceiverFlipX); int startX = shadowCaster.position.X + shadowCaster.physicsStartX; int endX = shadowCaster.position.X + shadowCaster.physicsEndX; if (endX <= startX) { endX = startX + 1; // <- whoops our shadow caster has no width... quick fix-up for now... } groundHeight = heightmapView.GetHeightForShadow(startX, endX, shadowCaster.position.Z, shadowReceiver.heightmapExtendDirection); } else { groundHeight = shadowReceiver.heightmap.DefaultHeight + shadowReceiverPosition.Y; } int shadowDifference = shadowCaster.position.Y - groundHeight; // NOTE: shadowOffset is pre-flipped Position shadowPosition = new Position(shadowCaster.position.X, groundHeight, shadowCaster.position.Z) + shadowCaster.shadowOffset; if (shadowCaster.shadows[0].startHeight > shadowDifference) { continue; // Out of range } int shadowIndex = 0; while (shadowIndex + 1 < shadowCaster.shadows.Count) { if (shadowCaster.shadows[shadowIndex + 1].startHeight > shadowDifference) { break; } shadowIndex++; } Sprite shadowSprite; if (!shadowCaster.shadows[shadowIndex].shadowSpriteRef.ResolveBestEffort(out shadowSprite)) { continue; } // Determine whether the shadow overlaps the whitemask Bounds shadowBounds = new Bounds(shadowSprite.WorldSpaceBounds).MaybeFlipX(shadowCaster.flipX) + shadowPosition.ToWorldZero; Bounds worldZeroDrawBounds = Bounds.Intersection(receiverBounds, shadowBounds); if (!worldZeroDrawBounds.HasPositiveArea) { continue; } if (!startedReceivingShadows) { startedReceivingShadows = true; context.SetupShadowReceiver(whitemask, shadowReceiver, shadowReceiverPosition, shadowReceiverFlipX); } // Drawing with clipping: { Rectangle clipRect = new Rectangle // <- Region within the source rectangle (NOTE: initially with Y+ up, we fix later) { X = worldZeroDrawBounds.startX - shadowBounds.startX, Y = worldZeroDrawBounds.startY - shadowBounds.startY, Width = worldZeroDrawBounds.endX - worldZeroDrawBounds.startX, Height = worldZeroDrawBounds.endY - worldZeroDrawBounds.startY, }; // Flipping: if (shadowCaster.flipX) { clipRect.X = shadowSprite.sourceRectangle.Width - (clipRect.X + clipRect.Width); // RegionFlipX } // IMPORTANT: Convert clipRect from Y+ Up coordinates to correct Texel coordinates clipRect.Y = shadowSprite.sourceRectangle.Height - (clipRect.Y + clipRect.Height); // RegionFlipY // Turn it into a source rectangle within the texture: clipRect.X += shadowSprite.sourceRectangle.X; clipRect.Y += shadowSprite.sourceRectangle.Y; Vector2 displayPosition = new Vector2(worldZeroDrawBounds.startX, -(worldZeroDrawBounds.startY + clipRect.Height)); // NOTE: don't need to consider origin, because it's built into the draw bounds context.SpriteBatch.Draw(shadowSprite.texture, displayPosition, clipRect, shadowCaster.color, 0f, Vector2.Zero, 1, shadowCaster.flipX ? SpriteEffects.FlipHorizontally : SpriteEffects.None, 0); } } if (startedReceivingShadows) { context.TeardownShadowReceiver(); } }