private static bool Compare(PCameraInfo f1, PCameraInfo f2) { bool ret = SoftMath.FloatEqual(f1.fieldOfView, f2.fieldOfView) && SoftMath.FloatEqual(f1.nearPlane, f2.nearPlane) && SoftMath.FloatEqual(f1.farPlane, f2.farPlane); return(ret); }
private void FlipTriangle(TriangleVertex vertex, RenderPassMode passMode) { // 三角形转到屏幕坐标系 RenderTarget target = this.Target; if (target != null) { if (IsShowVertexLog) { DebugVertexLog(vertex); } // 这里是VertexShader的部分 // 世界坐标系到屏幕坐标系 if (passMode.vertexShader == null) { // 默认的一个处理 //vertex.triangle.Trans(this.WorldToScreenPointEvt2, false); vertex.triangle.MulMatrix(this.Shader_MVP_Matrix); } else { InitPassMode(passMode); passMode.vertexShader.Main(ref vertex); } // 做个三角形的判断 if (vertex.IsAllZGreateOne) { return; } // 这里做背面剔除 if (SoftMath.Is_MVP_Culled(passMode.Cull, vertex.triangle)) { return; } vertex.triangle.MulMatrix(this.LinkerScreenMatrix); #if _Use_FlipTrangle2 target.FlipScreenTriangle2(this, vertex, passMode); #else target.FlipScreenTriangle(this, vertex, passMode); #endif } }
// 摄影机剔除 // visiableList: 可见列表 public void CameraCull(SoftCamera camera, Dictionary <int, SoftRenderObject> objs, out NativeList <int> visiableList) { visiableList = null; if (camera == null) { return; } if (objs == null || objs.Count <= 0) { m_Objs.Clear(false); return; } m_Objs.Clear(false); // 简单处理,直接干 var iter = objs.GetEnumerator(); while (iter.MoveNext()) { SoftRenderObject obj = iter.Current.Value; if (obj != null && obj.CanRenderer) { switch (obj.ObjType) { case SoftRenderObjType.MeshRender: SoftSpere spere = (obj as SoftMeshRenderer).WorldBoundSpere; // if (!camera.IsOpenCameraSpereCull || SoftMath.BoundSpereInCamera(spere, camera)) { if (!camera.IsOpenCameraSpereCull || SoftMath.BoundSpereInCamera_UseMVP(spere, camera)) { m_Objs.Add(obj.InstanceId); } break; } } } iter.Dispose(); if (m_Objs.Count > 0) { visiableList = m_Objs; } }
private static bool Compare(OCameraInfo f1, OCameraInfo f2) { bool ret = SoftMath.FloatEqual(f1.Size, f2.Size) && SoftMath.FloatEqual(f1.nearPlane, f2.nearPlane) && SoftMath.FloatEqual(f1.farPlane, f2.farPlane); return(ret); }
public override bool Main(PixelData data, out Color frag) { var target = this.param.target; var tex = data.mainTex; if (tex != null && target != null) { float dw = 1f / tex.Width; float dh = 1f / tex.Height; Vector2 uv = data.info.uv1; int u = data.info.u - 1; int v = data.info.v - 1; // 水平变化率 float ddx = 0f; if (u > 0) { var info1 = target.FrontColorBuffer.GetItem(u, data.info.v); if (info1.isFill != 0) { // UV变化率 除以1是因为是1距离的变化 Vector2 uv1 = info1.uv1; ddx = (((uv - uv1).magnitude) / 1f) / dw; } } // 垂直变化率 float ddy = 0f; if (v > 0) { // 这里和真实SHADER还是有点不一样的,这个是直接拿设备【当前】所有模型渲染后结果的BUFFER,SHADER并不是 var info2 = target.FrontColorBuffer.GetItem(data.info.u, v); if (info2.isFill != 0) { Vector2 uv2 = info2.uv1; ddy = (((uv - uv2).magnitude) / 1f) / dh; } } float maxDD = Mathf.Max(ddx, ddy); if (maxDD >= 0) { float n = Mathf.Log(maxDD, 2); int s = Mathf.FloorToInt(n); int e = Mathf.CeilToInt(n); float t = SoftMath.GetDeltaT(s, e, n); int idx = s - 1; idx = Mathf.Clamp(idx, 0, m_ColorCnt - 1); Color sC = m_MipColor[idx]; idx = e - 1; idx = Mathf.Clamp(idx, 0, m_ColorCnt - 1); Color eC = m_MipColor[idx]; frag = SoftMath.GetColorDeltaT(sC, eC, t); } else { frag = Color.black; } } else { frag = Color.black; } return(true); }