protected void InitMaterial(MaterialPropertyBlock mat, DrawSurfaceTask t) { if (shaderValueAtmEnabled) { InitAtmosphere(mat); } UpdateMaterial(mat, t); mat.SetVector(shaderPropertyUvTrans, VtsUtil.V2U4(t.data.uvTrans)); int flags = 0; // _Flags: mask, monochromatic, flat shading, uv source if (t.texMask != null) { flags |= 1 << 0; mat.SetTexture(shaderPropertyMaskTex, (t.texMask as VtsTexture).Get()); } if ((t.texColor as VtsTexture).monochromatic) { flags |= 1 << 1; } if (t.data.externalUv) { flags |= 1 << 3; } mat.SetInt(shaderPropertyFlags, flags); mat.SetTexture(shaderPropertyMainTex, (t.texColor as VtsTexture).Get()); mat.SetTexture(shaderPropertyTexBlueNoise, blueNoiseTexture); }
private void UpdatePart(GameObject o, DrawTask t) { o.layer = renderLayer; o.GetComponent <MeshFilter>().mesh = (t.mesh as VtsMesh).Get(); Material mat = o.GetComponent <MeshRenderer>().material; UpdateMaterial(mat); bool monochromatic = false; if (t.texColor != null) { var tt = t.texColor as VtsTexture; mat.SetTexture(shaderPropertyMainTex, tt.Get()); monochromatic = tt.monochromatic; } if (t.texMask != null) { var tt = t.texMask as VtsTexture; mat.SetTexture(shaderPropertyMaskTex, tt.Get()); } mat.SetMatrix(shaderPropertyUvMat, VtsUtil.V2U33(t.data.uvm)); mat.SetVector(shaderPropertyUvClip, VtsUtil.V2U4(t.data.uvClip)); mat.SetVector(shaderPropertyColor, VtsUtil.V2U4(t.data.color)); // flags: mask, monochromatic, flat shading, uv source mat.SetVector(shaderPropertyFlags, new Vector4(t.texMask == null ? 0 : 1, monochromatic ? 1 : 0, 0, t.data.externalUv ? 1 : 0)); VtsUtil.Matrix2Transform(o.transform, VtsUtil.V2U44(Math.Mul44x44(conv, System.Array.ConvertAll(t.data.mv, System.Convert.ToDouble)))); }
protected void UpdateMaterial(Material mat) { VtsTexture tex = draws.celestial.atmosphere.densityTexture as VtsTexture; if (atmosphere && tex != null) { var cel = draws.celestial; var atm = cel.atmosphere; mat.SetVector(shaderPropertyAtmSizes, new Vector4( (float)(atm.boundaryThickness / cel.majorRadius), (float)(cel.majorRadius / cel.minorRadius), (float)(1.0 / cel.majorRadius), 0)); mat.SetVector(shaderPropertyAtmCoefficients, new Vector4( (float)atm.horizontalExponent, (float)atm.colorGradientExponent, 0, 0)); mat.SetVector(shaderPropertyAtmCameraPosition, VtsUtil.V2U3(draws.camera.eye) / (float)cel.majorRadius); mat.SetMatrix(shaderPropertyAtmViewInv, VtsUtil.V2U44(Math.Inverse44(draws.camera.view))); mat.SetVector(shaderPropertyAtmColorHorizon, VtsUtil.V2U4(atm.colorHorizon)); mat.SetVector(shaderPropertyAtmColorZenith, VtsUtil.V2U4(atm.colorZenith)); mat.SetTexture("vtsTexAtmDensity", tex.Get()); mat.EnableKeyword("VTS_ATMOSPHERE"); } else { mat.DisableKeyword("VTS_ATMOSPHERE"); } }
private void RegenerateCommandBuffer(CommandBuffer buffer, List <DrawTask> tasks) { buffer.Clear(); if (atmosphere && draws.celestial.atmosphere.densityTexture as VtsTexture != null) { buffer.EnableShaderKeyword("VTS_ATMOSPHERE"); } else { buffer.DisableShaderKeyword("VTS_ATMOSPHERE"); } buffer.SetViewMatrix(Matrix4x4.identity); buffer.SetProjectionMatrix(cam.projectionMatrix); foreach (DrawTask t in tasks) { if (t.mesh == null) { continue; } MaterialPropertyBlock mat = new MaterialPropertyBlock(); VtsTexture atmTex = draws.celestial.atmosphere.densityTexture as VtsTexture; if (atmosphere && atmTex != null) { var cel = draws.celestial; var atm = cel.atmosphere; mat.SetVector(shaderPropertyAtmSizes, new Vector4( (float)(atm.boundaryThickness / cel.majorRadius), (float)(cel.majorRadius / cel.minorRadius), (float)(1.0 / cel.majorRadius), 0)); mat.SetVector(shaderPropertyAtmCoefficients, new Vector4( (float)atm.horizontalExponent, (float)atm.colorGradientExponent, 0, 0)); mat.SetVector(shaderPropertyAtmCameraPosition, VtsUtil.V2U3(draws.camera.eye) / (float)cel.majorRadius); mat.SetMatrix(shaderPropertyAtmViewInv, VtsUtil.V2U44(Math.Inverse44(draws.camera.view))); mat.SetVector(shaderPropertyAtmColorHorizon, VtsUtil.V2U4(atm.colorHorizon)); mat.SetVector(shaderPropertyAtmColorZenith, VtsUtil.V2U4(atm.colorZenith)); mat.SetTexture("vtsTexAtmDensity", atmTex.Get()); } bool monochromatic = false; if (t.texColor != null) { var tt = t.texColor as VtsTexture; mat.SetTexture(shaderPropertyMainTex, tt.Get()); monochromatic = tt.monochromatic; } if (t.texMask != null) { mat.SetTexture(shaderPropertyMaskTex, (t.texMask as VtsTexture).Get()); } mat.SetMatrix(shaderPropertyUvMat, VtsUtil.V2U33(t.data.uvm)); mat.SetVector(shaderPropertyUvClip, VtsUtil.V2U4(t.data.uvClip)); mat.SetVector(shaderPropertyColor, VtsUtil.V2U4(t.data.color)); // flags: mask, monochromatic, flat shading, uv source mat.SetVector(shaderPropertyFlags, new Vector4(t.texMask == null ? 0 : 1, monochromatic ? 1 : 0, 0, t.data.externalUv ? 1 : 0)); buffer.DrawMesh((t.mesh as VtsMesh).Get(), VtsUtil.V2U44(t.data.mv), renderMaterial, 0, -1, mat); } }
protected void UpdateMaterial(MaterialPropertyBlock mat, DrawSurfaceTask t) { if (shaderValueAtmEnabled) { UpdateAtmosphere(mat); } mat.SetVector(shaderPropertyUvClip, VtsUtil.V2U4(t.data.uvClip)); mat.SetVector(shaderPropertyColor, VtsUtil.V2U4(t.data.color)); mat.SetFloat(shaderPropertyBlendingCoverage, float.IsNaN(t.data.blendingCoverage) ? -1 : t.data.blendingCoverage); mat.SetInt(shaderPropertyFrameIndex, shaderValueFrameIndex); }
private void RegenerateCommandBuffer(CommandBuffer buffer, List <DrawSurfaceTask> tasks, Material renderMaterial) { buffer.Clear(); if (atmosphere && draws.celestial.atmosphere.densityTexture as VtsTexture != null) { buffer.EnableShaderKeyword("VTS_ATMOSPHERE"); } else { buffer.DisableShaderKeyword("VTS_ATMOSPHERE"); } buffer.SetViewMatrix(Matrix4x4.identity); buffer.SetProjectionMatrix(ucam.projectionMatrix); foreach (DrawSurfaceTask t in tasks) { if (t.mesh == null) { continue; } MaterialPropertyBlock mat = new MaterialPropertyBlock(); VtsTexture atmTex = draws.celestial.atmosphere.densityTexture as VtsTexture; if (atmosphere && atmTex != null) { mat.SetVector(shaderPropertyAtmSizes, shaderValueAtmSizes); mat.SetVector(shaderPropertyAtmCoefficients, shaderValueAtmCoefficients); mat.SetVector(shaderPropertyAtmCameraPosition, shaderValueAtmCameraPosition); mat.SetMatrix(shaderPropertyAtmViewInv, shaderValueAtmViewInv); mat.SetVector(shaderPropertyAtmColorHorizon, shaderValueAtmColorHorizon); mat.SetVector(shaderPropertyAtmColorZenith, shaderValueAtmColorZenith); mat.SetTexture("vtsTexAtmDensity", atmTex.Get()); } bool monochromatic = false; if (t.texColor != null) { var tt = t.texColor as VtsTexture; mat.SetTexture(shaderPropertyMainTex, tt.Get()); monochromatic = tt.monochromatic; } if (t.texMask != null) { mat.SetTexture(shaderPropertyMaskTex, (t.texMask as VtsTexture).Get()); } mat.SetMatrix(shaderPropertyUvMat, VtsUtil.V2U33(t.data.uvm)); mat.SetVector(shaderPropertyUvClip, VtsUtil.V2U4(t.data.uvClip)); mat.SetVector(shaderPropertyColor, VtsUtil.V2U4(t.data.color)); // flags: mask, monochromatic, flat shading, uv source mat.SetVector(shaderPropertyFlags, new Vector4(t.texMask == null ? 0 : 1, monochromatic ? 1 : 0, 0, t.data.externalUv ? 1 : 0)); buffer.DrawMesh((t.mesh as VtsMesh).Get(), VtsUtil.V2U44(t.data.mv), renderMaterial, 0, -1, mat); } }
private void UpdateParts(List <DrawTask> tasks, List <GameObject> parts, double[] conv) { if (parts.Count == tasks.Count) { return; } if (parts.Count > 0) { foreach (GameObject p in parts) { Destroy(p); } parts.Clear(); } foreach (DrawTask t in tasks) { GameObject o = Instantiate(renderPrefab); parts.Add(o); o.layer = renderLayer; UnityEngine.Mesh msh = (tasks[0].mesh as VtsMesh).Get(); o.GetComponent <MeshFilter>().mesh = msh; Material mat = o.GetComponent <MeshRenderer>().material; UpdateMaterial(mat); bool monochromatic = false; if (t.texColor != null) { var tt = t.texColor as VtsTexture; mat.SetTexture(shaderPropertyMainTex, tt.Get()); monochromatic = tt.monochromatic; } if (t.texMask != null) { var tt = t.texMask as VtsTexture; mat.SetTexture(shaderPropertyMaskTex, tt.Get()); } mat.SetMatrix(shaderPropertyUvMat, VtsUtil.V2U33(t.data.uvm)); mat.SetVector(shaderPropertyUvClip, VtsUtil.V2U4(t.data.uvClip)); mat.SetVector(shaderPropertyColor, VtsUtil.V2U4(t.data.color)); // flags: mask, monochromatic, flat shading, uv source mat.SetVector(shaderPropertyFlags, new Vector4(t.texMask == null ? 0 : 1, monochromatic ? 1 : 0, 0, t.data.externalUv ? 1 : 0)); VtsUtil.Matrix2Transform(o.transform, VtsUtil.V2U44(Math.Mul44x44(conv, System.Array.ConvertAll(t.data.mv, System.Convert.ToDouble)))); } }
private void PrepareShaderData() { var cel = draws.celestial; var atm = cel.atmosphere; shaderValueAtmSizes = new Vector4( (float)(atm.boundaryThickness / cel.majorRadius), (float)(cel.majorRadius / cel.minorRadius), (float)(1.0 / cel.majorRadius), 0); shaderValueAtmCoefficients = new Vector4( (float)atm.horizontalExponent, (float)atm.colorGradientExponent, 0, 0); shaderValueAtmCameraPosition = VtsUtil.V2U3(draws.camera.eye) / (float)cel.majorRadius; shaderValueAtmViewInv = VtsUtil.V2U44(Math.Inverse44(draws.camera.view)); shaderValueAtmColorHorizon = VtsUtil.V2U4(atm.colorHorizon); shaderValueAtmColorZenith = VtsUtil.V2U4(atm.colorZenith); }
private void PrepareShaderData() { var cel = draws.celestial; var atm = cel.atmosphere; shaderValueAtmSizes = new Vector4( (float)(atm.boundaryThickness / cel.majorRadius), (float)(cel.majorRadius / cel.minorRadius), (float)(1.0 / cel.majorRadius), 0); shaderValueAtmCoefficients = new Vector4( (float)atm.horizontalExponent, (float)atm.colorGradientExponent, 0, 0); shaderValueAtmCameraPosition = VtsUtil.V2U3(draws.camera.eye) / (float)cel.majorRadius; shaderValueAtmViewInv = VtsUtil.V2U44(Math.Inverse44(draws.camera.view)); shaderValueAtmColorHorizon = VtsUtil.V2U4(atm.colorHorizon); shaderValueAtmColorZenith = VtsUtil.V2U4(atm.colorZenith); shaderValueAtmEnabled = Shader.IsKeywordEnabled("VTS_ATMOSPHERE") && draws.celestial.atmosphere.densityTexture != null; shaderValueFrameIndex++; }