查看: 1216|回复: 1

请问array老师那个myocean的例子里边的水效的一些问题!

[复制链接]

该用户从未签到

发表于 2012-7-11 16:40:10 | 显示全部楼层 |阅读模式
如题:
我没有修改array老师的那个着色器代码,但是应用的时候发现了一些问题。如图所示: 未命名.jpg ,应用array老师给的那个着色器代码后,当相机从湖面的正上方向下看时(视线垂直湖面),湖面看着是很好很正常的,可是如果是站在湖边看的时候,却出现了如图中的样子,湖面有一道道的白色的条纹,应该是光照计算的问题,我也修改过,没有什么反应,不知道哪里出了问题!着色器代码:
顶点着色器:
const float Eta = 0.0;
const float FresnelPower = 1.0;

const float F = ((1.0-Eta) * (1.0-Eta))/((1.0+Eta) * (1.0+Eta));
varying float FresRatio;

varying vec3 lightDir;
varying vec3 eyeDir;
varying vec3 reflectDir;
varying vec3 refractDir;

attribute vec3 Tangent;
uniform vec3 LightPos;
uniform float time;

void main(void)
{


gl_Position = ftransform();
vec4 v = vec4(gl_Vertex);
vec3 norm = normalize(gl_NormalMatrix * gl_Normal);
vec3 tang = normalize(gl_NormalMatrix * Tangent);
vec3 binorm = cross(norm,tang);
   
eyeDir = vec3(gl_ModelViewMatrix * v);

//for refraction
vec4 neyeDir = gl_ModelViewMatrix * v;
vec3 refeyeDir = neyeDir.xyz / neyeDir.w;
refeyeDir = normalize(refeyeDir);

reflectDir = reflect(eyeDir,norm);
refractDir = refract(eyeDir,norm,Eta);
refractDir = vec3(gl_TextureMatrix[0] * vec4(refractDir,1.0));
FresRatio = F + (1.0-F) * pow((1.0-dot(-refeyeDir,norm)),FresnelPower);


vec3 tmp;
tmp.x = dot(LightPos,tang);
tmp.y = dot(LightPos,binorm);
tmp.z = dot(LightPos,norm);
lightDir = normalize(tmp);

tmp.x = dot(eyeDir,tang);
tmp.y = dot(eyeDir,binorm);
tmp.z = dot(eyeDir,norm);
eyeDir = normalize(tmp);



gl_TexCoord[0] = gl_MultiTexCoord0;

   vec4 texco = gl_MultiTexCoord0;
   texco.s = texco.s + time*0.01;
   texco.t = texco.t + time*0.01;
   texco.r = texco.r + time*0.03;
  
gl_TexCoord[1] = texco;

   texco = gl_MultiTexCoord0;
   texco.s = texco.s + -time*0.01;
   texco.t = texco.t + -time*0.01;
   texco.r = texco.r + time*0.03;
   
gl_TexCoord[2] = texco;
   
}

片元着色器:
varying vec3 lightDir;
varying vec3 eyeDir;
varying vec3 reflectDir;
varying vec3 refractDir;
varying float FresRatio;
uniform sampler2D normalMap;
uniform samplerCube cubeMap;


void main (void)
{

   float distSqr = dot(lightDir, lightDir);
   float att = clamp(1.0 - 0.0 * sqrt(distSqr), 0.0, 1.0);
   vec3 lVec = lightDir * inversesqrt(distSqr);

   vec3 vVec = normalize(eyeDir);

   vec4 base = vec4(0.17,0.67,0.93,1.0); //base water color
   //vec4 base = vec4(0.57,0.87,0.93,1.0); //base water color
   
   vec3 bump = normalize( texture2D(normalMap, gl_TexCoord[1].str).xyz * 2.0 - 1.0);
   vec3 secbump = normalize( texture2D(normalMap, gl_TexCoord[2].str).xyz * 2.0 - 1.0);
   vec3 modbump = mix(secbump,bump,0.5);
   //vec3 modbump = secbump;
   //vec3 modbump = bump;
  
   //vec3 reflection = vec3(textureCube(cubeMap,reflect(-lightDir,modbump)));
   vec3 reflection = vec3(textureCube(cubeMap,reflect(eyeDir,modbump)));
   vec3 refraction = vec3(textureCube(cubeMap,refract(eyeDir,modbump,0.66)));
   vec3 cubemap = mix(reflection,refraction,FresRatio);
   //vec3 cubemap = mix(reflection,refraction,0.0);


   vec4 vAmbient = gl_LightSource[0].ambient;

  float diffuse = max( dot(-lVec, modbump), 0.0 );
   
   vec4 vDiffuse = gl_LightSource[0].diffuse * gl_FrontMaterial.diffuse * diffuse;   
   float specular = 0.0*pow(clamp(dot(reflect(lVec, modbump), vVec), 0.0, 1.0), 0.5 );
   
   vec4 vSpecular = gl_LightSource[0].specular * gl_FrontMaterial.specular * specular;   
   
   vec4 newfrag = mix(vec4(cubemap,1.0) , (( vAmbient*base + vDiffuse*base * vSpecular*base ) * att),0.1);
   //vec4 newfrag = mix(vec4(cubemap,1.0) , (( vAmbient*base + vDiffuse*base + vSpecular*base ) * att),0.1);
   //vec4 newfrag = mix(vec4(cubemap,1.0) , vDiffuse*base ,0.1);
   
   gl_FragColor = newfrag; //mix(vec4(cubemap,1.0),base,0.5) ; //newfrag;
   //gl_FragColor = mix(vec4(cubemap,1.0),base,0.1) ;
}

该用户从未签到

 楼主| 发表于 2012-7-11 16:48:38 | 显示全部楼层
1.jpg ,这个是从湖面正上方看的时候的样子,没有什么问题!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

OSG中国官方论坛-有您OSG在中国才更好

网站简介:osgChina是国内首个三维相关技术开源社区,旨在为国内更多的技术开发人员提供最前沿的技术资讯,为更多的三维从业者提供一个学习、交流的技术平台。

联系我们

  • 工作时间:09:00--18:00
  • 反馈邮箱:1315785073@qq.com
快速回复 返回顶部 返回列表