Comments (8)
Hi @rujialiu, thanks for reporting this! I'm glad you're finding the library useful for your shader work.
As for the bug, it's a copy paste error on my part, it was quite repetitive to create all those operators and that one slipped through. It's fixed in bf7df71
As for changing float to float1, I don't know if you want to post your shader and we can work out how to improve it? Always keen to make changes for the better.
from hlslpp.
Wow, thanks for your quick reply & fix! Here is a very typical instance of the float1 issue I mentioned:
float Luma = ...; color = lerp( Luma.xxx, color, saturation.xyz );
I changed to float1 Luma = ...
from hlslpp.
Hi @rujialiu,
This is down to overloaded operators missing. I can add some for lerp, but if you are able to come up with a good list of functions that don't have them I can try to make your life a bit easier.
from hlslpp.
Hi! Could you elaborate? It looks like Luma.xxx itself would cause compile error. If you can show me (with code) the way to solve this particular issue, I can do this for the rest and make a PR :)
from hlslpp.
Oh I see what you mean! Calling .xxx on an actual float, yeah I don't think that's at all possible in C++. For some reason I thought you were casting to float1 and calling .xxx because passing in just the float wasn't working.
from hlslpp.
Hi!
I found a very ugly but working solution (myshader.hlsl is ALMOST unchanged, see below):
namespace hlslpp {
#include "hlslpp_extra.hpp"
#define float float1
#include "myshader.hlsl"
#undef float
}
Here hlslpp_extra.hpp is this (all of these are need to avoid compile error), you can choose some and add (with your modifications) to hlslpp:
#pragma once
using half = float1;
using half3 = float3;
using half4 = float4;
using uint = uint32_t;
float1 sqrt(double x) {
return sqrt(float1(x));
}
float3 operator < (const float3& x, const float1& y) {
return x < y.xxx;
}
float3 operator > (const float3& x, const float1& y) {
return x > y.xxx;
}
bool operator < (const float1& x, double y) {
return x < float1(y);
}
bool operator > (const float1& x, double y) {
return x > float1(y);
}
float3& operator *= (float3& x, double y) {
return x *= float3(y);
}
float3 lerp(const float3& f1, const float3& f2, const float1& a) {
return lerp(f1, f2, a.xxx);
}
float3 lerp(const float1& f1, const float3& f2, double a) {
return lerp(f1.xxx, f2, float1(a).xxx);
}
As mentioned above, the only thing I still have to change the following (by removing the equal sign):
static const float3x3 mymat =
{
0.0, 0.0, 0.0,
0.0, 0.0, 0.0,
0.0, 0.0, 0.0,
};
from hlslpp.
That define is pretty horrible 😄 I don't think I can put that as part of the general library unfortunately. I wonder whether a pair of helper header files that are included such as
#include "hlsl++_shader_helper_begin.h"
#include "shadercode.hlsl"
#include "hlsl++_shader_helper_end.h"
could help at all?
On the other hand, I'm noticing that you've had to put overloads for double, which is telling me that you must write float literals without the f. I think that is something that can probably be improved in hlsl++. I'll take a look at some of the other stuff too, like the halfs or the braced initialization which I thought should just work (TM)
Thanks for taking the time to come up with the example.
from hlslpp.
a pair of helper header files is a lot better!
you must write float literals without the f
Sure. Some thing like if(hue > 180.)
.
I've finished porting this time but since it looks like a good lightweight way to unit testing / playing with 3rd-party shaders, I think I'll expore more ways of using this library later 8-) Thanks again!
from hlslpp.
Related Issues (20)
- Memory packing difference C++ <-> HLSL HOT 16
- Integer vector division is working incorrectly on Macs with Apple M1 (ARM) HOT 7
- Integer vector comparison is working incorrectly on Intel based Macs with MacOS >= 11 HOT 3
- Improve HLSL++ unit tests by using full-featured testing framework HOT 2
- Matrix accessor operator HOT 6
- How well does this cover HLSL202x? HOT 11
- * operator brake mult function in quaternion HOT 7
- Quaternion slerp returning nan values HOT 2
- Clang error: unused variable 't4' in hlsl++_quaternion.h HOT 6
- Upgrade warnings to errors HOT 2
- round() on ARM Neon uses wrong rounding mode HOT 2
- mul() intrinsic is missing some overloads. HOT 2
- clamp() intrinsic is missing overloads for intN HOT 1
- Some non square matrix definitions are incorrect HOT 6
- Missing matrix constructors HOT 2
- Some vector double functions missing HOT 5
- Undefined behavior when accessing vector elements with operator[] HOT 10
- internal::round_float gives incorrect results HOT 4
- Build failure on G++13.2 HOT 11
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from hlslpp.