RError.com

RError.com Logo RError.com Logo

RError.com Navigation

  • 主页

Mobile menu

Close
  • 主页
  • 系统&网络
    • 热门问题
    • 最新问题
    • 标签
  • Ubuntu
    • 热门问题
    • 最新问题
    • 标签
  • 帮助
主页 / 问题 / 753344
Accepted
Павел Игорев
Павел Игорев
Asked:2020-12-04 05:40:18 +0000 UTC2020-12-04 05:40:18 +0000 UTC 2020-12-04 05:40:18 +0000 UTC

是否可以在 svg 中制作整个网站?

  • 772

如果网站的 html-layout 只用svg图片来做,而不是标准的imgor png,会不会有问题呢?跨浏览器兼容性等等?

html
  • 3 3 个回答
  • 10 Views

3 个回答

  • Voted
  1. Alexandr_TT
    2020-12-04T22:21:29Z2020-12-04T22:21:29Z

    是否可以在 svg 中制作整个网站?

    答案是不。因为这个问题太宽泛了。
    如果作者问 - 是否可以在 SVG 上制作所有设计图形、动画、交互式制图?那么答案将是 - 是的!
    因为 SVG 格式正是为此而设计的。网站上的图形应该是矢量,而不是光栅。我不想重复关于这个话题的陈词滥调——向量的重量更轻,这意味着网站飞得更快。根据定义,矢量是可扩展的,因此无需特殊技巧即可使网站在小型智能手机屏幕和巨型视频面板上看起来同样出色。

    2021年2月26日,Scalable Vector Graphics SVG2正式版 发布

    同时,SVG的可能性也大大扩展。特别是有一个新元素Mesh gradients

    在此处输入图像描述 在此处输入图像描述

    锥形渐变

    在此处输入图像描述

    • 关于动画的单独谈话SVG SMIL。

    四年来,他一直在Chrome写 smil 被“弃用”——翻译过来的意思是他不赞成 smil,但每次都延长了对 smil 的支持。

    看,这已经从当前版本的 45 版到 78 版Chrome,并且现在已经扩展到至少77更新 81的未来版本。正如他们所说,没有什么比暂时更永恒。
    为什么会出现这种情况,为什么smil没有关闭,近期也不会关闭?
    因为主要竞争对手:CSS Animations Level 1, Web Animations 没有达到 smil SVG 的水平。
    所有类型的,任何带有代码表的复杂 CSS 动画,都可以在 SVG 上用几行轻松简单地实现。另一方面,将一些 SVG 动画示例转换为 CSS 是根本不可能的。
    例如:沿文本、对象、标记的弯曲路径移动。

      <svg  width="55%" height="55%"  viewBox="0 0 300 200" >
     
    <defs>
    <style type="text/css"><![CDATA[
        #startButton:hover {
            text-decoration: underline;
            fill:green;
            opacity: 0.5;
                        }
        #stop:hover{
            opacity: 0.5; 
                   }     
             ]]> 
             
        
     </style>  
     <marker id="mark_path" viewBox="0 0 10 10" refX="1" refY="5" 
            markerUnits="strokeWidth" orient="auto"
              markerWidth="4" markerHeight="3">
            <polyline points="0,0 10,5 0,10 1,5" fill="black" />
     </marker>
     
      <linearGradient id="grad1" x2="0%" y2="100%"
            spreadMethod="pad" >
      <stop offset="0%" stop-color="skyblue"/>
      <stop offset="90%" stop-color="white"/> 
      <stop offset="100%" stop-color="yellowgreen"/>
    </linearGradient>
    
      <path id="balerina" transform="scale(0.05)  translate(-100 -200)"   d="M468 264c1 3 2 7 4 10 5 12 12 23 15 28s1 5 2 9c1 4 6 14 9 19 3 6 5 8 5 9 0 1-3 1-3 5s4 12 7 18 5 9 5 10c0 1-3 1-4 2 -2 2-3 5-5 7 -2 2-6 3-9 3 -3 0-6 0-8-1 -2-1-3-3-6-4 -2-1-5 0-8-2 -2-2-4-7-6-10 -2-3-5-4-7-6 -2-3-3-8-5-11 -2-3-5-5-7-8 -2-3-2-7-4-7 -1 0-3 4-5 10s-6 17-7 24 0 13-1 20c0 7-2 15-3 23 -1 8 0 16 2 30 2 14 5 34 9 49 3 14 6 23 7 32s0 19-2 28c-2 9-4 17-5 21s-2 5-4 6c-2 0-7 0-9-2 -2-2-1-6-1-12 0-6 0-15-2-21s-4-8-7-10c-3-3-6-5-8-9 -2-3-1-7 0-9 2-2 5-4 7-6 2-2 3-4 2-8 -1-3-2-8-7-17 -4-9-11-24-15-39s-3-32-4-45 0-21-1-35c-1-13-2-31-4-46 -1-15-3-28-4-36 -1-8-2-11-9-14 -7-4-20-8-36-14 -16-6-34-13-45-18 -12-6-17-10-24-15 -7-4-15-9-27-15 -11-6-26-15-37-20 -11-5-19-7-28-10 -9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-3s8 0 13 1c4 1 8 4 11 7 2 3 3 6 4 9s4 4 6 5c2 1 4 2 4 3 0 1-2 3-3 4 -1 1-1 2 0 3s2 2 2 3c0 1 0 2 0 2s1 1 1 2c0 1 0 2 0 4 0 2 1 3 1 4 0 1 0 3-2 3 -2 1-7 2-10 4 -3 3-4 7-3 12 1 5 3 11 5 14 3 3 5 3 9 2 4-2 9-5 15-8 6-2 12-4 19-7 8-3 17-9 24-15 7-5 11-11 18-16s15-10 21-15c6-4 9-7 14-11 4-4 9-8 13-10 5-2 9-2 15-3 6 0 12-1 17-1 4 0 6-1 8-1 2 0 4 0 7 0 3 0 6 0 9 1 3 1 6 3 5 4 -1 1-4 0-11 0 -6 0-14 2-18 3 -4 1-2 2 0 4 2 1 6 3 7 4 1 1 1 2-1 2 -2 0-4 0-8-1 -4 0-10 0-15-1s-8-2-10-2 -3 1-5 2c-2 2-6 5-12 11 -6 6-15 15-22 22 -7 7-12 11-22 19 -10 8-25 18-35 25 -10 7-14 9-15 13 -1 4 1 9 1 18 0 9-3 22-8 34 -5 12-12 22-17 33 -6 11-11 21-13 32C469 262 468 263 468 264z" fill-rule="evenodd" />
         
    
     </defs>
        
    
       <rect x="0" y="0" width="100%" height="100%" fill="url(#grad1)" stroke="none" />
    
        <path id="t_path"  d="m28 30c16-18 51-12 72-1 35 18 34 79 66 96 32 17 79 24 102 0C291 102 295 43 266 25 194-19 112 177 38 136 7 118 4 56 28 30Z" marker-mid="url(#mark_path)" stroke="#c3c3c3" stroke-width="1" fill="none"   />
    
    
        
         
          <path transform="  scale(0.15) scale(-1 1) translate(-10 -200) " fill="black"  d="m142.2 23.5c9-0.1 3.7-16.5 10.9-17.7 2.9-0.5 4 1.1 6.3 2.3 0.1 2.4-1.7 2.9-2.3 4.6 2.1 1.8 3.6-0.6 5.7-0.6 0.7 4-5.3 3.2-6.9 1.7-1.2-2.1 0.4-3.4 1.1-5.1-8.1-3.6-5 5.1-6.3 9.7-1.9 6.9-12.7 10.8-13.7 1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-0.5 2.8 1.3 4 0 0.2-2.9-4-2.7-4 0zm49.2 23.5c0.8-1.7 0.5-3.3-1.7-3.4 0.5 1.3 0.3 3.1 1.7 3.4zm5.2 6.3c-0.3-2.3-1.3-4.1-3.4-4.6-1.3 2 1.6 3.9 3.4 4.6z" fill-rule="evenodd">
         <animateMotion  begin="startButton.mouseover+0.1s" end="stopRed.mouseover"
             dur="18s" repeatCount="1" rotate="auto" fill="freeze" restart="whenNotActive" >
             <mpath xlink:href="#t_path" />
        </animateMotion>
         </path>
    
    <use xlink:href="#balerina"  style="fill:orangered;"  >
         <animateMotion  begin="startButton.mouseover+0.25s" end="stopOrangered.mouseover"
             dur="6s" repeatCount="2" rotate="auto" fill="freeze" restart="whenNotActive" >
             <mpath xlink:href="#t_path" />
        </animateMotion>
    </use>  
    
    <use xlink:href="#balerina"  style="fill:purple;" >
         <animateMotion  begin="startButton.mouseover+0.25s" end="stopTeal.mouseover"
             dur="8s" repeatCount="2" rotate="auto" fill="freeze" restart="whenNotActive" >
             <mpath xlink:href="#t_path" />
        </animateMotion>
    </use>
    
        
    <g  id="startButton" transform="scale(0.7) translate(-20 220)" >
    <rect  x="20" y="20" rx="3" ry="3" width="60" height="20" fill="deepskyblue" />
    <text  x="50" y="35" font-size="16" font-weight="bold" font-family="Arial" text-anchor="middle" 
    fill="white" >Start</text> 
    </g>
     <g transform="translate(95 -5)">
    <g id="stop" fill-opacity="1" > 
       <rect  x="180" y="140" rx="3" ry="3" width="20" height="60" fill="none" stroke-width="2px" stroke="#c3c3c3" />           
        <g id="stopRed" >
            <circle  r="6" cx="190" cy="150" fill="none" stroke="black"  /> 
            <circle  r="4" cx="190" cy="150" fill="black"  />   
        </g>    
            <g id="stopOrangered" >
                <circle  r="6" cx="190" cy="170" fill="none" stroke="black"  /> 
                <circle  r="4" cx="190" cy="170" fill="orangered" stroke="orange"  />   
            </g>
        <g id="stopTeal" >
            <circle r="6" cx="190" cy="190" fill="none" stroke="black"  />  
            <circle  r="4" cx="190" cy="190" fill="darkblue" stroke="orange"  />    
        </g>        
        
    </g>
        <text  x="170" y="170"  transform="rotate(-90 170,170)" 
          font-size="18" font-weight="bold" font-family="serif" text-anchor="middle" fill="gray"  >Stop
        </text>
    </g>    
    </svg>

    另一个例子

    使用贝塞尔曲线动画链接

    将鼠标悬停在链接上时动画开始

    <!DOCTYPE html>
    <html>
     <head>
      <meta charset="utf-8">
     
     </head>
     
     <body>  
     <style>
      svg {
      background-image: url(https://s3-us-west-2.amazonaws.com/s.cdpn.io/4273/hawaii-beach.jpg);
      background-size:cover;
      width:50%
      height:50%
      }
     </style>
      
     <svg   viewBox="0 0 600 500">
        
     
    <defs> 
     <path id="Lsvg" d="M100 200Q200,200 300,200 T500,200" style="stroke:teal;fill-opacity:0.3;stroke-width:3;fill:none">
    <animate begin="animLink.mouseover"  dur="10s" restart="whenNotActive"  attributeName="d" 
    values="M100 200Q200,200 300,200 T500,200;
    M100 200Q200,100 300,200 T500,200;
    M100 200Q200,200 300,200 T500,200;
    M100 200Q200,300 300,200 T500,200;
    M100 200Q200,200 300,200 T500,200"/> 
    </path>
    
    </defs>
    <text text-anchor="middle" font-size="25" fill="#026282">
          <textPath id="result" method="align" spacing="auto" startOffset="50%" xlink:href="#Lsvg"><tspan dy="-20">So easy to do with SVG just  few lines</tspan></textPath>
    <animate begin="animLink.mouseover"   dur="10s" repeatCount="1" attributeName="fill"
    values="red;green;red;green;red"/>
    </text>
    <use xlink:href="#Lsvg" transform="translate(0 -10)"/>
       
      <rect id="animLink" x="100" y="150" width="400" height="60" fill="#E0E0E0" fill-opacity="0.01" stroke="none" />  
    
        </svg>
     </body>
     </html>

    • SVG 和 CSS 相得益彰。CSS 在其规则中包含了 SVG 属性和参数。

    例如:用于线条着色,svg 元素的颜色填充,添加到 cssstroke:#中,fill:#

    可以在 SVG 和 CSS 中使用的所有属性的列表

    2018 年 10 月 20 日更新

    链接到一个完全用 SVG 制作的网站:

    在此处输入图像描述

    • 35
  2. Best Answer
    Гончаров Александр
    2020-12-04T06:15:51Z2020-12-04T06:15:51Z

    viewBox对于SVG,如果您希望 svg 表现得像图像,则需要指定一个属性。否则 svg 将无法缩放。这有多大的问题取决于你。否则,现代浏览器已经支持 svg 很长时间了,您不必担心。

    第二个问题是 svg 比 png 更难制作。艺术家/设计师倾向于使用光栅图形:矢量 svg 比新方法更能有效地添加到网络中。

    例如,它针对矢量图形进行了锐化Flash,但现在不存在。

    • 18
  3. Stranger in the Q
    2020-03-14T22:40:49Z2020-03-14T22:40:49Z

    如果该站点不是用于阅读,而是一个 Web 应用程序,例如用于绘图或播放,那么在我看来,它至少应该使用SVG来完成。

    还有CANVAS,当SVG由于仍然是DOM元素而开始缓慢工作时,或者当SVG的功能不够用时(3D 图形),它可以提供帮助。


    SVG 的优点:

    1. 所有这一切都源于 SVG 是一种具有相当简单语法的矢量格式,允许您轻松创建“复杂形状”元素。

    2. 易于交互——通过对 DOM 事件的支持,对 CSS 的支持,就像 HTML 元素一样。

    3. 用于处理滤镜、蒙版、动画的最丰富的内置功能。


    SVG的缺点:

    1. 毕竟这是一个 DOM 结构,如果很大,那么渲染速度可能会下降。

    2. 不同的浏览器/设备支持不同的规范。

    3. 与HTML相比,很难输入纯文本,但没有人禁止为此使用纯HTML


    示例,样条编辑器和对称性,请参阅扩展:

    样条对称

    let size = 800;
    
    let color = d3.scaleLinear(d3.schemeCategory10)
    
    var points = d3.range(0, 5).map(function(i) {
      return [
          size/2 - Math.sin(i/3)*100*Math.random(), 
          size/2 + i*(33+33*Math.random())];
    });
    
    let dragged = null,
        selected = points[points.length-1];
    
    let line = d3.line().curve(d3.curveCardinal);
    
    let svg = d3.select("svg")
        .attr("width", size)
        .attr("height", size);
    
    svg.append("rect")
        .attr("width", size)
        .attr("height", size)
        .on("mousedown", mousedown);
    
    let copies = svg.append("g");
    
    let path = svg.append("path")
        .style("stroke", 'red')
        .datum(points)
        .classed("line", true);
    
    d3.select(window)
        .on("mousemove", mousemove)
        .on("mouseup", mouseup);
    
    fillCopies();
    redraw();
    
    d3.select('#axes').on('input', redraw)
    
    function fillCopies() {
        
      copies.html('');
      let axes = d3.select('#axes').node().value;
      for (let i = 0; i < axes; i++) {
          
          let transformValue = `
            translate(${size/2} ${size/2}) 
            rotate(${i*(360/axes)}) 
            translate(${-size/2} ${-size/2})
          `;
          
           axes-1&&copies.append("line")
            .attr('x1', -size)
            .attr('y1', size/2)
            .attr('x2', size/2)
            .attr('y2', size/2)
            .attr('transform', transformValue)
          
          i && copies.append("path")
            .style('stroke', color(i/axes))
            .attr('transform', transformValue)
            .datum(points)
            .classed("line", true)
      
      }
    }
    
    
    function redraw() {
        
      fillCopies();
        
      svg.selectAll("path").attr("d", line);  
    
      var circle = svg.selectAll("circle.knob")
          .data(points, d => d);
    
      circle.exit()
          .remove();
        
      let newNodes = circle.enter()
          .append("circle")
          .classed('knob', true)
          .attr("r", 1e-6)
          .on("mousedown", d => { 
              selected = dragged = d; 
              redraw(); 
          })
          .transition()
          .duration(250)
          .attr("r", 6.5);
    
      circle.merge(newNodes)
          .classed("selected", d => d === selected)
          .attr("cx", d => d[0])
          .attr("cy", d => d[1]);
    
      if (d3.event) {
        d3.event.preventDefault();
        d3.event.stopPropagation();
      }
    }
    
    function mousedown() {
      points.push(selected = dragged = d3.mouse(svg.node()));
      redraw();
    }
    
    function mousemove() {
      if (!dragged) 
          return;
      let m = d3.mouse(svg.node());
      dragged[0] = Math.max(0, Math.min(size, m[0]));
      dragged[1] = Math.max(0, Math.min(size, m[1]));
      redraw();
    }
    
    function mouseup() {
      if (!dragged) 
          return;
      mousemove();
      dragged = null;
    }
    
       
    body {
        margin: 0;
    }
    
    rect {
      fill: none;
      pointer-events: all;
    }
    
    line {
       stroke: gray; 
       stroke-dasharray: 5 10;
    }
    
    circle,
    .line {
      fill: none;
      stroke: red;
      stroke-width: 1.5px;
    }
    
    circle {
      fill: #fff;
      fill-opacity: .2;
      cursor: move;
    }
    
    .selected {
      fill: #ff7f0e;
      stroke: #ff7f0e;
    }
    
    .ui {
        padding: 5px;
        padding-top: 10px;
        box-shadow:  0 1px 1px 0 lightgray;
    }
    <script src="https://cdnjs.cloudflare.com/ajax/libs/d3/5.7.0/d3.min.js"></script>
    <div class="ui">
    <input type="range" min=1 max=99 value=3 id="axes"></input>
    </div>
    <svg></svg>


    帆布的优点:

    1. 2D 和 3D 上下文的可用性。

    2. 图形编程几乎无限的可能性,这一切都取决于你是否能快速工作。

    3. 能够利用显卡的强大功能,不仅用于图形,还用于计算。

    4. 您将能够在(网络)编程中发现新的东西=)


    画布的缺点:

    1. 相对复杂 (2D) 和非常复杂 (3D) API。(进入门槛高)

    2. 缺乏与元素交互的机制,即 您自己需要检查用户携带鼠标的位置并自己做出反应。

    3. 调试难度。(您在检查器中什么都不看,等等)


    示例:3D 分形 - Menger Sponge,使用片段着色器中的光线追踪获得。

    在示例中实现:

    • 带有移动光源的 phong 照明/阴影

    • 柔和的阴影

    • 环境光遮蔽

    控制:

    拖动=旋转

    滚动=缩放

    门格尔海绵

    let fragCode = [...document.scripts].find(s => s.type === "frag").textContent;
    
    let fst = FullScreenTriangle(fragCode);
    let resolution = fst.triangleProgram.uniform('2f', 'resolution');
    let time = fst.triangleProgram.uniform('1f', 'time');
    let eye = fst.triangleProgram.uniform('3f', 'eye');
    let lightPos = fst.triangleProgram.uniform('3f', 'lightPos');
    let started = new Date().getTime();
    
    Mouse3D.init();
    
    animate();
    
    function animate() {
        requestAnimationFrame(animate);
        drawFrame();
    }
    
    function drawFrame() {
        let t = (new Date().getTime() - started)/1000;
        resolution.set(fst.gl.drawingBufferWidth, fst.gl.drawingBufferHeight);
        time.set(t);
        eye.set(Mouse3D.eye[0], Mouse3D.eye[1], Mouse3D.eye[2]);
        lightPos.set(Math.cos(t/3)*0.8,0,Math.sin(t/3)*0.8);
        fst.draw();
    }
    body {
        margin: 0;
        overflow: hidden
    }
    canvas {
        position: absolute;
        width: 100%;
        height: 100%;
    }
    <script src="https://cdn.jsdelivr.net/gh/strangerintheq/glx@0.0.2/js/glx.js"></script>
    <script src="https://cdn.jsdelivr.net/gh/strangerintheq/glx@0.0.2/js/ShaderLoader.js"></script>
    <script src="https://cdn.jsdelivr.net/gh/strangerintheq/glx@0.0.2/js/FullScreenTriangle.js"></script>
    <script src="https://cdn.jsdelivr.net/gh/strangerintheq/glx@0.0.2/js/mouse3d.js"></script>
    
    <script type="frag">
    
    uniform vec2 resolution;
    uniform vec3 eye;
    uniform vec3 lookAt;
    uniform vec3 lightPos;
    uniform float time;
    
    float sdBox( vec3 p, vec3 b ){
      vec3 d = abs(p) - b;
      return length(max(d,0.0))
             + min(max(d.x,max(d.y,d.z)),0.0); 
    }
    
    vec3 sponge( in vec3 p ){
       float d = sdBox(p,vec3(1.0));
       vec3 res = vec3( d, 1.0, 0.0 );
       float s = 1.;
       for( int m=0; m<6; m++ )  {
          vec3 a = mod( p*s, 2.0 )-1.0;
          s *= 3.0;
          vec3 r = abs(1.0 - 3.0*abs(a));
          float da = max(r.x,r.y);
          float db = max(r.y,r.z);
          float dc = max(r.z,r.x);
          float c = (min(da,min(db,dc))-1.0)/s;
          if( c>d ) {
              d = c;
              res = vec3( d, 0.2*da*db*dc, (1.0+float(m))/4.0);
           }
       }
       return res;
    }
    
    vec2 map(vec3 p) {
        vec3 r =sponge(p);
        return vec2(r.x, abs(r.y - r.z));
    }
    
    vec3 rayDirection(float fieldOfView, vec2 size) {
        vec2 xy = gl_FragCoord.xy - size / 2.0;
        float z = size.y / tan(radians(fieldOfView) / 2.0);
        return normalize(vec3(xy, -z));
    }
    
    mat4 viewMatrix(vec3 eye, vec3 center, vec3 up) {
    	vec3 f = normalize(center - eye);
    	vec3 s = normalize(cross(f, up));
    	vec3 u = cross(s, f);
    	return mat4(
    		vec4(s, 0.0),
    		vec4(u, 0.0),
    		vec4(-f, 0.0),
    		vec4(0.0, 0.0, 0.0, 1)
    	);
    }
    
    vec2 castRay( vec3 ro, vec3 rd ) {
        float tmin = 0.01;
        float tmax = 32.0;
        float t = tmin;
        float m = -1.0;
        for ( int i=0; i<64; i++ ) {
    	    float precis = 0.0001*t;
    	    vec2 res = map( ro+rd*t );
            if ( res.x<precis || t>tmax )
                break;
            t += res.x;
    	    m = res.y;
        }
        if ( t>tmax )
            m=-1.0;
        return vec2( t, m );
    }
    
    const float NORMAL_EPSILON = 0.0005;
    
    vec3 estimateNormal(vec3 pos) {
        vec2 e = vec2(1.0,-1.0)*0.5773*NORMAL_EPSILON;
        return normalize( e.xyy*map( pos + e.xyy ).x +
    					  e.yyx*map( pos + e.yyx ).x +
    					  e.yxy*map( pos + e.yxy ).x +
    					  e.xxx*map( pos + e.xxx ).x );
    }
    
    const vec3 K_a = vec3(.5, .5, .5);
    const vec3 K_d = vec3(.5, .5, .5);
    const vec3 K_s = vec3(.1, .1, .1);
    const float shininess = 3.5;
    const vec3 lightIntensity = vec3(1., 1., 1.);
    
    vec3 phongContribForLight(vec3 k_d, vec3 k_s, float alpha, vec3 p, vec3 N, vec3 eye,
                              vec3 lightPos, vec3 lightIntensity) {
    
        vec3 L = normalize(lightPos - p);
        vec3 V = normalize(eye - p);
        vec3 R = normalize(reflect(-L, N));
        float dotLN = dot(L, N);
        float dotRV = dot(R, V);
        if (dotLN < 0.0) {
            return vec3(0.0, 0.0, 0.0);
        }
        if (dotRV < 0.0) {
            return lightIntensity * (k_d * dotLN);
        }
        return lightIntensity * (k_d * dotLN + k_s * pow(dotRV, alpha));
    }
    
    vec3 phongIllumination(vec3 k_a, vec3 k_d, vec3 k_s, float alpha, vec3 p, vec3 nor, vec3 eye, vec3 materialColor) {
        vec3 color = materialColor * k_a;
        color += phongContribForLight(k_d, k_s, alpha, p, nor, eye, lightPos, lightIntensity);
        return color;
    }
    
    vec3 decodeMaterial(float m) {
        return vec3(1.-m/3.);
    }
    
    vec3 phong(vec3 p, vec3 nor, vec3 eye, float material) {
        vec3 materialColor = decodeMaterial(material);
        return phongIllumination(K_a, K_d, K_s, shininess, p, nor, eye, materialColor);
    }
    
    float softShadow( in vec3 ro, in vec3 rd, in float mint, in float tmax ){
    	float res = 1.0;
        float t = mint;
        for( int i=0; i<16; i++ ) {
    		float h = map( ro + rd*t ).x;
            res = min( res, 8.0*h/t );
            t += clamp( h, 0.02, 0.10 );
            if( res<0.005 || t>tmax ) break;
        }
        return clamp( res, 0.0, 1.0 );
    }
    
    float ao( vec3 pos, vec3 nor ){
    	float occ = 0.0;
        float sca = 1.0;
        for( int i=0; i<5; i++ )
        {
            float hr = 0.01 + 0.12*float(i)/4.0;
            vec3 aopos =  nor * hr + pos;
            float dd = map( aopos ).x;
            occ += -(dd-hr)*sca;
            sca *= 0.95;
        }
        return clamp( 1.0 - 3.0*occ, 0.0, 1.0 );
    }
    
    void drawScene(vec3 pt, float material) {
        vec3 nor = estimateNormal( pt );
        float occ = ao( pt, nor );
        float shadow = softShadow( pt, normalize(lightPos-pt), 0.1, 22.2);
        vec3 color = phong(pt, nor, eye, material)*sqrt(occ);
        color += color * shadow;
        gl_FragColor = vec4(color, 1.0);
    }
    
    void main(void) {
    	vec3 direction = rayDirection(60.0, resolution);
        mat4 viewToWorld = viewMatrix(eye, lookAt, vec3(0.0, 1.0, 0.0));
        vec3 worldDir = (viewToWorld * vec4(direction, 0.0)).xyz;
        vec2 dist = castRay(eye, worldDir);
        if (dist.x > 32.) {
             gl_FragColor = vec4(0.9, 0.9, 0.9, 1.0);
        } else {
            drawScene(eye + dist.x * worldDir, dist.y);
        }
    }
    </script>

    • 9

相关问题

Sidebar

Stats

  • 问题 10021
  • Answers 30001
  • 最佳答案 8000
  • 用户 6900
  • 常问
  • 回答
  • Marko Smith

    Python 3.6 - 安装 MySQL (Windows)

    • 1 个回答
  • Marko Smith

    C++ 编写程序“计算单个岛屿”。填充一个二维数组 12x12 0 和 1

    • 2 个回答
  • Marko Smith

    返回指针的函数

    • 1 个回答
  • Marko Smith

    我使用 django 管理面板添加图像,但它没有显示

    • 1 个回答
  • Marko Smith

    这些条目是什么意思,它们的完整等效项是什么样的

    • 2 个回答
  • Marko Smith

    浏览器仍然缓存文件数据

    • 1 个回答
  • Marko Smith

    在 Excel VBA 中激活工作表的问题

    • 3 个回答
  • Marko Smith

    为什么内置类型中包含复数而小数不包含?

    • 2 个回答
  • Marko Smith

    获得唯一途径

    • 3 个回答
  • Marko Smith

    告诉我一个像幻灯片一样创建滚动的库

    • 1 个回答
  • Martin Hope
    Air 究竟是什么标识了网站访问者? 2020-11-03 15:49:20 +0000 UTC
  • Martin Hope
    Алексей Шиманский 如何以及通过什么方式来查找 Javascript 代码中的错误? 2020-08-03 00:21:37 +0000 UTC
  • Martin Hope
    Qwertiy 号码显示 9223372036854775807 2020-07-11 18:16:49 +0000 UTC
  • Martin Hope
    user216109 如何为黑客设下陷阱,或充分击退攻击? 2020-05-10 02:22:52 +0000 UTC
  • Martin Hope
    Qwertiy 并变成3个无穷大 2020-11-06 07:15:57 +0000 UTC
  • Martin Hope
    koks_rs 什么是样板代码? 2020-10-27 15:43:19 +0000 UTC
  • Martin Hope
    user207618 Codegolf——组合选择算法的实现 2020-10-23 18:46:29 +0000 UTC
  • Martin Hope
    Sirop4ik 向 git 提交发布的正确方法是什么? 2020-10-05 00:02:00 +0000 UTC
  • Martin Hope
    faoxis 为什么在这么多示例中函数都称为 foo? 2020-08-15 04:42:49 +0000 UTC
  • Martin Hope
    Pavel Mayorov 如何从事件或回调函数中返回值?或者至少等他们完成。 2020-08-11 16:49:28 +0000 UTC

热门标签

javascript python java php c# c++ html android jquery mysql

Explore

  • 主页
  • 问题
    • 热门问题
    • 最新问题
  • 标签
  • 帮助

Footer

RError.com

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

帮助

© 2023 RError.com All Rights Reserve   沪ICP备12040472号-5