I am using the simarboreal PBR leaf and tree shaders that were created with JmonkeyBuilder’s simarboreal plugin, and it seems as though both the leaf and tree MatDefs do not have proper preshadow techniques, which is causing the trees and leaves to create self-casting shadow artifacts.
I figured that I should start this thread, rather than continuing in the other thread about shadows, since @pspeed has informed me that this specific shadow problem is related to the preshadow technique. (However this is a new shader concept to me and I may require some guidance fixing the PBR tree shaders to work with shadows)
I believe I must have messed up something with my modified version of the shader.
I updated my MatDef files to include the proper .vert files in the preshadow technique, but trees are still creating shadow artifacts as they sway.
Here is my .j3md file for the PBR tree shader, which was originally based off of Javasabre’s simarboreal shaders for the JMB Simarboreal plugin.
MaterialDef AfflictedTrees {
MaterialParameters {
Boolean UseVertexColorsAsSunIntensity
Float StaticSunIntensity
Vector4 ProbeColor
Boolean BrightenIndoorShadows
// Alpha threshold for fragment discarding
Float AlphaDiscardThreshold (AlphaTestFallOff)
//metalness of the material
Float Metallic : 1.0
//Roughness of the material
Float Roughness : 1.0
// Base material color
Color BaseColor : 1.0 1.0 1.0 1.0
// The emissive color of the object
Color Emissive
// the emissive power
Float EmissivePower : 3.0
// the emissive intensity
Float EmissiveIntensity : 2.0
// BaseColor map
Texture2D BaseColorMap
// Metallic map
Texture2D MetallicMap -LINEAR
// Roughness Map
Texture2D RoughnessMap -LINEAR
//Metallic and Roughness are packed respectively in the b and g channel of a single map
Texture2D MetallicRoughnessMap -LINEAR
// Texture of the emissive parts of the material
Texture2D EmissiveMap
// Normal map
Texture2D NormalMap -LINEAR
// the light map is a gray scale ao map, on ly the r channel will be read.
Boolean LightMapAsAOMap
//The type of normal map: -1.0 (DirectX), 1.0 (OpenGl)
Float NormalType : -1.0
// For Spec gloss pipeline
Boolean UseSpecGloss
Texture2D SpecularMap
Texture2D GlossinessMap
Texture2D SpecularGlossinessMap
Color Specular : 1.0 1.0 1.0 1.0
Float Glossiness : 1.0
Vector4 ProbeData
// Prefiltered Env Map for indirect specular lighting
TextureCubeMap PrefEnvMap -LINEAR
// Irradiance map for indirect diffuse lighting
TextureCubeMap IrradianceMap -LINEAR
//integrate BRDF map for indirect Lighting
Texture2D IntegrateBRDF -LINEAR
// Parallax/height map
Texture2D ParallaxMap -LINEAR
//Set to true is parallax map is stored in the alpha channel of the normal map
Boolean PackedNormalParallax
//Sets the relief height for parallax mapping
Float ParallaxHeight : 0.05
//Set to true to activate Steep Parallax mapping
Boolean SteepParallax
// Set to Use Lightmap
Texture2D LightMap
// Set to use TexCoord2 for the lightmap sampling
Boolean SeparateTexCoord
//shadows
Int FilterMode
Boolean HardwareShadows
Texture2D ShadowMap0
Texture2D ShadowMap1
Texture2D ShadowMap2
Texture2D ShadowMap3
//pointLights
Texture2D ShadowMap4
Texture2D ShadowMap5
Float ShadowIntensity
Vector4 Splits
Vector2 FadeInfo
Matrix4 LightViewProjectionMatrix0
Matrix4 LightViewProjectionMatrix1
Matrix4 LightViewProjectionMatrix2
Matrix4 LightViewProjectionMatrix3
//pointLight
Matrix4 LightViewProjectionMatrix4
Matrix4 LightViewProjectionMatrix5
Vector3 LightPos
Vector3 LightDir
Float PCFEdge
Float ShadowMapSize
// For hardware skinning
Int NumberOfBones
Matrix4Array BoneMatrices
//For instancing
Boolean UseInstancing
//For Vertex Color
Boolean UseVertexColor
Boolean BackfaceShadows : false
// Wind related parameters
Vector3 WorldNoiseOffset
Texture2D WindNoise
Boolean UseWind
Float FlexHeight : 2.0
Float TrunkFlexibility : 1.0
Float BranchFlexibility : 1.0
Boolean UseTriplanarPlagueMapping
Int PlaguedMapScale : 8
Texture2D AfflictionTexture
Texture2D PlaguedAlbedoMap
Texture2D PlaguedNormalMap -LINEAR
Texture2D PlaguedRoughnessMetallicMap -LINEAR
Vector3 TileLocation
Float TileWidth : 512.0
Boolean Bark
Boolean UseFog
Color FogColor
Vector2 LinearFog
Float ExpFog
Float ExpSqFog
}
Technique {
LightMode SinglePassAndImageBased
VertexShader GLSL110 GLSL150: MatDefs/vert/AfflictedPBRTrees.vert
FragmentShader GLSL110 GLSL150: MatDefs/frag/pbrGrass.frag
WorldParameters {
WorldViewProjectionMatrix
ViewProjectionMatrix
NormalMatrix
WorldNormalMatrix
WorldViewMatrix
ViewMatrix
CameraPosition
WorldMatrix
Time
}
Defines {
USE_FOG : UseFog
FOG_LINEAR : LinearFog
FOG_EXP : ExpFog
FOG_EXPSQ : ExpSqFog
AFFLICTIONTEXTURE : AfflictionTexture
PLAGUEDALBEDOMAP: PlaguedAlbedoMap
PLAGUEDNORMALMAP : PlaguedNormalMap
PLAGUEDROUGHNESSMETALLICMAP : PlaguedRoughnessMetallicMap
PROBE_COLOR : ProbeColor
USE_VERTEX_COLORS_AS_SUN_INTENSITY : UseVertexColorsAsSunIntensity
STATIC_SUN_INTENSITY : StaticSunIntensity
BRIGHTEN_INDOOR_SHADOWS : BrightenIndoorShadows
TILEWIDTH : TileWidth
TILELOCATION : TileLocation
AO_MAP : LightMapAsAOMap
BARK: Bark
USE_TRIPLANAR_PLAGUE_MAPPING : UseTriplanarPlagueMapping
BASECOLORMAP : BaseColorMap
NORMALMAP : NormalMap
METALLICMAP : MetallicMap
ROUGHNESSMAP : RoughnessMap
EMISSIVEMAP : EmissiveMap
EMISSIVE : Emissive
SPECGLOSSPIPELINE : UseSpecGloss
PARALLAXMAP : ParallaxMap
NORMALMAP_PARALLAX : PackedNormalParallax
STEEP_PARALLAX : SteepParallax
LIGHTMAP : LightMap
SEPARATE_TEXCOORD : SeparateTexCoord
DISCARD_ALPHA : AlphaDiscardThreshold
NUM_BONES : NumberOfBones
INSTANCING : UseInstancing
USE_PACKED_MR: MetallicRoughnessMap
USE_PACKED_SG: SpecularGlossinessMap
SPECULARMAP : SpecularMap
GLOSSINESSMAP : GlossinessMap
NORMAL_TYPE: NormalType
VERTEX_COLOR : UseVertexColor
// Wind related
USE_WIND : UseWind
}
}
Technique PreShadow {
VertexShader GLSL110 : MatDefs/TreePreShadow.vert
FragmentShader GLSL100 : Common/MatDefs/Shadow/PreShadow.frag
WorldParameters {
WorldViewProjectionMatrix
WorldViewMatrix
WorldMatrix
ViewMatrix
ViewProjectionMatrix
Time
}
Defines {
DISCARD_ALPHA : AlphaDiscardThreshold
NUM_BONES : NumberOfBones
INSTANCING : UseInstancing
// Wind related
USE_WIND : UseWind
}
ForcedRenderState {
FaceCull Off
DepthTest On
DepthWrite On
PolyOffset 5 3
ColorWrite Off
}
}
Technique PostShadow {
VertexShader GLSL100 GLSL150: Common/MatDefs/Shadow/PostShadow.vert
FragmentShader GLSL100 GLSL150: Common/MatDefs/Shadow/PostShadow.frag
WorldParameters {
WorldViewProjectionMatrix
WorldMatrix
ViewProjectionMatrix
ViewMatrix
}
Defines {
HARDWARE_SHADOWS : HardwareShadows
FILTER_MODE : FilterMode
PCFEDGE : PCFEdge
DISCARD_ALPHA : AlphaDiscardThreshold
SHADOWMAP_SIZE : ShadowMapSize
SHADOWMAP_SIZE : ShadowMapSize
FADE : FadeInfo
PSSM : Splits
POINTLIGHT : LightViewProjectionMatrix5
NUM_BONES : NumberOfBones
INSTANCING : UseInstancing
BACKFACE_SHADOWS: BackfaceShadows
}
ForcedRenderState {
Blend Modulate
DepthWrite Off
PolyOffset -0.1 0
}
}
Technique PreNormalPass {
VertexShader GLSL100 : Common/MatDefs/SSAO/normal.vert
FragmentShader GLSL100 : Common/MatDefs/SSAO/normal.frag
WorldParameters {
WorldViewProjectionMatrix
WorldViewMatrix
NormalMatrix
ViewProjectionMatrix
ViewMatrix
}
Defines {
NUM_BONES : NumberOfBones
INSTANCING : UseInstancing
}
}
Technique Glow {
VertexShader GLSL100 GLSL150: Common/MatDefs/Misc/Unshaded.vert
FragmentShader GLSL100 GLSL150: Common/MatDefs/Light/Glow.frag
WorldParameters {
WorldViewProjectionMatrix
ViewProjectionMatrix
ViewMatrix
}
Defines {
NEED_TEXCOORD1
HAS_GLOWMAP : GlowMap
HAS_GLOWCOLOR : GlowColor
NUM_BONES : NumberOfBones
INSTANCING : UseInstancing
}
}
}
and here is the SinglePass .vert file for the shader where the wind code happens - i believe the code for windiness is the same as simarboreal’s original Phong .vert shader
#import "Common/ShaderLib/GLSLCompat.glsllib"
#import "Common/ShaderLib/Instancing.glsllib"
#import "Common/ShaderLib/Skinning.glsllib"
#ifdef USE_WIND
uniform float g_Time;
#endif
#ifdef INSTANCING
#else
#define worldMatrix g_WorldMatrix
#endif
#import "MatDefs/TreeWind.glsllib"
uniform vec4 m_BaseColor;
uniform vec4 g_AmbientLightColor;
varying vec2 texCoord;
#ifdef SEPARATE_TEXCOORD
varying vec2 texCoord2;
attribute vec2 inTexCoord2;
#endif
varying vec4 Color;
attribute vec3 inPosition;
attribute vec2 inTexCoord;
attribute vec3 inNormal;
#ifdef VERTEX_COLOR
attribute vec4 inColor;
#endif
varying vec3 wNormal;
varying vec3 wPosition;
#if defined(NORMALMAP) || defined(PARALLAXMAP)
attribute vec4 inTangent;
varying vec4 wTangent;
#endif
#ifdef USE_FOG
varying float fogDistance;
uniform vec3 g_CameraPosition;
#endif
void main() {
vec4 modelSpacePos = vec4(inPosition, 1.0);
vec3 modelSpaceNorm = inNormal;
wPosition = TransformWorld(modelSpacePos).xyz;
#if (defined(NORMALMAP) || defined(PARALLAXMAP)) && !defined(VERTEX_LIGHTING)
vec3 modelSpaceTan = inTangent.xyz;
#endif
#ifdef NUM_BONES
#if defined(NORMALMAP) && !defined(VERTEX_LIGHTING)
Skinning_Compute(modelSpacePos, modelSpaceNorm, modelSpaceTan);
#else
Skinning_Compute(modelSpacePos, modelSpaceNorm);
#endif
#endif
#ifdef USE_WIND
// some simple wind
float windStrength = 0.75;
// Need to know the model's ground position for noise basis
// otherwise the tree will warp all over the place and it
// will look strange as the trunk stretches and shrinks.
vec4 groundPos = worldMatrix * vec4(0.0, 0.0, 0.0, 1.0);
// Wind is applied to world space
vec4 wPos = worldMatrix * modelSpacePos;
wPos.xyz += calculateWind(groundPos.xyz, wPos.xyz - groundPos.xyz, windStrength);
gl_Position = g_ViewProjectionMatrix * wPos;
#else
gl_Position = TransformWorldViewProjection(modelSpacePos);
#endif
texCoord = inTexCoord;
#ifdef SEPARATE_TEXCOORD
texCoord2 = inTexCoord2;
#endif
wNormal = TransformWorldNormal(modelSpaceNorm);
#if defined(NORMALMAP) || defined(PARALLAXMAP)
wTangent = vec4(TransformWorldNormal(modelSpaceTan),inTangent.w);
#endif
Color = m_BaseColor;
#ifdef VERTEX_COLOR
Color *= inColor;
#endif
#ifdef USE_FOG
fogDistance = distance(g_CameraPosition, (g_WorldMatrix * modelSpacePos).xyz);
#endif
}
Thanks in advance for any help, and for any advice/knowledge about the PreShadow technique and how it works