ShaderMaterial with shadows doesn't compile after threejs v0.118.0 - three.js

Followed this example but the vertex shader doesn't compile after threejs v0.118.0:
https://codesandbox.io/s/shader-light-shadow-experiments-forked-5e14lh
You can test this in codesandbox by selecting different three versions in the dependencies section on the sidebar.
Error msg in printed in console:
THREE.WebGLProgram: shader error: 0 35715 false gl.getProgramInfoLog Vertex shader is not compiled.
THREE.WebGLShader: gl.getShaderInfoLog() vertex
ERROR: 0:197: 'transformedNormal' : undeclared identifier
ERROR: 0:197: 'inverseTransformDirection' : no matching overloaded function found
ERROR: 0:197: '=' : dimension mismatch
ERROR: 0:197: '=' : cannot convert from 'const mediump float' to 'highp 3-component vector of float'
Checked the migration guide for r117 -> r118 but could not figure out how to fix it.
https://github.com/mrdoob/three.js/wiki/Migration-Guide#r117--r118

Error is:
ERROR: 0:199: 'transformedNormal' : undeclared identifier
ERROR: 0:199: 'inverseTransformDirection' : no matching overloaded function found
To relsolve it, you need to add normal definition to your vertex shader. The following code fixes your case.
#include <common>
#include <fog_pars_vertex>
#include <shadowmap_pars_vertex>
void main() {
#include <begin_vertex>
#include <beginnormal_vertex> // Defines objectNormal
#include <project_vertex>
#include <worldpos_vertex>
#include <defaultnormal_vertex> // Defines transformedNormal
#include <shadowmap_vertex>
#include <fog_vertex>
}

Related

In Keil MDK-ARM C++11 *default NAN value* for member and function's parameter generates strange errors

Have you ever faced with yet another Keil's "feature" when next code
#include <cmath>
struct AB {
float f=NAN;
float foo(float a=NAN);
};
generates next build output:
compiling main.cpp...
..\..\src\main.cpp(24): error: #65: expected a ";"
float foo(float a=
AN);
..\..\src\main.cpp(24): error: #109: expression preceding parentheses of apparent call must have (pointer-to-) function type
float foo(float a=NAN);
..\..\src\main.cpp(24): error: #18: expected a ")"
float foo(float a=NAN);
..\..\src\main.cpp(24): error: #18: expected a ")"
float foo(float a=NAN);
..\..\src\main.cpp(23): error: #65: expected a ";"
float f=NAN;
..\..\src\main.cpp: 0 warnings, 5 errors`
For me it looks like bug. I have never met same nuisance in GCC and other compilers.
5 errors in 2 rows. Fantastic. WTF? MDK-ARM cannot resolve NAN.
This could be fixed with next row:
#define __ESCAPE__(__x) (__x)
Better make it for only this "cool" compiler:
#ifdef __CC_ARM
#define __ESCAPE__(__x) (__x)
#endif
Another solution (not sure, but it could be compiler's extension):
float f = 0f_7FC00000;

Operating on thrust::complex types with thrust::transform

I'm trying to use thrust::transform to operate on vectors of type thrust:complex<float> without success. The following example blows up during compilation with several pages of errors.
#include <cuda.h>
#include <cuda_runtime.h>
#include <cufft.h>
#include <thrust/device_vector.h>
#include <thrust/host_vector.h>
#include <thrust/transform.h>
#include <thrust/complex.h>
int main(int argc, char *argv[]) {
thrust::device_vector< thrust::complex<float> > d_vec1(4);
thrust::device_vector<float> d_vec2(4);
thrust::fill(d_vec1.begin(), d_vec1.end(), thrust::complex<float>(1,1));
thrust::transform(d_vec1.begin(), d_vec1.end(), d_vec2.begin(), thrust::abs< thrust::complex<float> >() );
}
I'm using CUDA 8.0 on Ubuntu Xenial and compiling with clang 3.8.0-2ubuntu4 using nvcc --std=c++11 main.cpp -o main.
Main errors appear to be:
main.cpp: In function ‘int main(int, char**)’:
main.cpp:17:105: error: no matching function for call to ‘abs()’
gin(), d_vec1.end(), d_vec2.begin(), thrust::abs< thrust::complex<float> >() );
and
/usr/local/cuda-8.0/bin/../targets/x86_64-linux/include/thrust/detail/complex/arithmetic.h:143:20: note: template argument deduction/substitution failed:
main.cpp:17:105: note: candidate expects 1 argument, 0 provided
gin(), d_vec1.end(), d_vec2.begin(), thrust::abs< thrust::complex<float> >() );
^
No problem working on real floats, but no such with complex ones. I'm thinking there's a type error that I'm missing, but I'm very much still on the steep part of the learning curve with Thrust & templates.
The error message is quite descriptive:
thrust::abs<thrust::complex<...>> is a function which expects exactly one parameter, see thrust/detail/complex/arithmetic.h#L143:
template <typename ValueType>
__host__ __device__
inline ValueType abs(const complex<ValueType>& z){
return hypot(z.real(),z.imag());
}
For your use case, you need to wrap that function by a functor:
struct complex_abs_functor
{
template <typename ValueType>
__host__ __device__
ValueType operator()(const thrust::complex<ValueType>& z)
{
return thrust::abs(z);
}
};
Finally, employ that functor here:
thrust::transform(d_vec1.begin(),
d_vec1.end(),
d_vec2.begin(),
complex_abs_functor());

'USB_Close': identifier not found... 'len': undeclared identifier...

I wrote a code that accesses LEDs on an FPGA. Anyway, I cannot successfully compile the following code in Visual Studio:
#ifdef STATS_LIBRARY_EXPORTS
# define LIBRARY_API __declspec(dllexport)
#else
# define LIBRARY_API __declspec(dllimport)
#endif
#include <windows.h>
#include "stdafx.h"
#include <iostream>
#include <fstream>
#include <conio.h>
#include <time.h>
#include <bitset>
#include <stdio.h>
#include "C:\Cypress\Cypress Suite USB 3.4.7\CyAPI\inc\CyAPI.h"
_declspec(dllexport) int excite_LED(bool start, int on) {
int i;
USB_Open();
for(i=0; i<100; i++) // blink the LEDs for a few seconds
{
USB_BulkWrite(2, &i, 1); // send one single byte (= the value of i) to FIFO2
Sleep(50); // and wait 50ms
BulkOutPipe2->XferData((PUCHAR)&i, len); // send one byte (the value of i) to FIFO2
//Send command to FPGA
//status = !BulkOutPipe2->XferData(fpgaCommunicator, fpgaCommunicatorBytes);
}
USB_Close();
}
I am getting the following errors:
left of '->XferData' must point to class/struct/union/generic type
identifier "USB_Open" is undefined
identifier "USB_Close" is undefined
identifier "USB_BulkWrite" is undefined
identifier "len" is undefined
identifier "BulkOutPipe2" is undefined
cannot open source file "stdafx.h"
'USB_Open': identifier not found
'USB_Close': identifier not found
'USB_BulkWrite': identifier not found
'len': undeclared identifier
'BulkOutPipe2': undeclared identifier
How can I fix my code to get rid of these errors?
BulkOutPipe2 is a common define for EndPoint 3 in many samples, but its not set in CyAPI.h, so you need to set it yourself:
#define BulkOutPipe2 USBDevice->EndPoints[3]
Which you need to initialise:
CCyUSBDevice *USBDevice = new CCyUSBDevice(NULL, ...);
Len is also not defined:
LONG len= 512000;
USB_BulkWrite (and other USB_) looks like usb_bulk_write, which is part of the libusb api. But you are trying to use with the CyApi (which is a lot different), so remove those method calls.

Boost error, trouble compiling xtime.hpp

I've been working on a C++ project using Boost, and between compiles, I must have upgraded something in boost without meaning to or something, because now Boost dependencies won't compile:
In file included from /usr/include/boost/thread/pthread/mutex.hpp:14:0,
from /usr/include/boost/thread/mutex.hpp:16,
from /usr/include/boost/thread/pthread/thread_data.hpp:12,
from /usr/include/boost/thread/thread.hpp:17,
from /usr/include/boost/thread.hpp:13,
from /blah.h:4,
from bluh.h:3,
from bleh/main.cpp:4:
/usr/include/boost/thread/xtime.hpp:23:5: error: expected identifier before numeric constant
/usr/include/boost/thread/xtime.hpp:23:5: error: expected '}' before numeric constant
/usr/include/boost/thread/xtime.hpp:23:5: error: expected unqualified-id before numeric constant
/usr/include/boost/thread/xtime.hpp:46:14: error: expected type-specifier before 'system_time'
In file included from /usr/include/boost/thread/pthread/mutex.hpp:14:0,
from /usr/include/boost/thread/mutex.hpp:16,
from /usr/include/boost/thread/pthread/thread_data.hpp:12,
from /usr/include/boost/thread/thread.hpp:17,
from /usr/include/boost/thread.hpp:13,
from /blah,
from /bleh,(changed these names, obviously)
from /bluh /main.cpp:4:
/usr/include/boost/thread/xtime.hpp: In function 'int xtime_get(xtime*, int)':
/usr/include/boost/thread/xtime.hpp:73:40: error: 'get_system_time' was not declared in this scope
/usr/include/boost/thread/xtime.hpp:73:40: note: suggested alternative:
/usr/include/boost/thread/thread_time.hpp:19:24: note: 'boost::get_system_time'
/usr/include/boost/thread/xtime.hpp: At global scope:
/usr/include/boost/thread/xtime.hpp:88:1: error: expected declaration before '}' token
make[2]: *** [CMakeFiles/edge_based_tracker.dir/main.o] Error 1
make[1]: *** [CMakeFiles/edge_based_tracker.dir/all] Error 2
make: *** [all] Error 2
Any ideas? I tried changing TIME_UTC to TIME_UTC_ as this was recommended to me on another site, but that didn't seem to help.
EDIT: The Boost Version is Version: 1.48.0.2. I've attached xtime below:
// Copyright (C) 2001-2003
// William E. Kempf
// Copyright (C) 2007-8 Anthony Williams
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
#ifndef BOOST_XTIME_WEK070601_HPP
#define BOOST_XTIME_WEK070601_HPP
#include <boost/thread/detail/config.hpp>
#include <boost/cstdint.hpp>
#include <boost/thread/thread_time.hpp>
#include <boost/date_time/posix_time/conversion.hpp>
#include <boost/config/abi_prefix.hpp>
namespace boost {
enum xtime_clock_types
{
TIME_UTC=1 //LINE 23
// TIME_TAI,
// TIME_MONOTONIC,
// TIME_PROCESS,
// TIME_THREAD,
// TIME_LOCAL,
// TIME_SYNC,
// TIME_RESOLUTION
};
struct xtime
{
#if defined(BOOST_NO_INT64_T)
typedef int_fast32_t xtime_sec_t; //INT_FAST32_MIN <= sec <= INT_FAST32_MAX
#else
typedef int_fast64_t xtime_sec_t; //INT_FAST64_MIN <= sec <= INT_FAST64_MAX
#endif
typedef int_fast32_t xtime_nsec_t; //0 <= xtime.nsec < NANOSECONDS_PER_SECOND
xtime_sec_t sec;
xtime_nsec_t nsec;
operator system_time() const
{
return boost::posix_time::from_time_t(0)+
boost::posix_time::seconds(static_cast<long>(sec))+
#ifdef BOOST_DATE_TIME_HAS_NANOSECONDS
boost::posix_time::nanoseconds(nsec);
#else
boost::posix_time::microseconds((nsec+500)/1000);
#endif
}
};
inline xtime get_xtime(boost::system_time const& abs_time)
{
xtime res;
boost::posix_time::time_duration const time_since_epoch=abs_time-boost::posix_time::from_time_t(0);
res.sec=static_cast<xtime::xtime_sec_t>(time_since_epoch.total_seconds());
res.nsec=static_cast<xtime::xtime_nsec_t>(time_since_epoch.fractional_seconds()*(1000000000/time_since_epoch.ticks_per_second()));
return res;
}
inline int xtime_get(struct xtime* xtp, int clock_type)
{
if (clock_type == TIME_UTC)
{
*xtp=get_xtime(get_system_time());
return clock_type;
}
return 0;
}
inline int xtime_cmp(const xtime& xt1, const xtime& xt2)
{
if (xt1.sec == xt2.sec)
return (int)(xt1.nsec - xt2.nsec);
else
return (xt1.sec > xt2.sec) ? 1 : -1;
}
} // namespace boost
#include <boost/config/abi_suffix.hpp>
#endif //BOOST_XTIME_WEK070601_HPP
EDIT: To make it clear, the code is failing on an import of boost/thread.hpp
For those running into the same issue and struggling to find the solution here.
Derived from noodlebox' link (https://svn.boost.org/trac/boost/ticket/6940):
You can edit /usr/include/boost/thread/xtime.hpp (or whereever your xtime.hpp lies)
and change all occurrences of TIME_UTC to TIME_UTC_ - Probably around lines 23 and 71.
i.e. sed -i 's/TIME_UTC/TIME_UTC_/g' /usr/include/boost/thread/xtime.hpp
If you're getting syntax errors when using Boost, you may need to compile your code with -std=c++11.
The TIME_UTC issue you might have read about is a side effect of using c++11. TIME_UTC is now defined as a macro in c++11, so you will need to either replace all instances of TIME_UTC with TIME_UTC_, or just use a newer (1.50.0+) version of Boost where this has been fixed already.
See: https://svn.boost.org/trac/boost/ticket/6940
Since you do not show your code, we can only guess. My guess is that you define TIME_UTC macro somewhere in your code. This macro messes-up xtime.hpp header.

Compile error when using ffmpeg

I've found a strange problem during the compile of an example of ffmpeg in Qt Mac.
I have installed the ffmpeg library and I have tested the examples of this with cc and gcc compiler on the terminal, and I don't have any problem in the case of compile and run.
But when I call the library (ffmpeg are C library) in Qt for compile the same code of the example, the g++ compiler give me many error.
I have used this structure in the main.cpp code:
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QFileDialog>
extern "C" {
#include <libavutil/imgutils.h>
#include <libavutil/samplefmt.h>
#include <libavutil/timestamp.h>
#include <libavformat/avformat.h>
}
#include <QDebug>
and the Compile Output gives me:
In file included from ../audvid/main.cpp:7:
/opt/local/include/libavutil/timestamp.h: In function 'char*
av_ts_make_string(char*, int64_t)':
/opt/local/include/libavutil/timestamp.h:48: warning: comparison
between signed and unsigned integer expressions
/opt/local/include/libavutil/timestamp.h:49: error: expected `)'
before 'PRId64' /opt/local/include/libavutil/timestamp.h:49: warning:
spurious trailing '%' in format
/opt/local/include/libavutil/timestamp.h:49: warning: too many
arguments for format /opt/local/include/libavutil/timestamp.h: At
global scope: /opt/local/include/libavutil/timestamp.h:68: error:
'AVRational' has not been declared
/opt/local/include/libavutil/timestamp.h: In function 'char*
av_ts_make_time_string(char*, int64_t, int*)':
/opt/local/include/libavutil/timestamp.h:70: warning: comparison
between signed and unsigned integer expressions
/opt/local/include/libavutil/timestamp.h:71: error: 'av_q2d' was not
declared in this scope ../audvid/main.cpp: In function 'int
decode_packet(int*, int)': ../audvid/main.cpp:50: error: cannot
convert 'AVRational*' to 'int*' for argument '3' to 'char*
av_ts_make_time_string(char*, int64_t, int*)' ../audvid/main.cpp:73:
error: cannot convert 'AVRational*' to 'int*' for argument '3' to
'char* av_ts_make_time_string(char*, int64_t, int*)'
../audvid/main.cpp:75: error: 'struct AVFrame' has no member named
'channels' ../audvid/main.cpp:84: error: 'struct AVFrame' has no
member named 'channels' ../audvid/main.cpp:90: error: 'struct AVFrame'
has no member named 'channels' ../audvid/main.cpp: In function 'int
open_codec_context(int*, AVFormatContext*, AVMediaType)':
../audvid/main.cpp:112: error: 'av_get_media_type_string' was not
declared in this scope ../audvid/main.cpp:123: error:
'av_get_media_type_string' was not declared in this scope
../audvid/main.cpp:129: error: 'av_get_media_type_string' was not
declared in this scope ../audvid/main.cpp: In function 'int
get_format_from_sample_fmt(const char**, AVSampleFormat)':
../audvid/main.cpp:152: warning: comparison between signed and
unsigned integer expressions ../audvid/main.cpp: In function 'int
main(int, char**)': ../audvid/main.cpp:239: error: invalid conversion
from 'void*' to 'uint8_t**' make: *** [main.o] Error 1 make: Leaving
directory
`/Users/polin/Desktop/audvid/audvid-build- Qt_4_8_0_qt_everywhere_opensource_src_4_8_0_tp-Release'
10:44:37: The process "/usr/bin/make" exited with code 2. Error while
building/deploying project audvid (target: Qt 4.8.0
(qt-everywhere-opensource-src-4.8.0-tp)) When executing step 'Make'
I don't understand if I make a mistake in the code or if I must change the Qt compiler? (and I don't know how can do this)
You need to include libavutil/avutil.h before #include <libavutil/imgutils.h>. Also you need to add #include <libavcodec/avcodec.h>
Because ffmpeg is written in pure C. Some C99 design is incompatible with g++ compiler. So one way to solve it is to find where the "wrong" source codes are and replace them with C++ design style.
e.g.
av_get_bytes_per_sample( static_cast<AVSampleFormat>(format) )
#undef av_err2str
#define av_err2str(errnum) \
av_make_error_string((char*)__builtin_alloca(AV_ERROR_MAX_STRING_SIZE), AV_ERROR_MAX_STRING_SIZE, errnum)
#undef av_ts2timestr
#define av_ts2timestr(ts, tb) \
av_ts_make_time_string((char*)__builtin_alloca(AV_TS_MAX_STRING_SIZE), ts, tb)

Resources