Error: Cannot find buffer gate in the library - yosys

While attempting to synthesize with Yosys, I am unable to map the logic circuit using only AND, XOR, NOT, and MUX's. This is because I get an error whenever my liberty file excludes BUFX2:
Error:
ABC: ** cmd error: aborting 'source <abc-temp-dir>/abc.script'
ABC: Error: Cannot find buffer gate in the library.
ABC: Error: Abc_CommandAbc9Nf(): Mapping into LUTs has failed.
ERROR: Can't open ABC output file `/tmp/yosys-abc-L2LNHN/output.blif'.
BUFX2 in liberty file:
cell (BUFX2) {
cell_footprint : buf;
area : 25;
cell_leakage_power : 0.0660639;
pin(A) {
direction : input;
capacitance : 0.00933171;
rise_capacitance : 0.00930577;
fall_capacitance : 0.00933171;
}
pin(Y) {
direction : output;
capacitance : 0;
rise_capacitance : 0;
fall_capacitance : 0;
max_capacitance : 0.975984;
function : "A";
timing() {
related_pin : "A";
timing_sense : positive_unate;
cell_rise(delay_template_5x5) {
index_1 ("0.01, 0.025, 0.05, 0.15, 0.3");
index_2 ("0.06, 0.18, 0.42, 0.6, 1.2");
values ( \
"0.080192, 0.099332, 0.125551, 0.141601, 0.160879", \
"0.09527, 0.119121, 0.146424, 0.159624, 0.180791", \
"0.119549, 0.142384, 0.170285, 0.182826, 0.208459", \
"0.206725, 0.226318, 0.258778, 0.269216, 0.29682", \
"0.336459, 0.356012, 0.387945, 0.399852, 0.425204");
}
cell_fall(delay_template_5x5) {
index_1 ("0.01, 0.025, 0.05, 0.15, 0.3");
index_2 ("0.06, 0.18, 0.42, 0.6, 1.2");
values ( \
"0.089994, 0.120328, 0.164981, 0.192952, 0.273426", \
"0.105036, 0.137433, 0.18812, 0.215291, 0.293841", \
"0.126393, 0.161711, 0.209388, 0.240117, 0.319216", \
"0.207389, 0.241744, 0.292741, 0.321104, 0.405447", \
"0.326255, 0.363651, 0.411543, 0.440746, 0.523808");
}
fall_transition(delay_template_5x5) {
index_1 ("0.01, 0.025, 0.05, 0.15, 0.3");
index_2 ("0.06, 0.18, 0.42, 0.6, 1.2");
values ( \
"0.039104, 0.036002, 0.057053, 0.0624, 0.0708", \
"0.045857, 0.047088, 0.0684, 0.0702, 0.0768", \
"0.0726, 0.0744, 0.0786, 0.084, 0.0972", \
"0.165, 0.1656, 0.1668, 0.1692, 0.1764", \
"0.315, 0.3156, 0.3168, 0.3162, 0.3198");
}
}
}
}
Note that I only get this error when trying to use the command (in yosys) [Must include to see delay time]
abc -liberty asic_cell_yosys_3.lib -constr yosys_timing.constr;
Using the constr file above allows me to see critical path timing delays as illustrated by Clifford in this post.
Setting the area of BUFX2 to an extremely large value like 9999999 still makes Yosys include it in the circuit, even when highly un-optimal.
My goal is trying to optimize depth/critical path timing rather than area/total # of gates, but I can not find a way to do that when
I can't remove the buffer gate from the liberty file [with the .constr file]
All gates which I need to use (AND,XOR,NOT, MUX) require cell_rise, cell_fall, and fall_transition timing constraints which I have included in the file, but do not necessarily know how it works/ effects delay result
To address #2, how should I change the values to reflect XOR gates requiring approximately 0 delay:
cell (XOR2X1) {
area : 1;
cell_leakage_power : 0.161354;
pin(A) {
direction : input;
capacitance : 0.0296528;
rise_capacitance : 0.029651;
fall_capacitance : 0.0296528;
}
pin(B) {
direction : input;
capacitance : 0.0342661;
rise_capacitance : 0.0339918;
fall_capacitance : 0.0342661;
}
pin(Y) {
direction : output;
capacitance : 0;
rise_capacitance : 0;
fall_capacitance : 0;
max_capacitance : 0.484395;
function : "(A^B)";
timing() {
related_pin : "A";
timing_sense : non_unate;
cell_rise(delay_template_5x5) {
index_1 ("0.005, 0.0125, 0.025, 0.075, 0.15");
index_2 ("0.06, 0.18, 0.42, 0.6, 1.2");
values ( \
"0.084668, 0.100252, 0.11425, 0.123569, 0.136197", \
"0.097915, 0.113723, 0.126398, 0.138879, 0.150616", \
"0.119426, 0.133803, 0.150727, 0.160469, 0.175347", \
"0.200291, 0.21109, 0.234434, 0.245604, 0.260628", \
"0.324762, 0.343132, 0.359931, 0.370218, 0.387403");
}
cell_fall(delay_template_5x5) {
index_1 ("0.005, 0.0125, 0.025, 0.075, 0.15");
index_2 ("0.06, 0.18, 0.42, 0.6, 1.2");
values ( \
"0.080217, 0.104741, 0.14405, 0.166439, 0.230805", \
"0.089887, 0.114359, 0.158704, 0.181241, 0.244897", \
"0.104894, 0.129666, 0.174768, 0.197644, 0.261257", \
"0.164496, 0.19114, 0.235815, 0.259502, 0.326338", \
"0.254884, 0.281399, 0.324471, 0.350019, 0.419374");
}
fall_transition(delay_template_5x5) {
index_1 ("0.005, 0.0125, 0.025, 0.075, 0.15");
index_2 ("0.06, 0.18, 0.42, 0.6, 1.2");
values ( \
"0.041331, 0.040781, 0.050767, 0.044749, 0.0696", \
"0.053453, 0.052285, 0.0624, 0.063, 0.0738", \
"0.0756, 0.069, 0.078, 0.0792, 0.084", \
"0.1518, 0.1512, 0.1482, 0.1488, 0.1536", \
"0.273, 0.273, 0.2682, 0.2652, 0.27");
}
}
timing() {
related_pin : "B";
timing_sense : non_unate;
cell_rise(delay_template_5x5) {
index_1 ("0.005, 0.0125, 0.025, 0.075, 0.15");
index_2 ("0.06, 0.18, 0.42, 0.6, 1.2");
values ( \
"0.095856, 0.109639, 0.124914, 0.132649, 0.149393", \
"0.112134, 0.122918, 0.138721, 0.14656, 0.164175", \
"0.132565, 0.144856, 0.161456, 0.170028, 0.185654", \
"0.217554, 0.231394, 0.246536, 0.255419, 0.27072", \
"0.343798, 0.357936, 0.373613, 0.388316, 0.398061");
}
cell_fall(delay_template_5x5) {
index_1 ("0.005, 0.0125, 0.025, 0.075, 0.15");
index_2 ("0.06, 0.18, 0.42, 0.6, 1.2");
values ( \
"0.090864, 0.115106, 0.148564, 0.176005, 0.236451", \
"0.101631, 0.126046, 0.162396, 0.186432, 0.247857", \
"0.118398, 0.142704, 0.177128, 0.20129, 0.267362", \
"0.181148, 0.206, 0.241266, 0.265038, 0.330296", \
"0.273354, 0.298267, 0.333521, 0.3571, 0.42352");
}
fall_transition(delay_template_5x5) {
index_1 ("0.005, 0.0125, 0.025, 0.075, 0.15");
index_2 ("0.06, 0.18, 0.42, 0.6, 1.2");
values ( \
"0.038733, 0.04056, 0.054628, 0.057339, 0.0624", \
"0.051463, 0.051355, 0.063, 0.0618, 0.0684", \
"0.0732, 0.0744, 0.0792, 0.0774, 0.0882", \
"0.1524, 0.1542, 0.1518, 0.1542, 0.1584", \
"0.2724, 0.2724, 0.2736, 0.2724, 0.2748");
}
}
}
}
Thank you.

You can actually achieve point 1 with some trickery.
Yosys' internal cells start with $, e.g. $_AND_ which you can see if you run abc without any other arguments. One of these internal cells is $_BUF_ which represents a buffer cell. Since to Yosys buffer cells are identical to wires, the opt command will replace all instances of $_BUF_ with simple wires.
This means you can instantiate $_BUF_ cells by replacing the BUFX2 cell name with "$_BUF_" (the quotes are needed to escape the $), keeping ABC happy because there's a cell buffer, and then after running an opt pass, the buffers have disappeared from your netlist.

Related

Filter/Shader "Godrays" which does not darken the background

Dear Magnificent Community and Developers,
There's a PixiJs filter which is based on a shader ""Godrays" by alaingalvan", but it is required to somehow achieve such a filter/shader which does lighten certain areas where "lights" exist on a transparent stage without darkening the background.
The current version creates dark places ('0x000000') where the "lights" are not shown, but the darkness must not surpass the background ('0x333333' or '0xffffff' as in CSS), so it would look like a transparent filter in the result. This is the incorrect behavior since it creates black background where the "lights" are (it is correct that it affects the background):
const uniformData = {
time: {
type: 'float',
value: 0.0
},
lacunarity: {
type: 'float',
value: 30.0
},
gain: {
type: 'float',
value: 1.0
},
parallel: {
type: 'b',
value: true
},
light: {
type: 'v2',
value: [0.0, 0.0]
},
dimensions: {
type: 'v2',
value: [800, 400]
},
aspect: {
type: 'float',
value: 1.0
}
};
// 3D gradient Noise
// MIT License
// Copyright © 2013 Inigo Quilez
// https://www.shadertoy.com/view/Xsl3Dl
// Original: https://codepen.io/alaingalvan/pen/gOoEpW
const fragSource = '' +
`precision mediump float;
varying vec2 vTextureCoord;
uniform sampler2D uSampler;
uniform vec4 filterArea;
uniform vec2 dimensions;
uniform vec2 light;
uniform bool parallel;
uniform float aspect;
uniform float gain;
uniform float lacunarity;
uniform float time;
vec3 hash(vec3 p) {
p = vec3(
dot(p, vec3(127.1, 311.7, 74.7)),
dot(p, vec3(269.5, 183.3, 246.1)),
dot(p, vec3(113.5, 271.9, 124.6))
);
return -1.0 + 2.0 * fract(sin(p) * 43758.5453123);
}
float noise(in vec3 p) {
vec3 i = floor(p);
vec3 f = fract(p);
vec3 u = f * f * (3.0 - 2.0 * f);
return mix(
mix(
mix(
dot(hash(i + vec3(0.0, 0.0, 0.0)), f - vec3(0.0, 0.0, 0.0)),
dot(hash(i + vec3(1.0, 0.0, 0.0)), f - vec3(1.0, 0.0, 0.0)),
u.x
),
mix(
dot(hash(i + vec3(0.0, 1.0, 0.0)), f - vec3(0.0, 1.0, 0.0)),
dot(hash(i + vec3(1.0, 1.0, 0.0)), f - vec3(1.0, 1.0, 0.0)),
u.x
),
u.y
),
mix(
mix(
dot(hash(i + vec3(0.0, 0.0, 1.0)), f - vec3(0.0, 0.0, 1.0)),
dot(hash(i + vec3(1.0, 0.0, 1.0)), f - vec3(1.0, 0.0, 1.0)),
u.x
),
mix(
dot(hash(i + vec3(0.0, 1.0, 1.0)), f - vec3(0.0, 1.0, 1.0)),
dot(hash(i + vec3(1.0, 1.0, 1.0)), f - vec3(1.0, 1.0, 1.0)),
u.x
),
u.y
),
u.z
);
}
float turb(vec3 pos, float lacunarity, float gain) {
float f, totalGain;
totalGain = gain;
vec3 q = 2.0 * pos;
f = totalGain * noise(q);
q = q * 2.01 * lacunarity;
totalGain *= gain;
f += totalGain * noise(q);
q = q * 3.02 * lacunarity;
totalGain *= gain;
f += totalGain * noise(q);
q = q * 3.03 * lacunarity;
totalGain *= gain;
f += totalGain * noise(q);
q = q * 3.01 * lacunarity;
totalGain *= gain;
f += totalGain * noise(q);
q = q * 3.99 * lacunarity;
totalGain *= gain;
f += totalGain * noise(q);
q = q * 3.98 * lacunarity;
totalGain *= gain;
f += totalGain * noise(q);
f = 3.0 * f;
return abs(f);
}
void main(void) {
gl_FragColor = texture2D(uSampler, vTextureCoord);
float d = 0.0;
vec2 coord = vTextureCoord;
if (parallel) {
float _cos = light.x;
float _sin = light.y;
d = (_cos * coord.x) + (_sin * coord.y * aspect);
} else {
float dx = coord.x - light.x / dimensions.x;
float dy = (coord.y - light.y / dimensions.y) * aspect;
float dis = sqrt(dx * dx + dy * dy) + 0.00001;
d = dy / dis;
}
vec2 dir = vec2(d, d);
float noise = turb(vec3(dir, 0.0) + vec3(time, 0.0, 62.1 + time) * 0.1, lacunarity, gain);
vec4 mist = vec4(noise, noise, noise, 1.0);
noise = mix(noise, 0.0, 0.3);
mist *= 1.0 - coord.y;
mist = clamp(mist, 0.0, 1.0);
gl_FragColor += mist;
}`;
class Rays extends PIXI.Filter
{
_options = {
angle: 30,
lacunarity: 1.5,
gain: 0.4,
parallel: Math.round(Math.random()),
speed: 0.0003
}
_timeInit = null;
constructor()
{
super(null, fragSource, uniformData);
this._timeInit = Date.now() - Math.floor(Math.random() * 99999999);
}
apply(filterManager, input, output, clearMode, _currentState)
{
this.uniforms.time = (Date.now() - this._timeInit) * this._options.speed;
this.uniforms.lacunarity = this._options.lacunarity;
this.uniforms.gain = this._options.gain;
this.uniforms.parallel = this._options.parallel;
const radians = this._options.angle * Math.PI / 180.0;
this.uniforms.light[0] = Math.cos(radians);
this.uniforms.light[1] = Math.sin(radians);
const {width, height} = input.filterFrame;
this.uniforms.dimensions[0] = width;
this.uniforms.dimensions[1] = height;
this.uniforms.aspect = height / width;
filterManager.applyFilter(this, input, output, clearMode);
}
}
// -------------------------------
class App
{
_app = null;
_resources = null;
constructor() {
this._app = new PIXI.Application({
view: canvas,
width: 800,
height: 600,
transparent: true,
resolution: window.devicePixelRatio
});
this._init();
}
addRelativeFeather(x, y) {
const feather = new PIXI.Sprite(this._resources.feather.texture);
const scale = Math.max(
this._app.screen.width / (feather.width * 3),
this._app.screen.height / (feather.height * 3)
);
feather.scale.set(scale, scale);
feather.position.set(x * feather.width, y * feather.height);
feather.filters = [new Rays()];
this._app.stage.addChild(feather);
}
_main() {
this.addRelativeFeather(0, 0);
this.addRelativeFeather(1, 0);
this.addRelativeFeather(2, 0);
this.addRelativeFeather(0, 1);
this.addRelativeFeather(2, 1);
}
_init() {
const loader = PIXI.Loader.shared;
loader.add({
name: 'feather',
// Icon "feather": https://www.flaticon.com/free-icon/feathers_6981026
url: 'https://cdn-icons-png.flaticon.com/512/6981/6981026.png',
});
loader.onComplete.once((loaderProcessed, resources) => {
this._resources = resources;
this._main();
});
loader.load();
}
}
const app = new App();
* {
margin: 0;
padding: 0;
background: #333;
}
<script src="https://pixijs.download/v6.5.8/pixi.js"></script>
<canvas id="canvas"></canvas>
Is it possible using this filter/shader? Is it correct that the issue is in the color matrix ("float noise(in vec3 p)")?
Also, it's probably the mist = clamp(mist, 0.0, 1.0); where the second parameter might assume the minimum allowed if that makes sense.
Would it be correct to somehow base a pixel color on the source and only increase its "gain" instead?
I would highly appreciate any suggestion since I have already tried various options but it still darkens the origin!
Best and kind regards ✨
const uniformData = {
time: {
type: 'float',
value: 0.0
},
lacunarity: {
type: 'float',
value: 30.0
},
gain: {
type: 'float',
value: 1.0
},
parallel: {
type: 'b',
value: true
},
light: {
type: 'v2',
value: [0.0, 0.0]
},
dimensions: {
type: 'v2',
value: [800, 400]
},
aspect: {
type: 'float',
value: 1.0
}
};
// 3D gradient Noise
// MIT License
// Copyright © 2013 Inigo Quilez
// https://www.shadertoy.com/view/Xsl3Dl
// Original: https://codepen.io/alaingalvan/pen/gOoEpW
const fragSource = '' +
`precision mediump float;
varying vec2 vTextureCoord;
uniform sampler2D uSampler;
uniform vec4 filterArea;
uniform vec2 dimensions;
uniform vec2 light;
uniform bool parallel;
uniform float aspect;
uniform float gain;
uniform float lacunarity;
uniform float time;
vec3 hash(vec3 p) {
p = vec3(
dot(p, vec3(127.1, 311.7, 74.7)),
dot(p, vec3(269.5, 183.3, 246.1)),
dot(p, vec3(113.5, 271.9, 124.6))
);
return -1.0 + 2.0 * fract(sin(p) * 43758.5453123);
}
float noise(in vec3 p) {
vec3 i = floor(p);
vec3 f = fract(p);
vec3 u = f * f * (3.0 - 2.0 * f);
return mix(
mix(
mix(
dot(hash(i + vec3(0.0, 0.0, 0.0)), f - vec3(0.0, 0.0, 0.0)),
dot(hash(i + vec3(1.0, 0.0, 0.0)), f - vec3(1.0, 0.0, 0.0)),
u.x
),
mix(
dot(hash(i + vec3(0.0, 1.0, 0.0)), f - vec3(0.0, 1.0, 0.0)),
dot(hash(i + vec3(1.0, 1.0, 0.0)), f - vec3(1.0, 1.0, 0.0)),
u.x
),
u.y
),
mix(
mix(
dot(hash(i + vec3(0.0, 0.0, 1.0)), f - vec3(0.0, 0.0, 1.0)),
dot(hash(i + vec3(1.0, 0.0, 1.0)), f - vec3(1.0, 0.0, 1.0)),
u.x
),
mix(
dot(hash(i + vec3(0.0, 1.0, 1.0)), f - vec3(0.0, 1.0, 1.0)),
dot(hash(i + vec3(1.0, 1.0, 1.0)), f - vec3(1.0, 1.0, 1.0)),
u.x
),
u.y
),
u.z
);
}
float turb(vec3 pos, float lacunarity, float gain) {
float f, totalGain;
totalGain = gain;
vec3 q = 2.0 * pos;
f = totalGain * noise(q);
q = q * 2.01 * lacunarity;
totalGain *= gain;
f += totalGain * noise(q);
q = q * 3.02 * lacunarity;
totalGain *= gain;
f += totalGain * noise(q);
q = q * 3.03 * lacunarity;
totalGain *= gain;
f += totalGain * noise(q);
q = q * 3.01 * lacunarity;
totalGain *= gain;
f += totalGain * noise(q);
q = q * 3.99 * lacunarity;
totalGain *= gain;
f += totalGain * noise(q);
q = q * 3.98 * lacunarity;
totalGain *= gain;
f += totalGain * noise(q);
f = 3.0 * f;
return abs(f);
}
void main(void) {
gl_FragColor = texture2D(uSampler, vTextureCoord);
float d = 0.0;
vec2 coord = vTextureCoord;
if (parallel) {
float _cos = light.x;
float _sin = light.y;
d = (_cos * coord.x) + (_sin * coord.y * aspect);
} else {
float dx = coord.x - light.x / dimensions.x;
float dy = (coord.y - light.y / dimensions.y) * aspect;
float dis = sqrt(dx * dx + dy * dy) + 0.00001;
d = dy / dis;
}
vec2 dir = vec2(d, d);
float noise = turb(vec3(dir, 0.0) + vec3(time, 0.0, 62.1 + time) * 0.1, lacunarity, gain);
vec4 mist = vec4(noise, noise, noise, noise);
noise = mix(noise, 0.0, 0.3);
mist *= 1.0 - coord.y;
mist = clamp(mist, 0.0, 1.0);
gl_FragColor += mist;
}`;
class Rays extends PIXI.Filter
{
_options = {
angle: 30,
lacunarity: 1.5,
gain: 0.4,
parallel: Math.round(Math.random()),
speed: 0.0003
}
_timeInit = null;
constructor()
{
super(null, fragSource, uniformData);
this._timeInit = Date.now() - Math.floor(Math.random() * 99999999);
}
apply(filterManager, input, output, clearMode, _currentState)
{
this.uniforms.time = (Date.now() - this._timeInit) * this._options.speed;
this.uniforms.lacunarity = this._options.lacunarity;
this.uniforms.gain = this._options.gain;
this.uniforms.parallel = this._options.parallel;
const radians = this._options.angle * Math.PI / 180.0;
this.uniforms.light[0] = Math.cos(radians);
this.uniforms.light[1] = Math.sin(radians);
const {width, height} = input.filterFrame;
this.uniforms.dimensions[0] = width;
this.uniforms.dimensions[1] = height;
this.uniforms.aspect = height / width;
filterManager.applyFilter(this, input, output, clearMode);
}
}
// -------------------------------
class App
{
_app = null;
_resources = null;
constructor() {
this._app = new PIXI.Application({
view: canvas,
width: 800,
height: 600,
transparent: true,
resolution: window.devicePixelRatio
});
this._init();
}
addRelativeFeather(x, y) {
const feather = new PIXI.Sprite(this._resources.feather.texture);
const scale = Math.max(
this._app.screen.width / (feather.width * 3),
this._app.screen.height / (feather.height * 3)
);
feather.scale.set(scale, scale);
feather.position.set(x * feather.width, y * feather.height);
feather.filters = [new Rays()];
this._app.stage.addChild(feather);
}
_main() {
this.addRelativeFeather(0, 0);
this.addRelativeFeather(1, 0);
this.addRelativeFeather(2, 0);
this.addRelativeFeather(0, 1);
this.addRelativeFeather(2, 1);
}
_init() {
const loader = PIXI.Loader.shared;
loader.add({
name: 'feather',
// Icon "feather": https://www.flaticon.com/free-icon/feathers_6981026
url: 'https://cdn-icons-png.flaticon.com/512/6981/6981026.png',
});
loader.onComplete.once((loaderProcessed, resources) => {
this._resources = resources;
this._main();
});
loader.load();
}
}
const app = new App();
* {
margin: 0;
padding: 0;
background: #333;
}
<script src="https://pixijs.download/v6.5.8/pixi.js"></script>
<canvas id="canvas"></canvas>
The shader defines the following vec4 for painting with hardcoded 1.0 alpha:
vec4 mist = vec4(noise, noise, noise, 1.0);
Use the whiteness of the noise value as alpha as following to get rid of the black background:
vec4 mist = vec4(noise, noise, noise, noise);

How to implement Emission with MSL

I have been studying the Metal API (newbie here) and working with the examples and documentation to create a 3D animation in my iOS app. I know I can use SceneKit but for the moment I want to understand and learn how Metal API works.
One of the examples from Apple implements a decent number of textures mapping for the object, but the emission texture is missing. After a bit of study I came with a solution like this:
float3 computeDiffuse(LightingParameters parameters)
{
float3 diffuseRawValue = float3(((1.0/PI) * parameters.baseColor) * (1.0 - parameters.metalness));
return diffuseRawValue * parameters.nDotl * parameters.ambientOcclusion;
}
float3 computeSpecular(LightingParameters parameters)
{
float specularRoughness = parameters.roughness * (1.0 - parameters.metalness) + parameters.metalness;
float Ds = Distribution(parameters.nDoth, specularRoughness);
float3 Cspec0 = float3(1.0f);
float3 Fs = float3(mix(float3(Cspec0), float3(1), Fresnel(parameters.hDotl)));
float alphaG = sqr(specularRoughness * 0.5 + 0.5);
float Gs = Geometry(parameters.nDotl, alphaG) * Geometry(parameters.nDotv, alphaG);
float3 specularOutput = (Ds * Gs * Fs * parameters.irradiatedColor)
* (1.0 + parameters.metalness * float3(parameters.baseColor))
+ float3(parameters.metalness)
* parameters.irradiatedColor
* float3(parameters.baseColor);
return specularOutput * parameters.ambientOcclusion;
}
float3 computeEmissive(LightingParameters parameters)
{
float3 diffuseRawValue = float3(((1.0/PI) * parameters.emissiveColor));
return diffuseRawValue;
}
//...
fragment float4
fragmentLighting(ColorInOut in [[stage_in]],
constant AAPLUniforms & uniforms [[ buffer(AAPLBufferIndexUniforms) ]],
constant AAPLMaterialUniforms & materialUniforms [[ buffer(AAPLBufferIndexMaterialUniforms) ]],
texture2d<float> baseColorMap [[ texture(AAPLTextureIndexBaseColor), function_constant(has_base_color_map) ]],
texture2d<float> normalMap [[ texture(AAPLTextureIndexNormal), function_constant(has_normal_map) ]],
texture2d<float> metallicMap [[ texture(AAPLTextureIndexMetallic), function_constant(has_metallic_map) ]],
texture2d<float> roughnessMap [[ texture(AAPLTextureIndexRoughness), function_constant(has_roughness_map) ]],
texture2d<float> ambientOcclusionMap [[ texture(AAPLTextureIndexAmbientOcclusion), function_constant(has_ambient_occlusion_map) ]],
texture2d<float> emissiveMap [[ texture(AAPLTextureIndexEmissive), function_constant(has_emissive_map) ]],
texturecube<float> irradianceMap [[ texture(AAPLTextureIndexIrradianceMap), function_constant(has_irradiance_map)]])
{
float4 final_color = float4(0);
LightingParameters parameters = calculateParameters(in,
uniforms,
materialUniforms,
baseColorMap,
normalMap,
metallicMap,
roughnessMap,
ambientOcclusionMap,
emissiveMap,
irradianceMap);
final_color = float4(computeSpecular(parameters) + computeDiffuse(parameters) + computeEmissive(parameters), 1.0f);
return final_color;
}
This code above makes the object get slightly white, which is not the desired effect.
Note the line computeSpecular(parameters) + computeDiffuse(parameters) + computeEmissive(parameters), in the original source code computeEmissive(parameters) does not exist, that's something that I have implemented trying to make the color more intense, probably this is totally wrong and what I have should be doing is to change the contrast, brightness and luminance, but I am not sure how to do this.
I am probably doing everything wrong, I am open to any suggestion. :)
Thank you.

GLSL variables not storing?

I am learning GLSL through Unity and I recently came across a problem involving the storing of variables.
Shader "Shader" {
Properties{
_Hole_Position("hole_Position", Vector) = (0., 0., 0., 1.0)
_Hole_EventHorizonDistance("hole_EventHorizonDistance", Float) = 1.0
_DebugValue("debugValue", Float) = 0.0
}
SubShader{
Pass{
GLSLPROGRAM
uniform mat4 _Object2World;
//Variables
varying float debugValue;
varying vec4 pos;
varying vec4 hole_Position;
varying float hole_EventHorizonDistance = 1;
#ifdef VERTEX
void main()
{
pos = _Object2World * gl_Vertex;
gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
}
#endif
#ifdef FRAGMENT
void main()
{
float dist = distance(vec4(pos.x, 0.0,pos.z, 1.0), vec4(hole_Position.x, 0.0, hole_Position.z, 1.0));
debugValue = dist;
if (dist < hole_EventHorizonDistance)
{
gl_FragColor = vec4(0.3, 0.3, 0.3, 1.0);
}
else
{
gl_FragColor = vec4(0.4, 0.6, 1.0, 1.0);
}
//gl_FragColor = vec4(hole_EventHorizonDistance, 0, 0, 1.0);
}
#endif
ENDGLSL
}
}
}
Now Hole_Position and EventHorizonDistance are changed from an outside C#-script with:
g.GetComponent<Renderer>().sharedMaterial.SetVector("_Hole_Position", new Vector4(transform.position.x, transform.position.y, transform.position.z, 1));
g.GetComponent<Renderer>().sharedMaterial.SetFloat("_Hole_EventHorizonDistance", 2);
this does not work as I intend it too (by changing the fragments color if its position is within 2 units from Hole_Position. However debugging with:
gl_FragColor = vec4(hole_EventHorizonDistance, 0, 0, 1.0);
seemingly suggests that EventHorizon is 0 at all times (the mesh tested on remains completely black), however debugging by getting and printing the variable from an outside (via
print(g.GetComponent<Renderer>().sharedMaterial.GetFloat("_Hole_EventHorizonDistance"));
) tells me EventHorizonDistance = 2. I cannot wrap my head around why this is the case, why is it so?

Variable TT is not defined: Error in OpenBUGS

I am trying to run a model in OpenBUGS. But I am getting an error "Variable TT is not defined". Here is my BUGS code:
model{
for(t in 2:TT){
for(i in 1:N){
y[t,i] ~ dmnorm(y1[t,i], tau[i])
}
y1[t,1] <- (p[1,1] * y[t-1,1]) + (p[1,2] *y[t-1,2]) + (p[1,3] *y[t-1,3])
y1[t,2] <- (p[2,1] * y[t-1,1]) + (p[2,2] *y[t-1,2]) + (p[2,3] *y[t-1,3])
y1[t,3] <- (p[3,1] * y[t-1,1]) + (p[3,2] *y[t-1,2]) + (p[3,3] *y[t-1,3])
}
for (s1 in 1:N) {
for (s2 in 1:N) {
p[s1, s2]~ dnorm(1, 1)
}
}
for(i in 1:N){
tau[i] ~ dgamma(0.001, 0.001)
}
}
Here is my data and R code to run the BUGS code:
Data=structure(.Data=c(0.1, 0.2, 0.5, 0.2, 0.2, 0.8, 0.2, 0.4, 0.3, 0.2, 0.1, 0.6, 0.1, 0.5, 0.6), .Dim=c(5,3))
TT=nrow(Data)
N=ncol(Data)
y=as.matrix(Data)
sp.data = list(y, N, TT)
Sp.sim0<- bugs (sp.data, inits=NULL,
parameters=c('p'), model.file= "model2.txt",n.chains=2, DIC=TRUE,n.iter=1000, codaPkg=FALSE,debug=TRUE)
Can any please help to t solve this problem? Thanks in advance.

How to compile with DevIL?

I'm trying to get a proper setup for 3D programs, and the next step is a texture loader. I am trying to use DevIL, but I can't seem to get it working, and no explanatory text seems to be up to date.
To start with, I'm just going to include a dump of my project: (Keep in mind that it just happens to be in this state, it's not all relevant; Also note that 'IOUtil.cpp' just defines 'Print', which prints to 'cout'. It didn't seem relevant, so I excluded it.)
Project Structure:
+- bin
+- include
| +- GLFW
| | +- glfw3.h
| | +- glfw3native.h
| +- IL
| | +- config.h
| | +- config.h.win
| | +- devil_internal_exports.h
| | +- il.h
| | +- il_wrap.h
| | +- ilu.h
| | +- ilu_region.h
| | +- ilut.h
| | +- ilut_config.h
+- lib
| +- unicode
| | +- DevIL.dll
| | +- DevIL.lib
| | +- ILU.dll
| | +- ILU.lib
| | +- ILUT.dll
| | +- ILUT.lib
| +- DevIL.dll
| +- DevIL.lib
| +- ILU.dll
| +- ILU.lib
| +- ILUT.dll
| +- ILUT.lib
| +- libglfw3dll.a
+- logs
+- src
| +- Main.exe
+- build.bat
+- run.bat
Main.exe:
#include <GLFW/glfw3.h>
#include <IL/il.h>
#include <IL/ilu.h>
#include <IL/ilut.h>
#include <stdlib.h>
#include <algorithm>
#include "util/IOUtil.cpp"
float SENSITIVITY = 0.25;
float cursorX = 0;
float cursorY = 0;
float camX = 0;
float camY = 0;
static void error_callback(int error, const char* description) {
Print("GLFW ERROR: " + (std::string)description);
}
static void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods) {
if (key == GLFW_KEY_ESCAPE && action == GLFW_PRESS) {
glfwSetWindowShouldClose(window, GL_TRUE);
}
}
static void cursor_position_callback(GLFWwindow* window, double xpos, double ypos) {
float dx = xpos - cursorX;
float dy = -ypos - cursorY;
cursorX = xpos;
cursorY = -ypos;
camX += dx * SENSITIVITY;
camY += dy * SENSITIVITY;
if (camX < 0) {
camX += 360;
}
if (camX > 360) {
camX -= 360;
}
camY = std::max(-90.0f, std::min(90.0f, camY));
}
int main(void) {
glfwSetErrorCallback(error_callback); //Set the error callback
Print("Initializing GLFW");
if (!glfwInit()) { //If initialization fails, crash
Print("GLFW initialization failed!");
exit(EXIT_FAILURE);
}
Print("Initializing window");
GLFWwindow* window = glfwCreateWindow(600, 600, "FPS", NULL, NULL); //Initialize the window
if (!window) { //If window initialization fails, crash
Print("Window initialization failed!");
glfwTerminate(); //Deinitialize
exit(EXIT_FAILURE);
}
ilutRenderer(ILUT_OPENGL); //Bind Texture Loader to Renderer
glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_DISABLED); //Capture the cursor
glfwMakeContextCurrent(window); //Create the context
glfwSwapInterval(1); //Set the swap interval
glfwSetKeyCallback(window, key_callback); //Set the key callback
glfwSetCursorPosCallback(window, cursor_position_callback); //Set the cursor callback
//ilInit();
//ILuint image;
//ilGenImages(1, &image);
//ilBindImage(image);
//ilLoadImage("data/image.png");
glEnable(GL_TEXTURE_2D);
GLuint tex;
//tex = ilutGLBindTexImage();
Print("Beginning main loop");
while (!glfwWindowShouldClose(window)) { //Main loop, ends when window close is requested
float ratio;
int width, height;
glfwGetFramebufferSize(window, &width, &height); //Load the window dimensions
ratio = width / (float) height; //Calculate the aspect ratio
glViewport(0, 0, width, height); //Configure the viewport
glClear(GL_COLOR_BUFFER_BIT); //Clear the buffer
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
float near = 1; //Near Clipping Plane
float far = 1000; //Far Clipping Plane
float fov = 1; //tan(fovAngle)/2.
glFrustum(-ratio * near * fov, ratio * near * fov, -fov, fov, near, far);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
//Enable depth testing
//glEnable(GL_DEPTH_TEST);
//Set background color
//glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glPushMatrix();
glRotatef(camY, -1.0, 0.0, 0.0);
glRotatef(camX, 0.0, 1.0, 0.0);
//glTranslatef(0,0,-10);
glBegin(GL_QUADS);
//glColor3f(1.0, 0.0, 0.0);
glVertex3f(-1.0, -1.0, -10.0);
//glColor3f(1.0, 0.0, 1.0);
glVertex3f(-1.0, 1.0, -10.0);
//glColor3f(1.0, 1.0, 1.0);
glVertex3f(1.0, 1.0, -10.0);
//glColor3f(1.0, 1.0, 0.0);
glVertex3f(1.0, -1.0, -10.0);
glEnd();
glBegin(GL_QUADS);
glColor3f(1.0, 0.0, 0.0);
glVertex3f(-1.0, -1.0, 10.0);
glColor3f(1.0, 0.0, 1.0);
glVertex3f(-1.0, 1.0, 10.0);
glColor3f(1.0, 1.0, 1.0);
glVertex3f(1.0, 1.0, 10.0);
glColor3f(1.0, 1.0, 0.0);
glVertex3f(1.0, -1.0, 10.0);
glEnd();
glPopMatrix();
glfwSwapBuffers(window); //Swap buffers
glfwPollEvents(); //Poll events
}
Print("Window close requested");
glfwDestroyWindow(window); //Close the window
Print("Deinitializing");
glfwTerminate(); //Deinitialize
exit(EXIT_SUCCESS); //End the program
}
build.bat:
g++ -c -v -Iinclude src/Main.cpp 2>logs/build.txt
g++ -v -o bin/main Main.o -Llib -lglfw3dll -lopengl32 -lgdi32 -lDevIL -lILU -lILUT 2>logs/link.txt
del Main.o
pause
Here is the log from line one of the batch file:
Using built-in specs.
COLLECT_GCC=g++
Target: mingw32
Configured with: ../gcc-4.8.1/configure --prefix=/mingw --host=mingw32 --build=mingw32 --without-pic --enable-shared --enable-static --with-gnu-ld --enable-lto --enable-libssp --disable-multilib --enable-languages=c,c++,fortran,objc,obj-c++,ada --disable-sjlj-exceptions --with-dwarf2 --disable-win32-registry --enable-libstdcxx-debug --enable-version-specific-runtime-libs --with-gmp=/usr/src/pkg/gmp-5.1.2-1-mingw32-src/bld --with-mpc=/usr/src/pkg/mpc-1.0.1-1-mingw32-src/bld --with-mpfr= --with-system-zlib --with-gnu-as --enable-decimal-float=yes --enable-libgomp --enable-threads --with-libiconv-prefix=/mingw32 --with-libintl-prefix=/mingw --disable-bootstrap LDFLAGS=-s CFLAGS=-D_USE_32BIT_TIME_T
Thread model: win32
gcc version 4.8.1 (GCC)
COLLECT_GCC_OPTIONS='-c' '-v' '-I' 'include' '-shared-libgcc' '-mtune=generic' '-march=pentiumpro'
c:/mingw/bin/../libexec/gcc/mingw32/4.8.1/cc1plus.exe -quiet -v -I include -iprefix c:\mingw\bin\../lib/gcc/mingw32/4.8.1/ src/Main.cpp -quiet -dumpbase Main.cpp -mtune=generic -march=pentiumpro -auxbase Main -version -o C:\Users\MyUsername\AppData\Local\Temp\cccPMwk6.s
GNU C++ (GCC) version 4.8.1 (mingw32)
compiled by GNU C version 4.8.1, GMP version 5.1.2, MPFR version 3.1.2, MPC version 1.0.1
warning: MPC header version 1.0.1 differs from library version 1.0.2.
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
ignoring duplicate directory "c:/mingw/lib/gcc/../../lib/gcc/mingw32/4.8.1/include/c++"
ignoring duplicate directory "c:/mingw/lib/gcc/../../lib/gcc/mingw32/4.8.1/include/c++/mingw32"
ignoring duplicate directory "c:/mingw/lib/gcc/../../lib/gcc/mingw32/4.8.1/include/c++/backward"
ignoring duplicate directory "c:/mingw/lib/gcc/../../lib/gcc/mingw32/4.8.1/include"
ignoring duplicate directory "c:/mingw/lib/gcc/../../lib/gcc/mingw32/4.8.1/../../../../include"
ignoring duplicate directory "/mingw/include"
ignoring duplicate directory "c:/mingw/lib/gcc/../../lib/gcc/mingw32/4.8.1/include-fixed"
ignoring duplicate directory "c:/mingw/lib/gcc/../../lib/gcc/mingw32/4.8.1/../../../../mingw32/include"
ignoring duplicate directory "/mingw/include"
#include "..." search starts here:
#include <...> search starts here:
include
c:\mingw\bin\../lib/gcc/mingw32/4.8.1/include/c++
c:\mingw\bin\../lib/gcc/mingw32/4.8.1/include/c++/mingw32
c:\mingw\bin\../lib/gcc/mingw32/4.8.1/include/c++/backward
c:\mingw\bin\../lib/gcc/mingw32/4.8.1/include
c:\mingw\bin\../lib/gcc/mingw32/4.8.1/../../../../include
c:\mingw\bin\../lib/gcc/mingw32/4.8.1/include-fixed
c:\mingw\bin\../lib/gcc/mingw32/4.8.1/../../../../mingw32/include
End of search list.
GNU C++ (GCC) version 4.8.1 (mingw32)
compiled by GNU C version 4.8.1, GMP version 5.1.2, MPFR version 3.1.2, MPC version 1.0.1
warning: MPC header version 1.0.1 differs from library version 1.0.2.
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: 1ebc2a6f92fbd3aadc367a20a63fdf9f
src/Main.cpp: In function 'int main()':
src/Main.cpp:95:14: error: expected unqualified-id before '=' token
float near = 1; //Near Clipping Plane
^
src/Main.cpp:96:13: error: expected unqualified-id before '=' token
float far = 1000; //Far Clipping Plane
^
src/Main.cpp:98:29: error: invalid type argument of unary '*' (have 'float')
glFrustum(-ratio * near * fov, ratio * near * fov, -fov, fov, near, far);
^
src/Main.cpp:98:49: error: invalid type argument of unary '*' (have 'float')
glFrustum(-ratio * near * fov, ratio * near * fov, -fov, fov, near, far);
^
src/Main.cpp:98:69: error: expected primary-expression before ',' token
glFrustum(-ratio * near * fov, ratio * near * fov, -fov, fov, near, far);
^
src/Main.cpp:98:74: error: expected primary-expression before ')' token
glFrustum(-ratio * near * fov, ratio * near * fov, -fov, fov, near, far);
^
Sorry for just dumping everything, but I don't know what else to do. I don't see why the IL includes would cause syntax errors in syntactically correct code.
Anyone know what's going wrong?
As it turns out, the issue was being caused by the names of the variables, which I realized when I noticed that 'fov' was not affected. Changing 'near' and 'far' to 'near_plane' and 'far_plane' (along with all references) fixed the issue.
Out of interest, what do 'near' and 'far' define in DevIL?