private void OnPostUseShader(ShaderProgramBase shader) { if (!_enabled) { return; } if (!shader.includes.Contains("shadowcoords.vsh")) { return; } shader.Uniform("cameraWorldPosition", _mod.Uniforms.CameraWorldPosition); }
// ReSharper disable once InconsistentNaming public static void UsePostfix(ShaderProgramBase __instance) { VolumetricShadingMod.Instance.Events.EmitPostUseShader(__instance); }
private void OnUseShader(ShaderProgramBase shader) { if (!_softShadowsEnabled) { return; } if (!shader.includes.Contains("fogandlight.fsh")) { return; } if (ExcludedShaders.Contains(shader.PassName)) { return; } if (ShaderProgramBase.shadowmapQuality <= 0) { return; } const string uniformFar = "shadowMapFarTex"; const string uniformNear = "shadowMapNearTex"; const string uniformShadowFar = "shadowMapFar"; const string uniformShadowNear = "shadowMapNear"; if (!shader.customSamplers.ContainsKey(uniformFar)) { var lookupSamplers = new int[2]; for (var i = 0; i < lookupSamplers.Length; i++) { var s = lookupSamplers[i] = GL.GenSampler(); GL.SamplerParameter(s, SamplerParameterName.TextureCompareMode, (int)TextureCompareMode.None); GL.SamplerParameter(s, SamplerParameterName.TextureMinFilter, (int)TextureMinFilter.Nearest); GL.SamplerParameter(s, SamplerParameterName.TextureMagFilter, (int)TextureMagFilter.Nearest); GL.SamplerParameter(s, SamplerParameterName.TextureBorderColor, new [] { 1f, 1f, 1f, 1f }); GL.SamplerParameter(s, SamplerParameterName.TextureWrapS, (int)TextureWrapMode.ClampToBorder); GL.SamplerParameter(s, SamplerParameterName.TextureWrapT, (int)TextureWrapMode.ClampToBorder); } // emulate old texture lookup, because new lookup disables internal sampler parameters var oldSamplers = new int[2]; for (var i = 0; i < oldSamplers.Length; ++i) { var s = oldSamplers[i] = GL.GenSampler(); GL.SamplerParameter(s, SamplerParameterName.TextureCompareMode, (int)TextureCompareMode.CompareRToTexture); GL.SamplerParameter(s, SamplerParameterName.TextureCompareFunc, (int)DepthFunction.Lequal); GL.SamplerParameter(s, SamplerParameterName.TextureMinFilter, (int)TextureMinFilter.Linear); GL.SamplerParameter(s, SamplerParameterName.TextureMagFilter, (int)TextureMagFilter.Linear); GL.SamplerParameter(s, SamplerParameterName.TextureBorderColor, new [] { 1f, 1f, 1f, 1f }); GL.SamplerParameter(s, SamplerParameterName.TextureWrapS, (int)TextureWrapMode.ClampToBorder); GL.SamplerParameter(s, SamplerParameterName.TextureWrapT, (int)TextureWrapMode.ClampToBorder); } shader.customSamplers[uniformFar] = lookupSamplers[0]; shader.customSamplers[uniformNear] = lookupSamplers[1]; shader.customSamplers[uniformShadowFar] = oldSamplers[0]; shader.customSamplers[uniformShadowNear] = oldSamplers[1]; } var fbs = _mod.CApi.Render.FrameBuffers; var fbFar = fbs[(int)EnumFrameBuffer.ShadowmapFar]; var fbNear = fbs[(int)EnumFrameBuffer.ShadowmapNear]; shader.BindTexture2D(uniformFar, fbFar.DepthTextureId); shader.BindTexture2D(uniformNear, fbNear.DepthTextureId); shader.BindTexture2D(uniformShadowFar, fbFar.DepthTextureId); shader.BindTexture2D(uniformShadowNear, fbNear.DepthTextureId); }
public void EmitPostUseShader(ShaderProgramBase shader) { PostUseShader?.Invoke(shader); }