问题描述
我目前正在学习如何使用GLSL将2d纹理映射到3d对象。我有一个main.cpp,片段着色器和顶点着色器以及一些PNG图像来实现这一点。
下面列出了我的片段着色器代码以供参考:
#version 410
// Inputs from application.
// Generally,"in" like the eye and normal vectors for things that change frequently,// and "uniform" for things that change less often (think scene versus vertices).
in vec3 position_eye,normal_eye;
uniform mat4 view_mat;
// This light setup would usually be passed in from the application.
vec3 light_position_world = vec3 (10.0,25.0,10.0);
vec3 Ls = vec3 (1.0,1.0,1.0); // neutral,full specular color of light
vec3 Ld = vec3 (0.8,0.8,0.8); // neutral,lessened diffuse light color of light
vec3 La = vec3 (0.12,0.12,0.12); // ambient color of light - just a bit more than dk gray bg
// Surface reflectance properties for Phong or Blinn-Phong shading models below.
vec3 Ks = vec3 (1.0,1.0); // fully reflect specular light
vec3 Kd = vec3 (0.32,0.18,0.5); // purple diffuse surface reflectance
vec3 Ka = vec3 (1.0,1.0); // fully reflect ambient light
float specular_exponent = 400.0; // specular 'power' -- controls "roll-off"
// These come from the VAO for texture coordinates.
in vec2 texture_coords;
// And from the uniform outputs for the textures setup in main.cpp.
uniform sampler2D texture00;
uniform sampler2D texture01;
out vec4 fragment_color; // color of surface to draw
void main ()
{
// Ambient intensity
vec3 Ia = La * Ka;
// These next few lines sample the current texture coord (s,t) in texture00 and 01 and mix.
vec4 texel_a = texture (texture00,fract(texture_coords*2.0));
vec4 texel_b = texture (texture01,fract(texture_coords*2.0));
vec4 mixed = mix (texel_a,texel_b,texture_coords.x);
Kd.x = mixed.x;
Kd.y = mixed.y;
Kd.z = mixed.z;
// Transform light position to view space.
// Vectors here are appended with _eye as a reminder once in view space versus world space.
vec3 light_position_eye = vec3 (view_mat * vec4 (light_position_world,1.0));
vec3 distance_to_light_eye = light_position_eye - position_eye;
vec3 direction_to_light_eye = normalize (distance_to_light_eye);
// Diffuse intensity
float dot_prod = dot (direction_to_light_eye,normal_eye);
dot_prod = max (dot_prod,0.0);
vec3 Id = Ld * Kd * dot_prod; // final diffuse intensity
// Specular is view dependent; get vector toward camera.
vec3 surface_to_viewer_eye = normalize (-position_eye);
// Blinn
vec3 half_way_eye = normalize (surface_to_viewer_eye + direction_to_light_eye);
float dot_prod_specular = max (dot (half_way_eye,normal_eye),0.0);
float specular_factor = pow (dot_prod_specular,specular_exponent);
// Specular intensity
vec3 Is = Ls * Ks * specular_factor; // final specular intensity
// final color
fragment_color = vec4 (Is + Id + Ia,1.0);
}
我在终端中输入以下命令来运行我的软件包: ./go fs.glsl与.glsl Sphere.obj image.png image2.png
我需要通过将s,t纹理坐标乘以整数来修改片段着色器,然后使用frac()函数创建平铺效果。我是否只需在texel_a和texel_b的fract()函数中更改整数值?任何示例都很赞赏。
此外,我将如何实施“ Wang”拼贴?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)