gpt-4-0314· openai
Suzhen/CodeChat
用glsl帮我实现一块陆地,陆地上有几个小山丘
- User
用glsl帮我实现一块陆地,陆地上有几个小山丘
- Assistant
我可以为你提供一个基本的示例,你可以基于它进一步扩展。以下是使用GLSL生成具有一些小山丘的陆地的方式。这个示例将基于噪声生成一些简单的小山丘。
#ifdef GL_ES precision mediump float; #endif uniform float u_time; uniform vec2 u_resolution; float noise(vec2 st) { vec2 i = floor(st); vec2 f = fract(st); // Calculate derivatives of the smoothstep function vec3 nor = vec3(-1.0 + 2.0*f, 0); // Get random numbers for the four surrounding pixel coordinates float a = dot(nor, vec3(0.0, 0.0)); float b = dot(nor, vec3(1.0, 0.0)); float c = dot(nor, vec3(0.0, 1.0)); float d = dot(nor, vec3(1.0, 1.0)); // Interpolate between the values at the four surrounding pixel coordinates float u = f.x * f.x * (3.0 - 2.0 * f.x); float v = f.y * f.y * (3.0 - 2.0 * f.y); float value = mix(a, b, u) + (c - a) * v * (1.0 - u) + (d - b) * u * v; return value; } void main() { vec2 st = gl_FragCoord.xy/u_resolution.xy; vec3 color = vec3(0.0); // Generate terrain height based on the noise function float height = noise(st * 10.0); height = pow(height, 2.5); // Add some color to the terrain based on the height color.r = height; color.g = height * 0.5; color.b = height * 0.2; gl_FragColor = vec4(color, 1.0); }
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.