19bool PostProcessingShaderLightScatteringImplementation::isSupported(
Renderer* renderer) {
34 "shader/" + shaderVersion +
"/postprocessing",
35 "light_scattering_fragmentshader.frag",
43 "shader/" + shaderVersion +
"/postprocessing",
44 "light_scattering_vertexshader.vert",
69 Engine::ShaderType::SHADERTYPE_POSTPROCESSING,
79 if (light->isEnabled() ==
false || light->isRenderSource() ==
false) {
84 Vector3 lightSourcePosition =
Vector3(light->getPosition().getX(), light->getPosition().getY(), light->getPosition().getZ());
85 if (light->getPosition().getW() > Math::EPSILON) lightSourcePosition.
scale(1.0f / light->getPosition().getW());
87 lightSourcePosition2D.
setX(Math::clamp(lightSourcePosition2D.
getX() /
static_cast<float>(_width), 0.0f, 1.0f));
88 lightSourcePosition2D.
setY(Math::clamp(1.0f - (lightSourcePosition2D.
getY() /
static_cast<float>(_height)), 0.0f, 1.0f));
89 float intensity = 1.0f;
90 float _intensity = 1.0f;
91 if (lightSourcePosition2D.
getX() < 0.4f) _intensity = lightSourcePosition2D.
getX() / 0.4f;
92 if (_intensity < intensity) intensity = _intensity;
93 if (lightSourcePosition2D.
getX() > 0.6f) _intensity = (1.0f - lightSourcePosition2D.
getX()) / 0.4f;
94 if (_intensity < intensity) intensity = _intensity;
95 if (lightSourcePosition2D.
getY() < 0.4f) _intensity = lightSourcePosition2D.
getY() / 0.4f;
96 if (_intensity < intensity) intensity = _intensity;
97 if (lightSourcePosition2D.
getY() > 0.6f) _intensity = (1.0f - lightSourcePosition2D.
getY()) / 0.4f;
98 if (_intensity < intensity) intensity = _intensity;
99 if (intensity < Math::EPSILON) {
103 lightSourcePosition2D =
Vector2(lightSourcePosition2D.
getX(), 1.0f - lightSourcePosition2D.
getY());
Light * getLightAt(int32_t idx)
Returns light at idx (0 <= idx < 8)
static void registerShader(ShaderType type, const string &shaderId, const map< string, ShaderParameter > ¶meterDefaults={})
Register shader.
bool computeScreenCoordinateByWorldCoordinate(const Vector3 &worldCoordinate, Vector2 &screenCoordinate, int width=-1, int height=-1)
Convert screen coordinate by world coordinate.
static constexpr int LIGHTS_MAX
int32_t getScaledHeight()
Shader parameter model class.
Post processing shader base implementation.
virtual void initialize() override
Initialize post processing shader.
Post processing shader implementation.
virtual void setShaderParameters(int contextIdx, Engine *engine) override
Set shader parameters.
virtual void initialize() override
Initialize post processing shader.
PostProcessingShaderLightScatteringImplementation(Renderer *renderer)
Public constructor.
array< int32_t, Engine::LIGHTS_MAX > uniformLightPosition
array< int32_t, Engine::LIGHTS_MAX > uniformLightEnabled
array< int32_t, Engine::LIGHTS_MAX > uniformLightIntensity
virtual int32_t loadShader(int32_t type, const string &pathName, const string &fileName, const string &definitions=string(), const string &functions=string())=0
Loads a shader.
int32_t SHADER_FRAGMENT_SHADER
int32_t SHADER_VERTEX_SHADER
virtual int32_t createProgram(int type)=0
Creates a shader program.
virtual void setProgramUniformFloatVec2(int contextIdx, int32_t uniformId, const array< float, 2 > &data)=0
Set up a float vec2 uniform value.
virtual void setProgramUniformInteger(int contextIdx, int32_t uniformId, int32_t value)=0
Set up a integer uniform value.
RendererType getRendererType()
virtual void attachShaderToProgram(int32_t programId, int32_t shaderId)=0
Attaches a shader to a program.
virtual int32_t getProgramUniformLocation(int32_t programId, const string &name)=0
Returns location of given uniform variable.
virtual const string getShaderVersion()=0
virtual void setProgramUniformFloat(int contextIdx, int32_t uniformId, float value)=0
Set up a float uniform value.
Vector2 & setX(float x)
set X
array< float, 2 > & getArray() const
Vector2 & setY(float y)
set Y
Vector3 & scale(float scale)
Scale this vector.