Giter Club home page Giter Club logo

Comments (8)

redorav avatar redorav commented on May 25, 2024

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.

rujialiu avatar rujialiu commented on May 25, 2024

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.

redorav avatar redorav commented on May 25, 2024

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.

rujialiu avatar rujialiu commented on May 25, 2024

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.

redorav avatar redorav commented on May 25, 2024

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.

rujialiu avatar rujialiu commented on May 25, 2024

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.

redorav avatar redorav commented on May 25, 2024

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.

rujialiu avatar rujialiu commented on May 25, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.