Skip to content

Commit

Permalink
ren CreateMaterial to CreateOpaqueMaterial + works - missing tex paths
Browse files Browse the repository at this point in the history
  • Loading branch information
xoxor4d committed Jul 8, 2024
1 parent a9a38fe commit 61102ca
Show file tree
Hide file tree
Showing 4 changed files with 175 additions and 15 deletions.
53 changes: 40 additions & 13 deletions src/api/bridge_api/bridge_c.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,29 @@ extern "C" {

typedef const wchar_t* remixapi_Path;

typedef struct remixapi_MaterialInfoOpaqueEXT {
remixapi_StructType sType;
//void* pNext;
remixapi_Path roughnessTexture;
remixapi_Path metallicTexture;
float anisotropy;
remixapi_Float3D albedoConstant;
float opacityConstant;
float roughnessConstant;
float metallicConstant;
remixapi_Bool thinFilmThickness_hasvalue;
float thinFilmThickness_value;
remixapi_Bool alphaIsThinFilmThickness;
remixapi_Path heightTexture;
float heightTextureStrength;
// If true, InstanceInfoBlendEXT is used as a source for alpha state
remixapi_Bool useDrawCallAlphaState;
remixapi_Bool blendType_hasvalue;
int blendType_value;
remixapi_Bool invertedBlend;
int alphaTestType;
uint8_t alphaReferenceValue;
} remixapi_MaterialInfoOpaqueEXT;

typedef struct remixapi_MaterialInfo {
remixapi_StructType sType;
Expand Down Expand Up @@ -263,6 +286,8 @@ extern "C" {


typedef void(BRIDGEAPI_PTR* PFN_bridgeapi_DebugPrint)(const char* text);
typedef uint64_t(BRIDGEAPI_PTR* PFN_bridgeapi_CreateOpaqueMaterial)(const x86::remixapi_MaterialInfo* info, const x86::remixapi_MaterialInfoOpaqueEXT* opaque_info);
typedef void(BRIDGEAPI_PTR* PFN_bridgeapi_DestroyMaterial)(uint64_t handle);
typedef uint64_t(BRIDGEAPI_PTR* PFN_bridgeapi_CreateTriangleMesh)(const x86::remixapi_MeshInfo* info);
typedef void(BRIDGEAPI_PTR* PFN_bridgeapi_DestroyMesh)(uint64_t handle);
typedef void(BRIDGEAPI_PTR* PFN_bridgeapi_DrawMeshInstance)(uint64_t handle, const x86::remixapi_Transform* t, x86::remixapi_Bool double_sided);
Expand All @@ -278,19 +303,21 @@ extern "C" {

typedef struct bridgeapi_Interface {
bool initialized;
PFN_bridgeapi_DebugPrint DebugPrint; // const char* text
PFN_bridgeapi_CreateTriangleMesh CreateTriangleMesh; // x86::remixapi_MeshInfo* info
PFN_bridgeapi_DestroyMesh DestroyMesh; // uint64_t handle
PFN_bridgeapi_DrawMeshInstance DrawMeshInstance; // uint64_t handle --- x86::remixapi_Transform* t --- x86::remixapi_Bool double_sided
PFN_bridgeapi_CreateSphereLight CreateSphereLight; // x86::remixapi_LightInfo* info --- x86::remixapi_LightInfoSphereEXT* sphere_info
PFN_bridgeapi_CreateRectLight CreateRectLight; // x86::remixapi_LightInfo* info --- x86::remixapi_LightInfoRectEXT* rect_info
PFN_bridgeapi_CreateDiskLight CreateDiskLight; // x86::remixapi_LightInfo* info --- x86::remixapi_LightInfoDiskEXT* disk_info
PFN_bridgeapi_CreateCylinderLight CreateCylinderLight; // x86::remixapi_LightInfo* info --- x86::remixapi_LightInfoCylinderEXT* cylinder_info
PFN_bridgeapi_CreateDistantLight CreateDistantLight; // x86::remixapi_LightInfo* info --- x86::remixapi_LightInfoDistantEXT* dist_info
PFN_bridgeapi_DestroyLight DestroyLight; // uint64_t handle
PFN_bridgeapi_DrawLightInstance DrawLightInstance; // uint64_t handle
PFN_bridgeapi_SetConfigVariable SetConfigVariable; // const char* var --- const char* value
PFN_bridgeapi_RegisterDevice RegisterDevice; // void
PFN_bridgeapi_DebugPrint DebugPrint; // const char* text
PFN_bridgeapi_CreateOpaqueMaterial CreateOpaqueMaterial; // x86::remixapi_MaterialInfo* info
PFN_bridgeapi_DestroyMaterial DestroyMaterial; // uint64_t handle
PFN_bridgeapi_CreateTriangleMesh CreateTriangleMesh; // x86::remixapi_MeshInfo* info
PFN_bridgeapi_DestroyMesh DestroyMesh; // uint64_t handle
PFN_bridgeapi_DrawMeshInstance DrawMeshInstance; // uint64_t handle --- x86::remixapi_Transform* t --- x86::remixapi_Bool double_sided
PFN_bridgeapi_CreateSphereLight CreateSphereLight; // x86::remixapi_LightInfo* info --- x86::remixapi_LightInfoSphereEXT* sphere_info
PFN_bridgeapi_CreateRectLight CreateRectLight; // x86::remixapi_LightInfo* info --- x86::remixapi_LightInfoRectEXT* rect_info
PFN_bridgeapi_CreateDiskLight CreateDiskLight; // x86::remixapi_LightInfo* info --- x86::remixapi_LightInfoDiskEXT* disk_info
PFN_bridgeapi_CreateCylinderLight CreateCylinderLight; // x86::remixapi_LightInfo* info --- x86::remixapi_LightInfoCylinderEXT* cylinder_info
PFN_bridgeapi_CreateDistantLight CreateDistantLight; // x86::remixapi_LightInfo* info --- x86::remixapi_LightInfoDistantEXT* dist_info
PFN_bridgeapi_DestroyLight DestroyLight; // uint64_t handle
PFN_bridgeapi_DrawLightInstance DrawLightInstance; // uint64_t handle
PFN_bridgeapi_SetConfigVariable SetConfigVariable; // const char* var --- const char* value
PFN_bridgeapi_RegisterDevice RegisterDevice; // void
} bridgeapi_Interface;

BRIDGE_API BRIDGEAPI_ErrorCode __cdecl bridgeapi_InitFuncs(bridgeapi_Interface* out_result);
Expand Down
63 changes: 62 additions & 1 deletion src/client/bridge_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
SEND_FLOAT(MSG, (V).z); \
SEND_FLOAT(MSG, (V).w)

#define SEND_INT(MSG, T) \
(MSG).send_data((int32_t) (T))

#define SEND_STYPE(MSG, T) \
(MSG).send_data((uint32_t) (T))

Expand All @@ -40,6 +43,62 @@ namespace {
command.send_data(strlen(text), (void*) text);
}

uint64_t BRIDGEAPI_CALL bridgeapi_CreateOpaqueMaterial(const x86::remixapi_MaterialInfo* info, const x86::remixapi_MaterialInfoOpaqueEXT* opaque_info) {
UID currentUID = 0;
{
ClientMessage c(Commands::Api_CreateOpaqueMaterial);
currentUID = c.get_uid();

// MaterialInfo
SEND_STYPE(c, info->sType);
SEND_U64(c, info->hash);
// path albedoTexture
// path normalTexture
// path tangentTexture
// path emissiveTexture
SEND_FLOAT(c, info->emissiveIntensity);
SEND_FLOAT3D(c, info->emissiveColorConstant);
c.send_data((uint8_t) info->spriteSheetRow);
c.send_data((uint8_t) info->spriteSheetCol);
c.send_data((uint8_t) info->spriteSheetFps);
c.send_data((uint8_t) info->filterMode);
c.send_data((uint8_t) info->wrapModeU);
c.send_data((uint8_t) info->wrapModeV);

// MaterialInfoOpaqueEXT
SEND_STYPE(c, opaque_info->sType);
// path roughnessTexture
// path metallicTexture
SEND_FLOAT(c, opaque_info->anisotropy);
SEND_FLOAT3D(c, opaque_info->albedoConstant);
SEND_FLOAT(c, opaque_info->opacityConstant);
SEND_FLOAT(c, opaque_info->roughnessConstant);
SEND_FLOAT(c, opaque_info->metallicConstant);
SEND_U32(c, opaque_info->thinFilmThickness_hasvalue);
SEND_FLOAT(c, opaque_info->thinFilmThickness_value);
SEND_U32(c, opaque_info->alphaIsThinFilmThickness);
// path heightTexture;
SEND_FLOAT(c, opaque_info->heightTextureStrength);
// If true, InstanceInfoBlendEXT is used as a source for alpha state
SEND_U32(c, opaque_info->useDrawCallAlphaState);
SEND_U32(c, opaque_info->blendType_hasvalue);
SEND_INT(c, opaque_info->blendType_value);
SEND_U32(c, opaque_info->invertedBlend);
SEND_INT(c, opaque_info->alphaTestType);
c.send_data((uint8_t) opaque_info->alphaReferenceValue);
}

WAIT_FOR_SERVER_RESPONSE("CreateMaterial()", 0, currentUID);
uint64_t result = DeviceBridge::get_data();
DeviceBridge::pop_front();
return result;
}

void BRIDGEAPI_CALL bridgeapi_DestroyMaterial(uint64_t handle) {
ClientMessage c(Commands::Api_DestroyMaterial);
SEND_U64(c, handle);
}

uint64_t BRIDGEAPI_CALL bridgeapi_CreateTriangleMesh(const x86::remixapi_MeshInfo* info) {
UID currentUID = 0;
{
Expand All @@ -49,7 +108,7 @@ namespace {
//Logger::info("bridgeapi_CreateTriangleMesh::");
//Logger::info("|> surface_count = " + std::to_string(info->surfaces_count));

// remixapi_MeshInfo
// MeshInfo
SEND_STYPE(c, info->sType);
SEND_U64(c, info->hash);

Expand Down Expand Up @@ -293,6 +352,8 @@ namespace {
auto interf = bridgeapi_Interface {};
{
interf.DebugPrint = bridgeapi_DebugPrint;
interf.CreateOpaqueMaterial = bridgeapi_CreateOpaqueMaterial;
interf.DestroyMaterial = bridgeapi_DestroyMaterial;
interf.CreateTriangleMesh = bridgeapi_CreateTriangleMesh;
interf.DestroyMesh = bridgeapi_DestroyMesh;
interf.DrawMeshInstance = bridgeapi_DrawMeshInstance;
Expand Down
70 changes: 69 additions & 1 deletion src/server/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
#include <assert.h>
#include <map>
#include <atomic>

#include <locale>
#include "remix_api/remix_c.h"
#include "bridge_api.h"

Expand Down Expand Up @@ -2680,9 +2680,77 @@ void ProcessDeviceCommandQueue() {



case Api_CreateOpaqueMaterial:
{
remixapi_MaterialInfo info = {};
{
info.sType = NVPULL_STYPE();
info.hash = NVPULL_U64();

info.albedoTexture = L""; //DeviceBridge::getReaderChannel().data->pull((void**)&info.albedoTexture);
info.normalTexture = L""; //DeviceBridge::getReaderChannel().data->pull((void**)&info.normalTexture);
info.tangentTexture = L""; //DeviceBridge::getReaderChannel().data->pull((void**)&info.tangentTexture);
info.emissiveTexture = L""; //DeviceBridge::getReaderChannel().data->pull((void**)&info.emissiveTexture);

info.emissiveIntensity = NVPULL_FLOAT();
info.emissiveColorConstant = NVPULL_FLOAT3D();
info.spriteSheetRow = (uint8_t) DeviceBridge::get_data();
info.spriteSheetCol = (uint8_t) DeviceBridge::get_data();
info.spriteSheetFps = (uint8_t) DeviceBridge::get_data();
info.filterMode = (uint8_t) DeviceBridge::get_data();
info.wrapModeU = (uint8_t) DeviceBridge::get_data();
info.wrapModeV = (uint8_t) DeviceBridge::get_data();
}

remixapi_MaterialInfoOpaqueEXT opaque_info = {};
{
opaque_info.sType = NVPULL_STYPE();
opaque_info.roughnessTexture = L""; // path roughnessTexture
opaque_info.metallicTexture = L""; // path metallicTexture
opaque_info.anisotropy = NVPULL_FLOAT();
opaque_info.albedoConstant = NVPULL_FLOAT3D();
opaque_info.opacityConstant = NVPULL_FLOAT();
opaque_info.roughnessConstant = NVPULL_FLOAT();
opaque_info.metallicConstant = NVPULL_FLOAT();
opaque_info.thinFilmThickness_hasvalue = NVPULL_U32();
opaque_info.thinFilmThickness_value = NVPULL_FLOAT();
opaque_info.alphaIsThinFilmThickness = NVPULL_U32();
opaque_info.heightTexture = L""; // path heightTexture;
opaque_info.heightTextureStrength = NVPULL_FLOAT();
// If true, InstanceInfoBlendEXT is used as a source for alpha state
opaque_info.useDrawCallAlphaState = NVPULL_U32();
opaque_info.blendType_hasvalue = NVPULL_U32();
opaque_info.blendType_value = NVPULL_I();
opaque_info.invertedBlend = NVPULL_U32();
opaque_info.alphaTestType = NVPULL_I();
opaque_info.alphaReferenceValue = (uint8_t) DeviceBridge::get_data();
}

// assign ext
info.pNext = &opaque_info;

remixapi_MaterialHandle temp_handle = nullptr;
api::g_remix.CreateMaterial(&info, &temp_handle);

ServerMessage c(Commands::Bridge_Response, currentUID);
c.send_data((uint64_t) temp_handle);
break;
}

case Api_DestroyMaterial:
{
PULL(uint64_t, material_handle);

if (material_handle) {
/*remixapi_ErrorCode r =*/ api::g_remix.DestroyMaterial((remixapi_MaterialHandle) material_handle);
/*if (r != REMIXAPI_ERROR_CODE_SUCCESS) {
Logger::info("[API-SV] DestroyLight(): failed = " + std::to_string(r));
}*/
} else {
Logger::info("[API-SV] DestroyMaterial(): invalid light_handle");
}
break;
}

case Api_CreateTriangleMesh:
{
Expand Down
4 changes: 4 additions & 0 deletions src/util/util_commands.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ namespace Commands {
Bridge_Response,
Bridge_DebugMessage,

Api_CreateOpaqueMaterial,
Api_DestroyMaterial,
Api_CreateTriangleMesh,
Api_DestroyMesh,
Api_DrawMeshInstance,
Expand Down Expand Up @@ -477,6 +479,8 @@ namespace Commands {
case Bridge_Response: return "Response";
case Bridge_DebugMessage: return "DebugMessage";

case Api_CreateOpaqueMaterial: return "ApiCreateOpaqueMaterial";
case Api_DestroyMaterial: return "ApiDestroyMaterial";
case Api_CreateTriangleMesh: return "ApiCreateTriangleMesh";
case Api_DestroyMesh: return "ApiDestroyMesh";
case Api_DrawMeshInstance: return "ApiDrawMeshInstance";
Expand Down

0 comments on commit 61102ca

Please sign in to comment.