Arbeiten aus dem URlaub
This commit is contained in:
332
simarboreal/assets/MatDefs/MultiResolution.frag
Normal file
332
simarboreal/assets/MatDefs/MultiResolution.frag
Normal file
@@ -0,0 +1,332 @@
|
||||
#import "Common/ShaderLib/Parallax.glsllib"
|
||||
#import "Common/ShaderLib/Optics.glsllib"
|
||||
#define ATTENUATION
|
||||
//#define HQ_ATTENUATION
|
||||
|
||||
#import "MatDefs/FragScattering.glsllib"
|
||||
|
||||
varying vec2 texCoord;
|
||||
#ifdef SEPARATE_TEXCOORD
|
||||
varying vec2 texCoord2;
|
||||
#endif
|
||||
|
||||
varying vec3 AmbientSum;
|
||||
varying vec4 DiffuseSum;
|
||||
varying vec3 SpecularSum;
|
||||
|
||||
varying float z;
|
||||
|
||||
#ifndef VERTEX_LIGHTING
|
||||
uniform vec4 g_LightDirection;
|
||||
//varying vec3 vPosition;
|
||||
varying vec3 vViewDir;
|
||||
varying vec4 vLightDir;
|
||||
varying vec3 lightVec;
|
||||
#else
|
||||
varying vec2 vertexLightValues;
|
||||
#endif
|
||||
|
||||
#ifdef DIFFUSEMAP
|
||||
uniform sampler2D m_DiffuseMap;
|
||||
uniform sampler2D m_BackgroundDiffuseMap;
|
||||
uniform sampler2D m_NoiseMap;
|
||||
#endif
|
||||
|
||||
#ifdef SPECULARMAP
|
||||
uniform sampler2D m_SpecularMap;
|
||||
#endif
|
||||
|
||||
#ifdef PARALLAXMAP
|
||||
uniform sampler2D m_ParallaxMap;
|
||||
#endif
|
||||
#if (defined(PARALLAXMAP) || (defined(NORMALMAP_PARALLAX) && defined(NORMALMAP))) && !defined(VERTEX_LIGHTING)
|
||||
uniform float m_ParallaxHeight;
|
||||
#endif
|
||||
|
||||
#ifdef LIGHTMAP
|
||||
uniform sampler2D m_LightMap;
|
||||
#endif
|
||||
|
||||
#ifdef NORMALMAP
|
||||
uniform sampler2D m_NormalMap;
|
||||
#else
|
||||
varying vec3 vNormal;
|
||||
#endif
|
||||
|
||||
#ifdef ALPHAMAP
|
||||
uniform sampler2D m_AlphaMap;
|
||||
#endif
|
||||
|
||||
#ifdef COLORRAMP
|
||||
uniform sampler2D m_ColorRamp;
|
||||
#endif
|
||||
|
||||
uniform float m_AlphaDiscardThreshold;
|
||||
|
||||
#ifndef VERTEX_LIGHTING
|
||||
uniform float m_Shininess;
|
||||
|
||||
#ifdef HQ_ATTENUATION
|
||||
uniform vec4 g_LightPosition;
|
||||
#endif
|
||||
|
||||
#ifdef USE_REFLECTION
|
||||
uniform float m_ReflectionPower;
|
||||
uniform float m_ReflectionIntensity;
|
||||
varying vec4 refVec;
|
||||
|
||||
uniform ENVMAP m_EnvMap;
|
||||
#endif
|
||||
|
||||
float tangDot(in vec3 v1, in vec3 v2){
|
||||
float d = dot(v1,v2);
|
||||
#ifdef V_TANGENT
|
||||
d = 1.0 - d*d;
|
||||
return step(0.0, d) * sqrt(d);
|
||||
#else
|
||||
return d;
|
||||
#endif
|
||||
}
|
||||
|
||||
float lightComputeDiffuse(in vec3 norm, in vec3 lightdir, in vec3 viewdir){
|
||||
#ifdef MINNAERT
|
||||
float NdotL = max(0.0, dot(norm, lightdir));
|
||||
float NdotV = max(0.0, dot(norm, viewdir));
|
||||
return NdotL * pow(max(NdotL * NdotV, 0.1), -1.0) * 0.5;
|
||||
#else
|
||||
return max(0.0, dot(norm, lightdir));
|
||||
#endif
|
||||
}
|
||||
|
||||
float lightComputeSpecular(in vec3 norm, in vec3 viewdir, in vec3 lightdir, in float shiny){
|
||||
// NOTE: check for shiny <= 1 removed since shininess is now
|
||||
// 1.0 by default (uses matdefs default vals)
|
||||
#ifdef LOW_QUALITY
|
||||
// Blinn-Phong
|
||||
// Note: preferably, H should be computed in the vertex shader
|
||||
vec3 H = (viewdir + lightdir) * vec3(0.5);
|
||||
return pow(max(tangDot(H, norm), 0.0), shiny);
|
||||
#elif defined(WARDISO)
|
||||
// Isotropic Ward
|
||||
vec3 halfVec = normalize(viewdir + lightdir);
|
||||
float NdotH = max(0.001, tangDot(norm, halfVec));
|
||||
float NdotV = max(0.001, tangDot(norm, viewdir));
|
||||
float NdotL = max(0.001, tangDot(norm, lightdir));
|
||||
float a = tan(acos(NdotH));
|
||||
float p = max(shiny/128.0, 0.001);
|
||||
return NdotL * (1.0 / (4.0*3.14159265*p*p)) * (exp(-(a*a)/(p*p)) / (sqrt(NdotV * NdotL)));
|
||||
#else
|
||||
// Standard Phong
|
||||
vec3 R = reflect(-lightdir, norm);
|
||||
return pow(max(tangDot(R, viewdir), 0.0), shiny);
|
||||
#endif
|
||||
}
|
||||
|
||||
vec2 computeLighting(in vec3 wvNorm, in vec3 wvViewDir, in vec3 wvLightDir){
|
||||
float diffuseFactor = lightComputeDiffuse(wvNorm, wvLightDir, wvViewDir);
|
||||
float specularFactor = lightComputeSpecular(wvNorm, wvViewDir, wvLightDir, m_Shininess);
|
||||
|
||||
#ifdef HQ_ATTENUATION
|
||||
float att = clamp(1.0 - g_LightPosition.w * length(lightVec), 0.0, 1.0);
|
||||
#else
|
||||
float att = vLightDir.w;
|
||||
#endif
|
||||
|
||||
if (m_Shininess <= 1.0) {
|
||||
specularFactor = 0.0; // should be one instruction on most cards ..
|
||||
}
|
||||
|
||||
specularFactor *= diffuseFactor;
|
||||
|
||||
return vec2(diffuseFactor, specularFactor) * vec2(att);
|
||||
}
|
||||
#endif
|
||||
|
||||
vec4 getColor( in sampler2D diffuseMap, in sampler2D diffuseMap2,
|
||||
in sampler2D normalMap, in vec2 tc, in float distMix,
|
||||
out vec3 normal ) {
|
||||
|
||||
vec2 tcOffset;
|
||||
tcOffset = texture2D(m_NoiseMap, tc * 0.01).xy * 6.0 - 3.0;
|
||||
vec4 diffuseColor = texture2D(diffuseMap, (tc + tcOffset) * 0.75);
|
||||
|
||||
tcOffset = (texture2D(m_NoiseMap, tc * 0.01).xy * 6.0) - 3.0;
|
||||
vec4 subColor = texture2D(diffuseMap2, ((tc + tcOffset) * 1.0) * 0.1 );
|
||||
diffuseColor = mix(diffuseColor, subColor, distMix);
|
||||
|
||||
#ifdef NORMALMAP
|
||||
vec4 normalHeight = texture2D(normalMap, tc);
|
||||
normal = normalize((normalHeight.xyz * vec3(2.0) - vec3(1.0)));
|
||||
#else
|
||||
normal = vec3(0.0, 1.0, 0.0);
|
||||
#endif
|
||||
|
||||
return diffuseColor;
|
||||
}
|
||||
|
||||
|
||||
void main(){
|
||||
vec2 newTexCoord;
|
||||
|
||||
#if (defined(PARALLAXMAP) || (defined(NORMALMAP_PARALLAX) && defined(NORMALMAP))) && !defined(VERTEX_LIGHTING)
|
||||
|
||||
#ifdef STEEP_PARALLAX
|
||||
#ifdef NORMALMAP_PARALLAX
|
||||
//parallax map is stored in the alpha channel of the normal map
|
||||
newTexCoord = steepParallaxOffset(m_NormalMap, vViewDir, texCoord, m_ParallaxHeight);
|
||||
#else
|
||||
//parallax map is a texture
|
||||
newTexCoord = steepParallaxOffset(m_ParallaxMap, vViewDir, texCoord, m_ParallaxHeight);
|
||||
#endif
|
||||
#else
|
||||
#ifdef NORMALMAP_PARALLAX
|
||||
//parallax map is stored in the alpha channel of the normal map
|
||||
newTexCoord = classicParallaxOffset(m_NormalMap, vViewDir, texCoord, m_ParallaxHeight);
|
||||
#else
|
||||
//parallax map is a texture
|
||||
newTexCoord = classicParallaxOffset(m_ParallaxMap, vViewDir, texCoord, m_ParallaxHeight);
|
||||
#endif
|
||||
#endif
|
||||
#else
|
||||
newTexCoord = texCoord;
|
||||
#endif
|
||||
|
||||
float distMix = z / 32.0;
|
||||
distMix = clamp(distMix, 0.4, 1.0);
|
||||
|
||||
#ifdef DIFFUSEMAP
|
||||
vec3 newNormal;
|
||||
#ifdef NORMALMAP
|
||||
vec4 diffuseColor = getColor(m_DiffuseMap, m_BackgroundDiffuseMap,
|
||||
m_NormalMap, texCoord, distMix, newNormal);
|
||||
#else
|
||||
vec4 diffuseColor = getColor(m_DiffuseMap, m_BackgroundDiffuseMap,
|
||||
m_DiffuseMap, texCoord, distMix, newNormal);
|
||||
#endif
|
||||
#else
|
||||
vec4 diffuseColor = vec4(1.0);
|
||||
vec3 newNormal = vec3(0.0, 1.0, 0.0);
|
||||
#endif
|
||||
|
||||
float alpha = DiffuseSum.a * diffuseColor.a;
|
||||
#ifdef ALPHAMAP
|
||||
alpha = alpha * texture2D(m_AlphaMap, newTexCoord).r;
|
||||
#endif
|
||||
if(alpha < m_AlphaDiscardThreshold){
|
||||
discard;
|
||||
}
|
||||
|
||||
#ifndef VERTEX_LIGHTING
|
||||
float spotFallOff = 1.0;
|
||||
|
||||
#if __VERSION__ >= 110
|
||||
// allow use of control flow
|
||||
if(g_LightDirection.w != 0.0){
|
||||
#endif
|
||||
|
||||
vec3 L = normalize(lightVec.xyz);
|
||||
vec3 spotdir = normalize(g_LightDirection.xyz);
|
||||
float curAngleCos = dot(-L, spotdir);
|
||||
float innerAngleCos = floor(g_LightDirection.w) * 0.001;
|
||||
float outerAngleCos = fract(g_LightDirection.w);
|
||||
float innerMinusOuter = innerAngleCos - outerAngleCos;
|
||||
spotFallOff = (curAngleCos - outerAngleCos) / innerMinusOuter;
|
||||
|
||||
#if __VERSION__ >= 110
|
||||
if(spotFallOff <= 0.0){
|
||||
gl_FragColor.rgb = AmbientSum * diffuseColor.rgb;
|
||||
gl_FragColor.a = alpha;
|
||||
return;
|
||||
}else{
|
||||
spotFallOff = clamp(spotFallOff, 0.0, 1.0);
|
||||
}
|
||||
}
|
||||
#else
|
||||
spotFallOff = clamp(spotFallOff, step(g_LightDirection.w, 0.001), 1.0);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
// ***********************
|
||||
// Read from textures
|
||||
// ***********************
|
||||
#if defined(NORMALMAP) && !defined(VERTEX_LIGHTING)
|
||||
vec3 normal = newNormal;
|
||||
#elif !defined(VERTEX_LIGHTING)
|
||||
vec3 normal = vNormal;
|
||||
#if !defined(LOW_QUALITY) && !defined(V_TANGENT)
|
||||
normal = normalize(normal);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef SPECULARMAP
|
||||
vec4 specularColor = texture2D(m_SpecularMap, newTexCoord);
|
||||
#else
|
||||
vec4 specularColor = vec4(1.0);
|
||||
#endif
|
||||
|
||||
#ifdef LIGHTMAP
|
||||
vec3 lightMapColor;
|
||||
#ifdef SEPARATE_TEXCOORD
|
||||
lightMapColor = texture2D(m_LightMap, texCoord2).rgb;
|
||||
#else
|
||||
lightMapColor = texture2D(m_LightMap, texCoord).rgb;
|
||||
#endif
|
||||
specularColor.rgb *= lightMapColor;
|
||||
diffuseColor.rgb *= lightMapColor;
|
||||
#endif
|
||||
|
||||
#ifdef VERTEX_LIGHTING
|
||||
vec2 light = vertexLightValues.xy;
|
||||
#ifdef COLORRAMP
|
||||
light.x = texture2D(m_ColorRamp, vec2(light.x, 0.0)).r;
|
||||
light.y = texture2D(m_ColorRamp, vec2(light.y, 0.0)).r;
|
||||
#endif
|
||||
|
||||
#ifndef USE_SCATTERING
|
||||
gl_FragColor.rgb = AmbientSum * diffuseColor.rgb +
|
||||
DiffuseSum.rgb * diffuseColor.rgb * vec3(light.x) +
|
||||
SpecularSum * specularColor.rgb * vec3(light.y);
|
||||
#else
|
||||
vec3 color = AmbientSum * diffuseColor.rgb +
|
||||
DiffuseSum.rgb * diffuseColor.rgb * vec3(light.x) +
|
||||
SpecularSum * specularColor.rgb * vec3(light.y);
|
||||
gl_FragColor.rgb = calculateGroundColor(vec4(color, 1.0)).rgb;
|
||||
#endif
|
||||
#else
|
||||
vec4 lightDir = vLightDir;
|
||||
lightDir.xyz = normalize(lightDir.xyz);
|
||||
vec3 viewDir = normalize(vViewDir);
|
||||
|
||||
vec2 light = computeLighting(normal, viewDir, lightDir.xyz) * spotFallOff;
|
||||
#ifdef COLORRAMP
|
||||
diffuseColor.rgb *= texture2D(m_ColorRamp, vec2(light.x, 0.0)).rgb;
|
||||
specularColor.rgb *= texture2D(m_ColorRamp, vec2(light.y, 0.0)).rgb;
|
||||
#endif
|
||||
|
||||
// Workaround, since it is not possible to modify varying variables
|
||||
vec4 SpecularSum2 = vec4(SpecularSum, 1.0);
|
||||
#ifdef USE_REFLECTION
|
||||
vec4 refColor = Optics_GetEnvColor(m_EnvMap, refVec.xyz);
|
||||
|
||||
// Interpolate light specularity toward reflection color
|
||||
// Multiply result by specular map
|
||||
specularColor = mix(SpecularSum2 * light.y, refColor, refVec.w) * specularColor;
|
||||
|
||||
SpecularSum2 = vec4(1.0);
|
||||
light.y = 1.0;
|
||||
#endif
|
||||
|
||||
#ifndef USE_SCATTERING
|
||||
gl_FragColor.rgb = AmbientSum * diffuseColor.rgb +
|
||||
DiffuseSum.rgb * diffuseColor.rgb * vec3(light.x) +
|
||||
SpecularSum * specularColor.rgb * vec3(light.y);
|
||||
#else
|
||||
vec3 color = AmbientSum * diffuseColor.rgb +
|
||||
DiffuseSum.rgb * diffuseColor.rgb * vec3(light.x) +
|
||||
SpecularSum * specularColor.rgb * vec3(light.y);
|
||||
gl_FragColor.rgb = calculateGroundColor(vec4(color, 1.0)).rgb;
|
||||
#endif
|
||||
|
||||
#endif
|
||||
gl_FragColor.a = alpha;
|
||||
}
|
||||
352
simarboreal/assets/MatDefs/MultiResolution.j3md
Normal file
352
simarboreal/assets/MatDefs/MultiResolution.j3md
Normal file
@@ -0,0 +1,352 @@
|
||||
MaterialDef Phong Lighting {
|
||||
|
||||
MaterialParameters {
|
||||
|
||||
// Compute vertex lighting in the shader
|
||||
// For better performance
|
||||
Boolean VertexLighting
|
||||
|
||||
// Use more efficent algorithms to improve performance
|
||||
Boolean LowQuality
|
||||
|
||||
// Improve quality at the cost of performance
|
||||
Boolean HighQuality
|
||||
|
||||
// Output alpha from the diffuse map
|
||||
Boolean UseAlpha
|
||||
|
||||
// Alpha threshold for fragment discarding
|
||||
Float AlphaDiscardThreshold (AlphaTestFallOff)
|
||||
|
||||
// Normal map is in BC5/ATI2n/LATC/3Dc compression format
|
||||
Boolean LATC
|
||||
|
||||
// Use the provided ambient, diffuse, and specular colors
|
||||
Boolean UseMaterialColors
|
||||
|
||||
// Activate shading along the tangent, instead of the normal
|
||||
// Requires tangent data to be available on the model.
|
||||
Boolean VTangent
|
||||
|
||||
// Use minnaert diffuse instead of lambert
|
||||
Boolean Minnaert
|
||||
|
||||
// Use ward specular instead of phong
|
||||
Boolean WardIso
|
||||
|
||||
// Use vertex color as an additional diffuse color.
|
||||
Boolean UseVertexColor
|
||||
|
||||
// Ambient color
|
||||
Color Ambient (MaterialAmbient)
|
||||
|
||||
// Diffuse color
|
||||
Color Diffuse (MaterialDiffuse)
|
||||
|
||||
// Specular color
|
||||
Color Specular (MaterialSpecular)
|
||||
|
||||
// Specular power/shininess
|
||||
Float Shininess (MaterialShininess) : 1
|
||||
|
||||
// Diffuse map
|
||||
Texture2D DiffuseMap
|
||||
|
||||
// Diffuse map
|
||||
Texture2D BackgroundDiffuseMap
|
||||
|
||||
// Diffuse map
|
||||
Texture2D NoiseMap
|
||||
|
||||
// Normal map
|
||||
Texture2D NormalMap
|
||||
|
||||
// Specular/gloss map
|
||||
Texture2D SpecularMap
|
||||
|
||||
// Parallax/height map
|
||||
Texture2D ParallaxMap
|
||||
|
||||
//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
|
||||
|
||||
// Texture that specifies alpha values
|
||||
Texture2D AlphaMap
|
||||
|
||||
// Color ramp, will map diffuse and specular values through it.
|
||||
Texture2D ColorRamp
|
||||
|
||||
// Texture of the glowing parts of the material
|
||||
Texture2D GlowMap
|
||||
|
||||
// Set to Use Lightmap
|
||||
Texture2D LightMap
|
||||
|
||||
// Set to use TexCoord2 for the lightmap sampling
|
||||
Boolean SeparateTexCoord
|
||||
|
||||
// The glow color of the object
|
||||
Color GlowColor
|
||||
|
||||
// Parameters for fresnel
|
||||
// X = bias
|
||||
// Y = scale
|
||||
// Z = power
|
||||
Vector3 FresnelParams
|
||||
|
||||
// Env Map for reflection
|
||||
TextureCubeMap EnvMap
|
||||
|
||||
// the env map is a spheremap and not a cube map
|
||||
Boolean EnvMapAsSphereMap
|
||||
|
||||
//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
|
||||
|
||||
Float PCFEdge
|
||||
Float ShadowMapSize
|
||||
|
||||
// For hardware skinning
|
||||
Int NumberOfBones
|
||||
Matrix4Array BoneMatrices
|
||||
|
||||
|
||||
// Ground scattering parameters
|
||||
Boolean UseScattering
|
||||
Vector3 SunPosition
|
||||
Float Exposure
|
||||
Float KmESun
|
||||
Float InnerRadius
|
||||
Float RadiusScale
|
||||
Float PlanetScale : 1
|
||||
Vector3 InvWavelengthsKrESun
|
||||
Float AverageDensityScale
|
||||
Float InvAverageDensityHeight;
|
||||
Vector3 KWavelengths4PI;
|
||||
|
||||
}
|
||||
|
||||
Technique {
|
||||
|
||||
LightMode MultiPass
|
||||
|
||||
VertexShader GLSL110: MatDefs/MultiResolution.vert
|
||||
FragmentShader GLSL110: MatDefs/MultiResolution.frag
|
||||
|
||||
WorldParameters {
|
||||
WorldViewProjectionMatrix
|
||||
NormalMatrix
|
||||
WorldViewMatrix
|
||||
ViewMatrix
|
||||
CameraPosition
|
||||
WorldMatrix
|
||||
}
|
||||
|
||||
Defines {
|
||||
LATC : LATC
|
||||
VERTEX_COLOR : UseVertexColor
|
||||
VERTEX_LIGHTING : VertexLighting
|
||||
ATTENUATION : Attenuation
|
||||
MATERIAL_COLORS : UseMaterialColors
|
||||
V_TANGENT : VTangent
|
||||
MINNAERT : Minnaert
|
||||
WARDISO : WardIso
|
||||
LOW_QUALITY : LowQuality
|
||||
HQ_ATTENUATION : HighQuality
|
||||
|
||||
DIFFUSEMAP : DiffuseMap
|
||||
NORMALMAP : NormalMap
|
||||
SPECULARMAP : SpecularMap
|
||||
PARALLAXMAP : ParallaxMap
|
||||
NORMALMAP_PARALLAX : PackedNormalParallax
|
||||
STEEP_PARALLAX : SteepParallax
|
||||
ALPHAMAP : AlphaMap
|
||||
COLORRAMP : ColorRamp
|
||||
LIGHTMAP : LightMap
|
||||
SEPARATE_TEXCOORD : SeparateTexCoord
|
||||
|
||||
USE_REFLECTION : EnvMap
|
||||
SPHERE_MAP : SphereMap
|
||||
|
||||
NUM_BONES : NumberOfBones
|
||||
|
||||
USE_SCATTERING : UseScattering
|
||||
}
|
||||
}
|
||||
|
||||
Technique PreShadow {
|
||||
|
||||
VertexShader GLSL110 : Common/MatDefs/Shadow/PreShadow.vert
|
||||
FragmentShader GLSL110 : Common/MatDefs/Shadow/PreShadow.frag
|
||||
|
||||
WorldParameters {
|
||||
WorldViewProjectionMatrix
|
||||
WorldViewMatrix
|
||||
}
|
||||
|
||||
Defines {
|
||||
COLOR_MAP : ColorMap
|
||||
DISCARD_ALPHA : AlphaDiscardThreshold
|
||||
NUM_BONES : NumberOfBones
|
||||
}
|
||||
|
||||
ForcedRenderState {
|
||||
FaceCull Off
|
||||
DepthTest On
|
||||
DepthWrite On
|
||||
PolyOffset 5 3
|
||||
ColorWrite Off
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
Technique PostShadow15{
|
||||
VertexShader GLSL150: Common/MatDefs/Shadow/PostShadow15.vert
|
||||
FragmentShader GLSL150: Common/MatDefs/Shadow/PostShadow15.frag
|
||||
|
||||
WorldParameters {
|
||||
WorldViewProjectionMatrix
|
||||
WorldMatrix
|
||||
}
|
||||
|
||||
Defines {
|
||||
HARDWARE_SHADOWS : HardwareShadows
|
||||
FILTER_MODE : FilterMode
|
||||
PCFEDGE : PCFEdge
|
||||
DISCARD_ALPHA : AlphaDiscardThreshold
|
||||
COLOR_MAP : ColorMap
|
||||
SHADOWMAP_SIZE : ShadowMapSize
|
||||
FADE : FadeInfo
|
||||
PSSM : Splits
|
||||
POINTLIGHT : LightViewProjectionMatrix5
|
||||
NUM_BONES : NumberOfBones
|
||||
}
|
||||
|
||||
ForcedRenderState {
|
||||
Blend Modulate
|
||||
DepthWrite Off
|
||||
PolyOffset -0.1 0
|
||||
}
|
||||
}
|
||||
|
||||
Technique PostShadow{
|
||||
VertexShader GLSL110: Common/MatDefs/Shadow/PostShadow.vert
|
||||
FragmentShader GLSL110: Common/MatDefs/Shadow/PostShadow.frag
|
||||
|
||||
WorldParameters {
|
||||
WorldViewProjectionMatrix
|
||||
WorldMatrix
|
||||
}
|
||||
|
||||
Defines {
|
||||
HARDWARE_SHADOWS : HardwareShadows
|
||||
FILTER_MODE : FilterMode
|
||||
PCFEDGE : PCFEdge
|
||||
DISCARD_ALPHA : AlphaDiscardThreshold
|
||||
COLOR_MAP : ColorMap
|
||||
SHADOWMAP_SIZE : ShadowMapSize
|
||||
FADE : FadeInfo
|
||||
PSSM : Splits
|
||||
POINTLIGHT : LightViewProjectionMatrix5
|
||||
NUM_BONES : NumberOfBones
|
||||
}
|
||||
|
||||
ForcedRenderState {
|
||||
Blend Modulate
|
||||
DepthWrite Off
|
||||
PolyOffset -0.1 0
|
||||
}
|
||||
}
|
||||
|
||||
Technique PreNormalPass {
|
||||
|
||||
VertexShader GLSL110 : Common/MatDefs/SSAO/normal.vert
|
||||
FragmentShader GLSL110 : Common/MatDefs/SSAO/normal.frag
|
||||
|
||||
WorldParameters {
|
||||
WorldViewProjectionMatrix
|
||||
WorldViewMatrix
|
||||
NormalMatrix
|
||||
}
|
||||
|
||||
Defines {
|
||||
DIFFUSEMAP_ALPHA : DiffuseMap
|
||||
NUM_BONES : NumberOfBones
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Technique GBuf {
|
||||
|
||||
VertexShader GLSL110: Common/MatDefs/Light/GBuf.vert
|
||||
FragmentShader GLSL110: Common/MatDefs/Light/GBuf.frag
|
||||
|
||||
WorldParameters {
|
||||
WorldViewProjectionMatrix
|
||||
NormalMatrix
|
||||
WorldViewMatrix
|
||||
WorldMatrix
|
||||
}
|
||||
|
||||
Defines {
|
||||
VERTEX_COLOR : UseVertexColor
|
||||
MATERIAL_COLORS : UseMaterialColors
|
||||
V_TANGENT : VTangent
|
||||
MINNAERT : Minnaert
|
||||
WARDISO : WardIso
|
||||
|
||||
DIFFUSEMAP : DiffuseMap
|
||||
NORMALMAP : NormalMap
|
||||
SPECULARMAP : SpecularMap
|
||||
PARALLAXMAP : ParallaxMap
|
||||
}
|
||||
}
|
||||
|
||||
Technique Glow {
|
||||
|
||||
VertexShader GLSL110: Common/MatDefs/Misc/Unshaded.vert
|
||||
FragmentShader GLSL110: Common/MatDefs/Light/Glow.frag
|
||||
|
||||
WorldParameters {
|
||||
WorldViewProjectionMatrix
|
||||
}
|
||||
|
||||
Defines {
|
||||
NEED_TEXCOORD1
|
||||
HAS_GLOWMAP : GlowMap
|
||||
HAS_GLOWCOLOR : GlowColor
|
||||
|
||||
NUM_BONES : NumberOfBones
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
237
simarboreal/assets/MatDefs/MultiResolution.vert
Normal file
237
simarboreal/assets/MatDefs/MultiResolution.vert
Normal file
@@ -0,0 +1,237 @@
|
||||
#define ATTENUATION
|
||||
//#define HQ_ATTENUATION
|
||||
|
||||
#import "Common/ShaderLib/Skinning.glsllib"
|
||||
#import "MatDefs/VertScattering.glsllib"
|
||||
|
||||
|
||||
uniform mat4 g_WorldViewProjectionMatrix;
|
||||
uniform mat4 g_WorldViewMatrix;
|
||||
uniform mat4 g_WorldMatrix;
|
||||
uniform mat3 g_NormalMatrix;
|
||||
uniform mat4 g_ViewMatrix;
|
||||
uniform vec3 g_CameraPosition;
|
||||
|
||||
uniform vec4 m_Ambient;
|
||||
uniform vec4 m_Diffuse;
|
||||
uniform vec4 m_Specular;
|
||||
uniform float m_Shininess;
|
||||
|
||||
uniform vec4 g_LightColor;
|
||||
uniform vec4 g_LightPosition;
|
||||
uniform vec4 g_AmbientLightColor;
|
||||
|
||||
varying vec2 texCoord;
|
||||
#ifdef SEPARATE_TEXCOORD
|
||||
varying vec2 texCoord2;
|
||||
attribute vec2 inTexCoord2;
|
||||
#endif
|
||||
|
||||
varying vec3 AmbientSum;
|
||||
varying vec4 DiffuseSum;
|
||||
varying vec3 SpecularSum;
|
||||
|
||||
varying float z;
|
||||
|
||||
attribute vec3 inPosition;
|
||||
attribute vec2 inTexCoord;
|
||||
attribute vec3 inNormal;
|
||||
|
||||
varying vec3 lightVec;
|
||||
//varying vec4 spotVec;
|
||||
|
||||
#ifdef VERTEX_COLOR
|
||||
attribute vec4 inColor;
|
||||
#endif
|
||||
|
||||
#ifndef VERTEX_LIGHTING
|
||||
attribute vec4 inTangent;
|
||||
|
||||
#ifndef NORMALMAP
|
||||
varying vec3 vNormal;
|
||||
#endif
|
||||
//varying vec3 vPosition;
|
||||
varying vec3 vViewDir;
|
||||
varying vec4 vLightDir;
|
||||
#else
|
||||
varying vec2 vertexLightValues;
|
||||
uniform vec4 g_LightDirection;
|
||||
#endif
|
||||
|
||||
#ifdef USE_REFLECTION
|
||||
uniform vec3 g_CameraPosition;
|
||||
uniform mat4 g_WorldMatrix;
|
||||
|
||||
uniform vec3 m_FresnelParams;
|
||||
varying vec4 refVec;
|
||||
|
||||
|
||||
/**
|
||||
* Input:
|
||||
* attribute inPosition
|
||||
* attribute inNormal
|
||||
* uniform g_WorldMatrix
|
||||
* uniform g_CameraPosition
|
||||
*
|
||||
* Output:
|
||||
* varying refVec
|
||||
*/
|
||||
void computeRef(in vec4 modelSpacePos){
|
||||
vec3 worldPos = (g_WorldMatrix * modelSpacePos).xyz;
|
||||
|
||||
vec3 I = normalize( g_CameraPosition - worldPos ).xyz;
|
||||
vec3 N = normalize( (g_WorldMatrix * vec4(inNormal, 0.0)).xyz );
|
||||
|
||||
refVec.xyz = reflect(I, N);
|
||||
refVec.w = m_FresnelParams.x + m_FresnelParams.y * pow(1.0 + dot(I, N), m_FresnelParams.z);
|
||||
}
|
||||
#endif
|
||||
|
||||
// JME3 lights in world space
|
||||
void lightComputeDir(in vec3 worldPos, in vec4 color, in vec4 position, out vec4 lightDir){
|
||||
float posLight = step(0.5, color.w);
|
||||
vec3 tempVec = position.xyz * sign(posLight - 0.5) - (worldPos * posLight);
|
||||
lightVec = tempVec;
|
||||
#ifdef ATTENUATION
|
||||
float dist = length(tempVec);
|
||||
lightDir.w = clamp(1.0 - position.w * dist * posLight, 0.0, 1.0);
|
||||
lightDir.xyz = tempVec / vec3(dist);
|
||||
#else
|
||||
lightDir = vec4(normalize(tempVec), 1.0);
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef VERTEX_LIGHTING
|
||||
float lightComputeDiffuse(in vec3 norm, in vec3 lightdir){
|
||||
return max(0.0, dot(norm, lightdir));
|
||||
}
|
||||
|
||||
float lightComputeSpecular(in vec3 norm, in vec3 viewdir, in vec3 lightdir, in float shiny){
|
||||
if (shiny <= 1.0){
|
||||
return 0.0;
|
||||
}
|
||||
#ifndef LOW_QUALITY
|
||||
vec3 H = (viewdir + lightdir) * vec3(0.5);
|
||||
return pow(max(dot(H, norm), 0.0), shiny);
|
||||
#else
|
||||
return 0.0;
|
||||
#endif
|
||||
}
|
||||
|
||||
vec2 computeLighting(in vec3 wvPos, in vec3 wvNorm, in vec3 wvViewDir, in vec4 wvLightPos){
|
||||
vec4 lightDir;
|
||||
lightComputeDir(wvPos, g_LightColor, wvLightPos, lightDir);
|
||||
float spotFallOff = 1.0;
|
||||
if(g_LightDirection.w != 0.0){
|
||||
vec3 L=normalize(lightVec.xyz);
|
||||
vec3 spotdir = normalize(g_LightDirection.xyz);
|
||||
float curAngleCos = dot(-L, spotdir);
|
||||
float innerAngleCos = floor(g_LightDirection.w) * 0.001;
|
||||
float outerAngleCos = fract(g_LightDirection.w);
|
||||
float innerMinusOuter = innerAngleCos - outerAngleCos;
|
||||
spotFallOff = clamp((curAngleCos - outerAngleCos) / innerMinusOuter, 0.0, 1.0);
|
||||
}
|
||||
float diffuseFactor = lightComputeDiffuse(wvNorm, lightDir.xyz);
|
||||
float specularFactor = lightComputeSpecular(wvNorm, wvViewDir, lightDir.xyz, m_Shininess);
|
||||
//specularFactor *= step(0.01, diffuseFactor);
|
||||
return vec2(diffuseFactor, specularFactor) * vec2(lightDir.w)*spotFallOff;
|
||||
}
|
||||
#endif
|
||||
|
||||
void main(){
|
||||
vec4 modelSpacePos = vec4(inPosition, 1.0);
|
||||
vec3 modelSpaceNorm = inNormal;
|
||||
|
||||
#ifndef VERTEX_LIGHTING
|
||||
vec3 modelSpaceTan = inTangent.xyz;
|
||||
#endif
|
||||
|
||||
#ifdef NUM_BONES
|
||||
#ifndef VERTEX_LIGHTING
|
||||
Skinning_Compute(modelSpacePos, modelSpaceNorm, modelSpaceTan);
|
||||
#else
|
||||
Skinning_Compute(modelSpacePos, modelSpaceNorm);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef USE_SCATTERING
|
||||
vec4 wPos = g_WorldMatrix * modelSpacePos;
|
||||
calculateVertexGroundScattering(wPos.xyz, g_CameraPosition);
|
||||
#endif
|
||||
|
||||
gl_Position = g_WorldViewProjectionMatrix * modelSpacePos;
|
||||
texCoord = inTexCoord;
|
||||
#ifdef SEPARATE_TEXCOORD
|
||||
texCoord2 = inTexCoord2;
|
||||
#endif
|
||||
|
||||
vec3 wvPosition = (g_WorldViewMatrix * modelSpacePos).xyz;
|
||||
|
||||
z = length(wvPosition);
|
||||
|
||||
vec3 wvNormal = normalize(g_NormalMatrix * modelSpaceNorm);
|
||||
vec3 viewDir = normalize(-wvPosition);
|
||||
|
||||
//vec4 lightColor = g_LightColor[gl_InstanceID];
|
||||
//vec4 lightPos = g_LightPosition[gl_InstanceID];
|
||||
//vec4 wvLightPos = (g_ViewMatrix * vec4(lightPos.xyz, lightColor.w));
|
||||
//wvLightPos.w = lightPos.w;
|
||||
|
||||
vec4 wvLightPos = (g_ViewMatrix * vec4(g_LightPosition.xyz,clamp(g_LightColor.w,0.0,1.0)));
|
||||
wvLightPos.w = g_LightPosition.w;
|
||||
vec4 lightColor = g_LightColor;
|
||||
|
||||
#if defined(NORMALMAP) && !defined(VERTEX_LIGHTING)
|
||||
vec3 wvTangent = normalize(g_NormalMatrix * modelSpaceTan);
|
||||
vec3 wvBinormal = cross(wvNormal, wvTangent);
|
||||
|
||||
mat3 tbnMat = mat3(wvTangent, wvBinormal * -inTangent.w,wvNormal);
|
||||
|
||||
//vPosition = wvPosition * tbnMat;
|
||||
//vViewDir = viewDir * tbnMat;
|
||||
vViewDir = -wvPosition * tbnMat;
|
||||
lightComputeDir(wvPosition, lightColor, wvLightPos, vLightDir);
|
||||
vLightDir.xyz = (vLightDir.xyz * tbnMat).xyz;
|
||||
#elif !defined(VERTEX_LIGHTING)
|
||||
vNormal = wvNormal;
|
||||
|
||||
//vPosition = wvPosition;
|
||||
vViewDir = viewDir;
|
||||
|
||||
lightComputeDir(wvPosition, lightColor, wvLightPos, vLightDir);
|
||||
|
||||
#ifdef V_TANGENT
|
||||
vNormal = normalize(g_NormalMatrix * inTangent.xyz);
|
||||
vNormal = -cross(cross(vLightDir.xyz, vNormal), vNormal);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
//computing spot direction in view space and unpacking spotlight cos
|
||||
// spotVec = (g_ViewMatrix * vec4(g_LightDirection.xyz, 0.0) );
|
||||
// spotVec.w = floor(g_LightDirection.w) * 0.001;
|
||||
// lightVec.w = fract(g_LightDirection.w);
|
||||
|
||||
lightColor.w = 1.0;
|
||||
#ifdef MATERIAL_COLORS
|
||||
AmbientSum = (m_Ambient * g_AmbientLightColor).rgb;
|
||||
DiffuseSum = m_Diffuse * lightColor;
|
||||
SpecularSum = (m_Specular * lightColor).rgb;
|
||||
#else
|
||||
AmbientSum = vec3(0.2, 0.2, 0.2) * g_AmbientLightColor.rgb; // Default: ambient color is dark gray
|
||||
DiffuseSum = lightColor;
|
||||
SpecularSum = vec3(0.0);
|
||||
#endif
|
||||
|
||||
#ifdef VERTEX_COLOR
|
||||
AmbientSum *= inColor.rgb;
|
||||
DiffuseSum *= inColor;
|
||||
#endif
|
||||
|
||||
#ifdef VERTEX_LIGHTING
|
||||
vertexLightValues = computeLighting(wvPosition, wvNormal, viewDir, wvLightPos);
|
||||
#endif
|
||||
|
||||
#ifdef USE_REFLECTION
|
||||
computeRef(modelSpacePos);
|
||||
#endif
|
||||
}
|
||||
10
simarboreal/assets/MatDefs/Null.frag
Normal file
10
simarboreal/assets/MatDefs/Null.frag
Normal file
@@ -0,0 +1,10 @@
|
||||
#import "Common/ShaderLib/MultiSample.glsllib"
|
||||
|
||||
uniform COLORTEXTURE m_Texture;
|
||||
varying vec2 texCoord;
|
||||
|
||||
void main() {
|
||||
vec4 texVal = getColor(m_Texture, texCoord);
|
||||
gl_FragColor = texVal;
|
||||
}
|
||||
|
||||
24
simarboreal/assets/MatDefs/Null.j3md
Normal file
24
simarboreal/assets/MatDefs/Null.j3md
Normal file
@@ -0,0 +1,24 @@
|
||||
MaterialDef Depth Blur {
|
||||
|
||||
MaterialParameters {
|
||||
Int NumSamples
|
||||
Int NumSamplesDepth
|
||||
Texture2D Texture
|
||||
Texture2D DepthTexture
|
||||
}
|
||||
|
||||
Technique {
|
||||
VertexShader GLSL100: Common/MatDefs/Post/Post.vert
|
||||
FragmentShader GLSL100: MatDefs/Null.frag
|
||||
|
||||
WorldParameters {
|
||||
WorldViewProjectionMatrix
|
||||
}
|
||||
|
||||
Defines {
|
||||
RESOLVE_MS : NumSamples
|
||||
RESOLVE_DEPTH_MS : NumSamplesDepth
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
72
simarboreal/assets/MatDefs/Shadows.frag
Normal file
72
simarboreal/assets/MatDefs/Shadows.frag
Normal file
@@ -0,0 +1,72 @@
|
||||
#import "Common/ShaderLib/MultiSample.glsllib"
|
||||
|
||||
//#define SHOW_BOX
|
||||
//#define SHOW_DELTA
|
||||
|
||||
uniform vec2 g_FrustumNearFar;
|
||||
uniform vec4 g_ViewPort;
|
||||
|
||||
uniform vec4 m_ShadowColor;
|
||||
uniform COLORTEXTURE m_FrameTexture;
|
||||
uniform DEPTHTEXTURE m_DepthTexture;
|
||||
|
||||
varying vec3 texCoord;
|
||||
varying vec3 vViewDir;
|
||||
varying vec3 boxScale;
|
||||
|
||||
void main(){
|
||||
vec4 color = vec4(1.0);
|
||||
|
||||
vec2 uv = vec2(gl_FragCoord.x/g_ViewPort.z, gl_FragCoord.y/g_ViewPort.w);
|
||||
|
||||
float zBuffer = getDepth( m_DepthTexture, uv ).r;
|
||||
|
||||
//
|
||||
// z_buffer_value = a + b / z;
|
||||
//
|
||||
// Where:
|
||||
// a = zFar / ( zFar - zNear )
|
||||
// b = zFar * zNear / ( zNear - zFar )
|
||||
// z = distance from the eye to the object
|
||||
//
|
||||
// Which means:
|
||||
// zb - a = b / z;
|
||||
// z * (zb - a) = b
|
||||
// z = b / (zb - a)
|
||||
//
|
||||
float a = g_FrustumNearFar.y / (g_FrustumNearFar.y - g_FrustumNearFar.x);
|
||||
float b = g_FrustumNearFar.y * g_FrustumNearFar.x / (g_FrustumNearFar.x - g_FrustumNearFar.y);
|
||||
float z = b / (zBuffer - a);
|
||||
|
||||
float us = b / (gl_FragCoord.z - a);
|
||||
|
||||
float modelScale = 1.0;
|
||||
|
||||
float delta = (z-us) * modelScale;
|
||||
|
||||
#if defined(SHOW_DELTA)
|
||||
color = vec4(delta, 0.0, 0.0, 1.0);
|
||||
#elif defined(SHOW_BOX)
|
||||
color = vec4(texCoord * boxScale,1.0);
|
||||
#else
|
||||
|
||||
vec3 view = normalize(vViewDir);
|
||||
vec3 scene = texCoord + view * delta;
|
||||
vec3 stu = scene * boxScale;
|
||||
|
||||
float xTex = (0.5 - stu.x) * 2.0;
|
||||
float zTex = (0.5 - stu.z) * 2.0;
|
||||
float t = stu.y;
|
||||
|
||||
float low = (t - 0.75) * 1.33333;
|
||||
float hi = (t - 0.75) * 4.0;
|
||||
float yTex = low * step(t, 0.75) + hi * step(0.75, t);
|
||||
|
||||
float col = sqrt((xTex * xTex) + (zTex * zTex) + (yTex * yTex));
|
||||
float shadow = (1.0 - col);
|
||||
color = vec4(m_ShadowColor);
|
||||
color.a *= clamp(shadow, 0.0, 0.8);
|
||||
#endif
|
||||
|
||||
gl_FragColor = color;
|
||||
}
|
||||
29
simarboreal/assets/MatDefs/Shadows.j3md
Normal file
29
simarboreal/assets/MatDefs/Shadows.j3md
Normal file
@@ -0,0 +1,29 @@
|
||||
MaterialDef Simple Shadows {
|
||||
|
||||
MaterialParameters {
|
||||
Int NumSamples
|
||||
Int NumSamplesDepth
|
||||
|
||||
Color ShadowColor
|
||||
|
||||
Texture2D FrameTexture
|
||||
Texture2D DepthTexture
|
||||
}
|
||||
|
||||
Technique {
|
||||
VertexShader GLSL120: MatDefs/Shadows.vert
|
||||
FragmentShader GLSL130: MatDefs/Shadows.frag
|
||||
|
||||
WorldParameters {
|
||||
ViewProjectionMatrix
|
||||
FrustumNearFar
|
||||
ViewPort
|
||||
}
|
||||
|
||||
Defines {
|
||||
RESOLVE_MS : NumSamples
|
||||
RESOLVE_DEPTH_MS : NumSamplesDepth
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
22
simarboreal/assets/MatDefs/Shadows.vert
Normal file
22
simarboreal/assets/MatDefs/Shadows.vert
Normal file
@@ -0,0 +1,22 @@
|
||||
|
||||
uniform mat4 g_ViewProjectionMatrix;
|
||||
|
||||
attribute vec3 inPosition; // the world position
|
||||
attribute vec3 inTexCoord; // the model space position, relative to a corner
|
||||
attribute vec3 inTexCoord2; // the x,y,z scale to get from model space to 0->1 space
|
||||
attribute vec3 inNormal; // the view direction in model-space
|
||||
|
||||
varying vec3 texCoord;
|
||||
varying vec3 vViewDir;
|
||||
varying vec3 boxScale;
|
||||
|
||||
|
||||
|
||||
void main(){
|
||||
vec4 modelSpacePos = vec4(inPosition, 1.0);
|
||||
gl_Position = g_ViewProjectionMatrix * modelSpacePos;
|
||||
|
||||
vViewDir = inNormal;
|
||||
texCoord = inTexCoord;
|
||||
boxScale = inTexCoord2;
|
||||
}
|
||||
BIN
simarboreal/assets/Models/female-parts.j3o
Normal file
BIN
simarboreal/assets/Models/female-parts.j3o
Normal file
Binary file not shown.
BIN
simarboreal/assets/Models/male-parts-no-bones.j3o
Normal file
BIN
simarboreal/assets/Models/male-parts-no-bones.j3o
Normal file
Binary file not shown.
BIN
simarboreal/assets/Textures/brown-dirt-norm.jpg
Normal file
BIN
simarboreal/assets/Textures/brown-dirt-norm.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 16 KiB |
BIN
simarboreal/assets/Textures/grass-flat.jpg
Normal file
BIN
simarboreal/assets/Textures/grass-flat.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 233 KiB |
BIN
simarboreal/assets/Textures/grass.jpg
Normal file
BIN
simarboreal/assets/Textures/grass.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 65 KiB |
BIN
simarboreal/assets/Textures/test-pattern.png
Normal file
BIN
simarboreal/assets/Textures/test-pattern.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 9.6 KiB |
Reference in New Issue
Block a user