private static GLShader FragmentShader() { return(GLShader.Create(ShaderType.FragmentShader, () => from f in Shader.Inputs <TerrainFragment> () from u in Shader.Uniforms <Terrain> () from l in Shader.Uniforms <LightingUniforms> () from c in Shader.Uniforms <CascadedShadowUniforms> () let rockColor = FragmentShaders.TextureColor(!u.rockSampler, f.fragTexturePos) let grassColor = FragmentShaders.TextureColor(!u.grassSampler, f.fragTexturePos) let sandColor = FragmentShaders.TextureColor(!u.sandSampler, f.fragTexturePos) let sandBlend = FMath.SmoothStep(2f, 4f, f.height) let flatColor = grassColor.Mix(sandColor, sandBlend) let rockBlend = FMath.SmoothStep(0.8f, 0.9f, f.slope) let terrainColor = rockColor.Mix(flatColor, rockBlend) let diffuseLight = LightingShaders.LightDiffuseIntensity( (!l.directionalLight).direction, (!l.directionalLight).intensity, f.vertexNormal) let ambient = (!l.globalLighting).ambientLightIntensity //let shadow = ShadowShaders.PcfShadowMapFactor (f.fragPositionLightSpace, 0.0015f) //let shadow = ShadowShaders.VarianceShadowMapFactor (new Vec4 (f.vertexPos, 1f)) let shadow = ShadowShaders.CascadedShadowMapFactor(new Vec4(f.vertexPos, 1f), 0.0015f) let litColor = LightingShaders.GlobalLightIntensity(!l.globalLighting, ambient, diffuseLight * shadow, new Vec3(0f), terrainColor, new Vec3(0f)) select new { outputColor = litColor.Mix(!u.skyColor, f.visibility) })); }
public static GLShader WhiteOutput <F> () where F : Fragment { return(GLShader.Create(ShaderType.FragmentShader, () => from f in Shader.Inputs <F> () select new { outputColor = new Vec3(1f) })); }
private static GLShader DepthFragmentShader() { return(GLShader.Create(ShaderType.FragmentShader, () => from f in Shader.Inputs <Fragment> () select new { depth = f.gl_FragCoord[2] } )); }
public static GLShader DirectOutput <F> () where F : Fragment, IFragmentDiffuse { return(GLShader.Create(ShaderType.FragmentShader, () => from f in Shader.Inputs <F> () select new { outputColor = new Vec3(f.fragDiffuse) })); }
private static GLShader FragmentShader() { return(GLShader.Create(ShaderType.FragmentShader, () => from f in Shader.Inputs <SkyboxFragment> () from u in Shader.Uniforms <Skybox> () select new { outputColor = (!u.cubeMap).Texture(f.texturePos)[Coord.x, Coord.y, Coord.z] })); }
public static GLShader Passthrough <V, F> () where V : struct, IVertex3D where F : Fragment, new () { return(GLShader.Create(ShaderType.VertexShader, () => from v in Shader.Inputs <V> () select new F() { gl_Position = new Vec4(v.position, 1f) })); }
private static GLShader VertexShader() { return(GLShader.Create(ShaderType.VertexShader, () => from v in Shader.Inputs <PositionalVertex> () from u in Shader.Uniforms <Skybox> () select new SkyboxFragment() { gl_Position = !u.perspectiveMatrix * !u.worldMatrix * new Vec4(v.position, 1f), texturePos = v.position + new Vec3(0f, 0.5f, 0f) })); }
private static GLShader VertexShaderCascaded() { return(GLShader.Create(ShaderType.VertexShader, () => from v in Shader.Inputs <EntityVertex> () from u in Shader.Uniforms <Shadows> () select new Fragment() { gl_Position = !u.modelViewMatrix * new Vec4(v.position, 1f) } )); }
public static GLShader TexturedOutput <F, U> () where F : Fragment, IFragmentTexture <Vec2> where U : TextureUniforms { return(GLShader.Create(ShaderType.FragmentShader, () => from f in Shader.Inputs <F> () from u in Shader.Uniforms <U> () select new { outputColor = (!u.textureMap).Texture(f.fragTexturePos) })); }
public static GLShader PassthroughTexture <V, F> () where V : struct, IVertex3D, ITextured where F : Fragment, IFragmentTexture <Vec2>, new () { return(GLShader.Create(ShaderType.VertexShader, () => from v in Shader.Inputs <V> () select new F() { gl_Position = new Vec4(v.position, 1f), fragTexturePos = v.texturePos } )); }
public static GLShader FragmentShader() { return(GLShader.Create(ShaderType.FragmentShader, () => from f in Shader.Inputs <PanelFragment> () from t in Shader.Uniforms <TextureUniforms> () from u in Shader.Uniforms <MaterialPanels> () let col = (!t.textureMap).Texture(f.fragTexturePos) select new { outputColor = !u.ColorOutput != 0 ? col : new Vec4(col[Coord.x, Coord.x, Coord.x], 1f) })); }
public static GLShader TransformedTexture <V, F, U> () where V : struct, IVertex3D, ITextured where F : Fragment, IFragmentTexture <Vec2>, new () where U : TransformUniforms { return(GLShader.Create(ShaderType.VertexShader, () => from v in Shader.Inputs <V> () from u in Shader.Uniforms <U> () select new F() { gl_Position = !u.perspectiveMatrix * !u.modelViewMatrix * new Vec4(v.position, 1f), fragTexturePos = v.texturePos })); }
private static GLShader VarianceFragmentShader() { return(GLShader.Create(ShaderType.FragmentShader, () => from f in Shader.Inputs <Fragment> () let depth = f.gl_FragCoord.Z let dx = FMath.dFdx(depth) let dy = FMath.dFdy(depth) let moment2 = depth * depth + 0.25f * (dx * dx + dy * dy) select new { variance = new Vec2(depth, moment2) } )); }
private static GLShader FragmentShader() { return(GLShader.Create(ShaderType.FragmentShader, () => from f in Shader.Inputs <GaussianFragment> () from u in Shader.Uniforms <TextureUniforms> () from c in Shader.Constants(new { weights = new float[] { 0.00598f, 0.060626f, 0.241843f, 0.383103f, 0.241843f, 0.060626f, 0.00598f } }) select new { outColor = Enumerable.Range(0, 7).Aggregate(new Vec4(0f), (r, i) => r + (!u.textureMap).Texture(f.fragTexturePos [i]) * c.weights[i]) } )); }
public static GLShader FragmentShader() { return(GLShader.Create ( ShaderType.FragmentShader, () => from f in Shader.Inputs <MaterialFragment> () from u in Shader.Uniforms <Materials> () let texCoords = ParallaxMapping(!u.heightMap, f.texPosition, f.tangentViewDir, 0.01f) let diffuse = (!u.diffuseMap).Texture(texCoords)[Coord.x, Coord.y, Coord.z] let normal = (!u.normalMap).Texture(texCoords)[Coord.x, Coord.y, Coord.z] * 2f - new Vec3(1f) select new { outputColor = (normal.Dot(f.tangentLightDir).Clamp(0f, 1f) * diffuse).Clamp(0f, 1f) } )); }
public static GLShader VertexShader() { return(GLShader.Create(ShaderType.VertexShader, () => from v in Shader.Inputs <EntityVertex> () from t in Shader.Uniforms <TransformUniforms> () let viewPos = !t.modelViewMatrix * new Vec4(v.position, 1f) select new EntityFragment() { gl_Position = !t.perspectiveMatrix * viewPos, fragPosition = viewPos[Coord.x, Coord.y, Coord.z], fragNormal = (!t.normalMatrix * v.normal).Normalized, fragDiffuse = v.diffuse, fragSpecular = v.specular, fragShininess = v.shininess, fragTexturePos = v.texturePos, fragReflectivity = v.reflectivity })); }
private static GLShader VertexShader() { return(GLShader.Create(ShaderType.VertexShader, () => from v in Shader.Inputs <TerrainVertex> () from u in Shader.Uniforms <Terrain> () from t in Shader.Uniforms <TransformUniforms> () let viewPos = !u.transforms.modelViewMatrix * new Vec4(v.position, 1f) select new TerrainFragment() { gl_Position = !t.perspectiveMatrix * viewPos, vertexNormal = (!t.normalMatrix * v.normal).Normalized, vertexPos = viewPos[Coord.x, Coord.y, Coord.z], visibility = LightingShaders.FogVisibility(viewPos.Z, 400f, 2f), height = v.position.Y, slope = v.normal.Dot(new Vec3(0f, 1f, 0f)), fragTexturePos = v.texturePos / 15f })); }
public static GLShader VertexShader() { return(GLShader.Create(ShaderType.VertexShader, () => from v in Shader.Inputs <MaterialVertex> () from t in Shader.Uniforms <TransformUniforms> () let viewPos = !t.modelViewMatrix * new Vec4(v.position, 1f) let tangent = (!t.normalMatrix * v.tangent).Normalized let normal = (!t.normalMatrix * v.normal).Normalized let bitangent = tangent.Cross(normal) let TBN = new Mat3(tangent, bitangent, normal).Transposed select new MaterialFragment() { gl_Position = !t.perspectiveMatrix * viewPos, texPosition = v.texturePos, tangentViewDir = (TBN * new Vec3(0f, 0f, 1f)).Normalized, tangentLightDir = (TBN * new Vec3(1f, 0f, 1f)).Normalized })); }
private static GLShader FragmentShader() { return(GLShader.Create ( ShaderType.FragmentShader, () => from f in Shader.Inputs <EntityFragment> () from u in Shader.Uniforms <Entities> () from l in Shader.Uniforms <LightingUniforms> () from c in Shader.Uniforms <CascadedShadowUniforms> () let samplerNo = (f.fragTexturePos.X / 10f).Truncate() let fragDiffuse = samplerNo == 0 ? FragmentShaders.TextureColor((!u.samplers)[0], f.fragTexturePos) : samplerNo == 1 ? FragmentShaders.TextureColor((!u.samplers)[1], f.fragTexturePos - new Vec2(10f)) : samplerNo == 2 ? FragmentShaders.TextureColor((!u.samplers)[2], f.fragTexturePos - new Vec2(20f)) : samplerNo == 3 ? FragmentShaders.TextureColor((!u.samplers)[3], f.fragTexturePos - new Vec2(30f)) : f.fragDiffuse let dirLight = LightingShaders.DirLightIntensity(!l.directionalLight, f.fragPosition, f.fragNormal, f.fragShininess) let totalLight = Control <LightingShaders.DiffuseAndSpecular> .For(0, (!u.pointLights).Length, dirLight, (i, total) => (from pl in (!u.pointLights)[i].ToShader() let plint = LightingShaders.PointLightIntensity(pl, f.fragPosition, f.fragNormal, f.fragShininess) select new LightingShaders.DiffuseAndSpecular(plint.diffuse + total.diffuse, plint.specular + total.specular)) .Evaluate()) let envLight = (!u.diffuseMap).Texture(f.fragNormal)[Coord.x, Coord.y, Coord.z] let ambient = envLight * (!l.globalLighting).ambientLightIntensity let reflectDiffuse = f.fragReflectivity == 0f ? fragDiffuse : fragDiffuse.Mix(LightingShaders.ReflectedColor(!u.diffuseMap, f.fragPosition, f.fragNormal), f.fragReflectivity) //let shadow = ShadowShaders.PcfShadowMapFactor (f.fragPositionLightSpace, 0.0015f) //let shadow = ShadowShaders.VarianceShadowMapFactor (new Vec4 (f.fragPosition, 1f)) let shadow = ShadowShaders.CascadedShadowMapFactor(new Vec4(f.fragPosition, 1f), 0.002f) select new { outputColor = LightingShaders.GlobalLightIntensity(!l.globalLighting, ambient, totalLight.diffuse * shadow, totalLight.specular * shadow, reflectDiffuse, f.fragSpecular) } )); }
public static GLShader BasicShader <V, F, U> () where V : struct, IVertex3D, IVertexColor <Vec3>, ITextured, IReflective where F : Fragment, IFragmentPosition, IFragmentDiffuse, IFragmentSpecular, IFragmentTexture <Vec2>, IFragmentReflectivity, new () where U : TransformUniforms { return(GLShader.Create(ShaderType.VertexShader, () => from v in Shader.Inputs <V> () from t in Shader.Uniforms <U> () let viewPos = !t.modelViewMatrix * new Vec4(v.position, 1f) select new F() { gl_Position = !t.perspectiveMatrix * viewPos, fragPosition = viewPos[Coord.x, Coord.y, Coord.z], fragNormal = (!t.normalMatrix * v.normal).Normalized, fragDiffuse = v.diffuse, fragSpecular = v.specular, fragShininess = v.shininess, fragTexturePos = v.texturePos, fragReflectivity = v.reflectivity, })); }
private static GLShader VerticalVertexShader() { return(GLShader.Create(ShaderType.VertexShader, () => from v in Shader.Inputs <TexturedVertex> () from u in Shader.Uniforms <TextureUniforms> () let height = (!u.textureMap).Size(0).Y let pixelSize = 1f / height select new GaussianFragment() { gl_Position = new Vec4(v.position, 1f), fragTexturePos = new Vec2[7] { v.texturePos + new Vec2(0f, pixelSize * -3f), v.texturePos + new Vec2(0f, pixelSize * -2f), v.texturePos + new Vec2(0f, pixelSize * -1f), v.texturePos, v.texturePos + new Vec2(0f, pixelSize * 1f), v.texturePos + new Vec2(0f, pixelSize * 2f), v.texturePos + new Vec2(0f, pixelSize * 3f) } } )); }