为什么着色器必须在 webgl 程序的 html 文件中? [英] Why do shaders have to be in html file for webgl program?

查看:13
本文介绍了为什么着色器必须在 webgl 程序的 html 文件中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看到以下问题,有人问如何从 html 中删除着色器:WebGL - 是否有替代在 HTML 中嵌入着色器的方法?

I have seen the following question where someone asked how to remove shaders from html: WebGL - is there an alternative to embedding shaders in HTML?

在包含问题答案中建议的着色器的文件中加载了详细的解决方法.

There are elaborate workarounds to load in a file containing the shader suggested in the answers to the question.

在我看到的教程中,着色器代码是直接嵌入到html中的.javascript 代码使用 getElementById 引用它.但是由于多种原因,将着色器直接嵌入到 html 中是很丑陋的.为什么我不能直接使用 src= 属性在外部引用它?

In the tutorial I saw, the shader code is embedded directly in the html. The javascript code refers to it using getElementById. But it's ugly embedding the shader directly in the html for many reasons. Why can't I just refer to it externally using the src= attribute?

<script type="x-shader/x-fragment" id="shader-fs" src="util/fs"></script>

以上不行,我只是想知道为什么不行.这显然与脚本本身的限制有关,但我不明白.

The above doesn't work, I just want to know why not. This is clearly something to do with limitations on script itself, but I don't get it.

推荐答案

您根本不必使用

登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆