forked from teamnwah/openmw-tes3coop
Add fog
This commit is contained in:
parent
41e1fd407d
commit
044e0a829a
4 changed files with 22 additions and 2 deletions
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
|
#include <osg/Fog>
|
||||||
#include <osg/Texture2D>
|
#include <osg/Texture2D>
|
||||||
#include <osg/Camera>
|
#include <osg/Camera>
|
||||||
#include <osg/PositionAttitudeTransform>
|
#include <osg/PositionAttitudeTransform>
|
||||||
|
@ -102,6 +103,12 @@ namespace MWRender
|
||||||
stateset->setMode(GL_LIGHTING, osg::StateAttribute::ON);
|
stateset->setMode(GL_LIGHTING, osg::StateAttribute::ON);
|
||||||
stateset->setMode(GL_NORMALIZE, osg::StateAttribute::ON);
|
stateset->setMode(GL_NORMALIZE, osg::StateAttribute::ON);
|
||||||
stateset->setMode(GL_CULL_FACE, osg::StateAttribute::ON);
|
stateset->setMode(GL_CULL_FACE, osg::StateAttribute::ON);
|
||||||
|
// assign large value to effectively turn off fog
|
||||||
|
// shaders don't respect glDisable(GL_FOG)
|
||||||
|
osg::ref_ptr<osg::Fog> fog (new osg::Fog);
|
||||||
|
fog->setStart(10000000);
|
||||||
|
fog->setEnd(10000000);
|
||||||
|
stateset->setAttributeAndModes(fog, osg::StateAttribute::OFF|osg::StateAttribute::OVERRIDE);
|
||||||
|
|
||||||
osg::ref_ptr<osg::LightModel> lightmodel = new osg::LightModel;
|
osg::ref_ptr<osg::LightModel> lightmodel = new osg::LightModel;
|
||||||
lightmodel->setAmbientIntensity(osg::Vec4(0.25, 0.25, 0.25, 1.0));
|
lightmodel->setAmbientIntensity(osg::Vec4(0.25, 0.25, 0.25, 1.0));
|
||||||
|
|
|
@ -180,7 +180,12 @@ osg::ref_ptr<osg::Camera> LocalMap::createOrthographicCamera(float x, float y, f
|
||||||
stateset->setMode(GL_LIGHTING, osg::StateAttribute::ON);
|
stateset->setMode(GL_LIGHTING, osg::StateAttribute::ON);
|
||||||
stateset->setMode(GL_NORMALIZE, osg::StateAttribute::ON);
|
stateset->setMode(GL_NORMALIZE, osg::StateAttribute::ON);
|
||||||
stateset->setMode(GL_CULL_FACE, osg::StateAttribute::ON);
|
stateset->setMode(GL_CULL_FACE, osg::StateAttribute::ON);
|
||||||
stateset->setMode(GL_FOG, osg::StateAttribute::OFF|osg::StateAttribute::OVERRIDE);
|
// assign large value to effectively turn off fog
|
||||||
|
// shaders don't respect glDisable(GL_FOG)
|
||||||
|
osg::ref_ptr<osg::Fog> fog (new osg::Fog);
|
||||||
|
fog->setStart(10000000);
|
||||||
|
fog->setEnd(10000000);
|
||||||
|
stateset->setAttributeAndModes(fog, osg::StateAttribute::OFF|osg::StateAttribute::OVERRIDE);
|
||||||
|
|
||||||
osg::ref_ptr<osg::LightModel> lightmodel = new osg::LightModel;
|
osg::ref_ptr<osg::LightModel> lightmodel = new osg::LightModel;
|
||||||
lightmodel->setAmbientIntensity(osg::Vec4(0.3f, 0.3f, 0.3f, 1.f));
|
lightmodel->setAmbientIntensity(osg::Vec4(0.3f, 0.3f, 0.3f, 1.f));
|
||||||
|
|
|
@ -5,11 +5,16 @@ uniform sampler2D diffuseMap;
|
||||||
varying vec2 diffuseMapUV;
|
varying vec2 diffuseMapUV;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
varying float depth;
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
#if @diffuseMap
|
#if @diffuseMap
|
||||||
gl_FragData[0] = texture2D(diffuseMap, diffuseMapUV);
|
gl_FragData[0] = texture2D(diffuseMap, diffuseMapUV);
|
||||||
#else
|
#else
|
||||||
gl_FragData[0] = vec4(1,1,1,1);
|
gl_FragData[0] = vec4(1.0, 1.0, 1.0, 1.0);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
float fogValue = clamp((depth - gl_Fog.start) * gl_Fog.scale, 0.0, 1.0);
|
||||||
|
gl_FragData[0].xyz = mix(gl_FragData[0].xyz, gl_Fog.color.xyz, fogValue);
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,10 +3,13 @@
|
||||||
#if @diffuseMap
|
#if @diffuseMap
|
||||||
varying vec2 diffuseMapUV;
|
varying vec2 diffuseMapUV;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
varying float depth;
|
||||||
|
|
||||||
void main(void)
|
void main(void)
|
||||||
{
|
{
|
||||||
gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
|
gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
|
||||||
|
depth = gl_Position.z;
|
||||||
|
|
||||||
#if @diffuseMap
|
#if @diffuseMap
|
||||||
diffuseMapUV = gl_MultiTexCoord@diffuseMapUV.xy;
|
diffuseMapUV = gl_MultiTexCoord@diffuseMapUV.xy;
|
||||||
|
|
Loading…
Reference in a new issue