当前位置: 首页 > 软件库 > Web应用开发 > Web框架 >

webgl-fundamentals

WebGL lessons that start with the basics
授权协议 View license
开发语言 JavaScript
所属分类 Web应用开发、 Web框架
软件类型 开源软件
地区 不详
投 递 者 宦源
操作系统 跨平台
开源组织
适用人群 未知
 软件概览

WebGL Fundamentals

This is a series of lessons or tutorials about WebGL.

Unlike most WebGL lessons these are not based off of OpenGL.OpenGL is 20 years old. The lessons of OpenGL don't match well with WebGL.The APIs have changed too much. The ideas of OpenGL and OpenGL tutorialsare out of date with WebGL, OpenGL ES 2.0 and the land of shaders.

I would argue that WebGL is actually a very simple API. What makes itappear complicated is the way in which it's used. The complicationsare added by the programmer. WebGL itself is simple.

These lessons try to show that simplicity and well as teach thefundamentals of 2D math and 3D math so readers can hopefullyhave an easier time writing their own WebGL programs andunderstanding the complexity that other programmers pile ontop of simple WebGL.

This is work in progress. Feel free to contribute.

Contributing

Of course bug fixes are always welcome.

If you'd like to write a new article please try to always takeone step at a time. Don't do 2 or more things in a single step.Explain any new math in the simplest terms possible. Ideallywith diagrams where possible.

Translating

Each translation goes in a folder under webgl/lessons/<country-code>.

Required files are

langinfo.hanson
index.md
toc.html

langinfo.hanson

Defines various language specific options.Hanson is a JSON like format but allows comments.

Current fields are

{
  // The language (will show up in the language selection menu)
  language: 'English',

  // Phrase that appears under examples
  defaultExampleCaption: "click here to open in a separate window",

  // Title that appears on each page
  title: 'WebGL Fundamentals',

  // Basic description that appears on each page
  description: 'Learn WebGL from the ground up. No magic',

  // Link to the language root.
  link: 'https://webglfundamentals.org/webgl/lessons/ja',  // replace `ja` with country code

  // html that appears after the article and before the comments
  commentSectionHeader: '<div>Issue/Bug? <a href="https://github.com/gfxfundamentals/webgl-fundamentals/issues">Create an issue on github</a>.</div>',

  // markdown that appears for untranslated articles
  missing: "Sorry this article has not been translated yet. [Translations Welcome](https://github.com/gfxfundamentals/webgl-fundamentals)! ��\n\n[Here's the original English article for now]({{{origLink}}}).",

  // the phrase "Table of Contents"
  toc: "Table of Contents",

  // translation of categories for table of contents
  categoryMapping: {
    'fundamentals': "Fundamentals",
    'image-processing': "Image Processing",
    'matrices': "2D translation, rotation, scale, matrix math",
    '3d': "3D",
    'lighting': "Lighting",
    'organization': "Structure and Organization",
    'geometry': "Geometry",
    'textures': "Textures",
    'rendertargets': "Rendering To A Texture",
    '2d': "2D",
    'text': "Text",
    'misc': "Misc",
    'reference': "Reference",
  },

}

index.md

This is the template for the main page for each language

toc.html

This is template for the table of contents for the language.It is included on both the index and on each article. The onlyparts not auto-generated are the links ending links whichyou can translate if you want to.The build system will create a placeholder for every English article for which there is no corresponding article in that language. It will be filled with the missing message from above.

lang.css

This is included if and only if it exists. I'd strongly prefer not to have touse it. In particular I don't want people to get into arguments about fontsbut basically it's a way to choose the fonts per language. You should only setthe variables that are absolutely needed. Example

/* lessons/ko/lang.css */

/* Only comment in overrides as absolutely necessary! */
:root {
  --article-font-family: "best font for korean article text";
  --headline-font-family: "best font for korean headlines";
  /* a block of code */
  /* --code-block-font-family: "Lucida Console", Monaco, monospace; */
  /* a word in a sentence */
  /* --code-font-family: monospace; */
}

Notice 2 settings are not changed. It seems unlikely to me that code wouldneed a different font per language.

PS: While we're here, I love code fonts with ligatures but they seem like a badidea for a tutorial site because the ligatures hide the actual characters neededso please don't ask for or use a ligature code font here.

Translation notes

The build process will make a placeholder html file for each article that has an English .md file inwebgl/lessons but no corresponding .md file for the language. This is to make it easy to includelinks in an article that links to another article but that other article has not yet been translated.This way you don't have to go back and fix already translated articles. Just translate one articleat a time and leave the links as is. They'll link to placeholders until someone translates the missingarticles.

Articles have front matter at the top

Title: Localized Title of article
Description: Localized description of article (used in RSS and social media tags)
TOC: Localized text for Table of Contents

DO NOT CHANGE LINKS : For example a link to a local resources might look like

[text](link)

or

<img src="somelink">

While you can add query parameters (see below) do not add "../" to try to make the link relative to the.md file. Links should stay as though the article exists at the same location as the original English.

UI localization

Some of the diagrams allow passing translations for the UI and other text.

For example if there is a slider named "rotation"you can add "?ui-rotation=girar" at the end of the URL for the diagram. For 2 or more translationsseparate them with a &. Certain characters are disallowed in URLs like =, #, & etc. For thoseuse their uri encoding.

For diagram labels you'll have to look inside the code. For example for thedirectional lighting diagram near the start of the code it looks like this

const lang = {
  lightDir: opt.lightDir || "light direction",
  dot: opt.dot || "dot(reverseLightDirection,surfaceDirection) = ",
  surface1: opt.surface1 || "surface",
  surface2: opt.surface2 || "direction",
};

Which means you can localize the labels like this

{{{diagram url="resources/directional-lighting.html?lightDir=光線方向&surface1=オブジェクト&surface2=表面方向&dot=dot(光線反対方向,表面方向)%20%3D%20&ui-rotation=角度" caption="方向を回転してみて" width="500" height="400"}}}

For testing, reference the sample directly in your browser. For example

http://localhost:8080/webgl/lessons/resources/directional-lighting.html?lightDir=光線方向&surface1=オブジェクト&surface2=表面方向&dot=dot(光線反対方向,表面方向)%20%3D%20&ui-rotation=角度

To build

The site is built into the out folder

Steps

git clone https://github.com/gfxfundamentals/webgl-fundamentals.git
cd webgl-fundamentals
npm install
npm run build
npm start

now open your browser to http://localhost:8080

Continuous build

You can run npm run watch after you've built to get continuous building.Only the article .md files and files that are normally copied are watched.The index files (the top page with the table of contents) is not regeneratednor does changing a template rebuild all the articles.

Build options

This is mostly for debugging build.js. Since it takes a while to process all the filesyou can set ARTICLE_FILTER to a substring of the filenames to process. For example

ARTICLE_FILTER=rotation npm run build

Will build the site as though only articles with rotation in their filename exist.

TO DO

A list of articles I'd like to write or see written

  • lighting
    • normal maps
  • geometry
    • plane, cube, sphere, cone, disc, torus
      • lines vs triangles
      • vertex colors
    • other
    • pre-process (don't load .obj, .dae, .fbx etc at runtime)
    • pre-optimize (texture atlas, sizes, combine meshes, etc...)
  • animation
    • blendshapes
    • hierarchical animation
  • debugging
    • debugging JS WebGL
      • example (https://goo.gl/8U5whT)
      • CHECK THE GAWD DAMN CONSOLE!
        • actually read the error message
        • understand it.
          • INVALID_ENUM means one of your gl.XXX values is not valid period
          • INVALID_VALUE means one of the int or float values is probably off
          • INVALID_OPERATION means something you tried to do won't work for the given state
          • texture not renderable
          • attribute out of range
          • check your framebuffers
          • check your extensions
      • make shorter samples (MCVE)
        • remove any code you don't need
        • get rid of CSS
        • get rid of HTML
        • consider using a POINT (no attributes needed)
        • don't use images if they are not relevant. Use a canvas or a single and double pixel texture
        • While creating this MCVE you'll often find the bug
    • debugging a shader
      • set fragment shader to solid color.
      • render normals
      • render texcoords
      • render cube/sphere/plane
  • text
    • glyph cache
  • post processing
    • DOF
    • glow
    • light rays
    • RGB glitch, CRT distortion, scanlines
    • color mapping/tone mapping
  • Creative coding
    • color palettes
    • tilemaps
    • generated geometry
    • histogram
    • particles
    • toon/ramp shading
    • procedural textures
  • code organization
    • scene graph
      • putting lights and camera in scene graph
  • Engine Creation
    • culling
      • frustum culling
      • grid culling
      • quad tree / oct tree
      • portals (is this still a thing?)
      • PVS
    • materials
    • lighting DB
  • Physically based rendering
  • WebGL   参考链接 https://webglfundamentals.org/webgl/lessons/webgl-fundamentals.html 转载于:https://www.cnblogs.com/yangwenhuan/p/10831844.html

  • 见:https://webgl2fundamentals.org/webgl/lessons/zh_cn/

  • 这段时间需要把原有的一个老项目改造成WebGL版本,遇到了一些困难,这里将记录改造的一些情况。 用Node.js来管理游戏内容 var express = require('express'); var app = express(); app.get('/', function (req, res) { res.send('Hello World!'); }); app.use(expre

  • 1.  webgl是什么?    WebGL其实是一个非常简单的API。好吧,“简单”可能是一个不恰当的描述。 它做的是一件简单的事,它仅仅运行用户提供的两个方法,一个顶点着色器和一个片断着色器,      去绘制点,线和三角形。虽然做三维可以变得很复杂,但是这种复杂只是作为程序员的你, 是一种复杂形式的“着色器”。WebGL API只做光栅化处理并且在概念上十分容易理解。 2. 怎么调用webg

  • 转自 BillL[Google] 谷歌开发者社区 ====>  很多学习WebGL的各种资源、参考材料、教程、和精彩的创新演示: 学什么、如何学:Stackoverflow上有人几句话的介绍:http://stackoverflow.com/questions/11966779/should-i-start-learning-webgl-or-use-three-js WebGL 1.0 开发接口

  •  相比其他前端技术,WebGL最大的特点的就是学习曲线异常之陡,入门感觉比较难。另外在这方面的资料也非常少,一部分因为该技术出现的时间还比较晚,另外它和OpenGL这样成熟的技术类似,很多人熟悉了OpenGL之后并不再需要单独介绍WebGL。这里沉淀了目前LBS-WEB所积累下来的WebGL资源,供大家学习。 如何学习 这里给大家一些学习方法和经验: 找一本入门书籍开始阅读,作者最好是该行业从业多

  • 1 <html> 2 <head> 3 <title>TeaPolt</title> 4 </head> 5 6 <body οnlοad="main()"> 7 <canvas id="viewPort" width="600" height="600"> 8 This brow

  • 通过优秀的博客及其站点,你可以找到灵感和WebGLass业界最新消息,下面向大家推荐一些好的资源。 WebGL规范(http://www.khronos.org/registry/webgl/specs/latest/1.0/) WebGL规范是由科纳斯组织开发与维护的。 Learning WebGL(http://learningwebgl.com/blog/) 该网站是WebGL业界比较早期的

 相关资料
  • WebGL是一种3D绘图标准,这种绘图技术标准允许把JavaScript和OpenGL ES 2.0结合在一起,通过增加OpenGL ES 2.0的一个JavaScript绑定,WebGL可以为HTML5 Canvas提供硬件3D加速渲染,这样Web开发人员就可以借助系统显卡来在浏览器里更流畅地展示3D场景和模型了,还能创建复杂的导航和数据视觉化。显然,WebGL技术标准免去了开发网页专用渲染插件

  • 一句话来描述,WebGL API指的就是gl=canvas.getContext('webgl')返回对象gl的一系列绘制渲染方法,通过WebGL API可以把一个三维场景绘制渲染出来。比如上面代码中gl.createShader()、gl.shaderSource()、gl.drawArrays()等方法就是WebGl API。 WebGL API多数与GPU硬件相关,控制相关图形处理单元,比如

  • WebGL 是针对Canvas 的3D 上下文。与其他Web 技术不同,WebGL 并不是W3C 制定的标准,而是由Khronos Group 制定的。其官方网站是这样介绍的:“Khronos Group 是一个非盈利的由会员资助的协会,专注于为并行计算以及各种平台和设备上的图形及动态媒体制定无版税的开放标准。” KhronosGroup 也设计了其他图形处理API,比如OpenGL ES 2.0

  • webGL-Shaders是一款分形渲染器,采用webGL标准。 效果查看地址:https://jonathan-potter.github.io/webgl-shaders/

  • 虽然这个问题现在已经变得越来不明显,但不可否定的是,某些设备以及浏览器直到现在仍然不支持WebGL。 以下的方法可以帮助你检测当前用户所使用的环境是否支持WebGL,如果不支持,将会向用户提示一条信息。 请将https://github.com/mrdoob/three.js/blob/master/examples/jsm/WebGL.js引入到你的文件,并在尝试开始渲染之前先运行该文件。 if

  • 为了比较说明Three.js能大大简化WebGL的开发,我们使用最简单的例子进行比较:渲染黑色背景下的白色正方形和三角形。效果如图: Three.js需要30行左右的代码: 例1.1.1 var renderer = new THREE.WebGLRenderer({ canvas: document.getElementById('mainCanvas') }); renderer.se