Exemple #1
0
        private void RenderSplineMesh(Camera cam)
        {
            MaterialProperties.Clear();
            if (Profile.EnableReflection)
            {
                MaterialProperties.SetTexture(PMat.REFLECTION_TEX, GetReflectionRt(cam));
            }
            MaterialProperties.SetTexture(PMat.NOISE_TEX, PPoseidonSettings.Instance.NoiseTexture);

            PMat.SetActiveMaterial(MaterialToRender);
            PMat.SetKeywordEnable(PMat.KW_BACK_FACE, false);
            PMat.SetKeywordEnable(PMat.KW_MESH_NOISE, meshNoise != 0);
            PMat.SetFloat(PMat.MESH_NOISE, meshNoise);
            PMat.SetActiveMaterial(null);

            List <PSplineSegment> segments = Spline.Segments;

            for (int i = 0; i < segments.Count; ++i)
            {
                Graphics.DrawMesh(
                    segments[i].Mesh,
                    transform.localToWorldMatrix,
                    MaterialToRender,
                    gameObject.layer,
                    cam,
                    0,
                    MaterialProperties,
                    ShadowCastingMode.Off,
                    false,
                    null,
                    LightProbeUsage.BlendProbes,
                    null);
            }
        }
Exemple #2
0
        private void RenderTiledMesh(Camera cam)
        {
            bool isBackface = cam.transform.position.y < transform.position.y;

            if (isBackface && !ShouldRenderBackface)
            {
                return;
            }

            MaterialProperties.Clear();
            if (Profile.EnableReflection)
            {
                MaterialProperties.SetTexture(PMat.REFLECTION_TEX, GetReflectionRt(cam));
            }
            MaterialProperties.SetTexture(PMat.NOISE_TEX, PPoseidonSettings.Instance.NoiseTexture);

            Material mat = isBackface ? MaterialBackFace : MaterialToRender;

            PMat.SetActiveMaterial(mat);
            PMat.SetKeywordEnable(PMat.KW_MESH_NOISE, meshNoise != 0);
            PMat.SetFloat(PMat.MESH_NOISE, meshNoise);
            PMat.SetActiveMaterial(null);

            for (int i = 0; i < TileIndices.Count; ++i)
            {
                PIndex2D   index    = TileIndices[i];
                Vector3    pos      = transform.TransformPoint(new Vector3(index.X * TileSize.x, 0, index.Z * TileSize.y));
                Quaternion rotation = transform.rotation;
                Vector3    scale    = new Vector3(TileSize.x * transform.lossyScale.x, 1 * transform.lossyScale.y, TileSize.y * transform.lossyScale.z);

                Graphics.DrawMesh(
                    Mesh,
                    Matrix4x4.TRS(pos, rotation, scale),
                    mat,
                    gameObject.layer,
                    cam,
                    0,
                    MaterialProperties,
                    ShadowCastingMode.Off,
                    false,
                    null,
                    LightProbeUsage.BlendProbes,
                    null);
            }
        }
Exemple #3
0
        public void UpdateMaterial()
        {
            if (Profile != null)
            {
                Shader shader = PWaterShaderProvider.GetShader(this);
                PMat.SetActiveMaterial(MaterialToRender);
                PMat.SetShader(shader);
                PMat.SetActiveMaterial(null);
                Profile.UpdateMaterialProperties(MaterialToRender);

                if (ShouldRenderBackface)
                {
                    Shader backFaceShader = PWaterShaderProvider.GetBackFaceShader();
                    PMat.SetActiveMaterial(MaterialBackFace);
                    PMat.SetShader(backFaceShader);
                    PMat.SetActiveMaterial(null);
                    Profile.UpdateMaterialProperties(MaterialBackFace);
                }
            }
        }
        public void UpdateMaterialProperties(Material mat)
        {
            if (mat == null)
            {
                return;
            }
            PMat.SetActiveMaterial(mat);

            PMat.SetKeywordEnable(PMat.KW_LIGHTING_PHYSICAL_BASED, lightingModel == PLightingModel.PhysicalBased);
            PMat.SetKeywordEnable(PMat.KW_LIGHTING_BLINN_PHONG, lightingModel == PLightingModel.BlinnPhong);
            PMat.SetKeywordEnable(PMat.KW_LIGHTING_LAMBERT, lightingModel == PLightingModel.Lambert);

            PMat.SetRenderQueue(PMat.QUEUE_TRANSPARENT + RenderQueueIndex);

            PMat.SetColor(PMat.COLOR, color);
            PMat.SetColor(PMat.SPEC_COLOR, specColor);
            PMat.SetFloat(PMat.SMOOTHNESS, smoothness);

            PMat.SetKeywordEnable(PMat.KW_LIGHT_ABSORPTION, enableLightAbsorption);
            PMat.SetColor(PMat.DEPTH_COLOR, depthColor);
            PMat.SetFloat(PMat.MAX_DEPTH, maxDepth);

            PMat.SetKeywordEnable(PMat.KW_FOAM, enableFoam);
            PMat.SetKeywordEnable(PMat.KW_FOAM_HQ, enableFoamHQ);
            PMat.SetKeywordEnable(PMat.KW_FOAM_CREST, crestFoamStrength > 0);
            PMat.SetKeywordEnable(PMat.KW_FOAM_SLOPE, slopeFoamStrength > 0);
            PMat.SetColor(PMat.FOAM_COLOR, foamColor);
            PMat.SetFloat(PMat.FOAM_DISTANCE, foamDistance);
            PMat.SetFloat(PMat.FOAM_NOISE_SCALE_HQ, foamNoiseScaleHQ);
            PMat.SetFloat(PMat.FOAM_NOISE_SPEED_HQ, foamNoiseSpeedHQ);
            PMat.SetFloat(PMat.SHORELINE_FOAM_STRENGTH, shorelineFoamStrength);
            PMat.SetFloat(PMat.CREST_FOAM_STRENGTH, crestFoamStrength);
            PMat.SetFloat(PMat.CREST_MAX_DEPTH, crestMaxDepth);
            PMat.SetFloat(PMat.SLOPE_FOAM_STRENGTH, slopeFoamStrength);
            PMat.SetFloat(PMat.SLOPE_FOAM_FLOW_SPEED, slopeFoamFlowSpeed);
            PMat.SetFloat(PMat.SLOPE_FOAM_DISTANCE, slopeFoamDistance);

            PMat.SetFloat(PMat.RIPPLE_HEIGHT, rippleHeight);
            PMat.SetFloat(PMat.RIPPLE_NOISE_SCALE, rippleNoiseScale);
            PMat.SetFloat(PMat.RIPPLE_SPEED, rippleSpeed);

            PMat.SetKeywordEnable(PMat.KW_WAVE, enableWave);
            PMat.SetVector(PMat.WAVE_DIRECTION, new Vector4(Mathf.Cos(waveDirection * Mathf.Deg2Rad), Mathf.Sin(waveDirection * Mathf.Deg2Rad), 0, 0));
            PMat.SetFloat(PMat.WAVE_SPEED, waveSpeed);
            PMat.SetFloat(PMat.WAVE_HEIGHT, waveHeight);
            PMat.SetFloat(PMat.WAVE_LENGTH, waveLength);
            PMat.SetFloat(PMat.WAVE_STEEPNESS, waveSteepness);
            PMat.SetFloat(PMat.WAVE_DEFORM, waveDeform);

            PMat.SetFloat(PMat.FRESNEL_STRENGTH, fresnelStrength);
            PMat.SetFloat(PMat.FRESNEL_BIAS, fresnelBias);

            PMat.SetKeywordEnable(PMat.KW_REFLECTION, enableReflection);
            PMat.SetFloat(PMat.REFLECTION_DISTORTION_STRENGTH, reflectionDistortionStrength);

            PMat.SetKeywordEnable(PMat.KW_REFRACTION, enableRefraction);
            PMat.SetFloat(PMat.REFRACTION_DISTORTION_STRENGTH, enableRefraction ? refractionDistortionStrength : 0);

            PMat.SetKeywordEnable(PMat.KW_CAUSTIC, enableCaustic);
            PMat.SetTexture(PMat.CAUSTIC_TEX, causticTexture);
            PMat.SetFloat(PMat.CAUSTIC_SIZE, causticSize);
            PMat.SetFloat(PMat.CAUSTIC_STRENGTH, causticStrength);
            PMat.SetFloat(PMat.CAUSTIC_DISTORTION_STRENGTH, causticDistortionStrength);

            PMat.SetActiveMaterial(null);
        }