我在香椿着色器中有强度问题。强度值总是0但不应该是,我从顶点法线和光线方向计算它。我用过这个 reference card
vertexShader:
varying vec2 vUv;
uniform vec3 ec_light_dir;
uniform mat3 normal_matrix;
varying float intensity;
attribute vec3 a_normal;
void main() {
vec3 ec_normal = normalize(normal_matrix * a_normal);
intensity = dot(ec_light_dir,ec_normal);
vUv = uv;
gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );}
fragmentShader:
uniform sampler2D tDiffuse;
varying vec2 vUv;
varying float intensity;
void main() {
vec4 color = texture2D(tDiffuse, vUv);
if (intensity > 0.95)
color = vec4(1.0,1.0,0.5,0.5);
else if (intensity > 0.5)
color = vec4(0.6,0.3,0.3,1.0);
else if (intensity > 0.25)
color = vec4(0.4,0.2,0.2,1.0);
else
color = vec4(0.2,0.1,0.1,1.0);
gl_FragColor = color;
}
你告诉我我做错了吗?为什么强度始终为零?
答案 0 :(得分:0)
确保 this is my js page content form_value.js
$(document).ready(function() {
// Function to get input value.
$('#text_value').click(function() {
var text_value = $("#text").val();
if(text_value=='') {
alert("Enter Some Text In Input Field");
}else{
alert(text_value);
}
});
// Funtion to get checked radio's value.
$('#gender_value').click(function() {
$('#result').empty();
var value = $("form input[type='gender']:checked").val();
if($("form input[type='gender']").is(':checked')) {
$('#result').append("Checked Radio Button Value is :<span> "+ value +" </span>");
}else{
alert(" Please Select any Option ");
}
});
// Get value Onchange radio function.
$('input:gender').change(function(){
var value = $("form input[type='gender']:checked").val();
alert("Value of Changed Radio is : " +value);
});
// Funtion to reset or clear selection.
$('#radio_reset').click(function() {
$('#result').empty();
$("input:radio").attr("checked", false);
});
$('#Email').click(function() {
function validate(Email) {
var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za- z]{2,4})$/;
//var address = document.getElementById[email].value;
if (reg.test(email) == false)
{
alert('Should be in the format example@gmail.com');
return (false);
}
}
});
});
$("#Age").click(function() {
var specialKeys = new Array();
specialKeys.push(8); //Backspace
function IsNumeric(e) {
var keyCode = e.which ? e.which : e.keyCode
var ret = ((keyCode >= 48 && keyCode <= 57) || specialKeys.indexOf(keyCode) != -1);
document.getElementById("error").style.display = ret ? "none" : "inline";
return ret;
}
function handleChange(input) {
if (input.value < 0) input.value = 0;
if (input.value > 100) input.value = 100;
}
});
</script>
已标准化且a_normal不是零向量。为此,您可以将其值(每次运行一次)写入ec_light_dir
并查看绘制的颜色。注意:将gl_FragColor
传递给ec_light_dir
不会确保它已标准化,因为如果其arg首先是零向量,则该函数具有未定义的行为。