Urho3D/bin/CoreData/Shaders/GLSL/PBRVegetation.glsl
gleblebedev c4a8e9b098
Vegetation shader and technique bugfixes (#2659)
* Vegetation shader and technique bugfixes

* GLSL bug fix for vegetation shader

* pivot fixed

* Shaders fixed

* Text formatting
2020-07-14 04:08:32 +03:00

129 lines
3.6 KiB
GLSL

#include "Uniforms.glsl"
#include "Samplers.glsl"
#include "Transform.glsl"
#include "ScreenPos.glsl"
#include "Lighting.glsl"
#include "Constants.glsl"
#include "Fog.glsl"
#include "PBR.glsl"
#include "IBL.glsl"
#line 30010
uniform float cWindHeightFactor;
uniform float cWindHeightPivot;
uniform float cWindPeriod;
uniform vec2 cWindWorldSpacing;
#ifdef WINDSTEMAXIS
uniform vec3 cWindStemAxis;
#endif
#if defined(NORMALMAP)
varying vec4 vTexCoord;
varying vec4 vTangent;
#else
varying vec2 vTexCoord;
#endif
varying vec3 vNormal;
varying vec4 vWorldPos;
#ifdef VERTEXCOLOR
varying vec4 vColor;
#endif
#ifdef PERPIXEL
#ifdef SHADOW
#ifndef GL_ES
varying vec4 vShadowPos[NUMCASCADES];
#else
varying highp vec4 vShadowPos[NUMCASCADES];
#endif
#endif
#ifdef SPOTLIGHT
varying vec4 vSpotPos;
#endif
#ifdef POINTLIGHT
varying vec3 vCubeMaskVec;
#endif
#else
varying vec3 vVertexLight;
varying vec4 vScreenPos;
#ifdef ENVCUBEMAP
varying vec3 vReflectionVec;
#endif
#if defined(LIGHTMAP) || defined(AO)
varying vec2 vTexCoord2;
#endif
#endif
void VS()
{
mat4 modelMatrix = iModelMatrix;
vec3 worldPos = GetWorldPos(modelMatrix);
#ifdef WINDSTEMAXIS
float stemDistance = dot(iPos.xyz, cWindStemAxis);
#else
float stemDistance = iPos.y;
#endif
float windStrength = max(stemDistance - cWindHeightPivot, 0.0) * cWindHeightFactor;
float windPeriod = cElapsedTime * cWindPeriod + dot(worldPos.xz, cWindWorldSpacing);
worldPos.x += windStrength * sin(windPeriod);
worldPos.z -= windStrength * cos(windPeriod);
gl_Position = GetClipPos(worldPos);
vNormal = GetWorldNormal(modelMatrix);
vWorldPos = vec4(worldPos, GetDepth(gl_Position));
#ifdef VERTEXCOLOR
vColor = iColor;
#endif
#if defined(NORMALMAP) || defined(DIRBILLBOARD)
vec4 tangent = GetWorldTangent(modelMatrix);
vec3 bitangent = cross(tangent.xyz, vNormal) * tangent.w;
vTexCoord = vec4(GetTexCoord(iTexCoord), bitangent.xy);
vTangent = vec4(tangent.xyz, bitangent.z);
#else
vTexCoord = GetTexCoord(iTexCoord);
#endif
#ifdef PERPIXEL
// Per-pixel forward lighting
vec4 projWorldPos = vec4(worldPos, 1.0);
#ifdef SHADOW
// Shadow projection: transform from world space to shadow space
for (int i = 0; i < NUMCASCADES; i++)
vShadowPos[i] = GetShadowPos(i, vNormal, projWorldPos);
#endif
#ifdef SPOTLIGHT
// Spotlight projection: transform from world space to projector texture coordinates
vSpotPos = projWorldPos * cLightMatrices[0];
#endif
#ifdef POINTLIGHT
vCubeMaskVec = (worldPos - cLightPos.xyz) * mat3(cLightMatrices[0][0].xyz, cLightMatrices[0][1].xyz, cLightMatrices[0][2].xyz);
#endif
#else
// Ambient & per-vertex lighting
#if defined(LIGHTMAP) || defined(AO)
// If using lightmap, disregard zone ambient light
// If using AO, calculate ambient in the PS
vVertexLight = vec3(0.0, 0.0, 0.0);
vTexCoord2 = iTexCoord1;
#else
vVertexLight = GetAmbient(GetZonePos(worldPos));
#endif
#ifdef NUMVERTEXLIGHTS
for (int i = 0; i < NUMVERTEXLIGHTS; ++i)
vVertexLight += GetVertexLight(i, worldPos, vNormal) * cVertexLights[i * 3].rgb;
#endif
vScreenPos = GetScreenPos(gl_Position);
#ifdef ENVCUBEMAP
vReflectionVec = worldPos - cCameraPos;
#endif
#endif
}