30 #include <OgreString.h>
36 #define _def_Water_Material_Name "_Hydrax_Water_Material"
37 #define _def_Water_Shader_VP_Name "_Hydrax_Water_VP"
38 #define _def_Water_Shader_FP_Name "_Hydrax_Water_FP"
40 #define _def_Depth_Material_Name "_Hydrax_Depth_Material"
41 #define _def_Depth_Shader_VP_Name "_Hydrax_Depth_VP"
42 #define _def_Depth_Shader_FP_Name "_Hydrax_Depth_FP"
44 #define _def_DepthTexture_Shader_VP_Name "_Hydrax_DepthTexture_VP"
45 #define _def_DepthTexture_Shader_FP_Name "_Hydrax_DepthTexture_FP"
47 #define _def_Underwater_Material_Name "_Hydrax_Underwater_Material"
48 #define _def_Underwater_Shader_VP_Name "_Hydrax_Underwater_Shader_VP"
49 #define _def_Underwater_Shader_FP_Name "_Hydrax_Underwater_Shader_FP"
51 #define _def_Underwater_Compositor_Material_Name "_Hydrax_Underwater_Compositor_Material"
52 #define _def_Underwater_Compositor_Shader_VP_Name "_Hydrax_Underwater_Compositor_Shader_VP"
53 #define _def_Underwater_Compositor_Shader_FP_Name "_Hydrax_Underwater_Compositor_Shader_FP"
55 #define _def_Underwater_Compositor_Name "_Hydrax_Underwater_Compositor_Name"
57 #define _def_Simple_Red_Material_Name "_Hydrax_Simple_Red_Material"
58 #define _def_Simple_Black_Material_Name "_Hydrax_Simple_Black_Material"
67 for (
int k = 0; k < 6; k++)
72 for (
int k = 0; k < 1; k++)
128 Ogre::String AlphaChannels[] = {
"x",
"y",
"z",
"w",
131 for (
int k = 0; k<8; k++)
187 HydraxLOG(
"Creating underwater material...");
200 HydraxLOG(
"Underwater material created.");
207 std::vector<Ogre::Technique*>::iterator TechIt;
218 bool isTextureDepthTechnique =
219 ((*TechIt)->getName() ==
"_Hydrax_Depth_Technique") ?
false :
true;
221 if (isTextureDepthTechnique)
223 Ogre::String DepthTextureName =
224 ((*TechIt)->getPass(0)->getTextureUnitState(0)->getName() ==
"_DetphTexture_Hydrax") ?
225 (*TechIt)->getPass(0)->getTextureUnitState(0)->getTextureName() : (*TechIt)->getPass(0)->getTextureUnitState(1)->getTextureName();
240 const Ogre::String GpuProgramNames[2],
242 const Ogre::String EntryPoints[2],
243 const Ogre::String Data[2])
247 for (
int k = 0; k < 2; k++)
249 if (!
createGpuProgram(GpuProgramNames[k], SM, GpuPrograms[k], EntryPoints[k], Data[k]))
255 Pass->setVertexProgram(GpuProgramNames[0]);
256 Pass->setFragmentProgram(GpuProgramNames[1]);
264 const Ogre::String& EntryPoint,
265 const Ogre::String& Data)
267 if (Ogre::HighLevelGpuProgramManager::getSingleton().resourceExists(Name))
269 HydraxLOG(
"Error in bool MaterialManager::createGpuProgram(): "+ Name +
" exists.");
273 Ogre::String ShaderModesStr[3] = {
"hlsl",
"cg",
"glsl"};
274 Ogre::String Profiles[2];
280 Profiles[0] =
"target";
284 Profiles[1] =
"vs_1_1";
288 Profiles[1] =
"ps_2_0";
295 Profiles[0] =
"profiles";
299 Profiles[1] =
"vs_1_1 arbvp1";
303 Profiles[1] =
"ps_2_0 arbfp1 fp20";
323 Ogre::GpuProgramType GpuPType;
327 GpuPType = Ogre::GPT_VERTEX_PROGRAM;
331 GpuPType = Ogre::GPT_FRAGMENT_PROGRAM;
334 Ogre::HighLevelGpuProgramPtr HLGpuProgram =
335 Ogre::HighLevelGpuProgramManager::getSingleton().
337 Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
341 HLGpuProgram->setSource(Data);
342 HLGpuProgram->setParameter(
"entry_point", EntryPoint);
343 HLGpuProgram->setParameter(Profiles[0], Profiles[1]);
344 HLGpuProgram->load();
357 Ogre::String VertexProgramData, FragmentProgramData;
373 "float4 iPosition : POSITION,\n" +
374 "float2 iUv : TEXCOORD0,\n" +
376 "out float4 oPosition : POSITION,\n" +
377 "out float4 oPosition_ : TEXCOORD0,\n" +
378 "out float2 oUvNoise : TEXCOORD1,\n" +
379 "out float4 oUvProjection : TEXCOORD2,\n";
383 VertexProgramData += Ogre::String(
384 "out float4 oWorldPosition : TEXCOORD3,\n") +
385 "uniform float4x4 uWorld,\n";
387 VertexProgramData += Ogre::String(
388 "uniform float4x4 uWorldViewProj)\n") +
390 "oPosition_ = iPosition;\n";
393 VertexProgramData +=
"oWorldPosition = mul(uWorld, iPosition);\n";
397 "oPosition = mul(uWorldViewProj, iPosition);\n") +
399 "float4x4 scalemat = float4x4(0.5, 0, 0, 0.5,"+
403 "oUvProjection = mul(scalemat, oPosition);\n" +
404 "oUvNoise = iUv;\n" +
411 VertexProgramData += Ogre::String(
"\n");
415 VertexProgramData +=
"uniform mat4 uWorld;\n";
419 VertexProgramData += Ogre::String(
420 "varying vec4 Position_;\n") +
421 "varying vec4 UVProjection;\n";
424 VertexProgramData +=
"varying vec4 WorldPosition;\n";
427 VertexProgramData += Ogre::String(
430 "Position_ = gl_Vertex;\n";
433 VertexProgramData +=
"WorldPosition = uWorld * gl_Vertex;\n";
435 VertexProgramData += Ogre::String(
436 "gl_Position = ftransform();\n") +
437 "mat4 scalemat = mat4( 1.0, 0.0, 0.0, 0.0,\n" +
438 " 0.0, -1.0, 0.0, 0.0,\n" +
439 " 0.0, 0.0, 1.0, 0.0,\n" +
440 " 0.0, 0.0, 0.0, 1.0);\n" +
441 "UVProjection = scalemat * gl_Position;\n" +
442 "gl_TexCoord[0] = gl_MultiTexCoord0;\n" +
460 "float4 iPosition : POSITION,\n" +
461 "float3 iNormal : NORMAL,\n"+
463 "out float4 oPosition : POSITION,\n" +
464 "out float4 oPosition_ : TEXCOORD0,\n" +
465 "out float4 oUvProjection : TEXCOORD1,\n" +
466 "out float3 oNormal : TEXCOORD2,\n";
469 VertexProgramData +=
"out float4 oWorldPosition : TEXCOORD3,\n uniform float4x4 uWorld,\n";
474 "uniform float4x4 uWorldViewProj)\n") +
476 "oPosition_ = iPosition;\n";
479 VertexProgramData +=
"oWorldPosition = mul(uWorld, iPosition);\n";
483 "oPosition = mul(uWorldViewProj, iPosition);\n") +
485 "float4x4 scalemat = float4x4(0.5, 0, 0, 0.5,"+
489 "oUvProjection = mul(scalemat, oPosition);\n" +
490 "oNormal = normalize(iNormal);\n"+
497 VertexProgramData += Ogre::String(
"\n");
501 VertexProgramData +=
"uniform mat4 uWorld;\n";
505 VertexProgramData += Ogre::String(
506 "varying vec4 Position_;\n") +
507 "varying vec4 UVProjection;\n" +
508 "varying vec3 Normal;\n";
511 VertexProgramData +=
"varying vec4 WorldPosition;\n";
514 VertexProgramData += Ogre::String(
517 "Position_ = gl_Vertex;\n";
520 VertexProgramData +=
"WorldPosition = uWorld * gl_Vertex;\n";
522 VertexProgramData += Ogre::String(
523 "gl_Position = ftransform();\n") +
524 "mat4 scalemat = mat4( 1.0, 0.0, 0.0, 0.0,\n" +
525 " 0.0, -1.0, 0.0, 0.0,\n" +
526 " 0.0, 0.0, 1.0, 0.0,\n" +
527 " 0.0, 0.0, 0.0, 1.0);\n" +
528 "UVProjection = scalemat * gl_Position;\n" +
529 "Normal = normalize(gl_Normal);\n" +
547 "float4 iPosition : POSITION,\n" +
549 "out float4 oPosition : POSITION,\n" +
550 "out float4 oPosition_ : TEXCOORD0,\n" +
551 "out float4 oUvProjection : TEXCOORD1,\n";
554 VertexProgramData +=
"out float4 oWorldPosition : TEXCOORD2,\n uniform float4x4 uWorld,\n";
559 "uniform float4x4 uWorldViewProj)\n") +
561 "oPosition_ = iPosition;\n";
564 VertexProgramData +=
"oWorldPosition = mul(uWorld, iPosition);\n";
568 "oPosition = mul(uWorldViewProj, iPosition);\n") +
570 "float4x4 scalemat = float4x4(0.5, 0, 0, 0.5,"+
574 "oUvProjection = mul(scalemat, oPosition);\n" +
581 VertexProgramData += Ogre::String(
"\n");
585 VertexProgramData +=
"uniform mat4 uWorld;\n";
589 VertexProgramData += Ogre::String(
590 "varying vec4 Position_;\n") +
591 "varying vec4 UVProjection;\n";
594 VertexProgramData +=
"varying vec4 WorldPosition;\n";
597 VertexProgramData +=Ogre::String(
600 "Position_ = gl_Vertex;\n";
603 VertexProgramData +=
"WorldPosition = uWorld * gl_Vertex;\n";
605 VertexProgramData += Ogre::String(
606 "gl_Position = ftransform();\n") +
607 "mat4 scalemat = mat4( 1.0, 0.0, 0.0, 0.0,\n" +
608 " 0.0, -1.0, 0.0, 0.0,\n" +
609 " 0.0, 0.0, 1.0, 0.0,\n" +
610 " 0.0, 0.0, 0.0, 1.0);\n" +
611 "UVProjection = scalemat * gl_Position;\n" +
631 FragmentProgramData +=
632 Ogre::String(
"float3 expand(float3 v)\n") +
634 "return (v - 0.5) * 2;\n" +
639 "float4 iPosition : TEXCOORD0,\n";
643 FragmentProgramData +=
644 "float2 iUvNoise : TEXCOORD" + Ogre::StringConverter::toString(TEXCOORDNUM) +
",\n";
647 FragmentProgramData +=
648 "float4 iUvProjection : TEXCOORD" + Ogre::StringConverter::toString(TEXCOORDNUM) +
",\n";
652 FragmentProgramData +=
653 "float4 iNormal : TEXCOORD" + Ogre::StringConverter::toString(TEXCOORDNUM) +
",\n";
658 FragmentProgramData +=
659 "float4 iWorldPosition : TEXCOORD" + Ogre::StringConverter::toString(TEXCOORDNUM) +
",\n";
661 FragmentProgramData +=
664 "out float4 oColor : COLOR,\n") +
666 "uniform float3 uEyePosition,\n" +
667 "uniform float uFullReflectionDistance,\n" +
668 "uniform float uGlobalTransparency,\n" +
669 "uniform float uNormalDistortion,\n";
673 FragmentProgramData +=
674 "uniform float3 uWaterColor,\n";
678 FragmentProgramData +=
679 "uniform float uSmoothPower,\n";
683 FragmentProgramData += Ogre::String(
684 "uniform float3 uSunPosition,\n") +
685 "uniform float uSunStrength,\n" +
686 "uniform float uSunArea,\n" +
687 "uniform float3 uSunColor,\n";
691 FragmentProgramData += Ogre::String(
692 "uniform float uFoamRange,\n") +
693 "uniform float uFoamMaxDistance,\n" +
694 "uniform float uFoamScale,\n" +
695 "uniform float uFoamStart,\n" +
696 "uniform float uFoamTransparency,\n";
700 FragmentProgramData +=
701 "uniform float uCausticsPower,\n";
708 FragmentProgramData +=
709 "uniform sampler2D uNormalMap : register(s" + Ogre::StringConverter::toString(TexNum) +
"),\n";
713 FragmentProgramData +=
715 "uniform sampler2D uReflectionMap : register(s" + Ogre::StringConverter::toString(TexNum) +
"),\n") +
716 "uniform sampler2D uRefractionMap : register(s" + Ogre::StringConverter::toString(TexNum+1) +
"),\n";
722 FragmentProgramData +=
723 "uniform sampler2D uDepthMap : register(s" + Ogre::StringConverter::toString(TexNum) +
"),\n";
727 FragmentProgramData +=
728 #if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
729 "uniform sampler1D uFresnelMap : register(s" + Ogre::StringConverter::toString(TexNum) +
")";
731 "uniform sampler2D uFresnelMap : register(s" + Ogre::StringConverter::toString(TexNum) +
")";
737 FragmentProgramData += Ogre::String(
738 ",\nuniform sampler2D uFoamMap : register(s" + Ogre::StringConverter::toString(TexNum) +
")\n");
741 FragmentProgramData +=
742 Ogre::String(
")\n") +
744 "float2 ProjectionCoord = iUvProjection.xy / iUvProjection.w;\n" +
745 "float3 camToSurface = iPosition.xyz - uEyePosition;\n" +
746 "float additionalReflection=camToSurface.x*camToSurface.x+camToSurface.z*camToSurface.z;\n";
751 FragmentProgramData +=
752 "float foamVisibility=1.0f-saturate(additionalReflection/uFoamMaxDistance);\n";
755 FragmentProgramData +=
757 "additionalReflection/=uFullReflectionDistance;\n") +
758 "camToSurface=normalize(-camToSurface);\n";
761 FragmentProgramData += Ogre::String(
762 "float3 pixelNormal = tex2D(uNormalMap,iUvNoise);\n") +
764 "pixelNormal.yz=pixelNormal.zy;\n" +
766 "pixelNormal.xyz=expand(pixelNormal.xyz);\n";
770 FragmentProgramData +=
771 "float3 pixelNormal = iNormal;\n";
775 FragmentProgramData +=
776 "float3 pixelNormal = 2.0*tex2D(uNormalMap, ProjectionCoord.xy) - 1.0;\n";
778 FragmentProgramData +=
779 "float2 pixelNormalModified = uNormalDistortion*pixelNormal.zx;\n";
782 FragmentProgramData +=
783 "float dotProduct=dot(camToSurface,pixelNormal);\n";
787 FragmentProgramData +=
788 "float dotProduct=dot(-camToSurface,pixelNormal);\n";
790 FragmentProgramData +=
792 "dotProduct=saturate(dotProduct);\n") +
793 #if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
794 "float fresnel = tex1D(uFresnelMap,dotProduct);\n" +
796 "float fresnel = tex2D(uFresnelMap,float2(dotProduct,dotProduct));\n" +
799 "fresnel+=additionalReflection;\n" +
800 "fresnel=saturate(fresnel);\n" +
802 "fresnel-=uGlobalTransparency;\n" +
803 "fresnel=saturate(fresnel);\n" +
804 #if OGRE_PLATFORM != OGRE_PLATFORM_WIN32
806 "if(uEyePosition.y < 0.0)\n" +
808 "ProjectionCoord.y = 1.0 - ProjectionCoord.y;\n" +
812 "float3 reflection=tex2D(uReflectionMap,ProjectionCoord.xy+pixelNormalModified);\n" +
813 "float3 refraction=tex2D(uRefractionMap,ProjectionCoord.xy-pixelNormalModified);\n";
819 FragmentProgramData += Ogre::String(
820 "float2 depth = tex2D(uDepthMap,ProjectionCoord.xy-pixelNormalModified).rg;\n") +
821 "refraction *= 1+depth.y*uCausticsPower;\n" +
822 "refraction = lerp(uWaterColor,refraction,depth.x);\n";
826 FragmentProgramData += Ogre::String(
827 "float depth = tex2D(uDepthMap,ProjectionCoord.xy-pixelNormalModified).r;\n") +
828 "refraction = lerp(uWaterColor,refraction,depth);\n";
832 FragmentProgramData +=
833 "oColor = float4(lerp(refraction,reflection,fresnel),1);\n";
837 FragmentProgramData += Ogre::String(
838 "float3 relfectedVector = normalize(reflect(-camToSurface,pixelNormal.xyz));\n") +
839 "float3 surfaceToSun=normalize(uSunPosition-iPosition.xyz);\n" +
840 "float3 sunlight = uSunStrength*pow(saturate(dot(relfectedVector,surfaceToSun)),uSunArea)*uSunColor;\n" +
841 "oColor.xyz+=sunlight;\n";
846 FragmentProgramData += Ogre::String(
847 "float hmap = iPosition.y/uFoamRange*foamVisibility;\n") +
848 "float2 foamTex=iWorldPosition.xz*uFoamScale+pixelNormalModified;\n" +
849 "float foam=tex2D(uFoamMap,foamTex).r;\n" +
850 "float foamTransparency=saturate(hmap-uFoamStart)*uFoamTransparency;\n" +
851 "oColor.xyz=lerp(oColor.xyz,1,foamTransparency*foam);\n";
856 FragmentProgramData +=
857 "oColor.xyz = lerp(tex2D(uRefractionMap,ProjectionCoord.xy).xyz,oColor.xyz,saturate((1-tex2D(uDepthMap,ProjectionCoord.xy).r)*uSmoothPower));\n";
860 FragmentProgramData +=
866 FragmentProgramData += Ogre::String(
"\n") +
868 "uniform vec3 uEyePosition;\n" +
869 "uniform float uFullReflectionDistance;\n" +
870 "uniform float uGlobalTransparency;\n" +
871 "uniform float uNormalDistortion;\n" +
872 "uniform vec3 uWaterColor;\n";
876 FragmentProgramData +=
877 "uniform float uSmoothPower;\n";
881 FragmentProgramData += Ogre::String(
882 "uniform vec3 uSunPosition;\n") +
883 "uniform float uSunStrength;\n" +
884 "uniform float uSunArea;\n" +
885 "uniform vec3 uSunColor;\n";
889 FragmentProgramData += Ogre::String(
890 "uniform float uFoamRange;\n") +
891 "uniform float uFoamMaxDistance;\n" +
892 "uniform float uFoamScale;\n" +
893 "uniform float uFoamStart;\n" +
894 "uniform float uFoamTransparency;\n";
898 FragmentProgramData +=
899 "uniform float uCausticsPower;\n";
905 FragmentProgramData +=
906 "uniform sampler2D uNormalMap;\n";
910 FragmentProgramData += Ogre::String(
911 "uniform sampler2D uReflectionMap;\n") +
912 "uniform sampler2D uRefractionMap;\n";
917 FragmentProgramData +=
918 "uniform sampler2D uDepthMap;\n";
922 FragmentProgramData +=
923 #if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
924 "uniform sampler1D uFresnelMap;\n";
926 "uniform sampler2D uFresnelMap;\n";
932 FragmentProgramData +=
933 "uniform sampler2D uFoamMap;\n";
936 FragmentProgramData +=
937 "varying vec4 Position_;\n";
943 FragmentProgramData +=
944 "varying vec4 UVProjection;\n";
948 FragmentProgramData +=
949 "varying vec3 Normal;\n";
954 FragmentProgramData +=
955 "varying vec4 WorldPosition;\n";
958 FragmentProgramData += Ogre::String(
959 "vec3 expand(vec3 v)\n") +
961 "return (v - 0.5) * 2.0;\n" +
966 "vec2 ProjectionCoord = UVProjection.xy / UVProjection.w;\n" +
967 "ProjectionCoord += 1.0;\n" +
968 "ProjectionCoord *= 0.5;\n" +
969 "vec3 camToSurface = Position_.xyz - uEyePosition;\n" +
970 "float additionalReflection=camToSurface.x*camToSurface.x+camToSurface.z*camToSurface.z;\n";
974 FragmentProgramData +=
975 "float foamVisibility=1.0-clamp(additionalReflection/uFoamMaxDistance, 0.0, 1.0);\n";
977 FragmentProgramData += Ogre::String(
978 "additionalReflection/=uFullReflectionDistance;\n") +
979 "camToSurface=normalize(-camToSurface);\n";
982 FragmentProgramData += Ogre::String(
983 "vec3 pixelNormal = texture2D(uNormalMap,gl_TexCoord[0].xy).xyz;\n") +
985 "pixelNormal.yz=pixelNormal.zy;\n" +
987 "pixelNormal.xyz=expand(pixelNormal.xyz);\n";
991 FragmentProgramData +=
992 "vec3 pixelNormal = Normal;\n";
996 FragmentProgramData +=
997 "vec3 pixelNormal = 2.0*texture2D(uNormalMap, ProjectionCoord.xy).xyz - 1.0;\n";
999 FragmentProgramData +=
1000 "vec2 pixelNormalModified = uNormalDistortion*pixelNormal.zx;\n";
1003 FragmentProgramData +=
1004 "float dotProduct=dot(camToSurface,pixelNormal);\n";
1008 FragmentProgramData +=
1009 "float dotProduct=dot(-camToSurface,pixelNormal);\n";
1011 FragmentProgramData += Ogre::String(
1012 "dotProduct=clamp(dotProduct, 0.0, 1.0);\n") +
1013 #if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
1014 "float fresnel = texture1D(uFresnelMap,dotProduct).x;\n" +
1016 "float fresnel = texture2D(uFresnelMap,vec2(dotProduct,dotProduct)).x;\n" +
1019 "fresnel +=additionalReflection;\n" +
1020 "fresnel = clamp(fresnel, 0.0, 1.0);\n" +
1022 "fresnel -= uGlobalTransparency;\n" +
1023 "fresnel = clamp(fresnel*fresnel, 0.0, 1.0);\n" +
1025 "vec3 reflection=texture2D(uReflectionMap,ProjectionCoord.xy+pixelNormalModified).xyz;\n" +
1026 "vec3 refraction=texture2D(uRefractionMap,ProjectionCoord.xy-pixelNormalModified).xyz;\n";
1031 FragmentProgramData += Ogre::String(
1032 "vec2 depth = texture2D(uDepthMap,ProjectionCoord.xy-pixelNormalModified).xy;\n") +
1033 "refraction *= 1.0 + depth.y*uCausticsPower;\n" +
1034 "refraction = mix(uWaterColor,refraction,depth.x);\n";
1038 FragmentProgramData += Ogre::String(
1039 "float depth = texture2D(uDepthMap,ProjectionCoord.xy-pixelNormalModified).x;\n") +
1040 "refraction = mix(uWaterColor,refraction,depth);\n";
1043 FragmentProgramData += Ogre::String(
1044 "gl_FragColor = vec4(mix(refraction,reflection,fresnel),1.0);\n") +
1045 "gl_FragColor.xyz = mix(gl_FragColor.xyz, uWaterColor, uGlobalTransparency);\n";
1048 FragmentProgramData += Ogre::String(
1049 "vec3 relfectedVector = normalize(reflect(-camToSurface,pixelNormal.xyz));\n") +
1050 "vec3 surfaceToSun=normalize(uSunPosition-Position_.xyz);\n" +
1051 "vec3 sunlight = uSunStrength*pow(clamp(dot(relfectedVector,surfaceToSun),0.0,1.0),uSunArea)*uSunColor;\n" +
1052 "gl_FragColor.xyz+=sunlight;\n";
1056 FragmentProgramData += Ogre::String(
1057 "float hmap = Position_.y/uFoamRange*foamVisibility;\n") +
1058 "vec2 foamTex=WorldPosition.xz*uFoamScale+pixelNormalModified;\n" +
1059 "float foam=texture2D(uFoamMap,foamTex).x;\n" +
1060 "float foamTransparency=clamp(hmap-uFoamStart, 0.0, 1.0)*uFoamTransparency;\n" +
1061 "gl_FragColor.xyz=mix(gl_FragColor.xyz,vec3(1.0,1.0,1.0),foamTransparency*foam);\n";
1065 FragmentProgramData +=
1066 "gl_FragColor.xyz = mix(texture2D(uRefractionMap,ProjectionCoord.xy).xyz,gl_FragColor.xyz,clamp((1.0-texture2D(uDepthMap,ProjectionCoord.xy).x)*uSmoothPower, 0.0, 1.0));\n";
1068 FragmentProgramData +=
1078 WaterMaterial = Ogre::MaterialManager::getSingleton().
1080 Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
1082 Ogre::Pass *WM_Technique0_Pass0 = WaterMaterial->getTechnique(0)->getPass(0);
1084 WM_Technique0_Pass0->setCullingMode(Ogre::CULL_NONE);
1085 WM_Technique0_Pass0->setDepthWriteEnabled(
true);
1087 Ogre::String GpuProgramsData[2] = {VertexProgramData, FragmentProgramData};
1089 Ogre::String EntryPoints[2];
1092 EntryPoints[0] = Ogre::String(
"main");
1093 EntryPoints[1] = Ogre::String(
"main");
1097 EntryPoints[0] = Ogre::String(
"main_vp");
1098 EntryPoints[1] = Ogre::String(
"main_fp");
1103 Ogre::GpuProgramParametersSharedPtr VP_Parameters = WM_Technique0_Pass0->getVertexProgramParameters();
1104 Ogre::GpuProgramParametersSharedPtr FP_Parameters = WM_Technique0_Pass0->getFragmentProgramParameters();
1108 VP_Parameters->setNamedAutoConstant(
"uWorldViewProj", Ogre::GpuProgramParameters::ACT_WORLDVIEWPROJ_MATRIX);
1112 VP_Parameters->setNamedAutoConstant(
"uWorld", Ogre::GpuProgramParameters::ACT_WORLD_MATRIX);
1114 FP_Parameters->setNamedAutoConstant(
"uEyePosition", Ogre::GpuProgramParameters::ACT_CAMERA_POSITION_OBJECT_SPACE);
1145 int GLSLTextUnit = 0;
1150 FP_Parameters->setNamedConstant(
"uNormalMap", GLSLTextUnit);
1153 WM_Technique0_Pass0->createTextureUnitState(
"HydraxNormalMap")->setTextureAddressingMode(Ogre::TextureUnitState::TAM_WRAP);
1158 FP_Parameters->setNamedConstant(
"uReflectionMap", GLSLTextUnit);
1161 WM_Technique0_Pass0->createTextureUnitState(
"HydraxReflectionMap")->setTextureAddressingMode(Ogre::TextureUnitState::TAM_CLAMP);
1164 FP_Parameters->setNamedConstant(
"uRefractionMap", GLSLTextUnit);
1167 WM_Technique0_Pass0->createTextureUnitState(
"HydraxRefractionMap")->setTextureAddressingMode(Ogre::TextureUnitState::TAM_CLAMP);
1173 FP_Parameters->setNamedConstant(
"uDepthMap", GLSLTextUnit);
1176 WM_Technique0_Pass0->createTextureUnitState(
"HydraxDepthMap")->setTextureAddressingMode(Ogre::TextureUnitState::TAM_CLAMP);
1181 FP_Parameters->setNamedConstant(
"uFresnelMap", GLSLTextUnit);
1184 WM_Technique0_Pass0->createTextureUnitState(
"Fresnel.bmp")->setTextureAddressingMode(Ogre::TextureUnitState::TAM_CLAMP);
1190 FP_Parameters->setNamedConstant(
"uFoamMap", GLSLTextUnit);
1193 WM_Technique0_Pass0->createTextureUnitState(
"Foam.png")->setTextureAddressingMode(Ogre::TextureUnitState::TAM_WRAP);
1196 WaterMaterial->setReceiveShadows(
false);
1197 WaterMaterial->load();
1206 Ogre::String VertexProgramData, FragmentProgramData;
1217 VertexProgramData +=
1219 "void main_vp(\n") +
1221 "float4 iPosition : POSITION,\n" +
1223 "out float4 oPosition : POSITION,\n" +
1224 "out float oPosition_ : TEXCOORD0,\n" +
1225 "out float2 oDistance : TEXCOORD1,\n" +
1227 "uniform float uPlaneYPos,\n" +
1228 "uniform float uPlanesError,\n" +
1229 "uniform float3 uCameraPos,\n" +
1230 "uniform float4x4 uWorld,\n" +
1231 "uniform float4x4 uWorldView,\n" +
1232 "uniform float4x4 uWorldViewProj)\n" +
1234 "oPosition = mul(uWorldViewProj, iPosition);\n" +
1235 "float3 wPos = mul(uWorld, iPosition).xyz;\n" +
1236 "float3 wCam = uCameraPos;\n" +
1237 "wPos.y -= uPlaneYPos;\n" +
1238 "wCam.y -= uPlaneYPos;\n" +
1239 "oPosition_ = wPos.y;\n" +
1241 "oDistance.x = distance(wPos, wCam);\n" +
1242 "oDistance.y = 1.0;\n" +
1244 "if(wCam.y > 0.0) {\n" +
1245 "oDistance.x *= 1.0 - wCam.y/(wCam.y + abs(wPos.y));\n" +
1247 "if(wPos.y > uPlanesError) {\n" +
1248 "oDistance.x *= abs(wCam.y)/(abs(wCam.y) + wPos.y);\n" +
1249 "oDistance.y = 0.0;\n" +
1255 VertexProgramData +=
1257 "void main_vp(\n") +
1259 "float4 iPosition : POSITION,\n" +
1261 "out float4 oPosition : POSITION,\n" +
1262 "out float oPosition_ : TEXCOORD0,\n" +
1263 "out float2 oDistance : TEXCOORD1,\n" +
1264 "out float2 oUvWorld : TEXCOORD2,\n" +
1266 "uniform float uPlaneYPos,\n" +
1267 "uniform float uPlanesError,\n" +
1268 "uniform float3 uCameraPos,\n" +
1269 "uniform float4x4 uWorld,\n" +
1270 "uniform float4x4 uWorldViewProj)\n" +
1272 "oPosition = mul(uWorldViewProj, iPosition);\n" +
1273 "float3 wPos = mul(uWorld, iPosition).xyz;\n" +
1274 "float3 wCam = uCameraPos;\n" +
1275 "wPos.y -= uPlaneYPos;\n" +
1276 "wCam.y -= uPlaneYPos;\n" +
1277 "oPosition_ = wPos.y;\n" +
1279 "oDistance.x = distance(wPos, wCam);\n" +
1280 "oDistance.y = 1.0;\n" +
1282 "if(wCam.y > 0.0) {\n" +
1283 "oDistance.x *= 1.0 - wCam.y/(wCam.y + abs(wPos.y));\n" +
1285 "if(wPos.y > uPlanesError) {\n" +
1286 "oDistance.x *= abs(wCam.y)/(abs(wCam.y) + wPos.y);\n" +
1287 "oDistance.y = 0.0;\n" +
1289 "oUvWorld = wPos.xz;\n" +
1299 VertexProgramData += Ogre::String(
"\n" ) +
1301 "uniform float uPlaneYPos;\n" +
1302 "uniform float uPlanesError;\n" +
1303 "uniform mat4 uWorld;\n" +
1306 "varying float Position_;\n" +
1307 "varying vec2 Distance_;\n" +
1312 "vec3 wPos = ( uWorld * gl_Vertex ).xyz;\n" +
1313 "vec3 wCam = ( uWorld * gl_ModelViewMatrixInverse * vec4(0.0, 0.0, 0.0, 1.0) ).xyz;\n" +
1314 "wPos.y -= uPlaneYPos;\n" +
1315 "wCam.y -= uPlaneYPos;\n" +
1316 "Position_ = wPos.y;\n" +
1318 "vec4 mwPos = gl_ModelViewMatrix * gl_Vertex;\n" +
1319 "Distance_.x = abs(mwPos.z);\n" +
1320 "Distance_.y = 1.0;\n" +
1322 "if(wCam.y > 0.0) {\n" +
1323 "Distance_.x *= 1.0 - wCam.y/(wCam.y + abs(wPos.y));\n" +
1325 "if(wPos.y > uPlanesError) {\n" +
1326 "Distance_.x *= abs(wCam.y)/(abs(wCam.y) + wPos.y);\n" +
1327 "Distance_.y = 0.0;\n" +
1333 VertexProgramData += Ogre::String(
"\n" ) +
1335 "uniform float uPlaneYPos;\n" +
1336 "uniform float uPlanesError;\n" +
1337 "uniform mat4 uWorld;\n" +
1340 "varying float Position_;\n" +
1341 "varying vec2 Distance_;\n" +
1342 "varying vec2 UVWorld;\n" +
1346 "gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;\n" +
1348 "vec3 wPos = ( uWorld * gl_Vertex ).xyz;\n" +
1349 "vec3 wCam = ( uWorld * gl_ModelViewMatrixInverse * vec4(0.0, 0.0, 0.0, 1.0) ).xyz;\n" +
1350 "wPos.y -= uPlaneYPos;\n" +
1351 "wCam.y -= uPlaneYPos;\n" +
1352 "Position_ = wPos.y;\n" +
1354 "vec4 mwPos = gl_ModelViewMatrix * gl_Vertex;\n" +
1355 "Distance_.x = abs(mwPos.z);\n" +
1356 "Distance_.y = 1.0;\n" +
1358 "if(wCam.y > 0.0) {\n" +
1359 "Distance_.x *= 1.0 - wCam.y/(wCam.y + abs(wPos.y));\n" +
1361 "if(wPos.y > uPlanesError) {\n" +
1368 "Distance_.x *= abs(wCam.y)/(abs(wCam.y) + wPos.y);\n" +
1369 "Distance_.y = 0.0;\n" +
1371 "UVWorld = wPos.xz;\n" +
1385 FragmentProgramData +=
1387 "void main_fp(\n") +
1389 "float iPosition : TEXCOORD0,\n" +
1390 "float2 iDistance : TEXCOORD1,\n" +
1392 "out float4 oColor : COLOR,\n" +
1394 "uniform float uDepthLimit,\n" +
1395 "uniform float uDistLimit)\n" +
1397 "float pixelYDepth = saturate(iPosition*uDepthLimit + 1.0);\n" +
1398 "float pixelDepth = saturate(1.0 - iDistance.x*uDistLimit);\n" +
1399 "pixelDepth = min(pixelYDepth, pixelDepth);\n" +
1400 "oColor = float4(pixelDepth,0,0,0);\n" +
1405 FragmentProgramData +=
1407 "void main_fp(\n") +
1409 "float iPosition : TEXCOORD0,\n" +
1410 "float2 iDistance : TEXCOORD1,\n" +
1411 "float2 iUvWorld : TEXCOORD2,\n" +
1413 "out float4 oColor : COLOR,\n" +
1415 "uniform float uDepthLimit,\n" +
1416 "uniform float uDistLimit,\n" +
1417 "uniform float uCausticsScale,\n" +
1418 "uniform float uCausticsEnd,\n" +
1419 "uniform sampler2D uCaustics : register(s0))\n" +
1421 "float pixelYDepth = saturate(iPosition*uDepthLimit + 1.0);\n" +
1423 "float pixelDepth = saturate(1.0 - iDistance.x*uDistLimit);\n" +
1424 "pixelDepth = min(pixelYDepth, pixelDepth);\n" +
1425 "oColor = float4(pixelDepth,0.0,0.0,0.0);\n" +
1426 "oColor.g = iDistance.y*saturate((pixelYDepth-uCausticsEnd)/(1.0-uCausticsEnd))*tex2D(uCaustics, iUvWorld/uCausticsScale).x;\n" +
1436 FragmentProgramData += Ogre::String(
"\n" ) +
1438 "uniform float uDepthLimit;\n" +
1439 "uniform float uDistLimit;\n" +
1441 "varying float Position_;\n" +
1442 "varying float Distance_;\n" +
1447 "float pixelYDepth = clamp(1.0 + Position_*uDepthLimit, 0.0, 1.0);\n" +
1448 "float pixelDepth = clamp(1.0 - Distance_.x*uDistLimit, 0.0, 1.0);\n" +
1449 "pixelDepth = min(pixelYDepth,pixelDepth);\n" +
1450 "gl_FragColor = vec4(pixelDepth,0.0,0.0,1.0);\n" +
1455 FragmentProgramData += Ogre::String(
"\n" ) +
1457 "uniform float uDepthLimit;\n" +
1458 "uniform float uDistLimit;\n" +
1459 "uniform float uCausticsScale;\n" +
1460 "uniform float uCausticsEnd;\n" +
1461 "uniform sampler2D uCaustics;\n" +
1463 "varying float Position_;\n" +
1464 "varying vec2 Distance_;\n" +
1465 "varying vec2 UVWorld;\n" +
1470 "float pixelYDepth = clamp(1.0 + Position_*uDepthLimit, 0.0, 1.0);\n" +
1471 "float pixelDepth = clamp(1.0 - Distance_.x*uDistLimit, 0.0, 1.0);\n" +
1472 "pixelDepth = min(pixelYDepth,pixelDepth);\n" +
1473 "gl_FragColor = vec4(pixelDepth,0.0,0.0,1.0);\n" +
1474 "gl_FragColor.y = Distance_.y*clamp((pixelYDepth-uCausticsEnd)/(1.0-uCausticsEnd), 0.0, 1.0)*texture2D(uCaustics, UVWorld/uCausticsScale).x;\n" +
1482 DepthMaterial = Ogre::MaterialManager::getSingleton().
1484 Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
1486 DepthMaterial->getTechnique(0)->setSchemeName(
"HydraxDepth");
1488 Ogre::Pass *DM_Technique0_Pass0 = DepthMaterial->getTechnique(0)->getPass(0);
1490 Ogre::String GpuProgramsData[2] = {VertexProgramData, FragmentProgramData};
1492 Ogre::String EntryPoints[2];
1495 EntryPoints[0] = Ogre::String(
"main");
1496 EntryPoints[1] = Ogre::String(
"main");
1500 EntryPoints[0] = Ogre::String(
"main_vp");
1501 EntryPoints[1] = Ogre::String(
"main_fp");
1506 Ogre::GpuProgramParametersSharedPtr VP_Parameters = DM_Technique0_Pass0->getVertexProgramParameters();
1507 Ogre::GpuProgramParametersSharedPtr FP_Parameters = DM_Technique0_Pass0->getFragmentProgramParameters();
1511 VP_Parameters->setNamedAutoConstant(
"uWorldViewProj", Ogre::GpuProgramParameters::ACT_WORLDVIEWPROJ_MATRIX);
1513 VP_Parameters->setNamedAutoConstant(
"uCameraPos", Ogre::GpuProgramParameters::ACT_CAMERA_POSITION);
1515 VP_Parameters->setNamedAutoConstant(
"uWorld", Ogre::GpuProgramParameters::ACT_WORLD_MATRIX);
1529 FP_Parameters->setNamedConstant(
"uCaustics", 0);
1531 Ogre::TextureUnitState *TUS_Caustics = DM_Technique0_Pass0->createTextureUnitState(
"Caustics.bmp");
1532 TUS_Caustics->setTextureAddressingMode(Ogre::TextureUnitState::TAM_WRAP);
1533 TUS_Caustics->setAnimatedTextureName(
"Caustics.bmp", 32, 1.5);
1536 DepthMaterial->setReceiveShadows(
false);
1537 DepthMaterial->load();
1546 Ogre::String VertexProgramData, FragmentProgramData;
1557 VertexProgramData +=
1559 "void main_vp(\n") +
1561 "float4 iPosition : POSITION,\n" +
1562 "float2 iUV : TEXCOORD0,\n" +
1564 "out float4 oPosition : POSITION,\n" +
1565 "out float3 oPosition_UV : TEXCOORD0,\n" +
1567 "uniform float uPlaneYPos,\n" +
1568 "uniform float4x4 uWorld,\n" +
1569 "uniform float4x4 uWorldViewProj)\n" +
1571 "oPosition = mul(uWorldViewProj, iPosition);\n" +
1572 "oPosition_UV.x = mul(uWorld, iPosition).y;\n" +
1573 "oPosition_UV.x-=uPlaneYPos;\n" +
1574 "oPosition_UV.yz = iUV;\n" +
1579 VertexProgramData +=
1581 "void main_vp(\n") +
1583 "float4 iPosition : POSITION,\n" +
1584 "float2 iUV : TEXCOORD0,\n" +
1586 "out float4 oPosition : POSITION,\n" +
1587 "out float3 oPosition_UV : TEXCOORD0,\n" +
1588 "out float2 oUvWorld : TEXCOORD1,\n" +
1590 "uniform float uPlaneYPos,\n" +
1591 "uniform float4x4 uWorld,\n" +
1592 "uniform float4x4 uWorldViewProj)\n" +
1594 "oPosition = mul(uWorldViewProj, iPosition);\n" +
1595 "float3 wPos = mul(uWorld, iPosition);\n" +
1596 "oPosition_UV.x = wPos.y;\n" +
1597 "oPosition_UV.x-=uPlaneYPos;\n" +
1598 "oPosition_UV.yz = iUV;\n" +
1599 "oUvWorld = wPos.xz;\n" +
1609 VertexProgramData += Ogre::String(
"\n" ) +
1611 "uniform float uPlaneYPos;\n" +
1612 "uniform mat4 uWorld;\n" +
1615 "varying vec3 Position_UV;\n" +
1619 "gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;\n" +
1620 "Position_UV.x = (uWorld * gl_Vertex).y;\n" +
1621 "Position_UV.x -= uPlaneYPos;\n" +
1622 "Position_UV.yz = gl_MultiTexCoord0;\n" +
1627 VertexProgramData += Ogre::String(
"\n" ) +
1629 "uniform float uPlaneYPos;\n" +
1630 "uniform mat4 uWorld;\n" +
1633 "varying vec3 Position_UV;\n" +
1634 "varying vec2 UVWorld;\n" +
1638 "gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;\n" +
1639 "vec3 wPos = uWorld * iPosition;\n" +
1640 "Position_UV.x = wPos.y;\n" +
1641 "Position_UV.x -= uPlaneYPos;\n" +
1642 "Position_UV.yz = gl_MultiTexCoord0;\n" +
1643 "UVWorld = wPos.xz;\n" +
1658 FragmentProgramData +=
1660 "void main_fp(\n") +
1662 "float3 iPosition_UV : TEXCOORD0,\n" +
1664 "out float4 oColor : COLOR,\n" +
1666 "uniform float uDepthLimit,\n" +
1667 "uniform sampler2D uAlphaTex : register(s0))\n" +
1669 "float pixelYDepth = (iPosition_UV.x*uDepthLimit+1);\n" +
1670 "pixelYDepth = saturate(pixelYDepth);\n" +
1671 "oColor = float4(pixelYDepth,0,0,0);\n" +
1672 "oColor.a = tex2D(uAlphaTex, iPosition_UV.yz)."+AlphaChannel+
";" +
1677 FragmentProgramData +=
1679 "void main_fp(\n") +
1681 "float3 iPosition_UV : TEXCOORD0,\n" +
1682 "float2 iUvWorld : TEXCOORD1,\n" +
1684 "out float4 oColor : COLOR,\n" +
1686 "uniform float uDepthLimit,\n" +
1687 "uniform float uCausticsScale,\n" +
1688 "uniform float uCausticsEnd,\n" +
1689 "uniform sampler2D uCaustics : register(s0),\n" +
1690 "uniform sampler2D uAlphaTex : register(s1))\n" +
1692 "float pixelYDepth = (iPosition_UV.x*uDepthLimit+1);\n" +
1693 "pixelYDepth = saturate(pixelYDepth);\n" +
1694 "oColor = float4(pixelYDepth,0,0,0);\n" +
1695 "oColor.g = saturate(uCausticsEnd-pixelYDepth)*tex2D(uCaustics, iUvWorld/uCausticsScale).r;\n" +
1696 "oColor.a = tex2D(uAlphaTex, iPosition_UV.yz)."+AlphaChannel+
";" +
1704 Ogre::String AlphaChannelGLSL = AlphaChannel;
1705 std::replace( AlphaChannelGLSL.begin(), AlphaChannelGLSL.end(),
'r',
'x' );
1706 std::replace( AlphaChannelGLSL.begin(), AlphaChannelGLSL.end(),
'g',
'y' );
1707 std::replace( AlphaChannelGLSL.begin(), AlphaChannelGLSL.end(),
'b',
'z' );
1708 std::replace( AlphaChannelGLSL.begin(), AlphaChannelGLSL.end(),
'a',
'w' );
1712 FragmentProgramData += Ogre::String(
"\n" ) +
1714 "uniform float uDepthLimit;\n" +
1715 "uniform float uDistLimit;\n" +
1716 "uniform sampler2D uAlphaTex;\n" +
1718 "variying vec3 Position_UV;\n" +
1723 "float pixelYDepth = clamp(Position_UV.x*uDepthLimit + 1.0, 0.0, 1.0);\n" +
1724 "gl_FragColor = vec4(pixelYDepth,0.0,0.0,0.0);\n" +
1725 "gl_FragColor.w = texture2D(uAlphaTex, iPosition_UV.yz)."+AlphaChannelGLSL+
";" +
1730 FragmentProgramData += Ogre::String(
"\n" ) +
1732 "uniform float uDistLimit;\n" +
1733 "uniform float uCausticsScale;\n" +
1734 "uniform float uCausticsEnd;\n" +
1735 "uniform sampler2D uCaustics;\n" +
1736 "uniform sampler2D uAlphaTex;\n" +
1738 "variying vec3 Position_UV;\n" +
1739 "variying vec2 UVWorld;\n" +
1744 "float pixelYDepth = clamp(Position_UV.x*uDepthLimit + 1.0, 0.0, 1.0);\n" +
1745 "gl_FragColor = vec4(pixelYDepth,0.0,0.0,0.0);\n" +
1746 "gl_FragColor.y = clamp(uCausticsEnd-pixelYDepth, 0.0, 1.0)*texture2D(uCaustics, UVWorld/uCausticsScale).x;\n" +
1747 "gl_FragColor.w = texture2D(uAlphaTex, iPosition_UV.yz)."+AlphaChannelGLSL+
";" +
1754 Ogre::String GpuProgramsData[2] = {VertexProgramData, FragmentProgramData};
1756 Ogre::String EntryPoints[2];
1759 EntryPoints[0] = Ogre::String(
"main");
1760 EntryPoints[1] = Ogre::String(
"main");
1764 EntryPoints[0] = Ogre::String(
"main_vp");
1765 EntryPoints[1] = Ogre::String(
"main_fp");
1770 for (
int k = 0; k < 2; k++)
1790 Ogre::String VertexProgramData, FragmentProgramData;
1802 VertexProgramData +=
1804 "void main_vp(\n") +
1806 "float4 iPosition : POSITION,\n" +
1807 "float2 iUv : TEXCOORD0,\n" +
1809 "out float4 oPosition : POSITION,\n" +
1810 "out float4 oPosition_ : TEXCOORD0,\n" +
1811 "out float2 oUvNoise : TEXCOORD1,\n" +
1812 "out float4 oUvProjection : TEXCOORD2,\n" +
1813 "out float2 oDistance : TEXCOORD3,\n";
1821 VertexProgramData += Ogre::String(
1823 "uniform float4x4 uWorldViewProj,\n") +
1824 "uniform float4x4 uWorldView,\n" +
1825 "uniform float4x4 uWorld,\n" +
1826 "uniform float3 uCameraPos)\n" +
1828 "oPosition_ = iPosition;\n";
1836 VertexProgramData += Ogre::String(
1837 "oPosition = mul(uWorldViewProj, iPosition);\n") +
1839 "float4x4 scalemat = float4x4(0.5, 0, 0, 0.5,"+
1843 "oUvProjection = mul(scalemat, oPosition);\n" +
1844 "oUvNoise = iUv;\n" +
1846 "float4 mwPos = mul(uWorldView, iPosition);\n" +
1847 "oDistance.x = abs(mwPos.z);\n" +
1848 "oDistance.y = -mul( uWorld, float4(uCameraPos, 1.0) ).y;\n" +
1855 VertexProgramData += Ogre::String(
"\n" );
1857 VertexProgramData +=
"uniform mat4 uWorld;\n";
1860 VertexProgramData += Ogre::String(
1861 "varying vec4 Position_;\n") +
1862 "varying vec4 UVProjection;\n" +
1863 "varying vec2 Distance_;\n";
1871 VertexProgramData += Ogre::String(
1874 "Position_ = gl_Vertex;\n";
1881 VertexProgramData += Ogre::String(
1883 "gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;\n") +
1884 "mat4 scalemat = mat4( 1.0, 0.0, 0.0, 0.0,\n" +
1885 " 0.0, -1.0, 0.0, 0.0,\n" +
1886 " 0.0, 0.0, 1.0, 0.0,\n" +
1887 " 0.0, 0.0, 0.0, 1.0);\n" +
1888 "UVProjection = scalemat * gl_Position;\n" +
1889 "gl_TexCoord[0] = gl_MultiTexCoord0;\n" +
1891 "vec4 mwPos = gl_ModelViewMatrix * gl_Vertex;\n" +
1892 "Distance_.x = abs(mwPos.z);\n" +
1893 "Distance_.y = -( uWorld * gl_ModelViewMatrixInverse * vec4(0.0, 0.0, 0.0, 1.0) ).y;\n" +
1907 VertexProgramData +=
1909 "void main_vp(\n") +
1911 "float4 iPosition : POSITION,\n" +
1912 "float3 iNormal : NORMAL,\n"+
1914 "out float4 oPosition : POSITION,\n" +
1915 "out float4 oPosition_ : TEXCOORD0,\n" +
1916 "out float4 oUvProjection : TEXCOORD1,\n" +
1917 "out float3 oNormal : TEXCOORD2,\n" +
1918 "out float2 oDistance : TEXCOORD3,\n";
1926 VertexProgramData += Ogre::String(
1928 "uniform float4x4 uWorldViewProj,\n") +
1929 "uniform float4x4 uWorldView,\n" +
1930 "uniform float4x4 uWorld,\n" +
1931 "uniform float3 uCameraPos)\n" +
1933 "oPosition_ = iPosition;\n";
1940 VertexProgramData += Ogre::String(
1941 "oPosition = mul(uWorldViewProj, iPosition);\n") +
1943 "float4x4 scalemat = float4x4(0.5, 0, 0, 0.5,"+
1947 "oUvProjection = mul(scalemat, oPosition);\n" +
1948 "oNormal = normalize(iNormal);\n"+
1950 "float4 mwPos = mul(uWorldView, iPosition);\n" +
1951 "oDistance.x = abs(mwPos.z);\n" +
1952 "oDistance.y = -mul( uWorld, float4(uCameraPos, 1.0) ).y;\n" +
1959 VertexProgramData += Ogre::String(
"\n");
1961 VertexProgramData +=
"uniform mat4 uWorld;\n";
1964 VertexProgramData += Ogre::String(
1965 "varying vec4 Position_;\n") +
1966 "varying vec4 UVProjection;\n" +
1967 "varying vec3 Normal;\n" +
1968 "varying vec2 Distance_;\n";
1976 VertexProgramData += Ogre::String(
1979 "Position_ = gl_Vertex;\n";
1986 VertexProgramData += Ogre::String(
1987 "gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;\n") +
1988 "mat4 scalemat = mat4( 1.0, 0.0, 0.0, 0.0,\n" +
1989 " 0.0, -1.0, 0.0, 0.0,\n" +
1990 " 0.0, 0.0, 1.0, 0.0,\n" +
1991 " 0.0, 0.0, 0.0, 1.0);\n" +
1992 "UVProjection = scalemat * gl_Position;\n" +
1993 "Normal = normalize(gl_Normal);\n" +
1995 "vec4 mwPos = gl_ModelViewMatrix * gl_Vertex;\n" +
1996 "Distance_.x = abs(mwPos.z);\n" +
1997 "Distance_.y = -( uWorld * gl_ModelViewMatrixInverse * vec4(0.0, 0.0, 0.0, 1.0) ).y;\n" +
2011 VertexProgramData +=
2013 "void main_vp(\n") +
2015 "float4 iPosition : POSITION,\n" +
2017 "out float4 oPosition : POSITION,\n" +
2018 "out float4 oPosition_ : TEXCOORD0,\n" +
2019 "out float4 oUvProjection : TEXCOORD1,\n" +
2020 "out float2 oDistance : TEXCOORD2,\n";
2028 VertexProgramData += Ogre::String(
2030 "uniform float4x4 uWorldViewProj,\n") +
2031 "uniform float4x4 uWorldView,\n" +
2032 "uniform float4x4 uWorld,\n" +
2033 "uniform float3 uCameraPos)\n" +
2035 "oPosition_ = iPosition;\n";
2042 VertexProgramData += Ogre::String(
2043 "oPosition = mul(uWorldViewProj, iPosition);\n") +
2045 "float4x4 scalemat = float4x4(0.5, 0, 0, 0.5,"+
2049 "oUvProjection = mul(scalemat, oPosition);\n" +
2051 "float4 mwPos = mul(uWorldView, iPosition);\n" +
2052 "oDistance.x = abs(mwPos.z);\n" +
2053 "oDistance.y = -mul( uWorld, float4(uCameraPos, 1.0) ).y;\n" +
2060 VertexProgramData += Ogre::String(
"\n");
2062 VertexProgramData +=
"uniform mat4 uWorld;\n";
2065 VertexProgramData += Ogre::String(
2066 "varying vec4 Position_;\n") +
2067 "varying vec4 UVProjection;\n" +
2068 "varying vec2 Distance_;\n";
2076 VertexProgramData +=Ogre::String(
2079 "Position_ = gl_Vertex;\n";
2086 VertexProgramData += Ogre::String(
2087 "gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;\n") +
2088 "mat4 scalemat = mat4( 1.0, 0.0, 0.0, 0.0,\n" +
2089 " 0.0, -1.0, 0.0, 0.0,\n" +
2090 " 0.0, 0.0, 1.0, 0.0,\n" +
2091 " 0.0, 0.0, 0.0, 1.0);\n" +
2092 "UVProjection = scalemat * gl_Position;\n" +
2094 "vec4 mwPos = gl_ModelViewMatrix * gl_Vertex;\n" +
2095 "Distance_.x = abs(mwPos.z);\n" +
2096 "Distance_.y = -( uWorld * gl_ModelViewMatrixInverse * vec4(0.0, 0.0, 0.0, 1.0) ).y;\n" +
2115 FragmentProgramData +=
2116 Ogre::String(
"float3 expand(float3 v)\n") +
2118 "return (v - 0.5) * 2;\n" +
2123 "float4 iPosition : TEXCOORD0,\n";
2124 int TEXCOORDNUM = 1;
2127 FragmentProgramData +=
2128 "float2 iUvNoise : TEXCOORD" + Ogre::StringConverter::toString(TEXCOORDNUM) +
",\n";
2131 FragmentProgramData +=
2132 "float4 iUvProjection : TEXCOORD" + Ogre::StringConverter::toString(TEXCOORDNUM) +
",\n";
2136 FragmentProgramData +=
2137 "float3 iNormal : TEXCOORD" + Ogre::StringConverter::toString(TEXCOORDNUM) +
",\n";
2140 FragmentProgramData +=
2141 "float2 iDistance : TEXCOORD" + Ogre::StringConverter::toString(TEXCOORDNUM) +
",\n";
2151 FragmentProgramData += Ogre::String(
2153 "out float4 oColor : COLOR,\n") +
2155 "uniform float3 uEyePosition,\n" +
2156 "uniform float uFullReflectionDistance,\n" +
2157 "uniform float uGlobalTransparency,\n" +
2158 "uniform float uNormalDistortion,\n" +
2159 "uniform float uDistLimit,\n" +
2160 "uniform float3 uWaterColor,\n";
2163 FragmentProgramData += Ogre::String(
2164 "uniform float3 uSunPosition,\n") +
2165 "uniform float uSunStrength,\n" +
2166 "uniform float uSunArea,\n" +
2167 "uniform float3 uSunColor,\n" +
2168 "uniform float uDepthLimit,\n";
2181 if (cCaustics && cUReflections)
2183 FragmentProgramData +=
2184 "uniform float uCausticsPower,\n";
2191 FragmentProgramData +=
2192 "uniform sampler2D uNormalMap : register(s" + Ogre::StringConverter::toString(TexNum) +
"),\n";
2197 FragmentProgramData +=
2198 "uniform sampler2D uReflectionMap : register(s" + Ogre::StringConverter::toString(TexNum) +
"),\n";
2202 FragmentProgramData +=
2203 "uniform sampler2D uRefractionMap : register(s" + Ogre::StringConverter::toString(TexNum) +
"),\n";
2206 if (cDepth && cUReflections)
2208 FragmentProgramData +=
2209 "uniform sampler2D uDepthReflectionMap : register(s" + Ogre::StringConverter::toString(TexNum) +
"),\n";
2213 FragmentProgramData +=
2214 #if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
2215 "uniform sampler1D uFresnelMap : register(s" + Ogre::StringConverter::toString(TexNum) +
")";
2217 "uniform sampler2D uFresnelMap : register(s" + Ogre::StringConverter::toString(TexNum) +
")";
2228 FragmentProgramData += Ogre::String(
2231 "float2 ProjectionCoord = iUvProjection.xy / iUvProjection.w;\n" +
2232 "float3 camToSurface = iPosition.xyz - uEyePosition;\n" +
2233 "float additionalReflection=camToSurface.x*camToSurface.x+camToSurface.z*camToSurface.z;\n";
2244 FragmentProgramData += Ogre::String(
2245 "additionalReflection/=uFullReflectionDistance;\n") +
2246 "camToSurface=normalize(-camToSurface);\n";
2249 FragmentProgramData += Ogre::String(
2250 "float3 pixelNormal = tex2D(uNormalMap,iUvNoise).xyz;\n") +
2252 "pixelNormal.yz=pixelNormal.zy;\n" +
2254 "pixelNormal.xyz=-expand(pixelNormal.xyz);\n";
2258 FragmentProgramData +=
2259 "float3 pixelNormal = -iNormal;\n";
2263 FragmentProgramData +=
2264 "float3 pixelNormal = -(2.0*tex2D(uNormalMap, ProjectionCoord.xy).xyz - 1.0);\n";
2266 FragmentProgramData +=
2267 "float2 pixelNormalModified = uNormalDistortion*pixelNormal.zx;\n";
2271 FragmentProgramData +=
2272 "float dotProduct=dot(camToSurface,pixelNormal);\n";
2276 FragmentProgramData +=
2277 "float dotProduct=dot(-camToSurface,pixelNormal);\n";
2279 FragmentProgramData += Ogre::String(
2280 "dotProduct=saturate(dotProduct);\n") +
2281 #if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
2282 "float fresnel = tex1D(uFresnelMap,dotProduct);\n" +
2284 "float fresnel = tex2D(uFresnelMap,float2(dotProduct,dotProduct));\n" +
2287 "fresnel+=additionalReflection;\n" +
2288 "fresnel=saturate(fresnel);\n" +
2290 "fresnel-=uGlobalTransparency;\n" +
2291 "fresnel=saturate(fresnel);\n" +
2292 "float3 reflection;\n" +
2293 #if OGRE_PLATFORM != OGRE_PLATFORM_WIN32
2295 "if(uEyePosition.y < 0.0)\n" +
2297 "ProjectionCoord.y = 1.0 - ProjectionCoord.y;\n" +
2301 "float3 refraction=tex2D(uRefractionMap,ProjectionCoord.xy-pixelNormalModified).xyz;\n";
2304 FragmentProgramData +=
2305 "reflection=tex2D(uReflectionMap,ProjectionCoord.xy+pixelNormalModified).xyz;\n";
2309 FragmentProgramData +=
2310 "reflection=uWaterColor;\n";
2313 if (cDepth && cUReflections)
2317 FragmentProgramData += Ogre::String(
2318 "float2 depth = tex2D(uDepthReflectionMap,ProjectionCoord.xy+pixelNormalModified).rg;\n") +
2319 "reflection *= 1+depth.y*uCausticsPower;\n" +
2320 "reflection = lerp(uWaterColor,reflection,depth.x);\n";
2324 FragmentProgramData += Ogre::String(
2325 "float depth = tex2D(uDepthReflectionMap,ProjectionCoord.xy-pixelNormalModified).r;\n") +
2326 "reflection = lerp(uWaterColor,reflection,depth);\n";
2329 FragmentProgramData += Ogre::String(
2330 "float4 Color = float4(lerp(refraction,reflection,fresnel),1);\n" ) +
2331 "float Distance = saturate(1.0 - iDistance.x*uDistLimit);\n" +
2332 "Color.xyz = lerp(uWaterColor, Color.xyz, Distance);\n" +
2333 "Color.xyz = lerp(Color.xyz, uWaterColor, uGlobalTransparency);\n";
2337 FragmentProgramData += Ogre::String(
2338 "float3 refractedVector = normalize(reflect(camToSurface, pixelNormal.xyz));\n") +
2339 "float3 surfaceToSun=normalize(uSunPosition-iPosition.xyz);\n" +
2341 "surfaceToSun.xz = -surfaceToSun.xz;" +
2342 "float3 sunlight = uSunStrength*pow(saturate(dot(refractedVector,surfaceToSun)),uSunArea)*uSunColor;\n" +
2343 "Distance = saturate(1.0 - iDistance.y*uDepthLimit);\n" +
2344 "Color.xyz+=Distance*sunlight*saturate(1.0-additionalReflection);\n";
2358 FragmentProgramData += Ogre::String(
2359 "oColor = Color;\n") +
2365 FragmentProgramData += Ogre::String(
"\n") +
2367 "uniform vec3 uEyePosition;\n" +
2368 "uniform float uFullReflectionDistance;\n" +
2369 "uniform float uGlobalTransparency;\n" +
2370 "uniform float uNormalDistortion;\n" +
2371 "uniform float uDistLimit;\n" +
2372 "uniform vec3 uWaterColor;\n";
2376 FragmentProgramData += Ogre::String(
2377 "uniform vec3 uSunPosition;\n") +
2378 "uniform float uSunStrength;\n" +
2379 "uniform float uSunArea;\n" +
2380 "uniform vec3 uSunColor;\n" +
2381 "uniform float uDepthLimit;\n";
2394 if (cCaustics && cUReflections)
2396 FragmentProgramData +=
2397 "uniform float uCausticsPower;\n";
2403 FragmentProgramData +=
2404 "uniform sampler2D uNormalMap;\n";
2410 FragmentProgramData += Ogre::String(
2411 "uniform sampler2D uReflectionMap;\n");
2414 FragmentProgramData += Ogre::String(
2415 "uniform sampler2D uRefractionMap;\n");
2418 if (cDepth && cUReflections)
2420 FragmentProgramData +=
2421 "uniform sampler2D uDepthReflectionMap;\n";
2425 FragmentProgramData +=
2426 #if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
2427 "uniform sampler1D uFresnelMap;\n";
2429 "uniform sampler2D uFresnelMap;\n";
2441 FragmentProgramData +=
2442 "varying vec4 Position_;\n";
2443 int TEXCOORDNUM = 1;
2448 FragmentProgramData +=
2449 "varying vec4 UVProjection;\n";
2453 FragmentProgramData +=
2454 "varying vec3 Normal;\n";
2464 FragmentProgramData +=
2465 "varying vec2 Distance_;\n";
2467 FragmentProgramData += Ogre::String(
2468 "vec3 expand(vec3 v)\n") +
2470 "return (v - 0.5) * 2.0;\n" +
2475 "vec2 ProjectionCoord = UVProjection.xy / UVProjection.w;\n" +
2476 "ProjectionCoord += 1.0;\n" +
2477 "ProjectionCoord *= 0.5;\n" +
2478 "vec3 camToSurface = Position_.xyz - uEyePosition;\n" +
2479 "float additionalReflection=camToSurface.x*camToSurface.x+camToSurface.z*camToSurface.z;\n";
2488 FragmentProgramData += Ogre::String(
2489 "additionalReflection/=uFullReflectionDistance;\n") +
2490 "camToSurface=normalize(-camToSurface);\n";
2493 FragmentProgramData += Ogre::String(
2494 "vec3 pixelNormal = texture2D(uNormalMap,gl_TexCoord[0].xy).xyz;\n") +
2496 "pixelNormal.yz=pixelNormal.zy;\n" +
2498 "pixelNormal.xyz=-expand(pixelNormal.xyz);\n";
2502 FragmentProgramData +=
2503 "vec3 pixelNormal = -Normal;\n";
2507 FragmentProgramData +=
2508 "vec3 pixelNormal = -2.0*texture2D(uNormalMap, ProjectionCoord.xy).xyz - 1.0;\n";
2510 FragmentProgramData +=
2511 "vec2 pixelNormalModified = uNormalDistortion*pixelNormal.zx;\n";
2514 FragmentProgramData +=
2515 "float dotProduct=dot(camToSurface,pixelNormal);\n";
2519 FragmentProgramData +=
2520 "float dotProduct=dot(-camToSurface,pixelNormal);\n";
2522 FragmentProgramData += Ogre::String(
2523 "dotProduct=clamp(dotProduct, 0.0, 1.0);\n") +
2524 #if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
2525 "float fresnel = texture1D(uFresnelMap,dotProduct).x;\n" +
2527 "float fresnel = texture2D(uFresnelMap,vec2(dotProduct,dotProduct)).x;\n" +
2530 "fresnel +=additionalReflection;\n" +
2531 "fresnel = clamp(fresnel, 0.0, 1.0);\n" +
2533 "fresnel -= uGlobalTransparency;\n" +
2534 "fresnel = clamp(fresnel, 0.0, 1.0);\n" +
2536 "vec3 reflection;\n" +
2537 #if OGRE_PLATFORM != OGRE_PLATFORM_WIN32
2539 "if(uEyePosition.y < 0.0)\n" +
2541 "ProjectionCoord.y = 1.0 - ProjectionCoord.y;\n" +
2544 "vec3 refraction=texture2D(uRefractionMap,ProjectionCoord.xy-pixelNormalModified).xyz;\n";
2547 FragmentProgramData +=
2548 "reflection=texture2D(uReflectionMap,ProjectionCoord.xy+pixelNormalModified).xyz;\n";
2552 FragmentProgramData +=
2553 "reflection=uWaterColor;\n";
2555 if (cDepth && cUReflections)
2559 FragmentProgramData += Ogre::String(
2560 "vec2 depth = texture2D(uDepthReflectionMap,ProjectionCoord.xy+pixelNormalModified).xy;\n") +
2561 "reflection *= 1.0 + depth.y*uCausticsPower;\n" +
2562 "reflection = mix(uWaterColor,reflection,depth.x);\n";
2566 FragmentProgramData += Ogre::String(
2567 "float depth = texture2D(uDepthReflectionMap,ProjectionCoord.xy+pixelNormalModified).x;\n") +
2568 "reflection = mix(uWaterColor,reflection,depth);\n";
2571 FragmentProgramData += Ogre::String(
2572 "gl_FragColor = vec4(mix(refraction,reflection,fresnel),1.0);\n") +
2573 "float Distance = clamp(1.0 - Distance_.x*uDistLimit, 0.0, 1.0);\n" +
2574 "gl_FragColor.xyz = mix(uWaterColor, gl_FragColor.xyz, Distance);\n" +
2575 "gl_FragColor.xyz = mix(gl_FragColor.xyz, uWaterColor, uGlobalTransparency);\n";
2578 FragmentProgramData += Ogre::String(
2579 "vec3 refractedVector = normalize(reflect(-camToSurface,pixelNormal.xyz));\n") +
2580 "vec3 surfaceToSun=normalize(uSunPosition-Position_.xyz);\n" +
2582 "surfaceToSun.xz = -surfaceToSun.xz;" +
2583 "vec3 sunlight = uSunStrength*pow(clamp(dot(refractedVector,surfaceToSun),0.0,1.0),uSunArea)*uSunColor;\n" +
2584 "Distance = clamp(1.0 - Distance_.y*uDepthLimit, 0.0, 1.0);\n";
2585 "gl_FragColor.xyz+=Distance*sunlight*clamp(1.0 - additionalReflection, 0.0, 1.0);\n";
2598 FragmentProgramData +=
2608 UnderwaterMaterial = Ogre::MaterialManager::getSingleton().
2610 Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
2612 Ogre::Pass *UM_Technique0_Pass0 = UnderwaterMaterial->getTechnique(0)->getPass(0);
2614 UM_Technique0_Pass0->setDepthWriteEnabled(
true);
2615 UM_Technique0_Pass0->setCullingMode(Ogre::CULL_NONE);
2617 Ogre::String GpuProgramsData[2] = {VertexProgramData, FragmentProgramData};
2619 Ogre::String EntryPoints[2];
2622 EntryPoints[0] = Ogre::String(
"main");
2623 EntryPoints[1] = Ogre::String(
"main");
2627 EntryPoints[0] = Ogre::String(
"main_vp");
2628 EntryPoints[1] = Ogre::String(
"main_fp");
2633 Ogre::GpuProgramParametersSharedPtr VP_Parameters = UM_Technique0_Pass0->getVertexProgramParameters();
2634 Ogre::GpuProgramParametersSharedPtr FP_Parameters = UM_Technique0_Pass0->getFragmentProgramParameters();
2638 VP_Parameters->setNamedAutoConstant(
"uWorldViewProj", Ogre::GpuProgramParameters::ACT_WORLDVIEWPROJ_MATRIX);
2639 VP_Parameters->setNamedAutoConstant(
"uWorldView", Ogre::GpuProgramParameters::ACT_WORLDVIEW_MATRIX);
2640 VP_Parameters->setNamedAutoConstant(
"uCameraPos", Ogre::GpuProgramParameters::ACT_CAMERA_POSITION_OBJECT_SPACE);
2642 VP_Parameters->setNamedAutoConstant(
"uWorld", Ogre::GpuProgramParameters::ACT_WORLD_MATRIX);
2643 FP_Parameters->setNamedAutoConstant(
"uEyePosition", Ogre::GpuProgramParameters::ACT_CAMERA_POSITION_OBJECT_SPACE);
2672 if (cCaustics && cDepth && cUReflections)
2677 int GLSLTextUnit = 0;
2683 FP_Parameters->setNamedConstant(
"uNormalMap", GLSLTextUnit);
2686 UM_Technique0_Pass0->createTextureUnitState(
"HydraxNormalMap")->setTextureAddressingMode(Ogre::TextureUnitState::TAM_WRAP);
2693 FP_Parameters->setNamedConstant(
"uReflectionMap", GLSLTextUnit);
2696 UM_Technique0_Pass0->createTextureUnitState(
"HydraxReflectionMap")->setTextureAddressingMode(Ogre::TextureUnitState::TAM_CLAMP);
2700 FP_Parameters->setNamedConstant(
"uRefractionMap", GLSLTextUnit);
2703 UM_Technique0_Pass0->createTextureUnitState(
"HydraxRefractionMap")->setTextureAddressingMode(Ogre::TextureUnitState::TAM_CLAMP);
2705 if (cDepth && cUReflections)
2709 FP_Parameters->setNamedConstant(
"uDepthReflectionMap", GLSLTextUnit);
2712 UM_Technique0_Pass0->createTextureUnitState()->setTextureAddressingMode(Ogre::TextureUnitState::TAM_CLAMP);
2717 FP_Parameters->setNamedConstant(
"uFresnelMap", GLSLTextUnit);
2720 UM_Technique0_Pass0->createTextureUnitState(
"Fresnel.bmp")->setTextureAddressingMode(Ogre::TextureUnitState::TAM_CLAMP);
2734 UnderwaterMaterial->setReceiveShadows(
false);
2735 UnderwaterMaterial->load();
2746 Ogre::String VertexProgramData, FragmentProgramData;
2753 VertexProgramData +=
2755 "void main_vp(\n") +
2757 "float4 iPosition : POSITION,\n" +
2759 "out float4 oPosition : POSITION,\n" +
2760 "out float3 oPosition_ : TEXCOORD0,\n" +
2761 "out float2 oUV : TEXCOORD1,\n";
2765 VertexProgramData +=
2767 "uniform float3 uCorner0,\n") +
2768 "uniform float3 uCorner01,\n" +
2769 "uniform float3 uCorner02,\n";
2771 VertexProgramData +=
2773 "uniform float4x4 uWorldViewProj)\n") +
2775 "oPosition = mul(uWorldViewProj, iPosition);\n"+
2776 "iPosition.xy = sign(iPosition.xy);\n"+
2777 "oUV = (float2(iPosition.x, -iPosition.y) + 1.0f) * 0.5f;";
2780 VertexProgramData += Ogre::String(
2781 "uCorner01 *= oUV.x;\n")+
2782 "uCorner02 *= oUV.y;\n"+
2783 "oPosition_ = uCorner0+uCorner01+uCorner02;";
2785 VertexProgramData +=
2792 VertexProgramData += Ogre::String(
"\n" );
2796 VertexProgramData += Ogre::String(
2797 "uniform vec3 uCorner0;\n") +
2798 "uniform vec3 uCorner01;\n" +
2799 "uniform vec3 uCorner02;\n";
2803 VertexProgramData += Ogre::String(
2804 "varying vec3 Position_;\n") +
2805 "varying vec2 UV;\n" +
2809 "gl_Position = ftransform();\n" +
2810 "vec2 iPosition = sign(gl_Vertex.xy);\n"+
2811 "UV = (vec2(iPosition.x, -iPosition.y) + 1.0) * 0.5;\n";
2814 VertexProgramData += Ogre::String(
2815 "vec3 vCorner01 = uCorner01 * UV.x;\n")+
2816 "vec3 vCorner02 = uCorner02 * UV.y;\n"+
2817 "Position_ = uCorner0+vCorner01+vCorner02;\n";
2819 VertexProgramData +=
2830 FragmentProgramData +=
2832 "void main_fp(\n") +
2834 "float3 iPosition : TEXCOORD0,\n" +
2835 "float2 iUV : TEXCOORD1,\n" +
2837 "out float4 oColor : COLOR,\n";
2841 FragmentProgramData +=
2842 "uniform float uCausticsPower,\n";
2846 FragmentProgramData += Ogre::String(
2847 "uniform float3 uSunColor,\n") +
2848 "uniform float3 uLightDirection,\n"+
2849 "uniform float uIntensity,\n"+
2850 "uniform float3 uHGg,\n"+
2851 "uniform float3 uCameraPos,\n";
2853 FragmentProgramData += Ogre::String(
2854 "uniform float uTime,\n") +
2855 "uniform float3 uWaterColor,\n" +
2856 "uniform sampler2D uOriginalMap : register(s0),\n" +
2857 "uniform sampler2D uDistortMap : register(s1)\n";
2860 FragmentProgramData +=
2861 ",\nuniform sampler2D uDepthMap : register(s2)";
2863 FragmentProgramData += Ogre::String(
2866 "float2 distortUV = (tex2D(uDistortMap, float2(iUV.x + uTime, iUV.y + uTime)).xy - 0.5)/50.0;\n";
2869 FragmentProgramData += Ogre::String(
2870 "float2 depth = tex2D(uDepthMap, iUV+distortUV).xy;\n") +
2871 "float4 Color = float4(lerp(uWaterColor,tex2D(uOriginalMap, iUV+distortUV)*(1.0+depth.y*uCausticsPower), depth.x),1.0);\n";
2874 FragmentProgramData += Ogre::String(
2875 "float3 view_vector = normalize(iPosition-uCameraPos);\n") +
2876 "float dot_product = dot(view_vector, -uLightDirection);\n"+
2877 "float num = uHGg.x;\n"+
2878 "float den = (uHGg.y - uHGg.z*dot_product);\n"+
2879 "den = rsqrt(den);\n"+
2880 "float phase = num * (den*den*den);\n" +
2881 "Color.xyz += (0.15 + uIntensity*tex2D(uDepthMap, iUV).z)*phase*uSunColor;\n";
2886 FragmentProgramData +=
2887 "float4 Color = float4(lerp(uWaterColor,tex2D(uOriginalMap, iUV+distortUV).xyz,tex2D(uDepthMap, iUV+distortUV).r),1.0);\n";
2890 FragmentProgramData += Ogre::String(
2891 "float3 view_vector = normalize(iPosition-uCameraPos);") +
2892 "float dot_product = dot(view_vector, -uLightDirection);"+
2893 "float num = uHGg.x;"+
2894 "float den = (uHGg.y - uHGg.z*dot_product); "+
2895 "den = rsqrt(den); "+
2896 "float phase = num * (den*den*den);"+
2897 "Color.xyz += (0.15 + uIntensity*tex2D(uDepthMap, iUV).y)*phase*uSunColor;";
2902 FragmentProgramData +=
2903 "float4 Color = tex2D(uOriginalMap, iUV+distortUV);";
2905 FragmentProgramData += Ogre::String(
2906 "oColor = Color;\n") +
2913 FragmentProgramData += Ogre::String(
"\n" );
2917 FragmentProgramData +=
2918 "uniform float uCausticsPower;\n";
2922 FragmentProgramData += Ogre::String(
2923 "uniform vec3 uSunColor;\n") +
2924 "uniform vec3 uLightDirection;\n"+
2925 "uniform float uIntensity;\n"+
2926 "uniform vec3 uHGg;\n"+
2927 "uniform vec3 uCameraPos;\n";
2929 FragmentProgramData += Ogre::String(
2930 "uniform float uTime;\n") +
2931 "uniform float uGlobalTransparency;\n" +
2932 "uniform vec3 uWaterColor;\n" +
2933 "uniform sampler2D uOriginalMap;\n" +
2934 "uniform sampler2D uDistortMap;\n";
2937 FragmentProgramData +=
2938 "uniform sampler2D uDepthMap;\n";
2941 FragmentProgramData += Ogre::String(
2942 "varying vec3 Position_;\n") +
2943 "varying vec2 UV;\n" +
2948 "vec2 distortUV = (texture2D(uDistortMap, vec2(UV.x + uTime, UV.y + uTime)).xy - 0.5)*0.02;\n";
2952 FragmentProgramData += Ogre::String(
2953 "vec2 depth = texture2D(uDepthMap, UV+distortUV).xy;\n") +
2954 "gl_FragColor = vec4(mix(uWaterColor,texture2D(uOriginalMap, UV+distortUV).xyz*(1.0+depth.y*uCausticsPower), depth.x),1.0);\n";
2957 FragmentProgramData += Ogre::String(
2958 "vec3 view_vector = normalize(Position_-uCameraPos);\n") +
2959 "float dot_product = dot(view_vector, -uLightDirection);\n"+
2960 "float num = uHGg.x;\n"+
2961 "float den = (uHGg.y - uHGg.z*dot_product);\n"+
2962 "den = inversesqrt(den);\n"+
2963 "float phase = num * pow(den, 3.0);\n"+
2964 "gl_FragColor.xyz += (0.15 + uIntensity*texture2D(uDepthMap, UV).z)*phase*uSunColor;";
2969 FragmentProgramData +=
2970 "gl_FragColor = vec4(mix(uWaterColor,texture2D(uOriginalMap, UV+distortUV).xyz,texture2D(uDepthMap, UV+distortUV).r),1.0);\n";
2973 FragmentProgramData += Ogre::String(
2974 "vec3 view_vector = normalize(Position_-uCameraPos);\n") +
2975 "float dot_product = dot(view_vector, -uLightDirection);\n"+
2976 "float num = uHGg.x;\n"+
2977 "float den = (uHGg.y - uHGg.z*dot_product);\n"+
2978 "den = inversesqrt(den);\n"+
2979 "float phase = num * pow(den, 3.0);\n"+
2980 "gl_FragColor.xyz += (0.15 + uIntensity*texture2D(uDepthMap, UV).z)*phase*uSunColor;\n";
2985 FragmentProgramData +=
2986 "gl_FragColor = texture2D(uOriginalMap, UV+distortUV);\n";
2988 FragmentProgramData +=
2996 UnderwaterCompositorMaterial = Ogre::MaterialManager::getSingleton().
2998 Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
3000 Ogre::Pass *DM_Technique0_Pass0 = UnderwaterCompositorMaterial->getTechnique(0)->getPass(0);
3002 DM_Technique0_Pass0->setCullingMode(Ogre::CULL_NONE);
3003 DM_Technique0_Pass0->setDepthFunction(Ogre::CMPF_ALWAYS_PASS);
3005 Ogre::String GpuProgramsData[2] = {VertexProgramData, FragmentProgramData};
3007 Ogre::String EntryPoints[2];
3010 EntryPoints[0] = Ogre::String(
"main");
3011 EntryPoints[1] = Ogre::String(
"main");
3015 EntryPoints[0] = Ogre::String(
"main_vp");
3016 EntryPoints[1] = Ogre::String(
"main_fp");
3021 Ogre::GpuProgramParametersSharedPtr VP_Parameters = DM_Technique0_Pass0->getVertexProgramParameters();
3022 Ogre::GpuProgramParametersSharedPtr FP_Parameters = DM_Technique0_Pass0->getFragmentProgramParameters();
3026 VP_Parameters->setNamedAutoConstant(
"uWorldViewProj", Ogre::GpuProgramParameters::ACT_WORLDVIEWPROJ_MATRIX);
3029 FP_Parameters->setNamedConstantFromTime(
"uTime", 0.1f);
3040 FP_Parameters->setNamedConstant(
"uLightDirection",
3046 FP_Parameters->setNamedAutoConstant(
"uCameraPos", Ogre::GpuProgramParameters::ACT_CAMERA_POSITION);
3050 int GLSLTextUnit = 0;
3053 FP_Parameters->setNamedConstant(
"uOriginalMap", GLSLTextUnit);
3056 DM_Technique0_Pass0->createTextureUnitState()->setTextureAddressingMode(Ogre::TextureUnitState::TAM_CLAMP);
3059 FP_Parameters->setNamedConstant(
"uDistortMap", GLSLTextUnit);
3062 DM_Technique0_Pass0->createTextureUnitState(
"UnderwaterDistortion.jpg")->setTextureAddressingMode(Ogre::TextureUnitState::TAM_WRAP);
3067 FP_Parameters->setNamedConstant(
"uDepthMap", GLSLTextUnit);
3070 DM_Technique0_Pass0->createTextureUnitState(
"HydraxDepthMap")->setTextureAddressingMode(Ogre::TextureUnitState::TAM_CLAMP);
3074 UnderwaterCompositorMaterial->setReceiveShadows(
false);
3075 UnderwaterCompositorMaterial->load();
3078 UnderwaterCompositor = Ogre::CompositorManager::getSingleton().
3081 Ogre::CompositionTechnique* UnderWaterComp_Technique = UnderwaterCompositor->createTechnique();
3084 Ogre::CompositionTechnique::TextureDefinition* TDef = UnderWaterComp_Technique->createTextureDefinition(
"OriginalScene");
3087 Ogre::PixelFormatList l;
3088 l.push_back(Ogre::PF_A8R8G8B8);
3089 TDef->formatList = l;
3092 Ogre::CompositionTargetPass* CTPass = UnderWaterComp_Technique->createTargetPass();
3093 CTPass->setInputMode(Ogre::CompositionTargetPass::IM_NONE);
3094 CTPass->setOutputName(
"OriginalScene");
3095 Ogre::CompositionPass* CPassClear = CTPass->createPass();
3096 CPassClear->setType(Ogre::CompositionPass::PT_CLEAR);
3099 CPassClear->setClearColour(Ogre::ColourValue(WC.x, WC.y, WC.z));
3101 Ogre::CompositionPass* CPass = CTPass->createPass();
3102 CPass->setType(Ogre::CompositionPass::PT_RENDERSCENE);
3103 CPass->setFirstRenderQueue(Ogre::RENDER_QUEUE_SKIES_EARLY+1);
3106 Ogre::CompositionTargetPass* CTOutputPass = UnderWaterComp_Technique->getOutputTargetPass();
3107 CTOutputPass->setInputMode(Ogre::CompositionTargetPass::IM_NONE);
3110 Ogre::CompositionPass* COutputPass = CTOutputPass->createPass();
3111 COutputPass->setType(Ogre::CompositionPass::PT_RENDERQUAD);
3113 COutputPass->setInput(0,
"OriginalScene");
3114 COutputPass->setLastRenderQueue(0);
3116 Ogre::CompositorManager::getSingleton().
3125 Ogre::MaterialPtr &SimpleColorMaterial =
getMaterial(MT);
3126 SimpleColorMaterial = Ogre::MaterialManager::getSingleton().
3128 Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
3130 Ogre::Pass *SCM_T0_Pass0 = SimpleColorMaterial->getTechnique(0)->getPass(0);
3131 SCM_T0_Pass0->setLightingEnabled(
false);
3132 SCM_T0_Pass0->setDepthCheckEnabled(DepthCheck);
3133 SCM_T0_Pass0->setDepthWriteEnabled(DepthWrite);
3134 SCM_T0_Pass0->setCullingMode(Ogre::CULL_NONE);
3135 SCM_T0_Pass0->createTextureUnitState()->setColourOperationEx(Ogre::LBX_MODULATE,Ogre::LBS_MANUAL,Ogre::LBS_CURRENT, Color);
3137 SimpleColorMaterial->setReceiveShadows(
false);
3138 SimpleColorMaterial->load();
3165 Ogre::Pass *M_Technique0_Pass0 = Mat->getTechnique(0)->getPass(0);
3171 M_Technique0_Pass0->getTextureUnitState(0)->setTextureName(
"HydraxNormalMap");
3172 M_Technique0_Pass0->getTextureUnitState(1)->setTextureName(
"HydraxReflectionMap");
3173 M_Technique0_Pass0->getTextureUnitState(2)->setTextureName(
"HydraxRefractionMap");
3176 M_Technique0_Pass0->getTextureUnitState(3)->setTextureName(
"HydraxDepthMap");
3183 M_Technique0_Pass0->getTextureUnitState(0)->setTextureName(
"HydraxReflectionMap");
3184 M_Technique0_Pass0->getTextureUnitState(1)->setTextureName(
"HydraxRefractionMap");
3187 M_Technique0_Pass0->getTextureUnitState(2)->setTextureName(
"HydraxDepthMap");
3193 Ogre::GpuProgramParametersSharedPtr VP_Parameters = M_Technique0_Pass0->getVertexProgramParameters();
3194 Ogre::GpuProgramParametersSharedPtr FP_Parameters = M_Technique0_Pass0->getFragmentProgramParameters();
3198 VP_Parameters->setNamedAutoConstant(
"uWorldViewProj", Ogre::GpuProgramParameters::ACT_WORLDVIEWPROJ_MATRIX);
3202 VP_Parameters->setNamedAutoConstant(
"uWorld", Ogre::GpuProgramParameters::ACT_WORLD_MATRIX);
3204 FP_Parameters->setNamedAutoConstant(
"uEyePosition", Ogre::GpuProgramParameters::ACT_CAMERA_POSITION_OBJECT_SPACE);
3239 Ogre::Pass *M_Technique0_Pass0 = Mat->getTechnique(0)->getPass(0);
3241 Ogre::GpuProgramParametersSharedPtr VP_Parameters = M_Technique0_Pass0->getVertexProgramParameters();
3242 Ogre::GpuProgramParametersSharedPtr FP_Parameters = M_Technique0_Pass0->getFragmentProgramParameters();
3246 VP_Parameters->setNamedAutoConstant(
"uWorldViewProj", Ogre::GpuProgramParameters::ACT_WORLDVIEWPROJ_MATRIX);
3248 VP_Parameters->setNamedAutoConstant(
"uCameraPos", Ogre::GpuProgramParameters::ACT_CAMERA_POSITION);
3250 VP_Parameters->setNamedAutoConstant(
"uWorld", Ogre::GpuProgramParameters::ACT_WORLD_MATRIX);
3267 Ogre::Pass *M_Technique0_Pass0 = Mat->getTechnique(0)->getPass(0);
3273 M_Technique0_Pass0->getTextureUnitState(0)->setTextureName(
"HydraxNormalMap");
3277 M_Technique0_Pass0->getTextureUnitState(Index)->setTextureName(
"HydraxReflectionMap");
3280 M_Technique0_Pass0->getTextureUnitState(Index)->setTextureName(
"HydraxRefractionMap");
3282 if (cDepth && cUReflections)
3284 M_Technique0_Pass0->getTextureUnitState(Index)->setTextureName(
"HydraxDepthReflectionMap");
3294 M_Technique0_Pass0->getTextureUnitState(Index)->setTextureName(
"HydraxReflectionMap");
3297 M_Technique0_Pass0->getTextureUnitState(Index)->setTextureName(
"HydraxRefractionMap");
3299 if (cDepth && cUReflections)
3301 M_Technique0_Pass0->getTextureUnitState(Index)->setTextureName(
"HydraxDepthReflectionMap");
3307 Ogre::GpuProgramParametersSharedPtr VP_Parameters = M_Technique0_Pass0->getVertexProgramParameters();
3308 Ogre::GpuProgramParametersSharedPtr FP_Parameters = M_Technique0_Pass0->getFragmentProgramParameters();
3312 VP_Parameters->setNamedAutoConstant(
"uWorldViewProj", Ogre::GpuProgramParameters::ACT_WORLDVIEWPROJ_MATRIX);
3313 VP_Parameters->setNamedAutoConstant(
"uWorldView", Ogre::GpuProgramParameters::ACT_WORLDVIEW_MATRIX);
3314 VP_Parameters->setNamedAutoConstant(
"uCameraPos", Ogre::GpuProgramParameters::ACT_CAMERA_POSITION_OBJECT_SPACE);
3316 VP_Parameters->setNamedAutoConstant(
"uWorld", Ogre::GpuProgramParameters::ACT_WORLD_MATRIX);
3317 FP_Parameters->setNamedAutoConstant(
"uEyePosition", Ogre::GpuProgramParameters::ACT_CAMERA_POSITION_OBJECT_SPACE);
3324 if ((cDepth && cUReflections) || (!cUReflections))
3347 if (cCaustics && cDepth && cUReflections)
3378 Technique->removeAllPasses();
3379 Technique->createPass();
3380 Technique->setName(
"_Hydrax_Depth_Technique");
3381 Technique->setSchemeName(
"HydraxDepth");
3383 Ogre::Pass *DM_Technique_Pass0 = Technique->getPass(0);
3388 Ogre::GpuProgramParametersSharedPtr VP_Parameters = DM_Technique_Pass0->getVertexProgramParameters();
3389 Ogre::GpuProgramParametersSharedPtr FP_Parameters = DM_Technique_Pass0->getFragmentProgramParameters();
3393 VP_Parameters->setNamedAutoConstant(
"uWorldViewProj", Ogre::GpuProgramParameters::ACT_WORLDVIEWPROJ_MATRIX);
3394 VP_Parameters->setNamedAutoConstant(
"uCameraPos", Ogre::GpuProgramParameters::ACT_CAMERA_POSITION);
3396 VP_Parameters->setNamedAutoConstant(
"uWorld", Ogre::GpuProgramParameters::ACT_WORLD_MATRIX);
3410 FP_Parameters->setNamedConstant(
"uCaustics", 0);
3412 Ogre::TextureUnitState *TUS_Caustics = DM_Technique_Pass0->createTextureUnitState(
"Caustics.bmp");
3413 TUS_Caustics->setName(
"Caustics");
3414 TUS_Caustics->setTextureAddressingMode(Ogre::TextureUnitState::TAM_WRAP);
3415 TUS_Caustics->setAnimatedTextureName(
"Caustics.bmp", 32, 1.5);
3431 Technique->removeAllPasses();
3432 Technique->createPass();
3433 Technique->setName(
"_Hydrax_DepthTexture_Technique");
3434 Technique->setSchemeName(
"HydraxDepth");
3436 Ogre::Pass *DM_Technique_Pass0 = Technique->getPass(0);
3439 DM_Technique_Pass0->setName(AlphaChannel);
3444 DM_Technique_Pass0->setSceneBlending(Ogre::SBT_TRANSPARENT_ALPHA);
3445 DM_Technique_Pass0->setDepthCheckEnabled(
true);
3446 DM_Technique_Pass0->setDepthWriteEnabled(
false);
3448 Ogre::GpuProgramParametersSharedPtr VP_Parameters = DM_Technique_Pass0->getVertexProgramParameters();
3449 Ogre::GpuProgramParametersSharedPtr FP_Parameters = DM_Technique_Pass0->getFragmentProgramParameters();
3453 VP_Parameters->setNamedAutoConstant(
"uWorldViewProj", Ogre::GpuProgramParameters::ACT_WORLDVIEWPROJ_MATRIX);
3454 VP_Parameters->setNamedAutoConstant(
"uCameraPos", Ogre::GpuProgramParameters::ACT_CAMERA_POSITION);
3456 VP_Parameters->setNamedAutoConstant(
"uWorld", Ogre::GpuProgramParameters::ACT_WORLD_MATRIX);
3470 FP_Parameters->setNamedConstant(
"uCaustics", 0);
3472 Ogre::TextureUnitState *TUS_Caustics = DM_Technique_Pass0->createTextureUnitState(
"Caustics.bmp");
3473 TUS_Caustics->setName(
"Caustics");
3474 TUS_Caustics->setTextureAddressingMode(Ogre::TextureUnitState::TAM_WRAP);
3475 TUS_Caustics->setAnimatedTextureName(
"Caustics.bmp", 32, 1.5);
3480 FP_Parameters->setNamedConstant(
"uAlphaTex", 0);
3482 Ogre::TextureUnitState *TUS_AlphaTex = DM_Technique_Pass0->createTextureUnitState(TextureName);
3483 TUS_AlphaTex->setName(
"_DetphTexture_Hydrax");
3484 TUS_AlphaTex->setTextureAddressingMode(Ogre::TextureUnitState::TAM_CLAMP);
3494 Ogre::CompositorPtr &Comp =
mCompositors[
static_cast<int>(Compositor)];
3501 Ogre::CompositorManager::getSingleton().
3534 Ogre::GpuProgramParametersSharedPtr Parameters;
3540 Parameters =
getMaterial(MType)->getTechnique(0)->getPass(0)->getVertexProgramParameters();
3546 Parameters =
getMaterial(MType)->getTechnique(0)->getPass(0)->getFragmentProgramParameters();
3551 Parameters->setNamedConstant(Name, Value);
3555 std::vector<Ogre::Technique*>::iterator TechIt;
3569 Parameters = (*TechIt)->getPass(0)->getVertexProgramParameters();
3575 Parameters = (*TechIt)->getPass(0)->getFragmentProgramParameters();
3580 Parameters->setNamedConstant(Name, Value);
3592 Ogre::GpuProgramParametersSharedPtr Parameters;
3598 Parameters =
getMaterial(MType)->getTechnique(0)->getPass(0)->getVertexProgramParameters();
3604 Parameters =
getMaterial(MType)->getTechnique(0)->getPass(0)->getFragmentProgramParameters();
3609 float Value_[2] = {Value.x, Value.y};
3613 std::vector<Ogre::Technique*>::iterator TechIt;
3627 Parameters = (*TechIt)->getPass(0)->getVertexProgramParameters();
3633 Parameters = (*TechIt)->getPass(0)->getFragmentProgramParameters();
3638 Parameters->setNamedConstant(Name, Value_, 1, 2);
3650 Ogre::GpuProgramParametersSharedPtr Parameters;
3656 Parameters =
getMaterial(MType)->getTechnique(0)->getPass(0)->getVertexProgramParameters();
3662 Parameters =
getMaterial(MType)->getTechnique(0)->getPass(0)->getFragmentProgramParameters();
3667 Parameters->setNamedConstant(Name, Value);
3671 std::vector<Ogre::Technique*>::iterator TechIt;
3685 Parameters = (*TechIt)->getPass(0)->getVertexProgramParameters();
3691 Parameters = (*TechIt)->getPass(0)->getFragmentProgramParameters();
3696 Parameters->setNamedConstant(Name, Value);
3705 Ogre::Pass* DM_Technique0_Pass0 = mat->getTechnique(0)->getPass(0);
3706 DM_Technique0_Pass0->getTextureUnitState(2)->setTextureName(
"HydraxDepthMap");
3712 const Ogre::Vector3& WC = mMaterialManager->mHydrax->getWaterColor();
3713 Ogre::CompositorPtr &UnderwaterCompositor = mMaterialManager->getCompositor(
COMP_UNDERWATER);
3714 UnderwaterCompositor->getTechnique(0)->getTargetPass(0)->getPass(0)->setClearColour(Ogre::ColourValue(WC.x, WC.y, WC.z));
3716 Ogre::GpuProgramParametersSharedPtr FP_Parameters = mat->getTechnique(0)->getPass(0)->getFragmentProgramParameters();
3721 setNamedConstant(
"uWaterColor", mMaterialManager->mHydrax->getWaterColor());
3727 setNamedConstant(
"uCausticsPower", mMaterialManager->mHydrax->getCausticsPower());
3733 setNamedConstant(
"uSunColor", mMaterialManager->mHydrax->getSunColor());
3735 FP_Parameters->setNamedConstant(
"uLightDirection",
3736 (mMaterialManager->mHydrax->getMesh()->getObjectSpacePosition(mMaterialManager->mHydrax->getCamera()->getPosition()) -
3737 mMaterialManager->mHydrax->getMesh()->getObjectSpacePosition(mMaterialManager->mHydrax->getSunPosition()))
3740 FP_Parameters->setNamedConstant(
"uIntensity", mMaterialManager->mHydrax->getGodRaysIntensity());
3741 FP_Parameters->setNamedConstant(
"uHGg", mMaterialManager->mHydrax->getGodRaysExposure());
3743 Ogre::GpuProgramParametersSharedPtr VP_Parameters = mat->getTechnique(0)->getPass(0)->getVertexProgramParameters();
3747 setNamedConstant(
"uCorner0", mMaterialManager->mHydrax->getCamera()->getWorldSpaceCorners()[5] );
3750 setNamedConstant(
"uCorner01", mMaterialManager->mHydrax->getCamera()->getWorldSpaceCorners()[4] - mMaterialManager->mHydrax->getCamera()->getWorldSpaceCorners()[5]);
3753 setNamedConstant(
"uCorner02", mMaterialManager->mHydrax->getCamera()->getWorldSpaceCorners()[6] - mMaterialManager->mHydrax->getCamera()->getWorldSpaceCorners()[5]);
3767 Ogre::Pass* DM_Technique0_Pass0 = mat->getTechnique(0)->getPass(0);
3768 DM_Technique0_Pass0->getTextureUnitState(2)->setTextureName(
"HydraxDepthMap");
3771 mMaterialManager->mCompositorsNeedToBeReloaded[
COMP_UNDERWATER] =
false;