/// <summary> /// Returns the pre defined Fusee uniform parameters of a vertex shader, depending on the given ShaderEffectProps. /// </summary> /// <param name="effectProps">The ShaderEffectProps.</param> /// <returns></returns> public static string FuseeUniforms(ShaderEffectProps effectProps) { var uniforms = new List <string> { GLSL.CreateUniform(GLSL.Type.Mat4, UniformNameDeclarations.ModelView), GLSL.CreateUniform(GLSL.Type.Mat4, UniformNameDeclarations.ModelViewProjection) }; if (effectProps.MeshProbs.HasNormals) { uniforms.Add(GLSL.CreateUniform(GLSL.Type.Mat4, UniformNameDeclarations.ITModelView)); } if (effectProps.MatProbs.HasSpecular && !effectProps.MeshProbs.HasWeightMap) { uniforms.Add(GLSL.CreateUniform(GLSL.Type.Mat4, UniformNameDeclarations.IModelView)); } if (effectProps.MeshProbs.HasWeightMap) { uniforms.Add(GLSL.CreateUniform(GLSL.Type.Mat4, UniformNameDeclarations.View)); uniforms.Add(GLSL.CreateUniform(GLSL.Type.Mat4, UniformNameDeclarations.Projection)); uniforms.Add(GLSL.CreateUniform(GLSL.Type.Mat4, UniformNameDeclarations.IModelView)); uniforms.Add(GLSL.CreateUniform(GLSL.Type.Mat4, UniformNameDeclarations.Bones + "[" + HeaderShard.BoneDefineVar + "]")); } return(string.Join("\n", uniforms)); }
/// <summary> /// Returns all uniforms, as they are given in the <see cref="MaterialProps"/> object. /// </summary> /// <param name="effectProps">The ShaderEffectProps.</param> /// <returns></returns> public static string MaterialPropsUniforms(ShaderEffectProps effectProps) { var matPropUnifroms = new List <string>(); if (effectProps.MatProbs.HasSpecular) { matPropUnifroms.Add(GLSL.CreateUniform(GLSL.Type.Vec4, UniformNameDeclarations.SpecularColor)); if (effectProps.MatType == MaterialType.MaterialPbr) { matPropUnifroms.Add(GLSL.CreateUniform(GLSL.Type.Float, UniformNameDeclarations.RoughnessValue)); matPropUnifroms.Add(GLSL.CreateUniform(GLSL.Type.Float, UniformNameDeclarations.FresnelReflectance)); matPropUnifroms.Add(GLSL.CreateUniform(GLSL.Type.Float, UniformNameDeclarations.DiffuseFraction)); } else if (effectProps.MatType == MaterialType.Standard) { matPropUnifroms.Add(GLSL.CreateUniform(GLSL.Type.Float, UniformNameDeclarations.SpecularShininess)); matPropUnifroms.Add(GLSL.CreateUniform(GLSL.Type.Float, UniformNameDeclarations.SpecularIntensity)); } } if (effectProps.MatProbs.HasAlbedo) { matPropUnifroms.Add(GLSL.CreateUniform(GLSL.Type.Vec4, UniformNameDeclarations.AlbedoColor)); } if (effectProps.MatProbs.HasEmissive) { matPropUnifroms.Add(GLSL.CreateUniform(GLSL.Type.Vec4, UniformNameDeclarations.EmissiveColor)); } //Textures if (effectProps.MatProbs.HasNormalMap) { matPropUnifroms.Add(GLSL.CreateUniform(GLSL.Type.Sampler2D, UniformNameDeclarations.NormalMap)); matPropUnifroms.Add(GLSL.CreateUniform(GLSL.Type.Float, UniformNameDeclarations.NormalMapIntensity)); } if (effectProps.MatProbs.HasAlbedoTexture) { matPropUnifroms.Add(GLSL.CreateUniform(GLSL.Type.Sampler2D, UniformNameDeclarations.AlbedoTexture)); matPropUnifroms.Add(GLSL.CreateUniform(GLSL.Type.Float, UniformNameDeclarations.AlbedoMix)); } if (effectProps.MatProbs.HasEmissiveTexture) { matPropUnifroms.Add(GLSL.CreateUniform(GLSL.Type.Sampler2D, UniformNameDeclarations.EmissiveTexture)); matPropUnifroms.Add(GLSL.CreateUniform(GLSL.Type.Float, UniformNameDeclarations.EmissiveMix)); } return(string.Join("\n", matPropUnifroms)); }
/// <summary> /// Returns the pre defined Fusee uniform parameters of a fragment shader, depending on the given ShaderEffectProps. /// </summary> /// <returns></returns> public static string FuseeMatrixUniforms() { var pxFusUniforms = new List <string> { GLSL.CreateUniform(GLSL.Type.Mat4, UniformNameDeclarations.ModelView), GLSL.CreateUniform(GLSL.Type.Mat4, UniformNameDeclarations.IModelView), GLSL.CreateUniform(GLSL.Type.Mat4, UniformNameDeclarations.ITView), GLSL.CreateUniform(GLSL.Type.Mat4, UniformNameDeclarations.IView), GLSL.CreateUniform(GLSL.Type.Mat4, UniformNameDeclarations.View), GLSL.CreateUniform(GLSL.Type.Mat4, UniformNameDeclarations.ITModelView) }; return(string.Join("\n", pxFusUniforms)); }
/// <summary> /// Creates the uniform texture parameters for the lighting pass, as used in deferred rendering. /// </summary> /// <returns></returns> public static string DeferredTextureUniforms() { var uniforms = new List <string>(); var texCount = 0; for (var i = 0; i < UniformNameDeclarations.DeferredRenderTextures.Count; i++) { var texName = UniformNameDeclarations.DeferredRenderTextures[i]; uniforms.Add(GLSL.CreateUniform(GLSL.Type.Sampler2D, texName)); texCount++; } return(string.Join("\n", uniforms)); }
/// <summary> /// Creates the uniforms for the deferred lighting pass for one light. /// </summary> /// <param name="lc">The light component, needed to decide if we have a Shadow Cube Map or a standard shadow map.</param> /// <param name="isCascaded">If cascaded shadow mapping is used, this should be set to true.</param> /// <param name="numberOfCascades">If cascaded shadow mapping is used this is the number of cascades.</param> public static string DeferredLightAndShadowUniforms(Light lc, bool isCascaded, int numberOfCascades) { var uniforms = new List <string> { "uniform Light light;" }; if (!isCascaded) { if (lc.IsCastingShadows) { if (lc.Type != LightType.Point) { uniforms.Add(GLSL.CreateUniform(GLSL.Type.Sampler2D, UniformNameDeclarations.ShadowMap)); } else { uniforms.Add(GLSL.CreateUniform(GLSL.Type.SamplerCube, UniformNameDeclarations.ShadowCubeMap)); } } uniforms.Add(GLSL.CreateUniform(GLSL.Type.Mat4, UniformNameDeclarations.LightSpaceMatrix)); } else { //No implementation for GLSL.CreateArrayUniform yet... uniforms.Add($"uniform {GLSL.DecodeType(GLSL.Type.Sampler2D)}[{numberOfCascades}] ShadowMaps;\n"); uniforms.Add($"uniform {GLSL.DecodeType(GLSL.Type.Vec2)}[{numberOfCascades}] ClipPlanes;\n"); uniforms.Add($"uniform {GLSL.DecodeType(GLSL.Type.Mat4)}[{numberOfCascades}] LightSpaceMatrices;\n"); } uniforms.Add(GLSL.CreateUniform(GLSL.Type.Int, UniformNameDeclarations.RenderPassNo)); uniforms.Add(GLSL.CreateUniform(GLSL.Type.Int, UniformNameDeclarations.SsaoOn)); uniforms.Add(GLSL.CreateUniform(GLSL.Type.Vec4, UniformNameDeclarations.BackgroundColor)); return(string.Join("\n", uniforms)); }